Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Post iTunes track info to del.icio.us via AppleScript Apps
I work in an office with lots of Macs with iTunes libraries, and often play stuff off other people's libraries to check it out. But I don't want to be busy looking up bands when I'm at work, so I wrote two AppleScripts to post a link containing a Google search for the current iTunes track info to my del.icio.us account.

By default, the posts are given the tag musictoget. Then every couple of weeks, I check out what I've accumulated under my musictoget tag. One script works with regular tracks, and the other one works with streams (provided the stream contains artist and title information).

Script #1 (for regular tracks):
(*
"Track info to del.icio.us"

uses del.icio.us API v1 - http://del.icio.us/help/api/

partly based on "Current to Clipboard" for iTunes and "Google Video Search" written by Doug Adams
*)

property base_url : "http://www.google.com/search?q="

tell application "iTunes"
  if player state is not stopped then
    set ct to current track
    set station_name to ""
    set {nom, art, alb} to {"", "", ""}
    
    tell ct
      try
        if artist is not "" and artist is not missing value then
          set art to (" - " & artist)
        end if
      end try
      try
        if name is not "" then
          set nom to name
        else
          set nom to ""
        end if
      end try
      try
        if album is not "" then
          set alb to (" - " & album)
        else
          set alb to ""
        end if
      end try
    end tell
    
    set search_term to (nom & art & alb)
  end if
end tell

set search_term to searchReplace(search_term, " ", "%20") as string

set the_command to ("curl \"https://username:password@api.del.icio.us/v1/posts/add?tags=musictoget&description=" & search_term & "&url=")

set search_url to (base_url & search_term) as string

set the_command to (the_command & search_url & "\"") as string

do shell script the_command

on searchReplace(origStr, searchStr, replaceStr)
  set old_delim to AppleScript's text item delimiters
  set AppleScript's text item delimiters to searchStr
  set origStr to text items of origStr
  set AppleScript's text item delimiters to replaceStr
  set origStr to origStr as string
  set AppleScript's text item delimiters to old_delim
  return origStr
end searchReplace
Script #2 (for streams):
(*
"Track info to del.icio.us"
uses del.icio.us API v1 - http://del.icio.us/help/api/
partly based on "Search iTMS for Current Song In Stream" by Doug Adams
*)

property base_url : "http://www.google.com/search?q="

tell application "iTunes"
	if player state is playing and current track's class is URL track then
		if current stream title is not "" then
			set {art, nom} to my text_to_list(current stream title, " - ")
			set art to my replace_chars(art, " ", "%20")
			set nom to my replace_chars(nom, " ", "%20")
			set search_term to (nom & "%20" & art)
		end if
	end if
end tell

set the_command to ("curl \"https://username:password@api.del.icio.us/v1/posts/add?tags=musictoget&description=" & search_term & "&url=")

set search_url to (base_url & search_term) as string

set the_command to (the_command & search_url & "\"") as string

do shell script the_command


on text_to_list(txt, delim)
	set saveD to AppleScript's text item delimiters
	try
		set AppleScript's text item delimiters to {delim}
		set theList to every text item of txt
	on error errStr number errNum
		set AppleScript's text item delimiters to saveD
		error errStr number errNum
	end try
	set AppleScript's text item delimiters to saveD
	return (theList)
end text_to_list

on replace_chars(txt, srch, repl)
	set AppleScript's text item delimiters to the srch
	set the item_list to every text item of txt
	set AppleScript's text item delimiters to the repl
	set txt to the item_list as string
	set AppleScript's text item delimiters to ""
	return txt
end replace_chars
[robg adds: To use these scripts, save them in your user's Library » iTunes » Scripts folder. Then when you hear a song you'd like to upload, just choose the proper script from iTunes' Scripts menu.]
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[8,012 views]  

Post iTunes track info to del.icio.us via AppleScript | 0 comments | Create New Account
Click here to return to the 'Post iTunes track info to del.icio.us via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.