Displaying iTunes Album Art

Posted on
Sun Sep 21, 2008 6:43 pm
netguykb offline
Posts: 6
Joined: Sep 07, 2008

Displaying iTunes Album Art

I would absolutely love the ability to display the Album Art from iTunes on my control pages. HAS ANYONE done this yet. Here is my example:

Image

Posted on
Sun Sep 21, 2008 7:16 pm
Skiddy offline
User avatar
Posts: 146
Joined: May 06, 2008

(No subject)

Yes.... and No.

I wrote an applescript to do this using variables and image files but there's an issue with Indigo in that when you display a variable as an image (the album art) it does not change/update the image file automatically when the variable itself changes like it does with text values. You have to do a manual refresh of the browser window. What I have is close but not close enough unfortunately.

Posted on
Sun Sep 21, 2008 7:35 pm
jay (support) offline
Site Admin
User avatar
Posts: 15543
Joined: Mar 19, 2008
Location: Austin, Texas

(No subject)

Interesting. I think that should be somewhere inside the IWS python code (the refresh stuff). I don't know the IWS code very well but if you know python it might be a pretty straight-forward patch...

jay

Posted on
Mon Sep 22, 2008 7:30 pm
Skiddy offline
User avatar
Posts: 146
Joined: May 06, 2008

(No subject)

I don't but if anyone else does who could suggest something then it could be a nice addition to the user Contributions once I cleaned the other code up a little.

Posted on
Thu Apr 07, 2011 12:52 pm
ckeyes888 offline
Posts: 2101
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Displaying iTunes Album Art

Anyone ever have any luck displaying iTunes art on a control page yet?
Even better for me would be able to display Squeezebox art.

Thanks,

Carl

Posted on
Mon Feb 13, 2012 2:27 pm
Dewster35 offline
Posts: 1029
Joined: Jul 06, 2010
Location: Petoskey, MI

Re:

Skiddy wrote:
Yes.... and No.

I wrote an applescript to do this using variables and image files but there's an issue with Indigo in that when you display a variable as an image (the album art) it does not change/update the image file automatically when the variable itself changes like it does with text values. You have to do a manual refresh of the browser window. What I have is close but not close enough unfortunately.


Would you mind sharing?

Latest version of airfoil will display album art of the source IE iTunes or another supported source:

http://rogueamoeba.com/support/knowledg ... ontrol-Mac

Perhaps you could pull it from there.

Posted on
Tue Feb 14, 2012 10:37 am
Dewster35 offline
Posts: 1029
Joined: Jul 06, 2010
Location: Petoskey, MI

Re: Displaying iTunes Album Art

Script to pull in current album art out of iTunes or pandoras box.

I have a trigger that watches my currentalbum variable for changes and fires off this script.

The developer for pandoras box wrote this as a favor for me so thank you Francisco!

A warning... don't try changing albums multiple times within a second.

Use a refreshing image url at the following location.

file:///Library/Application%20Support/Perceptive%20Automation/AlbumArt.PNG

Now if only indigo would allow a trigger action to refresh the image we'd be all set! ;) Mine currently refreshes at 10 seconds and it is pretty quick at the refresh in my opinion.... quick enough to give the wow factor I suppose. If you have script troubles... please direct your questions elsewhere since I'm fairly clueless and only know enough to be dangerous at this point. Enjoy.

Code: Select all

property outputFolder : "Library:Application Support:Perceptive Automation:"
property filename : "AlbumArt.png"

property maxImageDataSize : 340000 -- the maximum size of the outputted image data in bytes.
property scaleGranularity : 0.05 -- increase this for faster, but less accurate downscaling.

on run
   set outputPath to outputFolder & filename
   
   if isApplicationRunning("com.apple.iTunes") then
      tell application id "com.apple.iTunes"
         if (player state is playing) then
            my writeITunesArtworkToFile(outputPath)
            return
         end if
      end tell
   end if
   
   if isApplicationRunning("com.ilabs.PandorasBox") then
      tell application id "com.ilabs.PandorasBox"
         if (player state is playing) then
            my writePandorasBoxArtworkToFile(outputPath)
            return
         end if
      end tell
   end if
   
   display dialog "No active players." buttons {"OK"} default button 1
end run

-- is an application running?
on isApplicationRunning(bundleID)
   tell application "System Events" to return (exists (some process whose bundle identifier is bundleID))
end isApplicationRunning

-- write Pandoras Box current song artwork to path
on writePandorasBoxArtworkToFile(filename)
   try
      tell application id "com.ilabs.PandorasBox" to set the_data to (get artwork of current song)
      exportRawDataToPath(the_data, filename)
   end try
end writePandorasBoxArtworkToFile

-- write iTunes current track artwork to path
on writeITunesArtworkToFile(filename)
   try
      tell application id "com.apple.iTunes" to set the_data to (get raw data of artwork 1 of current track)
      exportRawDataToPath(the_data, filename)
   end try
end writeITunesArtworkToFile

-- write artwork data to path.
on exportRawDataToPath(theData, outputPath)
   try
      -- write temporary TIFF data.
      set tempPath to GetEnclosingFolder(outputPath) & "temp.tiff"
      set fileReference to (open for access tempPath with write permission)
      tell application "System Events"
         write theData to fileReference starting at 0
         set file type of (tempPath as alias) to ".tiff"
      end tell
      close access fileReference
      
      set scaleFactor to 1.0
      
      tell application "Image Events"
         launch
         repeat
            set tempImage to open tempPath
            scale tempImage by factor scaleFactor
            set outputImageFile to save tempImage in outputPath as PNG
            
            if (size of outputImageFile > maxImageDataSize and scaleFactor > 0) then
               set scaleFactor to scaleFactor - scaleGranularity
            else
               exit repeat
            end if
            
         end repeat
         close
      end tell
      
      -- delete temporary files.
      do shell script ("rm -f " & quoted form of POSIX path of (tempPath as alias))
      if (scaleFactor ≤ 0.01) then ¬
         do shell script ("rm -f  " & quoted form of POSIX path of (outputPath as alias))
      
   end try
end exportRawDataToPath

on GetEnclosingFolder(myPath)
   set oldDelimiters to AppleScript's text item delimiters -- always preserve original delimiters
   set AppleScript's text item delimiters to {":"}
   set pathItems to text items of (myPath as text)
   if last item of pathItems is "" then set pathItems to items 1 thru -2 of pathItems -- its a folder
   set parentPath to ((reverse of the rest of reverse of pathItems) as string) & ":"
   set AppleScript's text item delimiters to oldDelimiters -- always restore original delimiters
   return parentPath
end GetEnclosingFolder

on GetLastPathComponent(myPath)
   set oldDelimiters to AppleScript's text item delimiters -- always preserve original delimiters
   set AppleScript's text item delimiters to {":"}
   set pathItems to text items of (myPath as text)
   if last item of pathItems is "" then set pathItems to items 1 thru -2 of pathItems -- its a folder
   set parentPath to last item of pathItems
   set AppleScript's text item delimiters to oldDelimiters -- always restore original delimiters
   return parentPath
end GetLastPathComponent



This will be part of a much grander script package for full control of itunes/airfoil/pandoras box.... again with a lot of help from Francisco.

Edit: Updated script to include maximum album art size parameter at the top of the script.
Last edited by Dewster35 on Thu Feb 23, 2012 6:55 am, edited 1 time in total.

Posted on
Thu Feb 16, 2012 9:54 am
Dewster35 offline
Posts: 1029
Joined: Jul 06, 2010
Location: Petoskey, MI

Re: Displaying iTunes Album Art

Just a warning on this script.. it currently pushes out an image file commonly from pandoras box at 750K. Indigo has a limit on image sizes of 350K so I am going to be looking into getting this either compressed or scaled down. If anyone wants to take a stab at doing this in the interim, let me know and I'll update the code.

Posted on
Thu Feb 16, 2012 11:08 am
jay (support) offline
Site Admin
User avatar
Posts: 15543
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Displaying iTunes Album Art

So, you could create an Automator folder action that scales the image down (there is a built-in action for that). Add the automator action to a staging folder where your script drops the image. The automator action would scale the image down and move it to the right destination.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Feb 23, 2012 6:55 am
Dewster35 offline
Posts: 1029
Joined: Jul 06, 2010
Location: Petoskey, MI

Re: Displaying iTunes Album Art

Got the code reworked to see the above. It will work if you run either pandoras box, iTunes or both.

Posted on
Sat Feb 25, 2012 5:33 am
bbruck offline
Posts: 325
Joined: Oct 05, 2008

Re: Displaying iTunes Album Art

I use the free Remote iPhone app to control iTunes and the speakers to which it directs music.
What capabilities would I gain by controlling my music via Indigo?

Posted on
Sat Feb 25, 2012 7:16 am
Dewster35 offline
Posts: 1029
Joined: Jul 06, 2010
Location: Petoskey, MI

Re: Displaying iTunes Album Art

The advantages are that you can tie into your home automation system. Automatically turn a zone off if there isn't anyone around with motion. Have hard keys in your keypadlincs for control...I have a button for controlling each zone-on or off, and I intend to have a play/pause button as well.

I like to listen to pandora as well as have some spoken notifications. I unify all that with airfoil and there isn't an integrated app that can do all that well that I've seen so I've made my own.

Also, with my setup I can AirPlay from my phone and airfoil redistributes it to the rest of the zones.

If you look at my page, I actually jump out of indigo touch into the remote app to do hardcore music controls.

I think a lot of folks also have more than just their music controls on their control page so they can control other aspects of their hole automation system in a single custom UI enviornment.

Posted on
Sun Apr 01, 2012 7:51 pm
ckeyes888 offline
Posts: 2101
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Displaying iTunes Album Art

Curious if anyone has the above script working?
I do get a "blank" tiff file but it doesn't create the AlbumArt.png.

I don't use Pandoras Box so I did edit out that part of the script.

Thanks,

Carl

Posted on
Sun Apr 01, 2012 8:03 pm
Dewster35 offline
Posts: 1029
Joined: Jul 06, 2010
Location: Petoskey, MI

Re: Displaying iTunes Album Art

It works for me. I would try running the script as is without modifying it. You can just run iTunes and it will work just the same.

Posted on
Sun Apr 01, 2012 9:20 pm
gtreece offline
Posts: 169
Joined: Sep 26, 2011

Re: Displaying iTunes Album Art

I'm doing this with Pulsar for the Sirius channel logo, and the image refreshes on my control page by itself. It's the same approach as the script posted above. Get tiff, use image events to convert tiff to png, which always has the same name, and is the file reference in the refreshing image field on my control page. I have a schedule that refreshes the image file every 12 seconds whenever Pulsar is playing. I haven't tried to set it any shorter than that.

Who is online

Users browsing this forum: No registered users and 1 guest