text
stringlengths
0
15.7k
source
stringlengths
6
112
set numberSongs to (get count of tracks of thisPlaylist)
ExportPlaylists.applescript
if numberSongs = 0 then
ExportPlaylists.applescript
set thePlaylistsNumberZero to (thePlaylistsNumberZero + 1)
ExportPlaylists.applescript
set thePlaylistsNumberGood to (thePlaylistsNumberGood - 1)
ExportPlaylists.applescript
set the end of thePlaylistsNamesLength to ({thisPlaylistName, " (", numberSongs, " songs)"} as string)
ExportPlaylists.applescript
set AppleScript's text item delimiters to (return as string)
ExportPlaylists.applescript
set thePlaylistsDisplay to (thePlaylistsNamesLength as string)
ExportPlaylists.applescript
if thePlaylistsNumberInvalid = 1 then
ExportPlaylists.applescript
set delimiter_s to " delimiter. It"
ExportPlaylists.applescript
set delimiter_s to " delimiters. These"
ExportPlaylists.applescript
if thePlaylistsNumberZero = 1 then
ExportPlaylists.applescript
set playlist_s0 to "playlist. It"
ExportPlaylists.applescript
set playlist_s0 to "playlists. These"
ExportPlaylists.applescript
if thePlaylistsNumberGood = 1 then
ExportPlaylists.applescript
set playlist_s to " playlist"
ExportPlaylists.applescript
set playlist_s to " playlists"
ExportPlaylists.applescript
if (thePlaylistsNumberInvalid > 0) then
ExportPlaylists.applescript
set message to message & ({return, "- You have chosen ", thePlaylistsNumberInvalid, delimiter_s, " will be ignored."} as string)
ExportPlaylists.applescript
if (thePlaylistsNumberZero > 0) then
ExportPlaylists.applescript
set message to message & ({return, "- You have chosen ", thePlaylistsNumberZero, " empty ", playlist_s0, " will be ignored."} as string)
ExportPlaylists.applescript
if ((thePlaylistsNumberInvalid > 0) or (thePlaylistsNumberZero > 0)) then
ExportPlaylists.applescript
display dialog ({"Issues:", message} as string) with title myTitle buttons {"Cancel", "Continue"} default button 1 with icon iconWarning giving up after 10
ExportPlaylists.applescript
set button to button returned of (display dialog ({"The ", thePlaylistsNumberGood, playlist_s, " to export: ", return, return, thePlaylistsDisplay} as string) with title myTitle buttons {"Cancel", "Proceed"} default button 2 with icon iconApp giving up after 10)
ExportPlaylists.applescript
my log_out((thePlaylistsNumberGood & playlist_s & " to export:") as string, thePlaylistsDisplay)
ExportPlaylists.applescript
set folderPath to (choose folder with prompt "Choose the folder in which to export the playlists:" default location path to desktop)
ExportPlaylists.applescript
set folderPathPOSIX to POSIX path of folderPath
ExportPlaylists.applescript
if thePlaylistsNumberGood > 1 then
ExportPlaylists.applescript
set folderChoice to button returned of (display dialog ({"Would you like to save the playlists in the same folder or in different folders?", return, return, return, ¬ "Summary:", return, return, ¬ "Same folder - Create a new folder in the location chosen and place all songs from all playlists there. Create a subfolder and place all m3u playlist files in it.", return, return, ¬ "Different folders - Make separate subfolders for each playlist in the location chosen. The m3u playlist file is placed in the subfolder, and a further subfolder is created for the songs."} as string) with title myTitle buttons {"Cancel", "Same folder", "Different folders"} default button 1)
ExportPlaylists.applescript
set folderChoice to "Different folders"
ExportPlaylists.applescript
my log_out("Saving mode:", folderChoice)
ExportPlaylists.applescript
set availableAttributes to {"[album]", "[album artist]", "[artist]", "[composer]", "[track name]", "[track number]", "[disc number]", "[playlist order number]", "[original file name]"}
ExportPlaylists.applescript
set availableAttributesDisplay to (availableAttributes as string)
ExportPlaylists.applescript
set folderStructure to text returned of (display dialog ({"Choose the folder structure for the exported files.", return, return, return, ¬ "AVAILABLE ATTRIBUTES:", return, availableAttributesDisplay, return, return, ¬ "EXAMPLE:", return, "[artist] > [album] > [track number] - [track name]", return, " means", return, "In the music subfolder folder, make a folder for ARTIST, then make a folder for ALBUM inside this, then copy the files inside that, with the name structure \"[track number] - [track name]\"", return, return, ¬ "NOTE: The last item (filename) must include [file name] or [track name] or [original file name]!"} as string) with title myTitle buttons {"Cancel", "OK"} default button 2 default answer "")
ExportPlaylists.applescript
if folderStructure is "" then
ExportPlaylists.applescript
display dialog ({"WARNING:", return, "No attributes were chosen!", return, return, "The value used will be", return, " [original file name]"} as string) with title myTitle buttons {"Cancel", "Proceed"} default button 2 with icon iconWarning giving up after 10
ExportPlaylists.applescript
set folderStructure to "[original file name]"
ExportPlaylists.applescript
my log_out("Attributes chosen:", folderStructure)
ExportPlaylists.applescript
set AppleScript's text item delimiters to (" > ")
ExportPlaylists.applescript
set folderStructure_NewFolders to every text item of folderStructure
ExportPlaylists.applescript
log ({"Specified folder structure:", folderStructure_NewFolders, return} as string)
ExportPlaylists.applescript
set fileName to ((item -1 of folderStructure_NewFolders) as string)
ExportPlaylists.applescript
if (("[file name]" is not in fileName) and ("[track name]" is not in fileName) and ("[original file name]" is not in fileName)) then
ExportPlaylists.applescript
error ({"ERROR: The filename template given was", return, " ", fileName, return, "which does not contain [file name] or [track name] or [original file name]. Cannot continue."} as string) number 1
ExportPlaylists.applescript
set attrLength to (count of availableAttributes)
ExportPlaylists.applescript
set attrShow to {}
ExportPlaylists.applescript
repeat with attr from 1 to attrLength
ExportPlaylists.applescript
set the end of attrShow to null
ExportPlaylists.applescript
if folderStructure contains (item attr of availableAttributes) then
ExportPlaylists.applescript
set (item attr of attrShow) to true
ExportPlaylists.applescript
set (item attr of attrShow) to false
ExportPlaylists.applescript
if ((item 5 of attrShow) = true) then
ExportPlaylists.applescript
set nameChoice to button returned of (display dialog ({"You have included the Track Name. For tracks that have a work name and movement number set (usually classical music), would you like to use the work name or the track name?", return, return, "(If unsure, select 'Track Name'.)"} as string) with title myTitle buttons {"Cancel", "Work name", "Track name"} default button 3 with icon iconApp giving up after 60)
ExportPlaylists.applescript
if (nameChoice = "Track name") then
ExportPlaylists.applescript
set nameChoice to true
ExportPlaylists.applescript
else if (nameChoice = "Work name") then
ExportPlaylists.applescript
set nameChoice to false
ExportPlaylists.applescript
else if (nameChoice = "") then
ExportPlaylists.applescript
on error number -128 ------ "Cancel" button
ExportPlaylists.applescript
set thePlaylists to {}
ExportPlaylists.applescript
set thePlaylistsClean to {}
ExportPlaylists.applescript
repeat with i from 1 to thePlaylistsNumberGood ------ for each playlist:
ExportPlaylists.applescript
repeat 1 times ------ to allow skipping
ExportPlaylists.applescript
set tmp_list to {}
ExportPlaylists.applescript
set thisPlaylistNameClean to my clean_name(thisPlaylistName)
ExportPlaylists.applescript
if thePlaylistsClean does not contain thisPlaylistNameClean then
ExportPlaylists.applescript
set the end of thePlaylistsClean to thisPlaylistNameClean
ExportPlaylists.applescript
set {thisPlaylistNameClean, thePlaylistsClean} to my fix_duplicate("playlist", thisPlaylistName, thisPlaylistNameClean, thePlaylistsClean)
ExportPlaylists.applescript
if (thisPlaylistNameClean = "exit repeat") then
ExportPlaylists.applescript
set thePlaylistsNumberGood to thePlaylistsNumberGood - 1
ExportPlaylists.applescript
set the end of tmp_list to thisPlaylist
ExportPlaylists.applescript
set the end of tmp_list to thisPlaylistNameClean
ExportPlaylists.applescript
set the end of tmp_list to (get count of tracks of thisPlaylist)
ExportPlaylists.applescript
set the end of thePlaylists to tmp_list
ExportPlaylists.applescript
end repeat ------ to allow skipping
ExportPlaylists.applescript
end repeat ------ for each playlist
ExportPlaylists.applescript
if (folderChoice = "Same folder") then
ExportPlaylists.applescript
set newName to "iTunes Export"
ExportPlaylists.applescript
set rootPathExists to my folder_exists(folderPathPOSIX, newName, "d")
ExportPlaylists.applescript
if not rootPathExists then
ExportPlaylists.applescript
set rootPath to my make_dir(folderPathPOSIX, newName)
ExportPlaylists.applescript
set rootPath to {POSIX path of folderPath as string, newName, "/"} as string
ExportPlaylists.applescript
set newName to "_Playlists"
ExportPlaylists.applescript
set playlistsPathExists to my folder_exists(rootPath, newName, "d")
ExportPlaylists.applescript
if not playlistsPathExists then
ExportPlaylists.applescript
set playlistsPath to my make_dir(rootPath, newName)
ExportPlaylists.applescript
set playlistsPath to {POSIX path of rootPath as string, newName, "/"} as string
ExportPlaylists.applescript
set musicPath to rootPath
ExportPlaylists.applescript
else if (folderChoice = "Different folders") then
ExportPlaylists.applescript
set rootPath to (POSIX path of folderPath as string)
ExportPlaylists.applescript
if (i = 2) then
ExportPlaylists.applescript
set songsExported to (songsExported + 1)
ExportPlaylists.applescript
set thisPlaylistDetails to (item i of thePlaylists)
ExportPlaylists.applescript
set thisPlaylist to (item 1 of thisPlaylistDetails)
ExportPlaylists.applescript
set thisPlaylistName to (get name of thisPlaylist)
ExportPlaylists.applescript
set thisPlaylistNameClean to (item 2 of thisPlaylistDetails)
ExportPlaylists.applescript
set thisPlaylistNumberSongs to (item 3 of thisPlaylistDetails)
ExportPlaylists.applescript
log ({delim, return, "Exporting playlist: '", thisPlaylistName, "'", return, return} as string)
ExportPlaylists.applescript
if (folderChoice = "Different folders") then
ExportPlaylists.applescript
if not my folder_exists(rootPath, thisPlaylistNameClean, "d") then
ExportPlaylists.applescript
set playlistsPath to my make_dir(rootPath, thisPlaylistNameClean)
ExportPlaylists.applescript