Better iTunes Data Insert
-
Comments:
- here.
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.
1 -- Insert some data about the currently playing iTunes track into browser.
2
3 property star : «data utxt2605» as Unicode text
4 property half : «data utxt00BD» as Unicode text
5 property quarter : «data utxt00BC» as Unicode text
6 property threeq : «data utxt00BE» as Unicode text
7 property browser : "Firefox"
8 property URLprefix : "itms://phobos.apple.com/WebObjects/MZSearch.woa/wa/advancedSearchResults?"
9
10 on run {}
11
12 tell application "System Events"
13 try
14 get process "iTunes"
15 on error
16 return "No Track"
17 end try
18 end tell
19
20 tell application "iTunes"
21 set theTrack to current track
22 set theArtist to artist of theTrack
23 set theAlbum to album of theTrack
24 set theRating to rating of theTrack
25 set theComp to compilation of theTrack
26 set theTrack to name of theTrack
27 --set trackInfo to {theTrack, theArtist, theAlbum, theRating}
28 end tell
29
30 set trackLink to "<a href='" & URLprefix & "songTerm=" & HTMLify(theTrack) & "&artistTerm=" & HTMLify(theArtist) & "'>" & theTrack & "</a>"
31 set artistLink to "<a href='" & URLprefix & "artistTerm=" & HTMLify(theArtist) & "'>" & theArtist & "</a>"
32 if theComp is true then
33 set theArtist to "" -- No Artist if album is compilation!
34 end if
35 set albumLink to "<a href='" & URLprefix & "albumTerm=" & HTMLify(theAlbum) & "&artistTerm=" & HTMLify(theArtist) & "'>" & theAlbum & "</a>"
36
37 set theString to "<p class='itunes'> " & trackLink & " • " & artistLink & " • " & albumLink & " " & myRating(theRating) & "</p>"
38
39 set the clipboard to theString
40
41 tell application browser
42 activate
43 tell application "System Events" to keystroke "v" using {command down}
44 end tell
45 end run
46
47 on HTMLify(someText)
48 set someText to replace(someText, "&", "&")
49 set someText to replace(someText, "\"", """)
50 set someText to replace(someText, "<", "<")
51 set someText to replace(someText, ">", ">")
52 set someText to replace(someText, " ", "+")
53 set someText to replace(someText, "'", "'")
54 return someText
55 end HTMLify
56
57 on replace(theText, find, replace)
58 -- Nice replace function
59 set OldDelims to AppleScript's text item delimiters
60 set AppleScript's text item delimiters to find
61 set newText to text items of theText
62 set AppleScript's text item delimiters to replace
63 set theResult to newText as text
64 set AppleScript's text item delimiters to OldDelims
65 return theResult
66 end replace
67
68 on myRating(theRating)
69 set theResult to ""
70 repeat 5 times
71 if theRating ≥ 20 then
72 set theResult to theResult & star
73 else if theRating ≥ 10 then
74 set theResult to theResult & half
75 end if
76 set theRating to theRating - 20
77 end repeat
78 return theResult
79 end myRating
One More Time • Daft Punk • Triple J Hottest 100 – Volume 9 ★★★