Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 9 – Scripting II Testing scripts MP3 files id3tool.

Similar presentations


Presentation on theme: "Lecture 9 – Scripting II Testing scripts MP3 files id3tool."— Presentation transcript:

1 Lecture 9 – Scripting II Testing scripts MP3 files id3tool

2 Script Development 1.Plan your scripts 2.Source script files 3.Make “proper” functions 4.“echo” your code 5. Mystery Hint

3 1. Plan Your Scripts Hastily-written scripts suck to debug –Finding code snippets can be hard –“Analogous” code can be implemented differently (i.e., orders of params, etc)

4 2. Source Script Files Place functions into script file Instead of “main” at bottom, just source the script Call functions by hand at terminal

5 3. Make “Proper” Functions Collect all related code into a function If function is too large, break into sub-functions –Subjective, but lines Even a single line of code is okay –Could be called again –Could be a very complex line

6 4. “echo” Your Code Sometimes a line doesn’t seem to be working Placing an ‘echo’ on line can help You’ve been told to never debug like this…why? –

7 4. “echo” Your Code Sometimes a line doesn’t seem to be working Placing an ‘echo’ on line can help You’ve been told to never debug like this…why? –Alters pointer/stack setup –We’re not playing with pointers, so we’re (probably) good

8 5. _____?______

9 5. Walk Away Anime characters fight better when they’re mad Scientists/Engineers don’t code better when mad You’re not an anime character

10 MP3 Files We don’t care about the internals –JPEG6.2 is complex enough –Audio is worse! What do we care about? –

11 MP3 Files We don’t care about the internals –JPEG6.2 is complex enough –Audio is worse! What do we care about? –ID3 tags!

12 ID3 Tags They contain basic info: –Title –Artist –Album –Year –Track Number –etc

13 id3tool Actual audio is complex –Let’s ignore it ID3 tags are easy –Let’s use id3tool to view/alter it

14 id3tool –Lists attributes of the MP3 file Can set attributes –-a  album –-r  artist –-y  year File must already exist! –“touch” command

15 BASH Function #1 createOneDummyMP3() { touch $1 id3tool $1 -a $2 -r $3 -y $4 }

16 BASH Function #2 createTestMP3Files() { mkdir –p $1 pushd $1 for i in {0..9} do for j in {0..9} do createOneDummyMP3 song$i$j.mp3 Album$i Artist$j 200$i done popd }

17 PS Function #1 function createOneMP3File( $filename, $album, $artist, $year) { echo ‘’ > $filename id3tool $filename -a $album -r $artist -y $year }

18 PS Function #2 function createTestMP3Files( $dirName) { mkdir –force $dirName pushd $dirName foreach ($i in 0..9) { foreach ($j in 0..9) { createOneMP3File song$i$j.mp3 Album$i Artist$i 200$i } popd }


Download ppt "Lecture 9 – Scripting II Testing scripts MP3 files id3tool."

Similar presentations


Ads by Google