Sun 5th Mar 2006
Better iTunes Data Insert
Posted in the wee hours, filed under AppleScript , iTunes.I’ve updated my Insert iTunes Data (HTML) script for generating a block of text that describes the current playing iTunes track.
This version links to the iTunes Music Store, rather than Google. It is relatively smart, in that the track name link also has the artist name, and the album name does too, as long as the album isn’t a compilation.
The only (slight) bug is that the track name seems to need to be just the way iTMS displays it, so having (Live) might stuff up a link. This might be only if there isn’t a Live version in the iTMS.
I Can’t Tell You Why (Live) • Eagles • Hell Freezes Over ★★★★★
Code after the jump.
-- Insert some data about the currently playing iTunes track into browser. property star : «data utxt2605» as Unicode text property half : «data utxt00BD» as Unicode text property quarter : «data utxt00BC» as Unicode text property threeq : «data utxt00BE» as Unicode text property browser : "Firefox" property URLprefix : "itms://phobos.apple.com/WebObjects/MZSearch.woa/wa/advancedSearchResults?" on run {} tell application "System Events" try get process "iTunes" on error return "No Track" end try end tell tell application "iTunes" set theTrack to current track set theArtist to artist of theTrack set theAlbum to album of theTrack set theRating to rating of theTrack set theComp to compilation of theTrack set theTrack to name of theTrack --set trackInfo to {theTrack, theArtist, theAlbum, theRating} end tell set trackLink to "<a href='" & URLprefix & "songTerm=" & HTMLify(theTrack) & "&artistTerm=" & HTMLify(theArtist) & "'>" & theTrack & "</a>" set artistLink to "<a href='" & URLprefix & "artistTerm=" & HTMLify(theArtist) & "'>" & theArtist & "</a>" if theComp is true then set theArtist to "" -- No Artist if album is compilation! end if set albumLink to "<a href='" & URLprefix & "albumTerm=" & HTMLify(theAlbum) & "&artistTerm=" & HTMLify(theArtist) & "'>" & theAlbum & "</a>" set theString to "<p class='itunes'> " & trackLink & " • " & artistLink & " • " & albumLink & " " & myRating(theRating) & "</p>" set the clipboard to theString tell application browser activate tell application "System Events" to keystroke "v" using {command down} end tell end run on HTMLify(someText) set someText to replace(someText, "&", "&") set someText to replace(someText, "\"", """) set someText to replace(someText, "<", "<") set someText to replace(someText, ">", ">") set someText to replace(someText, " ", "+") set someText to replace(someText, "'", "'") return someText end HTMLify on replace(theText, find, replace) -- Nice replace function set OldDelims to AppleScript's text item delimiters set AppleScript's text item delimiters to find set newText to text items of theText set AppleScript's text item delimiters to replace set theResult to newText as text set AppleScript's text item delimiters to OldDelims return theResult end replace on myRating(theRating) set theResult to "" repeat 5 times if theRating ≥ 20 then set theResult to theResult & star else if theRating ≥ 10 then set theResult to theResult & half end if set theRating to theRating - 20 end repeat return theResult end myRating
One More Time • Daft Punk • Triple J Hottest 100 - Volume 9 ★★★
Apparently there are not any Eagles songs in the Australian iTMS.
11 minutes after the fact.
In order for me to get this to work, I had to switch all of the
<a href='and'>strings with<a href="and">.11 hours, 58 minutes after the fact.
Yeah, I think that’s got to do with the way quotes are displayed from HTML, rather than anything else.
I need to try to figure out how to get it to display “stupid” quotes.
18 hours, 19 minutes after the fact.
As it turns out, it is more to do with how
'is displayed (or rather, how'is displayed, since'isn’t really valid HTML). I need to tweak my script styler script(s).1 day, 13 hours after the fact.
I may also remove the artist from the track link, so that other versions of the same track can be found as well.
Also, I may make it so it uses http: links instead of itms: links, as IE PC seems to ignore/fail on itms: links.
1 day, 13 hours after the fact.