iTunes: Download Order mit iTunes abgleichen (mit playlists)

Das ging eigentlich schon etwas früher mit meinen iTunes-Scripts (04-scan folder and add to iTunes Lib), hinzugekommen ist aber das Anlegen der einzelnen Playlisten.
Ist recht praktisch, um einen Überblick über alle Medien-Datein zu bekommen, die so in den Downloads dümpeln… Coole Idee von
Rounak
Code zum markieren einmal anklicken Code im Skript-Editor öffnen

— hubionmac.com 10.10.2009

— scans download folder for folders containing media data iTunes can play

— creates a corresponding playlist within itunes

property special_bigChars : {“Ä”, “Å”, “Ç”, “É”, “Ñ”, “Ö”, “Ü”, “À”, “Ô, “Õ”, “Ÿ”, “”, “Ê”, “Á”, “Ë”, “È”, “Í”, “Δ, “Ï”, “Ì”, “Ó”, “Ô”, “Ò”, “Ú”, “Û”, “Ù”}

property special_smallChars : {“ä”, “å”, “ç”, “é”, “ñ”, “ö”, “ü”, “à”, “ã”, “õ”, “ÿ”, “â”, “ê”, “á”, “ë”, “è”, “í”, “î”, “ï”, “ì”, “ó”, “ô”, “ò”, “ú”, “û”, “ù”}

property action_list02 : {“01-Abcd Efg”, “02-Abcd efg”, “03-ABCD EFG”, “04-abcd efg”}

global folder2Scan, actionid

tell application “Finder”

set actionid to (my get_selection_index(action_list02, “Format of Playlist_names (cancel for no changes)”, false))

set folder2Scan to folder “Downloads” of home

set thefolders to every container of folder2Scan

set thefiles to every file of folder2Scan

–get my download folder

set thefolders_list to my makeDownloadPlaylist()

–clean the folderlist from old playlist // option dialog would be nice

my clean_iTunes_folder(thefolders_list)

— make a folder playlist called itunes or get reference to it

tell application “iTunes”

set files_in_folder2Scan to my check_playlist(thefolders_list, “•SINGLE FILES•”)

repeat with thefile in thefiles

if name of thefile does not end with “.pdf” then

add (thefile as alias) to files_in_folder2Scan

end if

end repeat

if (count of every track of files_in_folder2Scan) = 0 then

delete files_in_folder2Scan

else

–clean the playlist from duplicates

my cleanPlaylist(files_in_folder2Scan)

end if

repeat with thefolder in thefolders

set foldername to my do_string(actionid, my replace_chars((name of thefolder), “_”, ” “))

–now the script loops through every folder, creates a corrensponding playlist

— if there created playlist is empty after all, it will be removed again =)

set current_playlist to my check_playlist(thefolders_list, foldername)

add (thefolder as alias) to current_playlist

if (count of every track of current_playlist) = 0 then

delete current_playlist

else

–clean the playlist from duplicates

my cleanPlaylist(current_playlist)

end if

end repeat

end tell

end tell

display dialog “done…

***commerical***

created by hubionmac.com :-P

***commerical***”

on check_playlist(folderplaylist, playlistname2check)

tell application “iTunes”

set thelists to every user playlist of source 1 whose special kind is none and smart is false

set fpl_lists to {}

repeat with i in thelists

try

if parent of i = folderplaylist then

set fpl_lists to fpl_lists & {i}

end if

end try

end repeat

repeat with i in fpl_lists

if (name of i) as text = playlistname2check then

return i

end if

end repeat

make new playlist with properties {name:playlistname2check} at folderplaylist

end tell

end check_playlist

on makeDownloadPlaylist()

tell application “iTunes”

set thelists to name of every user playlist of source 1 whose special kind is none and smart is false

if (count of every folder playlist) = 0 or (name of every folder playlist) does not contain “Downloads” then

tell source 1 to make new folder playlist with properties {name:”Downloads”}

set fpl to folder playlist “Downloads” of source 1

else

set fpl to folder playlist “Downloads” of source 1

end if

return fpl

end tell

end makeDownloadPlaylist

on cleanPlaylist(theplaylist)

tell application “iTunes”

set idlist to {}

repeat with i from the (count of tracks) of theplaylist to 1 by -1

set currentID to database ID of track i of theplaylist

if currentID is in the idlist then

delete track i of theplaylist

else

if ((location of track i of theplaylist) as text) starts with folder2Scan then

set idlist to idlist & {currentID}

else

delete track i of theplaylist

end if

end if

end repeat

end tell

end cleanPlaylist

on replace_chars(this_text, search_string, replacement_string)

if this_text contains the search_string then

set AppleScript‘s text item delimiters to the search_string

set the item_list to every text item of this_text

set AppleScript‘s text item delimiters to the replacement_string

set this_text to the item_list as string

set AppleScript‘s text item delimiters to “”

end if

return do_string(actionid, this_text)

end replace_chars

on do_string(actionid, the_string)

if actionid = {} then

return the_string

else

set actionid to actionid as integer

set finalstring to “”

if actionid = 1 then

repeat with i from 1 to count of characters of the_string

set test_char to character i of the_string

if i = 1 then

set finalstring to makebig(test_char)

else

set prev_char to character (i – 1) of the_string –last character of finalstring as text

if followed_by_bigchar(prev_char) = true then

set finalstring to finalstring & makebig(test_char)

else

set finalstring to finalstring & makesmall(test_char)

end if

end if

end repeat

else if actionid = 2 then

set firstchar to makebig(character 1 of the_string)

repeat with i from 2 to count of characters of the_string

set test_char to character i of the_string

set finalstring to finalstring & makesmall(test_char)

end repeat

set finalstring to (firstchar & finalstring) as text

else if actionid = 3 then

repeat with i from 1 to count of characters of the_string

set test_char to character i of the_string

set finalstring to finalstring & makebig(test_char)

end repeat

else if actionid = 4 then

repeat with i from 1 to count of characters of the_string

set test_char to character i of the_string

set finalstring to finalstring & makesmall(test_char)

end repeat

end if

return finalstring

end if

end do_string

on followed_by_bigchar(test_char)

if ((ASCII number of test_char) is greater than 64) and ¬

((ASCII number of test_char) is less than 91) then

return false

else if ((ASCII number of test_char) is greater than 96) and ¬

((ASCII number of test_char) is less than 123) then

return false

else if special_bigChars contains test_char then

return false

else if test_char = “‘” then

return false

else

return true

end if

end followed_by_bigchar

on makesmall(test_char)

–when it’s a normal character

if ((ASCII number of test_char) is greater than 64) and ¬

((ASCII number of test_char) is less than 91) then

return (ASCII character ((ASCII number of test_char) + 32))

–when it’s a special character

else if test_char is in special_bigChars then

repeat with i from 1 to count of special_bigChars

if item i of special_bigChars = test_char then

return item i of special_smallChars

end if

end repeat

–when it’s something else

else

return test_char

end if

end makesmall

on makebig(test_char)

–when it’s a normal character

if ((ASCII number of test_char) is greater than 96) and ¬

((ASCII number of test_char) is less than 123) then

return (ASCII character ((ASCII number of test_char) – 32))

–when it’s a special character

else if test_char is in special_smallChars then

repeat with i from 1 to count of special_bigChars

if item i of special_smallChars = test_char then

return item i of special_bigChars

end if

end repeat

–when it’s something else

else

return test_char

end if

end makebig

on get_selection_index(action_list, theprompt, mult_selection)

set theselection to choose from list action_list multiple selections allowed mult_selection with prompt theprompt

set returnlist to {}

repeat with theselected in theselection

set i to 1

repeat with theaction in action_list

if theselected as text = theaction as text then

set returnlist to returnlist & i as list

end if

set i to i + 1

end repeat

end repeat

return returnlist

end get_selection_index

on clean_iTunes_folder(folder_playlist_2_clean)

tell application “iTunes”

set thelists to every user playlist of source 1 whose special kind is none and smart is false

repeat with i in thelists

try

if parent of i = folder_playlist_2_clean then

delete i

end if

end try

end repeat

end tell

end clean_iTunes_folder

2 thoughts on “iTunes: Download Order mit iTunes abgleichen (mit playlists)

  1. roman says:

    itunes has a folder in your music libryry that does the job with no scripting.
    ~/Music/iTunes/iTunes Music/Add*something-like-this*

  2. Hubi says:

    Der Gag ist ja gerade die Dateien im Download-Ordner zu lassen, bzw. einen Ordner abzubilden, der sich gar nicht auf dem Start-Volumen befindet… für Leute mit nur einer Festplatte mag aber die eingebaute iTunes-Funktion ausreichen ;-P

Leave a Reply