[AppleScript] iTunes et popdcast

Clarusad

Membre actif
5 Février 2004
398
9
Bonjour,

Je n'arrive pas à télécharger les épisodes manquants à mon podcast ; j'ai bien cherché et essayé ceci :
Bloc de code:
tell application "iTunes"
set podcastplaylist to some playlist whose special kind is Podcasts
set podcastcinema to (some track of podcastplaylist whose artist is "www.filmtrailer.com")
updatePodcast podcastcinema
mais ça ne fonctionne pas.
Auriez-vous une idée ?
 
Je n'ai pas encore piloté iTunes avec Applescript, mais ce ne serait pas plutot "every" au lieu de "some" ?

En plus un "end tell" à la fin, çà ne serait pas mal...

Bloc de code:
set podcastcinema to (every track of podcastplaylist whose artist is "www.filmtrailer.com")
 
Si les podcasts disponibles sont affichés dans iTunes, c'est ce script :

Bloc de code:
tell application "iTunes"
	set podcastplaylist to first playlist whose special kind is Podcasts
	--  URL tracks sont les podcasts qui ne sont pas téléchargés
	repeat with t_podcast in (get URL tracks of podcastplaylist whose album is "Filmtrailer.com: brand new film trailers")
		download t_podcast
	end repeat
end tell
 
Super ça fonctionne !
Merci Mac_Jac.

Pour que ça soit parfait, il me reste à trouver comment savoir si iTunes télécharge, ou pas.
Un truc du genre : "is downloading" qui me retournerait le booléen false ou true...

Comme ça je pourrais faire une boucle qui :
1) tant qu'il télécharge, on attend.
2) Ensuite on quitte iTunes.
3) Ensuite on quitte le script.
 
Super ça fonctionne !
Pour que ça soit parfait, il me reste à trouver comment savoir si iTunes télécharge, ou pas.
Un truc du genre : "is downloading" qui me retournerait le booléen false ou true...
Il n'y a pas de commande pour savoir quand il télécharge ou quand le téléchargement est terminé.

Mais, la solution est de vérifier la taille du dossier "Podcasts" dans le dossier "Downloads" de iTunes.

Voici le script
Bloc de code:
try
	run script (do shell script "/usr/bin/defaults read com.apple.iTunes  'alis:1:iTunes Library Location'  | /usr/bin/sed 's/ //g;s/</«data alis/;s/>/»/'")
	set podcastDownload to (the result as string) & "iTunes Media:Downloads:Podcasts:" -- emplacement par défaut
on error
	run script (do shell script "/usr/bin/defaults read com.apple.iTunes  'alis:11345:Music Folder Location'  | /usr/bin/sed 's/ //g;s/</«data alis/;s/>/»/'")
	set podcastDownload to (the result as string) & "Downloads:Podcasts:" -- emplacement personnalisé
end try

set t_size to 0
try
	set t_size to size of (info for (podcastDownload as alias))
end try

tell application "iTunes"
	set podcastplaylist to first playlist whose special kind is Podcasts
	set url_tracks to URL tracks of podcastplaylist whose album is "Filmtrailer.com: brand new film trailers"
	if url_tracks is not {} then
		repeat with t_podcast in url_tracks
			download t_podcast
		end repeat
		my checkSize(podcastDownload, t_size)
	end if
	quit
end tell


on checkSize(f, n)
	try (* un try à cause qu'iTunes supprime le dossier "Podcasts" du dossier "Downloads"
		 si les téléchagements sont tous terminés et si aucun téléchagement est suspendu ou arrêté*)
		repeat
			delay 60
			set n1 to size of (info for (f as alias))
			if n1 = n then exit repeat -- meme taille après une minute = aucun téléchargement en cours
			set n to n1
		end repeat
	end try
end checkSize
 
Merci l'ami :)
Je cherchais un truc du genre
Bloc de code:
if player state is playing then ...
mais cette solution fonctionne tout aussi bien.