{"id":134,"date":"2011-03-31T02:42:20","date_gmt":"2011-03-30T16:42:20","guid":{"rendered":"http:\/\/helms-deep.net\/~rwh\/blog\/?p=134"},"modified":"2011-04-20T19:04:13","modified_gmt":"2011-04-20T09:04:13","slug":"scripting-class-answers-1","status":"publish","type":"post","link":"https:\/\/helms-deep.net\/~rwh\/blog\/?p=134","title":{"rendered":"Scripting class, answers 1"},"content":{"rendered":"<p>1. In firefox, right click on an image and do Copy link location.  Then use that link in your script.  {1..21} is shorthand for the space separated list from 1 to 21, i.e.: &#8220;1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21&#8221;.<\/p>\n<p>[ $ii -le 21 ] is shorthand for &#8220;test $ii -le 21&#8221;<\/p>\n<pre lang=\"bash\"># using a for loop\r\nfor ii in {1..21}\r\ndo\r\n        wget \"http:\/\/helms-deep.net\/~rwh\/blog\/wp-content\/uploads\/2011\/03\/img${ii}.jpg\"\r\ndone\r\n\r\n# using a while loop\r\nii=1\r\nwhile [ $ii -le 21 ] # spaces are required\r\ndo\r\n        wget \"http:\/\/helms-deep.net\/~rwh\/blog\/wp-content\/uploads\/2011\/03\/img${ii}.jpg\"\r\n        ii=`expr $ii + 1` # spaces are required\r\ndone<\/pre>\n<p>For an interesting discussion: why did I use ii for my incrementer instead of i?<\/p>\n<p>2. Note the double quotes, which are required to escape the filenames which contain special characters (spaces and parentheses).  It is always good practice to wrap variables that contain filenames in double quotes for this reason.<\/p>\n<pre lang=\"bash\">for file in img*.jpg\r\ndo\r\n        mv \"$file\" \"`basename \"$file\" .jpg` (modified).jpg\"\r\ndone<\/pre>\n<p>3. First, make sure imagemagick is installed:<\/p>\n<pre lang=\"bash\">sudo apt-get install imagemagick<\/pre>\n<pre lang=\"bash\">for file in img*\\ \\(modified\\).jpg \r\ndo \r\n        convert -resize 50% \"$file\" \"`basename \"$file\" .jpg` (small).jpg\" \r\ndone<\/pre>\n<p>4. First, we install the software we need:<\/p>\n<pre lang=\"bash\">sudo apt-get install vorbis-tools\r\nsudo apt-get install lame<\/pre>\n<p>Then we convert the files:<\/p>\n<pre lang=\"bash\">wget http:\/\/helms-deep.net\/~rwh\/files\/lara_st_john.tar.gz\r\ntar xvzf lara_st_john.tar.gz\r\ncd lara_st_john\/bach_violin_concertos\r\nfor file in *.ogg\r\ndo\r\n        oggdec \"$file\"\r\n        lame --vbr-new `basename \"$file\" .ogg`.wav `basename \"$file\" .ogg`.mp3\r\ndone<\/pre>\n<p><a name=script_ans_5>5. First, we extract the track information from the ogg file using the vorbiscomment command and save it in a temporary file.  Then we use grep and sed to select each datum and save it in a shell variable.  Once we have all this info ready, we can decode the ogg file to wav, then encode the wav to mp3, passing in the shell variables which contain the track information.<\/p>\n<pre lang=\"bash\">for file in *.ogg\r\ndo\r\n        base=`basename \"$file\" .ogg`\r\n        vorbiscomment \"$file\" > \"$base.comment\"\r\n        tt=`grep -e \"^title\"  \"$base.comment\" | sed -e 's\/title=\\(.*\\)$\/\\1\/'`\r\n        ta=`grep -e \"^artist\" \"$base.comment\" | sed -e 's\/artist=\\(.*\\)$\/\\1\/'`\r\n        tg=`grep -e \"^genre\"  \"$base.comment\" | sed -e 's\/genre=\\(.*\\)$\/\\1\/'`\r\n        ty=`grep -e \"^date\"   \"$base.comment\" | sed -e 's\/date=\\(.*\\)$\/\\1\/'`\r\n        tl=`grep -e \"^album\"  \"$base.comment\" | sed -e 's\/album=\\(.*\\)$\/\\1\/'`\r\n        oggdec \"$file\"\r\n        lame --vbr-new --tt \"$tt\" --ta \"$ta\" --tg \"$tg\" --ty \"$ty\" --tl \"$tl\" \"$base.wav\" \"$base.mp3\"\r\n        rm -f \"$base.comment\"\r\n        rm -f \"$base.wav\"\r\ndone\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1. In firefox, right click on an image and do Copy link location. Then use that link in your script. {1..21} is shorthand for the space separated list from 1 to 21, i.e.: &#8220;1 2 3 4 5 6 7 &hellip; <a href=\"https:\/\/helms-deep.net\/~rwh\/blog\/?p=134\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[35,33],"tags":[],"class_list":["post-134","post","type-post","status-publish","format-standard","hentry","category-answers","category-scripting"],"_links":{"self":[{"href":"https:\/\/helms-deep.net\/~rwh\/blog\/index.php?rest_route=\/wp\/v2\/posts\/134","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/helms-deep.net\/~rwh\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/helms-deep.net\/~rwh\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/helms-deep.net\/~rwh\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/helms-deep.net\/~rwh\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=134"}],"version-history":[{"count":18,"href":"https:\/\/helms-deep.net\/~rwh\/blog\/index.php?rest_route=\/wp\/v2\/posts\/134\/revisions"}],"predecessor-version":[{"id":158,"href":"https:\/\/helms-deep.net\/~rwh\/blog\/index.php?rest_route=\/wp\/v2\/posts\/134\/revisions\/158"}],"wp:attachment":[{"href":"https:\/\/helms-deep.net\/~rwh\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/helms-deep.net\/~rwh\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/helms-deep.net\/~rwh\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}