{"id":37,"date":"2005-04-05T23:47:30","date_gmt":"2005-04-05T18:17:30","guid":{"rendered":"http:\/\/kunaldua.com\/2005\/04\/05\/the-internals\/"},"modified":"2005-04-05T23:47:30","modified_gmt":"2005-04-05T18:17:30","slug":"the-internals","status":"publish","type":"post","link":"https:\/\/kunaldua.com\/blog\/2005\/04\/05\/the-internals\/","title":{"rendered":"The internals"},"content":{"rendered":"<p>Carrying forward from yesterday, let&#8217;s take a behind-the-scenes peek at the &#8220;Now Playing in iTunes&#8221; album art feature you see in the sidebar.<\/p>\n<p>Here&#8217;s what you&#8217;ll need: 500 gms Mac OS X (sorry Windows people), 50 gms AppleScript, 2 tbspn Shell Script, 1 tbspn FTP, 1 Amazon developer ID, 250 gms PHP and 1\/2 tbsp Cron skills.<\/p>\n<p>Here&#8217;s how it functions. We schedule a <!--more-->AppleScript to run every 5 minutes. This AppleScript passes the name, artist and album of the song currently playing in iTunes to a shell script. This shell script FTPs this information to your webserver. The PHP script reads this file, queries the Amazon database using Amazon Web Services and gets the corresponding album art (if any). Simple, isn&#8217;t it?<\/p>\n<p>Le&#8217;ts dig into the code, shall we?<\/p>\n<p>The AppleScript<\/p>\n<pre lang=\"applescript\" line=\"1\">\ntell application \"iTunes\"\n\tif player state is paused or player state is playing then\n\t\tcopy current track to currTrack\n\t\tcopy artist of currTrack to currArtist\n\t\tset currArtist to \"\"\" & currArtist & \"\"\"\n\t\tcopy name of currTrack to currName\n\t\tset currName to \"\"\" & currName & \"\"\"\n\t\tcopy album of currTrack to currAlbum\n\t\tset currAlbum to \"\"\" & currAlbum & \"\"\"\n\t\tset myCommand to \"~\/uploads \" & currArtist & \" \" & currName & \" \" & currAlbum\n\t\tdo shell script myCommand password \"ADMINPASSWORD\" with administrator privileges\n\tend if\nend tell\n<\/pre>\n<p>It&#8217;s rather self explanatory isn&#8217;t it? The &#8220;&#8221;&#8221; bit is to enclose the string within quotes &#8211; just to be sure. We then call a shell script called &#8220;uploads&#8221; with 3 parameters. I store both the AppleScript and the shell script in my home (~) folder.<\/p>\n<p>The shell script<\/p>\n<pre lang=\"bash\" line=\"1\">\n#!\/bin\/sh\necho $1 > ~\/np.txt\necho $2 >> ~\/np.txt\necho $3 >> ~\/np.txt\nftp -n yourwebsite.com < <EOF\nuser usrname password\nput ~\/np.txt \/remote\/directory\/np.txt\nbye\nEOF\n<\/pre>\n<p>Again, rather simple. Store the information in a text file and upload it to the remote directory.<\/p>\n<p>Now to querying Amazon and parsing XML. And adding the crontab entry. Nah, all that later, a big Champions League night beckons!<\/p>\n<p>PS - This is perhaps the simplest of approaches with a LOT of disadvantages - this is nowhere near the best way of doing this. There's something in each of the steps that can be improved - I'll cover all that and more next time.<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to get &#8220;Now Playing in iTunes&#8221; album art on your website<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"enabled":false},"version":2}},"categories":[2,6,43],"tags":[],"class_list":["post-37","post","type-post","status-publish","format-standard","hentry","category-apple","category-code","category-www","entry"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/kunaldua.com\/blog\/wp-json\/wp\/v2\/posts\/37","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kunaldua.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kunaldua.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kunaldua.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kunaldua.com\/blog\/wp-json\/wp\/v2\/comments?post=37"}],"version-history":[{"count":0,"href":"https:\/\/kunaldua.com\/blog\/wp-json\/wp\/v2\/posts\/37\/revisions"}],"wp:attachment":[{"href":"https:\/\/kunaldua.com\/blog\/wp-json\/wp\/v2\/media?parent=37"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kunaldua.com\/blog\/wp-json\/wp\/v2\/categories?post=37"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kunaldua.com\/blog\/wp-json\/wp\/v2\/tags?post=37"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}