Skip to content

Instantly share code, notes, and snippets.

@ryanseys
Last active December 15, 2015 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanseys/5316766 to your computer and use it in GitHub Desktop.
Save ryanseys/5316766 to your computer and use it in GitHub Desktop.
Remove excess strings from lyrics which are inserted and generated from the app "Get Lyrical".
(* This is a script made by Ryan Seys to remove the excess strings from lyrics that are inserted and generated from the application "Get Lyrical". It properly removes the Title and Artist from the start of the Lyrics, and the text "branding" that Get Lyrical inserts to all the lyrics it fetches. Usage: Select the songs that you would like to clean in iTunes, then run the script.*)
on trim_line(this_text, trim_chars, trim_indicator)
-- 0 = beginning, 1 = end, 2 = both
set x to the length of the trim_chars
-- TRIM BEGINNING
if the trim_indicator is in {0, 2} then
repeat while this_text begins with the trim_chars
try
set this_text to characters (x + 1) thru -1 of this_text as string
on error
-- the text contains nothing but the trim characters
return ""
end try
end repeat
end if
-- TRIM ENDING
if the trim_indicator is in {1, 2} then
repeat while this_text ends with the trim_chars
try
set this_text to characters 1 thru -(x + 1) of this_text as string
on error
-- the text contains nothing but the trim characters
return ""
end try
end repeat
end if
return this_text
end trim_line
on findAndReplace(tofind, toreplace, TheString)
set ditd to text item delimiters
set text item delimiters to tofind
set textItems to text items of TheString
set text item delimiters to toreplace
if (class of TheString is string) then
set res to textItems as string
else -- if (class of TheString is Unicode text) then
set res to textItems as Unicode text
end if
set text item delimiters to ditd
return res
end findAndReplace
tell application "iTunes"
set selectedTracks to selection
end tell
if selection is {} then
--do nothing
else
repeat with nextTrack in selectedTracks
tell application "iTunes"
set NumOfChars to ((get (count characters of (get (name of nextTrack)))) + (get (count characters of (get (artist of nextTrack)))))
set textToEdit to (get lyrics of nextTrack)
set textToRemove to ((get (name of nextTrack) & "
") & (get (artist of nextTrack) & "
"))
end tell
--this is the first edit DONE
if (textToEdit is not "") then
--there are lyrics
if ((get (paragraph 1 of (textToEdit)) as string) = (get (name of nextTrack))) then
-- the lyrics appear to be made by Get Lyrical (correct format)
set revise1 to (get (trim_line(textToEdit, textToRemove, 0)))
--get the last paragraph
tell application "iTunes"
set numberOfParagraphs to (get (count paragraphs in (get (lyrics of nextTrack))))
set lastLine to (get paragraph numberOfParagraphs of (get (lyrics of nextTrack)))
end tell
set thefile to revise1 as Unicode text
findAndReplace(lastLine, "", thefile)
tell application "iTunes"
set lastLine to "
" & (get paragraph (numberOfParagraphs) of (get (lyrics of nextTrack)))
end tell
set thefile to get (findAndReplace(lastLine, "", thefile))
tell application "iTunes"
set (lyrics of nextTrack) to thefile
end tell
end if
end if
end repeat
end if
@tecklee
Copy link

tecklee commented Jan 1, 2015

Thanks for this. But there's a much easier way.

Just edit the PHP script in the app and it won't even fetch it in the first place 😀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment