Apple Script & chemin FTP

ramien

Membre confirmé
24 Août 2010
11
0
Bonjour à tous,
J'utilise un petit script qui upload un fichier html sur mon serveur, contenant les 3 derniers sons joués par iTunes.

Le problème c'est que j'ai changé d'hébergement. La racine de mon site est contenu dans un dossier "www"
J'aimerai donc savoir si quelqu'un sait ce que je dois modifier pour que le fichier HTML soit uploadé dans le dossier www

Voiçi le code.
Merci d'avance,
Damien

Bloc de code:
global ftp_Login, data_dir, t_id, ecrit

on run
	set ftp_address to "ftp.****" -- votre adresse FTP 
	set ftp_user to "*********" --  nom d'utilisateur FTP
	set ftp_password to "*****" -- votre mot de passe FTP	
	
	set data_dir to ((path to me) as string) & "Contents:"
	set ftp_Login to ftp_user & ":" & ftp_password & " " & ftp_address
	set t_id to 0
	try
		("" & data_dir & "currentTrack.html") as alias --le fichier existe, garde les dernieres infos
	on error
		-- le fichier n'existe pas, creation du fichier html, contient aucun texte
		do shell script "cd " & (quoted form of POSIX path of data_dir) & " && /bin/echo '<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">
<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></HEAD><BODY>
<div id=\"1\"<img src=\"artwork_1.jpg\" align=\"left\" width=\"50\" height=\"50\" />
<div id=\"titre\">...</div><div id=\"artiste\">...</div><br></div>
<div id=\"2\"<img src=\"artwork_2.jpg\" align=\"left\" width=\"50\" height=\"50\" />
<div id=\"titre\">...</div><div id=\"artiste\">...</div><br></div>
<div id=\"3\"<img src=\"artwork_3.jpg\" align=\"left\" width=\"50\" height=\"50\" />
<div id=\"titre\">...</div><div id=\"artiste\">...</div></div>
</BODY></HTML>' > currentTrack.html
touch artwork_1.jpg;touch artwork_2.jpg;touch artwork_3.jpg"
	end try
end run

on idle
	try
		tell application "iTunes" to if running and player state is playing then my getCurrentTrack()
	end try
	return 15 -- nombre de secondes avant la prochaibe vérification
end idle

on getCurrentTrack() -- subroutineto get the current track from itunes
	tell application "iTunes" to tell current track
		set currID to database ID
		if currID is not t_id then -- piste différente
			set ecrit to false
			if exists artworks then
				set t_data to data of artwork 1
			else -- aucun artwork, crée une image d'un point d'interogation
				set t_data to «data PICT03640000000000320032001102FF0C00FFFE00000048000000480000000000000032003200000000001F800080008000001E0001000A000000000032003282000000029C000000010000000000000000000000000000000100000000000000000000000000004000000000000000000000000000000000400000000000320032000003000000000000000056706E67200000000000000000000000006170706C000000000000040000320032004800000048000000000202000103504E47000000000000000000000000000000000000000000000000000000000018FFFF89504E470D0A1A0A0000000D4948445200000032000000320802000000915D1FE6000000097048597300000B1300000B1301009A9C18000001B4494441545809ED563DCA8340108D1FB10868914ED24B2CBD416CBC8720E805D26A9163A44B95C63EA710827636365616B108A409C46FC28224B84566768510760B19C7F979BE37EEAAF57D3FFBBEF5F77D909E88142C8C2E8A2DC51686014C2C65B6B85B1DD78941F216ABC92DF7565BE086C29640BB4F5325C09A826F25E2A7023EE3E698607E2C8858555559969665B9AE6B18063F0EE585A222EB72B9F8BE3F745C2C16C7E351A420CB9D099688A208301D0E87B66DB32CB36D1B6EF33C7F3C1E2295E9B058E3DD6E97A6E98000A80258E01C3C34033D5BD046D334E8CDAE4992803DACD56A05367B34382906ED6DB859F7FBDDF3BCE57259D73537E073275DC4718F300C755D3F9D4EEC91C8784983B5DFEF413B98FA315C82470EACDBED669A661CC70404DC140967224C745114D7EB75B3D950A69B972307D6F97C86E28EE3F05A507C7260ADD7EBED76CB76070A8A51CE4FFF41C0A6100441D334A3D7263AE48808BF0F702C765D4744314AA388089FB484E36504E5D54181F59A3F914D1411089B08102BFB5B6C4D4A1514278AA8604DCD00A6BE1251B185610013AB664BB185610013AB664BB185610013FBA5B3F50FC1722669AF16BDEA0000000049454E44AE426082000700AE007C0007000100010003000300040000000D000C00100032003200E400E400280017000E10517569636B54696D65AA20657420756E0000280019000C11648E636F6D707265737365757220504E470028001B000027736F6E742072657175697320706F757220766973696F6E6E657220636574746520696D6167652E000000FF»
			end if
			
			set ecrit to my write_to_file(get name, get artist, t_data)
			if ecrit then
				set t_id to currID
				set b to my uploadFile()
				if b then set ecrit to false
			end if
		else -- meme piste
			if ecrit then -- mais pas uploadé
				set b to my uploadFile()
				if b then set ecrit to false
			end if
		end if
	end tell
end getCurrentTrack

on write_to_file(titre, artiste, t_data)
	set newText to ""
	set data_file to ("" & data_dir & "currentTrack.html")
	set t to read alias data_file as «class utf8»
	set tP to paragraphs of t
	set J to 0
	set rc to character id 10
	repeat with ligne in tP
		set p to contents of ligne
		if p starts with "<div id=\"titre\"" then
			set J to J + 1
			if J = 1 then -- insere les infos de la nouvelle piste à la premiere position
				set newText to newText & "<div id=\"titre\">&nbsp;&nbsp;" & titre & "</div><div id=\"artiste\">&nbsp;&nbsp;" & artiste & "</div><br></div>" & rc
				set firstP to p
			else if J = 2 then -- insere les infos de la piste 1 à la deuxieme position
				set newText to newText & firstP & rc
				set secondP to p
			else if J = 3 then --insere les infos de la piste 2 à la troisieme position
				set newText to newText & secondP & rc
			end if
		else if p ends with "</HTML>" then
			set newText to newText & p
			exit repeat
		else
			set newText to newText & p & rc
		end if
	end repeat
	try
		set the open_target_file to open for access file data_file with write permission
		set eof of the open_target_file to 0
		write newText to the open_target_file as «class utf8»
		close access the open_target_file
	on error
		close access data_file
		return false
	end try
	
	set The_CD to (quoted form of POSIX path of data_dir)
	
	-- change les positions des images, renomme --> jaquette 2 devient 3, jaquette 1 devient 2
	do shell script "cd " & The_CD & " &&  /bin/mv -f artwork_2.jpg artwork_3.jpg; /bin/mv -f artwork_1.jpg artwork_2.jpg"
	set pictFile to "" & data_dir & "artwork_1.jpg"
	try
		set the open_target_file to open for access file pictFile with write permission
		set eof open_target_file to 0
		write "" to open_target_file starting at eof -- efface le contenu du fichier
		set eof open_target_file to 512
		write t_data to open_target_file starting at 513 -- fichier au format pict 
		close access the open_target_file
	on error
		close access pictFile
	end try
	-- converti le pict au format JPEG, 50 pixels x 50 pixels, qualité 95 pourcent
	do shell script "/usr/bin/sips -z 50 50 -s format jpeg  -s formatOptions 95 " & quoted form of POSIX path of pictFile
	return true
end write_to_file

on uploadFile() -- upload  les trois fichiers artwork_x et le fichier HTML (les infos des trois derniere pistes)
	try
		set The_CD to (quoted form of POSIX path of data_dir)
		with timeout of 50 seconds
			do shell script "cd " & The_CD & " && /usr/bin/curl -s -m 120 -T \"{currentTrack.html,artwork_1.jpg,artwork_2.jpg,artwork_3.jpg}\" -u " & ftp_Login
			return true
		end timeout
	on error
		return false
	end try
end uploadFile

on quit
	continue quit
end quit