Even better Current iTunes Track
-
Comments:
- here.
It’s nice to show other users what you are listening to, and provide a handy link for them to see more about the artist and track. I noticed that some IM systems don’t like HTML, and I figured out a way to make the link only be sent to a user of an AIM compatible or Jabber server.
Basically, you test the result of serviceClass of contact of the active chat of the first interface controller, and if it is “AIM-compatible” or “Jabber”, then you use HTML, if not, just plain text. You can download it from Adium Xtras: Now Playing in iTunes.
Full Source:
1 – Better itunes adium link script
2 – Includes rating (if present), and links.
3 property message_prefix : «data utxt266B0020» as Unicode text
4 property not_listening_message : "Quiet"
5 property star : «data utxt2605» as Unicode text
6 property google : "http://www.google.com/search?q="
7 property server : ""
8
9 property html_classes : {"AIM-compatible", "Jabber"}
10
11 on substitute()
12 –set server to "http://" & my getIP() & ":8080" — Use betterGetIP if on broadband!
13
14 tell application "System Events"
15 try
16 get process "iTunes"
17 on error
18 return message_prefix & not_listening_message
19 end try
20 end tell
21
22 tell application "iTunes"
23 if player state is not playing then
24 return message_prefix & not_listening_message
25 end if
26 set theArtist to artist of current track
27 if theArtist is "" then set theArtist to "Unknown Artist"
28 set theTrack to name of current track
29 set theRating to " " & my myRating(rating of current track)
30 set theLocation to location of current track
31 set pth to my encode_URL_string(characters 9 thru end of (POSIX path of theLocation) as string)
32 end tell
33
34 tell application "Adium" to set accountType to serviceClass of contact of the active chat of the first interface controller
35 if first item of accountType is in html_classes then
36 return html(message_prefix & my myLink(google, theArtist) & " • " & my myLink(server & pth, theTrack) & theRating)
37 else
38 return message_prefix & theArtist & " • " & theTrack & theRating
39 end if
40 end substitute
41
42 on myRating(theRating)
43 set theResult to ""
44 set theTimes to (theRating - 9) / 20 as integer
45 repeat theTimes times
46 set theResult to theResult & star
47 end repeat
48 return theResult
49 end myRating
50
51 on myLink(URI, theText)
52 if URI is google then
53 set URI to URI & first word of theText
54 repeat with wd in (rest of every word of theText)
55 set URI to URI & "+" & wd
56 end repeat
57 else if server is "" then
58 return theText
59 end if
60 return "<a href=\"" & URI & "\">" & theText & "</a>"
61 end myLink
62
63 on html(str)
64 return ("<HTML>" as Unicode text) & str & "</HTML>"
65 end html
66
67 on getIP()
68 return do shell script "ifconfig ppp0 | grep inet | awk ‘{print $2}’"
69 end getIP
70
71 on betterGetIP()
72 return do shell script "curl -s http://www.showmyip.com/simple/ | grep GMT | awk ‘{print $1}’"
73 end betterGetIP
74
75 property allowed_URL_chars : (characters of "/$-_.+!*’(),1234567890abcdefghijklmnopqrstuvwxyz")
76 property hex_list : (characters of "0123456789ABCDEF")
77
78 on encode_URL_string(this_item)
79 set character_list to (characters of this_item)
80 repeat with i from 1 to number of items in character_list
81 set this_char to item i of character_list
82 if this_char is not in allowed_URL_chars then set item i of character_list to my encode_URL_char(this_char)
83 end repeat
84 return character_list as string
85 end encode_URL_string
86
87 on encode_URL_char(this_char)
88 set ASCII_num to (ASCII number this_char)
89 return ("%" & (item ((ASCII_num div 16) + 1) of hex_list) & (item ((ASCII_num mod 16) + 1) of hex_list)) as string
90 end encode_URL_char
91
92 on run
93 tell application "Adium" to activate
94 my substitute()
95 end run