iTunes - sort compilation albums from selected tracks
iTunes - sort compilation albums from selected tracks
- Subject: iTunes - sort compilation albums from selected tracks
- From: DizzyPenguin <email@hidden>
- Date: Wed, 30 Jun 2004 11:29:01 +0100
Hi all,
When iTunes indexes music tracks, it does so by Artist, so therefore
any compilation albums are broken up into separate Artists, instead of
being grouped together.
I need to sort selected tracks or playlist so that all tracks from one
compilation album are grouped together and moved to the end of the list
of selected tracks or playlist.
I have the following which works, but it can be quite (read "very" in
Script Editor) slow when processing a large selection or playlist.
(Obviously, you'll need a compilation album in your selection to work
the script).
-- start
with timeout of 3000 seconds
tell application "iTunes"
set fixed indexing to true
set selectedPlaylist to a reference to (get view of front window)
set listOfSelectedTracks to (get selection of front window as list)
set trackCount to count of listOfSelectedTracks
(* Check to see if single or multiple items *)
if trackCount is 0 then -- no track selected so go with selected
playlist
set listOfSelectedTracks to (get tracks of view of front window as
list)
set trackCount to count listOfSelectedTracks
end if
--return listOfSelectedTracks -- debug
--set listOfCompAlbums_tmp to (album of (every track of
listOfSelectedTracks) whose compilation is true) -- < sadly I can't get
this line to work, so...
(* ... we get a list of albums of all the tracks whose compilation is
true from iTunes' front window
and we'll compare that list with the listOfSelectedTracks and re-sort
them *)
set listOfCompAlbums_tmp to (album of (every track of
selectedPlaylist) whose compilation is true)
end tell
--return listOfCompAlbums_tmp -- debug
end timeout
my sort_list(selectedPlaylist, listOfSelectedTracks,
listOfCompAlbums_tmp)
on sort_list(the_selectedPlaylist, the_listOfSelectedTracks,
the_listOfCompAlbums_tmp)
set listOfCompAlbums to {}
set listOfCompTracks to {}
repeat with anAlbum in the_listOfCompAlbums_tmp
set anAlbum to anAlbum as string
if anAlbum is not "" and listOfCompAlbums does not contain anAlbum
then set end of listOfCompAlbums to anAlbum
end repeat
repeat with thisAlbum in listOfCompAlbums
with timeout of 10000 seconds
set theseTracks to {}
tell application "iTunes"
-- collect all tracks of this album
set theseTracks to (file tracks of the_selectedPlaylist whose album
is thisAlbum)
--if theseTracks is not {} then set end of listOfCompTracks to
theseTracks
if theseTracks is not {} then set listOfCompTracks to
listOfCompTracks & theseTracks
end tell
end timeout
end repeat
--return listOfCompTracks -- debug
set adjusted_listOfCompTracks to {}
repeat with i from 1 to (count listOfCompTracks)
set aTrack to item i of listOfCompTracks
if {aTrack} is in the_listOfSelectedTracks then set end of
adjusted_listOfCompTracks to aTrack
end repeat
--return adjusted_listOfCompTracks -- debug
set adjusted_listOfSelectedTracks to {}
repeat with i from 1 to (count the_listOfSelectedTracks)
set aTrack to item i of the_listOfSelectedTracks
if {aTrack} is not in listOfCompTracks then set end of
adjusted_listOfSelectedTracks to aTrack
end repeat
set the_listOfSelectedTracks to adjusted_listOfSelectedTracks &
adjusted_listOfCompTracks
return the_listOfSelectedTracks
end sort_list
-- end
Any tips on improving the script would be much appreciated. I am
slightly familiar with Serge Belleudy-d'Espinose "QuickSort" routine,
and was wondering if any of it could be accommodated to speed things up
in here.
Regards,
DP
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.