Hello !
Ca fait un moment que je cherchais une manière de remplir mon iPod automatiquement et aléatoirement via iTunes. C'est possible, mais que par pistes et non par albums, c'est-à-dire que l'on obtient au final que des fragments d'albums... Pas terrible !
Donc j'ai concocté un petit AppleScript qui permet de faire ça assez rapidement. En gros, ça crée une playlist d'une taille déterminée avec uniquement des albums complets qu'il suffit alors de copier sur l'ipod.
A récupérer ici : http://www.deltazone.org/~red/stock/Random Albums.scpt
Et à copier dans ~/Bibliothèque/iTunes/Scripts
A bientôt !
Ca fait un moment que je cherchais une manière de remplir mon iPod automatiquement et aléatoirement via iTunes. C'est possible, mais que par pistes et non par albums, c'est-à-dire que l'on obtient au final que des fragments d'albums... Pas terrible !
Donc j'ai concocté un petit AppleScript qui permet de faire ça assez rapidement. En gros, ça crée une playlist d'une taille déterminée avec uniquement des albums complets qu'il suffit alors de copier sur l'ipod.
A récupérer ici : http://www.deltazone.org/~red/stock/Random Albums.scpt
Et à copier dans ~/Bibliothèque/iTunes/Scripts
A bientôt !
Bloc de code:
tell application "iTunes"
set tempname to "Autofilling... Please wait..."
set errorname to "Autofill error !"
-- USER INPUT
try
-- We ask for playlist name
set nameresult to display dialog "Playlist name" default answer "Fill my iPod !"
set playlistname to text returned of nameresult
-- Creating new playlist
make new playlist with properties {name:tempname}
-- We ask for target size
set sizeresult to display dialog "Target playlist size (in gigas)" default answer "6"
set maxsize to (text returned of sizeresult as real) * 1024 * 1024 * 1024
-- We ask if you want optimized mode
set optimizeresult to display dialog "Choose mode. The normal mode adds albums until the target space is full. The target space will be slightly exceeded. The optimized mode checks the size of the albums before adding them, so the target space is never exceeded. It also fills small space with small albums. It is MUCH slower than the normal mode." buttons {"Precise mode", "Quick mode"}
if button returned of optimizeresult is "Quick mode" then
set optimizedmode to false
else
set optimizedmode to true
end if
-- GET ALL THE ALBUMS
-- We get all the albums of the library in mylist
set mylist to the album of every track of library playlist 1
-- Init the copy list
set c to {}
-- For each track, we copy its album to c if it is not already presnt
repeat with loop_var from 1 to (number of items in mylist)
if c does not contain (item loop_var of mylist) then
copy item loop_var of mylist to the end of c
end if
end repeat
-- COPY THE TRACKS
repeat
-- While the size of our playlist is smaller than maxsize
if size of playlist tempname ≥ maxsize then
exit repeat
end if
-- And while there a are still albums left uncopied
if (number of items in c) = 0 then
exit repeat
end if
set randomnumber to random number from 1 to (number of items in c)
if optimizedmode then
set tracktocopy to (file tracks of library playlist 1 whose album is item randomnumber of c)
set tracktocopysize to 0
repeat with loop_var from 1 to (number of items in tracktocopy)
set tracktocopysize to tracktocopysize + (size of item loop_var of tracktocopy)
end repeat
-- If there is enough space to add the album, add it, else, just remove it from the list
if (size of playlist tempname) + tracktocopysize < maxsize then
duplicate (file tracks of library playlist 1 whose album is item randomnumber of c) to playlist tempname
end if
else
duplicate (file tracks of library playlist 1 whose album is item randomnumber of c) to playlist tempname
end if
if randomnumber = 1 then
set c to rest of c
else if randomnumber = (number of items in c) then
set c to reverse of rest of reverse of c
else
set c to items 1 thru (randomnumber - 1) of c & items (randomnumber + 1) thru -1 of c
end if
set playlistprogname to "Albums left : " & (number of items in c)
set name of playlist tempname to playlistprogname
set tempname to playlistprogname
end repeat
set displaysize to (round ((size of playlist tempname) / 1024 / 1024 / 1024 * 100)) / 100
set displaymore to (round (((size of playlist tempname) - maxsize) / 1024 / 1024 / 1024 * 100)) / 100
set displayless to (round ((maxsize - (size of playlist tempname)) / 1024 / 1024 / 1024 * 100)) / 100
if (number of items in c) = 0 then
if optimizedmode then
display alert "That's it ! Your list is now " & displaysize & " GB which is " & displayless & " GB less than required. If needed, add manually some tracks.
Comments & Postcards at olivier@rousso.ch !"
else
display alert "You ain't got enough songs to fill your iPod ! Your list is now " & displaysize & " GB which is " & displayless & " GB less than required. Go get some new tunes !
Comments & Postcards at olivier@rousso.ch !"
end if
else
display alert "That's it ! Your list is now " & displaysize & " GB which is " & displaymore & " GB more than required. If needed, remove manually some tracks.
Comments & Postcards at olivier@rousso.ch !"
end if
set name of playlist tempname to playlistname
on error
display dialog "Process cancelled by user or invalid entry..."
set name of playlist tempname to errorname
end try
end tell