iTunes: automat. Wiedergabelisten-Export (m3u8) mit Applescript

TGY

TGY

Aktives Mitglied
Thread Starter
Dabei seit
12.04.2004
Beiträge
1.129
Reaktionspunkte
104
Hallo.

Ich suche eine Möglichkeit, mit Applescript ausgewählte oder vorher festgelegte Wiedergabelisten automatisch als m3u8-Wiedergabelisten zu exportieren. Ich möchte Applescript nicht nur nutzen, weil es einfacher und schneller als ein Rechtsklick auf mehrere Wiedergabelisten ist, sondern vor allem weil das Skript die exportierten Wiedergabelisten hinterher weiterverarbeiten soll.

Weiß jemand, mit welchen Applescript-Befehl ich iTunes dazu bringe, eine ausgewählte oder angegebene Wiedergabeliste als m3u8 Wiedergabeliste zu exportieren?

Ich habe zwar im Internet ähnliche Skripte gefunden, konnte aber meist nicht deren Code anschauen ("nur ausführbar").

Vielen Dank für Eure Hilfe.

TGY
 
Frei nach Bery Rinaldo:

Code:
[COLOR=#5E6161][FONT=Verdana]-- Adapted from Bery Rinaldo's "Export Playlist to M3U" script. The original copyright[/FONT][/COLOR][COLOR=#5E6161][FONT=Verdana]-- information for this script is as follows:[/FONT][/COLOR]
[FONT=Verdana]
[/FONT]
[COLOR=#5E6161][FONT=Verdana]-- Export Playlist to M3U[/FONT][/COLOR]
[COLOR=#5E6161][FONT=Verdana]--[/FONT][/COLOR]
[COLOR=#5E6161][FONT=Verdana]-- This AppleScript is used to output the current iTunes playlist into an M3U format file suitable for use with the AudioTron.[/FONT][/COLOR]
[FONT=Verdana]
[/FONT]
[COLOR=#5E6161][FONT=Verdana]-- Copyright (C) 2002 Bery Rinaldo [/FONT][/COLOR]
[COLOR=#5E6161][FONT=Verdana]--[/FONT][/COLOR]
[COLOR=#5E6161][FONT=Verdana]-- This program is free software; you can redistribute it and/or modify it under the terms[/FONT][/COLOR]
[COLOR=#5E6161][FONT=Verdana]-- of the GNU General Public License as published by the Free Software Foundation; either[/FONT][/COLOR]
[COLOR=#5E6161][FONT=Verdana]-- version 2 of the License, or (at your option) any later version. [/FONT][/COLOR]
[COLOR=#5E6161][FONT=Verdana]--[/FONT][/COLOR]
[COLOR=#5E6161][FONT=Verdana]-- This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; [/FONT][/COLOR]
[COLOR=#5E6161][FONT=Verdana]-- without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.[/FONT][/COLOR]
[COLOR=#5E6161][FONT=Verdana]-- See the GNU General Public License for more details. [/FONT][/COLOR]
[COLOR=#5E6161][FONT=Verdana]--[/FONT][/COLOR]
[COLOR=#5E6161][FONT=Verdana]-- You should have received a copy of the GNU General Public License along with this program; if not, [/FONT][/COLOR]
[COLOR=#5E6161][FONT=Verdana]-- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. [/FONT][/COLOR]
[FONT=Verdana]
[/FONT]
[COLOR=#5E6161][FONT=Verdana]-- Script written by Bery Rinaldo beryrinaldo@mac.com on 18-March-2002[/FONT][/COLOR]
[COLOR=#5E6161][FONT=Verdana]--[/FONT][/COLOR]
[FONT=Verdana]
[/FONT]
[FONT=Verdana]
[/FONT]
[FONT=Verdana][B]property[/B] [COLOR=#4f8f00]|linefeed|[/COLOR] : [COLOR=#012fbe][B]ASCII character[/B][/COLOR] 10[/FONT]
[FONT=Verdana]
[/FONT]
[FONT=Verdana][B]try[/B][/FONT]
[FONT=Verdana]    [B]with[/B] [B]timeout[/B] [B]of[/B] 1800 [COLOR=#0433ff][I]seconds[/I][/COLOR][/FONT]
[FONT=Verdana]        [/FONT]
[FONT=Verdana]        [B]tell[/B] [COLOR=#0433ff][I]application[/I][/COLOR] "iTunes"[/FONT]
[FONT=Verdana]            [B]set[/B] [COLOR=#4f8f00]playlist_names[/COLOR] [B]to[/B] [COLOR=#812fdc]name[/COLOR] [B]of[/B] [COLOR=#0433ff][I]user playlists[/I][/COLOR][/FONT]
[FONT=Verdana]            [B]set[/B] [B]the[/B] [COLOR=#4f8f00]playlist_text[/COLOR] [B]to[/B] ""[/FONT]
[COLOR=#4F8F00][FONT=Verdana][COLOR=#000000]            [B]set[/B] [B]the[/B] [/COLOR]playlist_name[COLOR=#000000] [B]to[/B] [/COLOR][COLOR=#0433ff][I]item[/I][/COLOR][COLOR=#000000] 1 [B]of[/B] ([/COLOR][COLOR=#012fbe][B]choose from list [/B][/COLOR]playlist_names[COLOR=#000000])[/COLOR][/FONT][/COLOR]
[FONT=Verdana]            [B]set[/B] [B]the[/B] [COLOR=#4f8f00]export_folder[/COLOR] [B]to[/B] [COLOR=#812fdc]POSIX path[/COLOR] [B]of[/B] ([COLOR=#012fbe][B]choose folder[/B][/COLOR])[/FONT]
[COLOR=#4F8F00][FONT=Verdana][COLOR=#000000]            [B]set[/B] [B]the[/B] [/COLOR]target_file[COLOR=#000000] [B]to[/B] [/COLOR]export_folder[COLOR=#000000] & [/COLOR]playlist_name[COLOR=#000000] & ".m3u" [B]as[/B] [/COLOR][COLOR=#0433ff][I]Unicode text[/I][/COLOR][/FONT][/COLOR]
[COLOR=#4F8F00][FONT=Verdana][COLOR=#000000]            [B]tell[/B] [/COLOR][COLOR=#0433ff][I]playlist [/I][/COLOR]playlist_name[/FONT][/COLOR]
[FONT=Verdana]                [B]set[/B] [B]the[/B] [COLOR=#4f8f00]track_count[/COLOR] [B]to[/B] [B]the[/B] [COLOR=#0433ff][B]count[/B][/COLOR] [B]of[/B] [COLOR=#0433ff][I]tracks[/I][/COLOR][/FONT]
[FONT=Verdana]            [B]end[/B] [B]tell[/B][/FONT]
[FONT=Verdana]            [B]repeat[/B] [B]with[/B] [COLOR=#4f8f00]z[/COLOR] [B]from[/B] 1 [B]to[/B] [B]the[/B] [COLOR=#4f8f00]track_count[/COLOR][/FONT]
[FONT=Verdana]                [B]tell[/B] [COLOR=#0433ff][I]track[/I][/COLOR] [COLOR=#4f8f00]z[/COLOR] [B]of[/B] [COLOR=#0433ff][I]playlist[/I][/COLOR] [COLOR=#4f8f00]playlist_name[/COLOR][/FONT]
[FONT=Verdana]                    [B]copy[/B] {[COLOR=#812fdc]location[/COLOR]} [B]to[/B] {[COLOR=#4f8f00]loc[/COLOR]}[/FONT]
[FONT=Verdana]                [B]end[/B] [B]tell[/B][/FONT]
[FONT=Verdana]                [B]set[/B] [B]the[/B] [COLOR=#4f8f00]posixloc[/COLOR] [B]to[/B] [COLOR=#812fdc]POSIX path[/COLOR] [B]of[/B] [COLOR=#4f8f00]loc[/COLOR][/FONT]
[COLOR=#4F8F00][FONT=Verdana][COLOR=#000000]                [B]set[/B] [B]the[/B] [/COLOR]playlist_text[COLOR=#000000] [B]to[/B] [B]the[/B] [/COLOR]playlist_text[COLOR=#000000] & [/COLOR]posixloc[COLOR=#000000] & [/COLOR]|linefeed|[/FONT][/COLOR]
[FONT=Verdana]            [B]end[/B] [B]repeat[/B][/FONT]
[FONT=Verdana]        [B]end[/B] [B]tell[/B][/FONT]
[COLOR=#4F8F00][FONT=Verdana][COLOR=#000000]        [B]set[/B] [/COLOR]this_result[COLOR=#000000] [B]to[/B] [B]my[/B] [/COLOR]write_to_file[COLOR=#000000]([/COLOR]playlist_text[COLOR=#000000], [/COLOR][COLOR=#012fbe][I]POSIX file [/I][/COLOR]target_file[COLOR=#000000])[/COLOR][/FONT][/COLOR]
[FONT=Verdana]        [B]if[/B] [COLOR=#4f8f00]this_result[/COLOR] [B]is[/B] [B]not[/B] [COLOR=#5d3292]true[/COLOR] [B]then[/B][/FONT]
[COLOR=#5E6161][FONT=Verdana][COLOR=#000000]            [B]error[/B] [/COLOR][COLOR=#4f8f00]this_result[/COLOR]-- There was a problem writing the playlist file.[/FONT][/COLOR]
[FONT=Verdana]        [B]end[/B] [B]if[/B][/FONT]
[FONT=Verdana]    [B]end[/B] [B]timeout[/B][/FONT]
[COLOR=#4F8F00][FONT=Verdana][COLOR=#000000][B]on[/B] [B]error[/B] [/COLOR]error_message [COLOR=#0433ff]number [/COLOR]error_number[/FONT][/COLOR]
[FONT=Verdana]    [B]tell[/B] [COLOR=#0433ff][I]application[/I][/COLOR] "iTunes"[/FONT]
[FONT=Verdana]        [B]if[/B] [B]the[/B] [COLOR=#4f8f00]error_number[/COLOR] [B]is[/B] [B]not[/B] -128 [B]then[/B][/FONT]
[COLOR=#012FBE][FONT=Verdana][COLOR=#000000]            [/COLOR][B]beep[/B][/FONT][/COLOR]
[COLOR=#012FBE][FONT=Verdana][COLOR=#000000]            [/COLOR][B]display dialog [/B][COLOR=#4f8f00]error_message [/COLOR]buttons[COLOR=#000000] {"Cancel"} [/COLOR]default button[COLOR=#000000] 1[/COLOR][/FONT][/COLOR]
[FONT=Verdana]        [B]end[/B] [B]if[/B][/FONT]
[FONT=Verdana]    [B]end[/B] [B]tell[/B][/FONT]
[FONT=Verdana][B]end[/B] [B]try[/B][/FONT]
[FONT=Verdana]
[/FONT]
[COLOR=#4F8F00][FONT=Verdana][COLOR=#000000][B]on[/B] [/COLOR]write_to_file[COLOR=#000000]([/COLOR]this_data[COLOR=#000000], [/COLOR]target_file[COLOR=#000000])[/COLOR][/FONT][/COLOR]
[FONT=Verdana]    [B]try[/B][/FONT]
[FONT=Verdana]        [B]set[/B] [B]the[/B] [COLOR=#4f8f00]target_file[/COLOR] [B]to[/B] [B]the[/B] [COLOR=#4f8f00]target_file[/COLOR] [B]as[/B] [COLOR=#0433ff][I]Unicode text[/I][/COLOR][/FONT]
[COLOR=#012FBE][FONT=Verdana][COLOR=#000000]        [B]set[/B] [B]the[/B] [/COLOR][COLOR=#4f8f00]open_target_file[/COLOR][COLOR=#000000] [B]to[/B] [/COLOR][B]open for access [/B][COLOR=#0433ff][I]file [/I][/COLOR][COLOR=#4f8f00]target_file[/COLOR][COLOR=#000000] [B]with[/B] [/COLOR]write permission[/FONT][/COLOR]
[COLOR=#4F8F00][FONT=Verdana][COLOR=#000000]        [/COLOR][COLOR=#012fbe][B]set eof [/B][/COLOR]open_target_file [COLOR=#012fbe]to[/COLOR][COLOR=#000000] 0[/COLOR][/FONT][/COLOR]
[COLOR=#4F8F00][FONT=Verdana][COLOR=#000000]        [/COLOR][COLOR=#012fbe][B]write [/B][/COLOR]this_data [COLOR=#012fbe]to[/COLOR][COLOR=#000000] [B]the[/B] [/COLOR]open_target_file[/FONT][/COLOR]
[COLOR=#4F8F00][FONT=Verdana][COLOR=#000000]        [/COLOR][COLOR=#012fbe][B]close access[/B][/COLOR][COLOR=#000000] [B]the[/B] [/COLOR]open_target_file[/FONT][/COLOR]
[FONT=Verdana]        [B]return[/B] [COLOR=#5d3292]true[/COLOR][/FONT]
[COLOR=#4F8F00][FONT=Verdana][COLOR=#000000]    [B]on[/B] [B]error[/B] [/COLOR]error_message[/FONT][/COLOR]
[FONT=Verdana]        [B]try[/B][/FONT]
[COLOR=#012FBE][FONT=Verdana][COLOR=#000000]            [/COLOR][B]close access [/B][COLOR=#0433ff][I]file [/I][/COLOR][COLOR=#4f8f00]target_file[/COLOR][/FONT][/COLOR]
[FONT=Verdana]        [B]end[/B] [B]try[/B][/FONT]
[COLOR=#4F8F00][FONT=Verdana][COLOR=#000000]        [B]return[/B] [/COLOR]error_message[/FONT][/COLOR]
[FONT=Verdana]    [B]end[/B] [B]try[/B][/FONT]
[COLOR=#000000][FONT=Verdana][B]end[/B] [/FONT][/COLOR][COLOR=#4F8F00][FONT=Verdana]write_to_file[/FONT][/COLOR]
 
  • Gefällt mir
Reaktionen: TGY
Vielen Dank!!! Hab dadurch viel Zeit gespart. Ich habe das Skript ein wenig abgewandelt und erweitert:

- Es überprüft nun, ob eine gleichnamige Datei am angegebenen Speicherort bereits vorhanden ist.
- Der Dateipfad der Musikdateien wird geändert, da die Wiedergabeliste auf die Dateien verweisen soll, die auf meinem NAS liegen ("extdisk/iTunes Media" wird bei mir durch "music" ersetzt).
- Und die m3u-Wiedergabeliste ist formal konform mit den Anforderungen des Logitech Media Servers (LMS).


Code:
-- Adapted from Bery Rinaldo's "Export Playlist to M3U" script. The original copyright-- information for this script is as follows:


-- Export Playlist to M3U
--
-- This AppleScript is used to output the current iTunes playlist into an M3U format file suitable for use with the AudioTron.


-- Copyright (C) 2002 Bery Rinaldo 
--
-- This program is free software; you can redistribute it and/or modify it under the terms
-- of the GNU General Public License as published by the Free Software Foundation; either
-- version 2 of the License, or (at your option) any later version. 
--
-- This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
-- without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-- See the GNU General Public License for more details. 
--
-- You should have received a copy of the GNU General Public License along with this program; if not, 
-- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 


-- Script written by Bery Rinaldo beryrinaldo@mac.com on 18-March-2002
--




property |linefeed| : ASCII character 10


try
	with timeout of 1800 seconds
		
		tell application "iTunes"
			set playlist_names to name of user playlists
			set the playlist_text to "#CURTRACK 0" & |linefeed|
			set the playlist_name to item 1 of (choose from list playlist_names)
			set the export_folder to POSIX path of (choose folder)
			set the target_file to export_folder & playlist_name & ".m3u" as Unicode text
			tell application "System Events" to set fileExists to exists disk item (my POSIX file target_file as string)
			if the result then
				display dialog "There is already a file named " & playlist_name & ".m3u. Do you want to replace the file?" buttons {"Cancel", "Proceed"} cancel button 1 with icon caution
			end if
			tell playlist playlist_name
				set the track_count to the count of tracks
			end tell
			repeat with z from 1 to the track_count
				tell track z of playlist playlist_name
					copy {location} to {loc}
				end tell
				set name_z to name of (track z of playlist playlist_name)
				set time_z to duration of (track z of playlist playlist_name)
				set time_z to round (time_z) rounding down
				set the posixloc to POSIX path of loc as text
				set new_posixloc to my replace_chars(posixloc, "extdisk/iTunes Media", "music")
				set encoded_posixloc to my encode_text(new_posixloc, true, false)
				set the playlist_text to the playlist_text & "#EXTURL:file://" & encoded_posixloc & |linefeed|
				set the playlist_text to the playlist_text & "#EXTINF:" & time_z & "," & name_z & |linefeed|
				set the playlist_text to the playlist_text & new_posixloc & |linefeed|
			end repeat
		end tell
		set this_result to my write_to_file(playlist_text, POSIX file target_file)
		if this_result is not true then
			error this_result -- There was a problem writing the playlist file.
		end if
	end timeout
on error error_message number error_number
	tell application "iTunes"
		if the error_number is not -128 then
			beep
			display dialog error_message buttons {"Cancel"} default button 1
		end if
	end tell
end try

on write_to_file(this_data, target_file)
	try
		set the target_file to the target_file as Unicode text
		set the open_target_file to open for access file target_file with write permission
		set eof open_target_file to 0
		write this_data to the open_target_file
		close access the open_target_file
		return true
	on error error_message
		try
			close access file target_file
		end try
		return error_message
	end try
end write_to_file

on replace_chars(this_text, search_string, replacement_string)
	set AppleScript's text item delimiters to the search_string
	set the item_list to every text item of this_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

-- this sub-routine is used to encode text
on encode_text(this_text, encode_URL_A, encode_URL_B)
	set the standard_characters to "abcdefghijklmnopqrstuvwxyz0123456789"
	set the URL_A_chars to "$+!'?;&@=#%><{}[]\"~`^\\|*"
	set the URL_B_chars to ".-_:/()"
	set the acceptable_characters to the standard_characters
	if encode_URL_A is false then set the acceptable_characters to the acceptable_characters & the URL_A_chars
	if encode_URL_B is false then set the acceptable_characters to the acceptable_characters & the URL_B_chars
	set the encoded_text to ""
	repeat with this_char in this_text
		if this_char is in the acceptable_characters then
			set the encoded_text to (the encoded_text & this_char)
		else
			set the encoded_text to (the encoded_text & encode_char(this_char)) as string
		end if
	end repeat
	return the encoded_text
end encode_text

on encode_char(this_char)
	set the ASCII_num to (the ASCII number this_char)
	set the hex_list to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}
	set x to item ((ASCII_num div 16) + 1) of the hex_list
	set y to item ((ASCII_num mod 16) + 1) of the hex_list
	return ("%" & x & y) as string
end encode_char
 
Sehr cool, werde ich mal testen, wenn ich daheim bin. Wobei mein bisheriger Workaround nicht viel umständlicher war, aber das Script ist noch einfacher. Ich werde es für meinen DLNA Server noch modifizieren, aber soweit sieht es top aus.
 
Zurück
Oben Unten