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 "/PfadZuDeinemPlaylistOrdner/"
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 "Diese Datei existiert bereits " & playlist_name & ".m3u. Möchtest du diese Datei ersetzen?" buttons {"Abbrechen", "Forftahren"} 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, "/Volumes", "/media")
set encoded_posixloc to my encode_text(new_posixloc, true, false)
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 {"abbrechen"} 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