iTunes vers USB

Présentation

Le but est de facilement transférer les morceaux d’une liste de lecture sous iTunes vers une clef USB utilisée dans un autoradio.

L’autoradio (un Blaupunkt MP68) supporte que 32 caractères (il tolère plus mais réduit le nombre de morceaux affichés). Aussi il ne gère pas le genre, et ne permet d’afficher facilement soit le titre du morceau, soit le nom de l’artiste, soit le nom de l’album (en plus du nom du fichier).

 

Méthode

J’ai utilisé à l’origine un Apple Script de Doug Adam (Doug’s AppleScripts for iTunes http://www.dougscripts.com/itunes/ ).

En plus:

– Ne copie pas les morceaux désactivés de la liste

– Crée ur la clef un dossier spar genre de morceau (Pop, Electro, …)

– Réduit le nom du fichier MP3 à 32 caractères (après avoir supprimé les espaces et avoir mis des majuscules à chaque mot: Cela permet de quand même lire le morceau).

 

Utilisation

Comme pour le script de Doug Adam, il faut éditer le script et remplacer:

– le contenu de the_playlist par le nom de la liste de lecture sous iTunes

– le contenu de folder_disk par le nom de la clef USB

Ensuite, il faut mettre ce script dans le dossier « Bibliothèque:iTunes:Scripts » dans le « Départ » de l’utilisateur.

Le script peut être appelé de iTunes (un menu apparait).

 

AppleScript

(*

« Sync Playlist Files to Folder » for iTunes

written by Doug Adams

dougadams@mac.com

v1.0 August 12 2005

– initial release

V1.1 Sep 19 2010

– large mods for USB key used on car radio

Get more free AppleScripts and info on writing your own

at Doug’s AppleScripts for iTunes

http://www.dougscripts.com/itunes/

*)

— USER SETTINGS:

— this must be the EXACT name of the playlist–keeping in quotes:

propertythe_playlist : « cle_usb »

— this should be a string of the path to the folder you want to use–keeping in quotes:

propertyfolder_disk : « AUTORADIO »

— =========================================

— if iTunes is not running, then exit

tellapplication « System Events » toif (nameofeveryprocess) does notcontain « iTunes » thenreturn

— init some lists…

set track_filenames to {}

set track_locations to {}

set track_genres to {}

tellapplication « iTunes »

repeatwiththis_trackin (geteverytrackofplaylistthe_playlist)

ifclassofthis_trackisfile trackandthis_track‘s enabledistruethen

   setloctothis_track‘s location

   iflocastextis notequal to « missing value » then

      — track’s locations

      setendoftrack_locationsto (locasstring)

      — track’s filenames

      set file_name to my get_filename_from_filepath(loc)

      settmp_nametotext 1 thru -5 offile_name

      settmp_nameto (myreplace_chars(tmp_nameasstring, « ‘ », «  »))

      settmp_nameto (myreplace_chars(tmp_nameasstring, « (« , «  »))

      settmp_nameto (myreplace_chars(tmp_nameasstring, « ) », «  »))

      settmp_nameto (myreplace_chars(tmp_nameasstring, « é », « e »))

      settmp_nameto (myreplace_chars(tmp_nameasstring, « à », « a »))

      settmp_nameto (myreplace_chars(tmp_nameasstring, « ç », « c »))

      settmp_nametodo shell script « python -c \ »import sys; print unicode(sys.argv[1],  ‘utf8’).title().encode(‘utf8’)\ »  » & quoted formoftmp_name

      settmp_nameto (myreplace_chars(tmp_nameasstring,  » « , «  »))

      settmp_nameto (myreplace_chars(tmp_nameasstring, « . », « -« ))

      iflengthoftmp_name > 32 then

         copycharacters 1 through 32 oftmp_nameasstringtotmp_name

      endif

      log « name:  » & tmp_name

      setendoftrack_filenamestotmp_name & « .mp3 »

      — track’s genres

      set tmp_name to this_track‘s genre

      iftmp_nameastextisequal to «  » thensettmp_nameto « Autres »

      settmp_nameto (myreplace_chars(tmp_nameasstring, « / », « -« ))

      settmp_nameto (myreplace_chars(tmp_nameasstring, « & », « -« ))

      settmp_nameto (myreplace_chars(tmp_nameasstring, « é », « e »))

      settmp_nameto (myreplace_chars(tmp_nameasstring, « à », « a »))

      settmp_nameto (myreplace_chars(tmp_nameasstring, « è », « e »))

      settmp_nameto (myreplace_chars(tmp_nameasstring, « ç », « c »))

      setendoftrack_genresto (tmp_nameasstring)

   endif

end if — not file track

endrepeat

endtell

— check if any file tracks are in the folder…otherwise add to folder

tellapplication « Finder »

   repeatwithifrom 1 tolengthoftrack_filenames

      set folder_name to itemi of track_genres

      set file_location to itemi of track_locations

      set file_name to itemi of track_filenames

      — Create a folder per genre

      ifnot (existsfolder (folder_name) ofdiskfolder_disk) then

      makenewfolderatdiskfolder_diskwith properties {name:folder_name}

   endif

      — Copy track to destination file

      set destination_name to « Volumes: » & folder_disk & « : » & folder_name & « : » & file_name

      try

         do shell script « cp  » & (quoted form of POSIX path of file_location) &  »  » & (quoted form of POSIX path of destination_name)

      onerrorm

         logm

      endtry

   endrepeat

endtell

 

— HANDLERS

to get_filename_from_filepath(fp)

   if (classoffp) isnotstringthensetfpto (fpasstring)

   tellapplication « Finder » toreturnnameof (getinfo forfilefp)

end get_filename_from_filepath

 

on replace_chars(this_text, search_string, replacement_string)

   set AppleScript‘s text item delimiters to the search_string

   settheitem_listtoeverytext itemofthis_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 «  »

   return this_text

end replace_chars

 

on split_string(theString, theDelimiter)

   set AppleScript‘s text item delimiters to theDelimiter

   settheArraytoeverytext itemoftheStringasstring

   set AppleScript‘s text item delimiters to «  »

   returntheArray

end split_string