text stringlengths 0 15.7k | source stringlengths 6 112 |
|---|---|
set AppleScript's text item delimiters to ("]") | ExportPlaylists.applescript |
set newTemplate_split to every text item of (newTemplate_split as string) | ExportPlaylists.applescript |
set newNameAttrLength to (count of newTemplate_split) | ExportPlaylists.applescript |
set newName to {} | ExportPlaylists.applescript |
repeat with k from 1 to newNameAttrLength | ExportPlaylists.applescript |
set theItem to ((item k of newTemplate_split) as string) | ExportPlaylists.applescript |
set theItemBrackets to ({"[", theItem, "]"} as string) | ExportPlaylists.applescript |
set newNameTMP to my value_of_attr(theItemBrackets, thisTrackDetails) | ExportPlaylists.applescript |
if (newNameTMP is not null) then | ExportPlaylists.applescript |
if (newNameTMP = "[playlist order number]") then | ExportPlaylists.applescript |
if (i = 1) then | ExportPlaylists.applescript |
set playlistOrderNumber to j | ExportPlaylists.applescript |
set playlistOrderNumber to songsExported | ExportPlaylists.applescript |
if ((thisPlaylistNumberSongs > 9) and (playlistOrderNumber < 10)) then | ExportPlaylists.applescript |
set newNameTMP to (("0" & playlistOrderNumber) as string) | ExportPlaylists.applescript |
else if ((thisPlaylistNumberSongs > 99) and (playlistOrderNumber < 100)) then | ExportPlaylists.applescript |
set newNameTMP to (("00" & playlistOrderNumber) as string) | ExportPlaylists.applescript |
else if ((thisPlaylistNumberSongs > 999) and (playlistOrderNumber < 1000)) then | ExportPlaylists.applescript |
set newNameTMP to (("000" & playlistOrderNumber) as string) | ExportPlaylists.applescript |
set newNameTMP to (playlistOrderNumber as string) | ExportPlaylists.applescript |
else if (newNameTMP = "[original file name]") then | ExportPlaylists.applescript |
set newNameTMP to (item 11 of thisTrackDetails) | ExportPlaylists.applescript |
set {newNameTMP, _} to my extract_extension(newNameTMP) | ExportPlaylists.applescript |
set the end of newName to my clean_name(newNameTMP) | ExportPlaylists.applescript |
else -- if (newNameTMP is null) then | ExportPlaylists.applescript |
set the end of newName to my clean_name(theItem) | ExportPlaylists.applescript |
end define_from_attributes | ExportPlaylists.applescript |
on fix_duplicate(mode, nameOriginal, nameClean, thePlaylistsCleanOrCwd) | ExportPlaylists.applescript |
if (mode = "playlist") then | ExportPlaylists.applescript |
set plural to "playlists" | ExportPlaylists.applescript |
set skipButton to "Skip" | ExportPlaylists.applescript |
set nameOriginal to ({"'", nameOriginal, "''"} as string) | ExportPlaylists.applescript |
else if (mode = "song") then | ExportPlaylists.applescript |
set plural to "songs" | ExportPlaylists.applescript |
set skipButton to "Reference previous" | ExportPlaylists.applescript |
set {nameClean, nameCleanExtension} to my extract_extension(nameClean) | ExportPlaylists.applescript |
error ({"Unknown mode in the fix_duplicate method: '", mode, "'."} as string) number 1 | ExportPlaylists.applescript |
set dupeChoice to skipButton | ExportPlaylists.applescript |
set dupeChoice to button returned of (display dialog ({"The clean name of the ", mode, " ", nameOriginal, " is '", nameClean, "', which is taken by another ", mode, ".", return, return, ¬
"Would you like to skip this ", mode, " or try to fix the name by appending a number to the name?", return, return, ¬
"[default opti... | ExportPlaylists.applescript |
if (dupeChoice = "") then | ExportPlaylists.applescript |
if (dupeChoice = "Skip") then | ExportPlaylists.applescript |
return {"exit repeat", null} | ExportPlaylists.applescript |
else if (dupeChoice = "Reference previous") then | ExportPlaylists.applescript |
return {{nameClean, ".", nameCleanExtension} as string, "reference previous"} | ExportPlaylists.applescript |
else if (dupeChoice = "Try to fix") then | ExportPlaylists.applescript |
repeat with k from 2 to dupeLimit | ExportPlaylists.applescript |
set nameClean2 to ({nameClean, "_", k} as string) | ExportPlaylists.applescript |
set nameOK to false | ExportPlaylists.applescript |
if ((mode = "playlist") and (thePlaylistsCleanOrCwd does not contain nameClean2)) then | ExportPlaylists.applescript |
set the end of thePlaylistsCleanOrCwd to nameClean2 | ExportPlaylists.applescript |
set nameOK to true | ExportPlaylists.applescript |
else if ((mode = "song") and (my folder_exists(thePlaylistsCleanOrCwd, ({nameClean2, ".", nameCleanExtension} as string), "f")) = false) then | ExportPlaylists.applescript |
set nameClean2 to ({nameClean2, ".", nameCleanExtension} as string) | ExportPlaylists.applescript |
if (nameOK = true) then | ExportPlaylists.applescript |
display dialog ({"The clean name of the ", mode, " '", nameOriginal, "' is now '", nameClean2, "'."} as string) with title myTitle buttons {"Cancel", "Continue"} default button 2 with icon iconWarning giving up after 10 | ExportPlaylists.applescript |
set k to 1 | ExportPlaylists.applescript |
if ((k = dupeLimit) or (nameOK = false)) then | ExportPlaylists.applescript |
display dialog ({"There are already ", dupeLimit, " ", plural, " with the base name '", nameClean, "' - skipping the ", mode, " '", nameOriginal, "'."} as string) with title myTitle buttons {"Cancel", "Continue"} default button 2 with icon iconError giving up after 10 | ExportPlaylists.applescript |
return {nameClean2, thePlaylistsCleanOrCwd} | ExportPlaylists.applescript |
end fix_duplicate | ExportPlaylists.applescript |
on extract_extension(componentName) | ExportPlaylists.applescript |
set componentExtension to (do shell script ({"x=\"", componentName, "\"; echo ${x##*.}"} as string)) | ExportPlaylists.applescript |
set componentName to (do shell script ({"x=\"", componentName, "\"; echo ${x%.*}"} as string)) | ExportPlaylists.applescript |
return {componentName, componentExtension} | ExportPlaylists.applescript |
end extract_extension | ExportPlaylists.applescript |
on truncate_name(newNameStr, hasExtension) | ExportPlaylists.applescript |
if (hasExtension = false) then | ExportPlaylists.applescript |
set newName to newNameStr | ExportPlaylists.applescript |
set pathComponentLength to the length of newNameStr | ExportPlaylists.applescript |
set pathExtensionLength to 0 | ExportPlaylists.applescript |
else if (hasExtension = true) then | ExportPlaylists.applescript |
set {newName, newNameExtension} to my extract_extension(newNameStr) | ExportPlaylists.applescript |
set pathComponentLength to the length of newName | ExportPlaylists.applescript |
set pathExtensionLength to the length of newNameExtension | ExportPlaylists.applescript |
error ({"Unknown mode in the truncate_name method: '", hasExtension, "'."} as string) number 1 | ExportPlaylists.applescript |
if ((pathComponentLength + pathExtensionLength) ≤ maxPathComponentLength) then | ExportPlaylists.applescript |
return newNameStr | ExportPlaylists.applescript |
set ellipsisLength to (length of ellipsisChar) | ExportPlaylists.applescript |
set pathComponentMiddle to (round (pathComponentLength / 2) rounding down) + 1 | ExportPlaylists.applescript |
set charsToRemove to {pathComponentLength - maxPathComponentLength + 1} | ExportPlaylists.applescript |
set limitLeft to (pathComponentMiddle - (round (charsToRemove / 2) rounding down) - (round (ellipsisLength / 2) rounding down)) | ExportPlaylists.applescript |
set limitRight to (pathComponentMiddle + (round (charsToRemove / 2) rounding up) + (round (ellipsisLength / 2) rounding up)) | ExportPlaylists.applescript |
if (hasExtension = true) then | ExportPlaylists.applescript |
set limitLeft to (limitLeft - 2) | ExportPlaylists.applescript |
set limitRight to (limitRight + 2) | ExportPlaylists.applescript |
set newNameStr2 to {(characters 1 thru limitLeft of newName as string), ellipsisChar, (characters limitRight thru -1 of newName as string)} as string | ExportPlaylists.applescript |
set finalLength to (length of newNameStr2) | ExportPlaylists.applescript |
if (finalLength > maxPathComponentLength) then | ExportPlaylists.applescript |
display dialog ({"The name \"", newNameStr, "\" could not be truncated to ", maxPathComponentLength, " characters.", return, return, "The final length is ", finalLength, " characters."} as string) with title myTitle buttons {"Cancel", "Continue"} default button 1 with icon iconError giving up after 10 | ExportPlaylists.applescript |
return ({newNameStr2, ".", newNameExtension} as string) | ExportPlaylists.applescript |
return newNameStr2 | ExportPlaylists.applescript |
end truncate_name | ExportPlaylists.applescript |
on write_playlist_file_m3u(thePlaylistFile, thisTrackDetails, newFilePath) | ExportPlaylists.applescript |
write ("#EXTINF:" & (item 4 of thisTrackDetails as string) & "," & (item 2 of thisTrackDetails as string) & " - " & (item 1 of thisTrackDetails as string) & return) to thePlaylistFile | ExportPlaylists.applescript |
write (POSIX path of newFilePath & return) to thePlaylistFile | ExportPlaylists.applescript |
end write_playlist_file_m3u | ExportPlaylists.applescript |
on progress(i, thePlaylistsNumber, thisPlaylistName, j, thisPlaylistNumberSongs, thisTrackName, thisTrackArtist, thisTrackAlbum) | ExportPlaylists.applescript |
set progress total steps to thisPlaylistNumberSongs | ExportPlaylists.applescript |
set percent to ((round ((j / thisPlaylistNumberSongs * 100) * 100)) / 100) | ExportPlaylists.applescript |
set progress description to ({"Exporting playlist ", i, " of ", thePlaylistsNumber, " (\"", thisPlaylistName, "\").", return, return, ¬
"Processing track ", j, " of ", thisPlaylistNumberSongs, " (", percent, "%)"} as string) | ExportPlaylists.applescript |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.