Track info uploader applescript (feedback welcome)

  1. peeweejd

    Hi,

    I just made an applescript that "uploads" track info from iTunes to my website (Artist / Title / Album / Genre).

    It's meant to be used in conjunction with a wordpress plugin called wp-itunes.php (http://www.lucky-33.com/scripts/plugins/wp-itunes)

    
                    

    Synergy seems to fire off the applescript every time play/pause is pushed, not when the track changes. SO that presented a problem in that when I skipped a song before it was completed, it would upload the info anyway.

    I got around this by incorporating a clever playlist in iTUnes

    I made a smart playlist that shows the last track that was completely played.

    Here are the prameters: Last Played is after 10/1/05 Limit to 1 songs selected by most recently played Live updating is on

    I named this playlist "last_played"

    Here is the applescript (please tell me what you think) Code: -- change this to the address of your blog set blog_uri to "http://yourblog.com/" --include slash at the end

    -- change this to the text "key" you put in your wp-itunes plugin set wpitunes_key to "test"

    -- don't change anything else below here unless you know what you are doing (or feel like messing around

    -- try to get inormation about what is playing in itunes right now tell application "Finder" if process "iTunes" exists then tell application "iTunes" set current_track to name of track 1 of user playlist "last_played" set current_artist to artist of track 1 of user playlist "last_played" set current_album to album of track 1 of user playlist "last_played" set current_genre to genre of track 1 of user playlist "last_played" end tell -- form the website address with the information form iTunes in the querystring set this_uri to [blog_uri & "?wpitunes=" & wpitunes_key & "&track=" & current_track & "&artist=" & current_artist & "&album=" & current_album & "&genre=" & current_genre] -- create a temp file to catch the file being downloaded (which we don't care about anyway) set temp_file to ((path to temporary items) as string) & "itunes_upload_temp" -- hit the plugin to upload the song info tell application "URL Access Scripting" download this_uri to file temp_file replacing yes quit end tell end if end tell

  2. Greg Hurrell

    Excellent work!

    With respect to the question of when track change items are launched, I thought there was an entry in the feature requests database about this, but I can't find it right now. As noted in this thread here:

    https://wincent.dev/a/support/forums/showflat.php?Number=830

    Synergy launches the items whenever it receives a notification from iTunes; that may be an actual track change but it could also be a mere state change (like going from "Playing" to "Paused" state).

    Ok, I've now found the feature request I was looking for:

    https://wincent.dev/a/support/bugs/show_bug.cgi?id=171

    This deals with the ability to control which kinds of notifications will trigger a track change item to be launched. I've also opened a new bug report for the possibility of handling this kind of thing a little more elegantly from within a single script by passing data to the script as parameters and calling specific methods in response to specific notifications:

    https://wincent.dev/a/support/bugs/show_bug.cgi?id=313

    For reference, on the subject of website updating see also:

    https://wincent.dev/a/support/bugs/show_bug.cgi?id=96 https://wincent.dev/a/support/bugs/show_bug.cgi?id=230

  3. peeweejd

    thanks!

    I'm trying to handle the duplication due to play/pause toggling by modifying the php scripts that actually makes the database entry. I want to make it check to see if the last song added to the database is the same as the song that is trying to be added now.

    Or I could possibly put a date comparison if/then wrapper in my applescript that checks to see if the date the song was last played is within 5 seconds of now before it uploads the song information. That is may be the better way to handle it actually.

  4. peeweejd

    here is a little update on my script..

    it works much better now.

    I added a few lines to get around the play/pause thing synergy does that makes it upload the song info every time the play button is pushed

    THis extra stuff compares the current system time to the time the last song was completed, and if they are within 3 seconds, it uploads the info.

    anyway, here is the script

    Code:-- change this to the address of your blog set blog_uri to "http://yourblog.com/" --include slash at the end

    -- change this to the text "key" you put in your wp-itunes plugin set wpitunes_key to "test"

    -- this is how old the song in our magic playlist can be (in seconds) for us to accept it. -- don't mess with this unless the script is not fast enough to get your song info uploaded. set delay_time to 3

    -- don't change anything else below here unless you know what you are doing (or feel like messing around

    -- get the current date and time to compare against the date/time info we can get from iTunes set date_now to the current date

    -- try to get inormation about what is playing in itunes right now tell application "Finder" if process "iTunes" exists then tell application "iTunes" set last_played to played date of track 1 of user playlist "last_played" set current_track to name of track 1 of user playlist "last_played" set current_artist to artist of track 1 of user playlist "last_played" set current_album to album of track 1 of user playlist "last_played" set current_genre to genre of track 1 of user playlist "last_played" end tell if (date_now - last_played) < delay_time then -- form the website address with the information form iTunes in the querystring set this_uri to [blog_uri & "?wpitunes=" & wpitunes_key & "&track=" & current_track & "&artist=" & current_artist & "&album=" & current_album & "&genre=" & current_genre] -- create a temp file to catch the file being downloaded (which we don't care about anyway) set temp_file to ((path to temporary items) as string) & "itunes_upload_temp" -- hit the plugin to upload the song info tell application "URL Access Scripting" download this_uri to file temp_file replacing yes quit end tell end if end if end tell

Reply

This topic is now closed.