1 / 18

Lecture 9 – Scripting II

Lecture 9 – Scripting II. Testing scripts MP3 files id3tool. Script Development. Plan your scripts Source script files Make “proper” functions “echo” your code <bold>Mystery Hint</bold>. 1. Plan Your Scripts. Hastily-written scripts suck to debug Finding code snippets can be hard

justis
Download Presentation

Lecture 9 – Scripting II

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 9 – Scripting II • Testing scripts • MP3 files • id3tool

  2. Script Development • Plan your scripts • Source script files • Make “proper” functions • “echo” your code • <bold>Mystery Hint</bold>

  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 10-15 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 • id3tool <filename.mp3> • 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 iin {0..9} do for j in {0..9} do createOneDummyMP3 song$i$j.mp3 Album$iArtist$j 200$i done 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 }

More Related