Pages

29 oct. 2011

iTunes Tag Concatenate

property separator : "+" -- Séparateur des Tags concaténés

tell application "iTunes"
activate
set theseTracks to selection of browser window 1 -- Liste des pistes selectionnées
end tell

-- Vérification sélection non vide
if theseTracks is {} then
beep
display dialog "Sélectionnez les pistes à modifier." buttons {"Annuler"} default button 1 with icon 0
return
end if

-- Sélection des Tags à concatener
set theChoice to choose from list
"1 | TITRE + ARTISTE | | Artiste de l'album | Album ", ¬
"2 | | TITRE + ARTISTE | Artiste de l'album | Album ", ¬
"3 | Titre | ARTISTE + ARTISTE DE L'ALBUM | |  Album", ¬
"4 | Titre | | ARTISTE + ARTISTE DE L'ALBUM | Album", ¬
"5 | Titre | Artiste | ARTISTE dE L'ALBUM + ALBUM ||", ¬
"6 | Titre | Artiste | | ARTISTE dE L'ALBUM + ALBUM", ¬
"7 | TITRE + ARTISTE DE L'ALBUM | Artiste | | Album", ¬
"8 | | Artiste | TITRE + ARTISTE DE L'ALBUM | Album", ¬
"9 | TITRE + ALBUM | Artiste | Artiste de l'album | |", ¬
"10 | | Artiste | Artiste de l'album | TITRE + ALBUM |", ¬
"11 | Titre | ARTISTE + ALBUM | Artiste de l'album | |", ¬
"12 | Titre | | Artiste de l'album | ARTISTE + ALBUM |"} with prompt "Sélectionner les Tags à concaténer :" & return & " | Titre | Artiste | Artiste de l'album | Album |"
if theChoice is false then error "Annulation Utilisateur" number -128

-- numéro de la ligne selectionnée dans la liste
set num to (first word of (theChoice as string)) as number

-- choix du séparateur de Tags
set separator to text returned of (display dialog "Choisisez un séparateur de Tags" default answer separator)

-- concaténation des Tags sélectionnés
tell application "iTunes"
set ofi to fixed indexing
set fixed indexing to true
with timeout of 9999 seconds
repeat with theTrack in theseTracks
if num = 1 then
tell theTrack to set name to (get name) & separator & (get artist)
tell theTrack to set artist to ""
else if num = 2 then
tell theTrack to set artist to (get name) & separator & (get artist)
tell theTrack to set name to ""
else if num = 3 then
tell theTrack to set artist to (get artist) & separator & (get album artist)
tell theTrack to set album artist to ""
else if num = 4 then
tell theTrack to set album artist to (get artist) & separator & (get album artist)
tell theTrack to set artist to ""
else if num = 5 then
tell theTrack to set album artist to (get album artist) & separator & (get album)
tell theTrack to set album to ""
else if num = 6 then
tell theTrack to set album to (get album artist) & separator & (get album)
tell theTrack to set album artist to ""
else if num = 7 then
tell theTrack to set name to (get name) & separator & (get album artist)
tell theTrack to set album artist to ""
else if num = 8 then
tell theTrack to set album artist to (get name) & separator & (get album artist)
tell theTrack to set name to ""
else if num = 9 then
tell theTrack to set name to (get name) & separator & (get album)
tell theTrack to set album to ""
else if num = 10 then
tell theTrack to set album to (get name) & separator & (get album)
tell theTrack to set name to ""
else if num = 11 then
tell theTrack to set artist to (get artist) & separator & (get album)
tell theTrack to set album to ""
else if num = 12 then
tell theTrack to set album to (get artist) & separator & (get album)
tell theTrack to set artist to ""
end if
end repeat
end timeout
set fixed indexing to ofi
end tell
display dialog "Opération terminée." buttons {"OK"} default button 1 with icon note giving up after 5

Aucun commentaire: