text
stringlengths
0
15.7k
source
stringlengths
6
112
set skipChoice to button returned of (display dialog ({"Exporting playlist '", thisPlaylistName, "'.", return, ¬ "Folder exists:", return, " ", ({POSIX path of rootPath as string, thisPlaylistNameClean} as string), return, return, ¬
ExportPlaylists.applescript
"Would you like to skip this playlist or use the existing folder?"} as string) with title myTitle buttons {"Cancel", "Skip", "Use existing folder"} default button 3 with icon iconError)
ExportPlaylists.applescript
if (skipChoice = "Skip") then
ExportPlaylists.applescript
else if (skipChoice = "Use existing folder") then
ExportPlaylists.applescript
set playlistsPath to {POSIX path of rootPath as string, thisPlaylistNameClean, "/"} as string
ExportPlaylists.applescript
set newName to "Music"
ExportPlaylists.applescript
if not my folder_exists(playlistsPath, newName, "d") then
ExportPlaylists.applescript
set musicPath to my make_dir(playlistsPath, newName)
ExportPlaylists.applescript
set musicPath to {POSIX path of playlistsPath as string, newName, "/"} as string
ExportPlaylists.applescript
log ({"Folder structure:", return, ¬ "- Chosen folder: ", folderPathPOSIX, return, ¬ "- Root path: ", rootPath, return, ¬ "- Music path: ", musicPath, return, ¬ "- Playlists path: ", playlistsPath, return, return} as string)
ExportPlaylists.applescript
set playlistFileType to "m3u"
ExportPlaylists.applescript
set playlistFileName to ({thisPlaylistNameClean, ".", playlistFileType} as string)
ExportPlaylists.applescript
set playlistFileName to my truncate_name(playlistFileName, true)
ExportPlaylists.applescript
set playlistFilePath to {POSIX path of playlistsPath as string, thisPlaylistNameClean, ".", playlistFileType} as string
ExportPlaylists.applescript
try ------ if anything goes wrong, close the playlist file
ExportPlaylists.applescript
set thePlaylistFile to open for access (POSIX path of playlistFilePath) with write permission
ExportPlaylists.applescript
if (playlistFileType = "m3u") then
ExportPlaylists.applescript
tell current application to write ("#EXTM3U" & return) to thePlaylistFile starting at eof
ExportPlaylists.applescript
repeat with j from 1 to thisPlaylistNumberSongs ------ for each song:
ExportPlaylists.applescript
repeat 1 times ------ for skipping missing/duplicate songs
ExportPlaylists.applescript
set thisTrack to (get track j of thisPlaylist)
ExportPlaylists.applescript
set thisTrackDetails to my get_track_details(thisTrack)
ExportPlaylists.applescript
if ((item 4 of thisTrackDetails) is null) then
ExportPlaylists.applescript
set message to ({"MISSING DURATION: \"", (item 1 of thisTrackDetails as string), "\" by ", (item 2 of thisTrackDetails as string), return} as string)
ExportPlaylists.applescript
log message
ExportPlaylists.applescript
display dialog message with title myTitle buttons {"Continue"} default button 1 with icon iconError giving up after 10
ExportPlaylists.applescript
if (item 5 of thisTrackDetails) is equal to missing value then
ExportPlaylists.applescript
set message to ({"MISSING SONG: \"", (item 1 of thisTrackDetails as string), "\" by ", (item 2 of thisTrackDetails as string), return} as string)
ExportPlaylists.applescript
tell application "Finder" to set fileSize to size of file (item 5 of thisTrackDetails as string)
ExportPlaylists.applescript
set fileSize to (fileSize / 1.073741824E+9)
ExportPlaylists.applescript
if (fileSize ≥ 4) then
ExportPlaylists.applescript
set sizeChoice to button returned of (display dialog ({"The size of the file '", (POSIX path of (item 5 of thisTrackDetails as string) as string), "' is ", ((round (fileSize * 100)) / 100), "GB.", return, return, "For maximum compatibility, it is not recommended to export files over 4GB. Would you like to skip this file or continue copying it?"} as string) with title myTitle buttons {"Cancel", "Skip", "Continue"} default button 2 with icon iconWarning)
ExportPlaylists.applescript
if (sizeChoice = "Skip") then
ExportPlaylists.applescript
set thisTrackFileName to name of file (item 5 of thisTrackDetails)
ExportPlaylists.applescript
set AppleScript's text item delimiters to (".")
ExportPlaylists.applescript
set thisTrackExtension to the last text item of thisTrackFileName
ExportPlaylists.applescript
set the end of thisTrackDetails to thisTrackFileName
ExportPlaylists.applescript
set the end of thisTrackDetails to thisTrackExtension
ExportPlaylists.applescript
my progress(i, thePlaylistsNumberGood, thisPlaylistName, j, thisPlaylistNumberSongs, (item 1 of thisTrackDetails), (item 2 of thisTrackDetails), (item 3 of thisTrackDetails))
ExportPlaylists.applescript
set cwd to musicPath
ExportPlaylists.applescript
set foldersToMake to {}
ExportPlaylists.applescript
set foldersExist to {}
ExportPlaylists.applescript
set foldersAll to {}
ExportPlaylists.applescript
set folderStructure_NumberFolders to ((count of folderStructure_NewFolders) - 1)
ExportPlaylists.applescript
repeat with k from 1 to folderStructure_NumberFolders ------ for each new folder
ExportPlaylists.applescript
set newFolderTemplate to ((item k of folderStructure_NewFolders) as string)
ExportPlaylists.applescript
set newName to my define_from_attributes(newFolderTemplate, thisTrackDetails, thisPlaylistNumberSongs, j, i)
ExportPlaylists.applescript
set newNameStr to newName as string
ExportPlaylists.applescript
if ((length of newNameStr > 0) and ((item 1 of newNameStr) = ".")) then
ExportPlaylists.applescript
set newNameStr to ({"_", ((characters 2 thru -1 of newNameStr) as string)} as string)
ExportPlaylists.applescript
set newNameStr to my truncate_name(newNameStr, false)
ExportPlaylists.applescript
set pathExists to my folder_exists(cwd, newNameStr, "d")
ExportPlaylists.applescript
if not pathExists then
ExportPlaylists.applescript
set the end of foldersToMake to newNameStr
ExportPlaylists.applescript
set the end of foldersExist to newNameStr
ExportPlaylists.applescript
set the end of foldersAll to newNameStr
ExportPlaylists.applescript
set cwd to {POSIX path of cwd as string, newNameStr, "/"} as string
ExportPlaylists.applescript
end repeat ------ for each new folder
ExportPlaylists.applescript
set newNameTemplate to (item -1 of folderStructure_NewFolders)
ExportPlaylists.applescript
set newName to my define_from_attributes(newNameTemplate, thisTrackDetails, thisPlaylistNumberSongs, j, i)
ExportPlaylists.applescript
set the end of newName to ({".", (item 12 of thisTrackDetails as string)} as string)
ExportPlaylists.applescript
set newNameStr to (newName as string)
ExportPlaylists.applescript
set newNameStr to my truncate_name(newNameStr, true)
ExportPlaylists.applescript
set makeNewFile to true
ExportPlaylists.applescript
set newFileExists to my folder_exists(cwd, newNameStr, "f")
ExportPlaylists.applescript
if (newFileExists = true) then
ExportPlaylists.applescript
set {newNameStr, _} to my fix_duplicate("song", ({"'", (item 1 of thisTrackDetails as string), "' by ", (item 2 of thisTrackDetails as string)} as string), newNameStr, cwd)
ExportPlaylists.applescript
if (newNameStr = "exit repeat") then
ExportPlaylists.applescript
if (_ = "reference previous") then
ExportPlaylists.applescript
set makeNewFile to false
ExportPlaylists.applescript
repeat with currentFolder in foldersAll
ExportPlaylists.applescript
set currentFolder to (currentFolder as string)
ExportPlaylists.applescript
if foldersToMake contains currentFolder then
ExportPlaylists.applescript
set cwd to my make_dir(cwd, currentFolder)
ExportPlaylists.applescript
set cwd to {POSIX path of cwd as string, currentFolder, "/"} as string
ExportPlaylists.applescript
if (makeNewFile = true) then
ExportPlaylists.applescript
set newPath to ({cwd, newNameStr} as string)
ExportPlaylists.applescript
set newFile to (duplicate file (item 5 of thisTrackDetails) to (POSIX file cwd))
ExportPlaylists.applescript
set name of newFile to newNameStr
ExportPlaylists.applescript
my write_playlist_file_m3u(thePlaylistFile, thisTrackDetails, ({cwd, newNameStr} as string))
ExportPlaylists.applescript
log {POSIX path of (item 5 of thisTrackDetails as string) as string, " --> ", cwd, newNameStr} as string
ExportPlaylists.applescript
end repeat ------ for skipping missing/duplicate songs
ExportPlaylists.applescript
end repeat ------ for each song
ExportPlaylists.applescript
set playlistsExported to (playlistsExported + 1)
ExportPlaylists.applescript
close access thePlaylistFile
ExportPlaylists.applescript
on error e number n partial result r from f to t
ExportPlaylists.applescript
if n = -1728 then
ExportPlaylists.applescript
display dialog ({"Can't make folders from ", attribute} as string) with title myTitle buttons {"OK"} default button 1 with icon iconError giving up after 10
ExportPlaylists.applescript
error e number n partial result r from f to t
ExportPlaylists.applescript
end try ------ if anything goes wrong, close the playlist file
ExportPlaylists.applescript
if (playlistsExported = 1) then
ExportPlaylists.applescript
display notification ({"Finished exporting ", playlistsExported, playlist_s, " (", songsExported, " songs total)."} as string) with title myTitle
ExportPlaylists.applescript
on log_out(message, vars)
ExportPlaylists.applescript
if (vars is missing value) then
ExportPlaylists.applescript
log ({message, return} as string)
ExportPlaylists.applescript
log ({message, vars, return} as string)
ExportPlaylists.applescript
end log_out
ExportPlaylists.applescript
on count_matches(this_list, this_item)
ExportPlaylists.applescript
if (((item i of this_list) is this_item) or ((item i of this_list) contains this_item)) then
ExportPlaylists.applescript
end count_matches
ExportPlaylists.applescript