Alternative ways to embed image in iTunes??

GO TO ADMIN PANEL > ADD-ONS AND INSTALL VERTIFORO SIDEBAR TO SEE FORUMS AND SIDEBAR

Straw000

New member
Joined
Sep 21, 2008
Messages
4
Points
0
Hi!! I am making an applescript app to search for artwork for missing track on iTunes. :) Basically, it search the net for the images and downloads the images file to a folder. I found out in the iLounge Forum about converting JPEG images to PICT format in order to embed the artwork in iTunes.

However, I found out that converting them and emending the artwork takes 10-15 seconds :( So, the QN- is there any other method of converting the image and emending them in the shortest time possible?? I would be willing to try shell script, ruby, perl, cocoa, not just applescript.

Any help would be greatly appreciated!! Thanks a lot!!
 

S2_Mac

New member
Joined
Oct 24, 2006
Messages
4,876
Points
0
Location
About 3 feet in front of the monitor
I'm thinking you're referring to this post? For me, once the user has selected a file, that script runs completely in about 1 second -- QT conversion to PICT-wrapped JPEG, reading in the data, setting a track's artwork to the data in iTunes; using ImageEvents is maybe a wee bit quicker (unlike QT, ImageEvents converts without flashing the image in a window, but the files are huge -- 64K for QT, 480K for ImageEvents). So, not sure why yours is so slow....

Perl, Python, etc. aren't really going to help much here; you have to use iTunes at some point; there's one slowdown. And, until someone figures out how to add the PICT wrapper "by hand", you pretty much have to use something like QT or ImageEvents; there's the other slowdown. Perl or Python or whatever aren't going to make that appreciably faster AFAIK.

(You could also call "sips" from the shell. The command syntax looks like this:
#start out with foo_image.jpg; convert it to pict and output to foo_image.pict
sips --setProperty format pict foo_image.jpg --out foo_image.pict
But it's no faster than anything else (and it makes the "big files" too ;-)

Likewise, maybe you could use something like ImageMajick? But then you'd be walking into "non-standard install" territory, and it's still p'bly no faster than anything else....

Maybe if you posted some code we could figure out why your script runs slow.
 

Straw000

New member
Joined
Sep 21, 2008
Messages
4
Points
0
Wow!! Thx S2_Man!! Here is the script which takes about 7-8 seconds.( tested on a faster computer) i think my computer and internet might be might slow. Can you please help me test out the time for this script and see if there is anything I can improve with it? :)


straw000 dot googlepages dot com/ betaalbumart.scpt




(I can't post link, so I am breaking up the link to the code :( Sorry...)


I think the code looks a bit messed-up :) Sorry for that... I wonder how the cocoa apps can put the album art in itunes so fast?? Is cocoa more suited to itunes?? Any help would be greatly appreciated!
 

S2_Mac

New member
Joined
Oct 24, 2006
Messages
4,876
Points
0
Location
About 3 feet in front of the monitor
Well done! It's a great script!

Hmmm...you're not timing your script from the Script Editor with Event Log displayed, are you? Because I can get a 12-second conversion time in that environment -- the long runtime comes from the Event Log pane having to scroll the contents of the huge converted file. (If you're running/testing from Script Editor, click on the Description tab; your times will improve 12-fold ;-)

The script looks fine. (One comment -- be lavish in your use of variable names; no need to recycle so much. Saves lottsa head-scratchin' when you read the script a year from now ;-)

So, without Event Log displayed, this runs fine; my total runtime was rarely greater than 3 seconds:
Code:
-------------------------------------------
-- total runtime start
set time_in to the current date
-------------------------------------------

tell application "iTunes"
	if the player state is stopped then
		display dialog "Play a track!"
		return
	end if
	set songartist to artist of current track
	set songalbum to album of current track
end tell

-------------------------------------------
-- fetching files time start
set net_work_time_in to the current date
-------------------------------------------

set path_to_desktop to path to desktop folder as Unicode text
set html_source_file to (path_to_desktop & "web.html") as Unicode text

set x to "http://albumart.org/index.php?srchkey=" & songartist & " " & songalbum & "&itempage=1&newsearch=1&searchindex=Music"
tell application "URL Access Scripting" to download x to html_source_file replacing yes

set t to read (file html_source_file)
set song_art_url to extractBetween(t, "largeImagePopup('", "',") --> "'satiable curtiosity"

--set thePath to path to desktop folder as Unicode text -- redundant; see above
set downloaded_art_file to (path_to_desktop & "art.jpg") as Unicode text


tell application "URL Access Scripting" to download song_art_url to downloaded_art_file replacing yes

-------------------------------------------
set cd to the current date
-- total time to fetch network files
set net_work_time_elpased to cd - net_work_time_in
-- art conversion start time
set art_conversion_time_in to cd
-------------------------------------------

set converted_art_file to (path_to_desktop & "art.pict") as Unicode text

(*
-- much better output file
tell application "QuickTime Player"
	open downloaded_art_file
	export document 1 as picture to converted_art_file using default settings with replacing
	close document 1 saving no
end tell
*)

tell application "Image Events"
	--launch
	set the_image to open downloaded_art_file
	save the_image as PICT in converted_art_file
	close the_image
end tell

set the_artwork to read (file converted_art_file) from 513 as JPEG picture
tell application "iTunes" to set data of artwork 1 of current track to the_artwork

-------------------------------------------
set cd to the current date
set art_conversion_time_elapsed to cd - art_conversion_time_in
set total_time_elapsed to cd - time_in
display dialog "Times:" & return & return & "Total script time: " & total_time_elapsed & return & "Network time: " & net_work_time_elpased & return & "Art conversion and pasting time: " & art_conversion_time_elapsed
-------------------------------------------

to extractBetween(SearchText, startText, endText)
	set TID to AppleScript's text item delimiters -- save them for later.
	set AppleScript's text item delimiters to endText -- find the first one.
	set endItems to text of text item 1 of SearchText -- everything after the first.
	set AppleScript's text item delimiters to startText -- find the end one.
	set beginningToEnd to text of text item 2 of endItems -- get the first part.
	set AppleScript's text item delimiters to TID -- back to original values.
	return beginningToEnd -- pass back the piece.
end extractBetween
See what you come up with...maybe it's slow getting the net stuff (and to test that, run it once to get the files you need, then comment out the two calls to "URL Access Scripting").

And think about using QuickTime Player -- the files are soo much nicer.
 

Straw000

New member
Joined
Sep 21, 2008
Messages
4
Points
0
Thx!! : ) That was a really quick reply!! I should be making this script into a applescript studio app with really cool interface!! It would be a lot nicer than a faceless app!

I don't know what to say- I just joined this forum and I am really happy to see that the members of this forum are very helpful!! THX A LOT!! : D
 

S2_Mac

New member
Joined
Oct 24, 2006
Messages
4,876
Points
0
Location
About 3 feet in front of the monitor
How much benefit would there really be from converting it to a Studio app? As an applet you can run the thing from iTunes Scripts menu or from the Dock/Finder with no need to do anything more than launch it; putting a face on it just means more work for the user -- launch it, work it, quit it.

OTOH, I would really enjoy seeing some extra stuff at the top -- like, if there's no track currently playing, go get art for every track in the selection, or some variation of that. (Like, if artless track is playing and that track is also the sole track in the selection, go get its art; if the playing track has art, then get art for the selected track(s); if artless track is playing and different track(s) is selected, ask user what to do; etc.)

(Oh yeah -- and offering to add the art to the rest of the targeted track's album would be wunnerful! ;-)
 
Last edited:
Top