import lyricsgenius # https://github.com/johnwmillr/LyricsGenius
import sys
import os.path
# use $ python3 /home/kroon/lyrics.py "Gwen Guthrie" "Love In Moderation" "/media/local/TUNES/Gwen Guthrie/Just For You/Gwen_Guthrie_-_02_-_Love_In_Moderation.mp3"
fullpath = sys.argv[3]
title = sys.argv[2]
artist = sys.argv[1]
title = title.split(" ")
title = ' '.join((filter(lambda x: x not in ['01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21'], title)))
pad = fullpath.rstrip('.mp3') + '.lrc'
print(pad)
if os.path.exists(pad) :
    print("exists")
    ##if os.path.getsize(pad) > 8 : sys.exit()
file = open(pad, "w")
genius = lyricsgenius.Genius('zTxO8rZchsFENu4LqXVLC2gbPLveJro33Y3LK_0fsWfJp5y_nSEs8FWW6HNUVRet',
         skip_non_songs=True, excluded_terms=["(Remix)", "instrumental"], remove_section_headers=True)
song = genius.search_song(title, artist)
lyric = song.lyrics
lyric = lyric.replace('EmbedShare URLCopyEmbedCopy', '')
if lyric == '' : lyric = 'not found'
lyric = lyric + '\n\n' +  '~ ' + fullpath
if (file.write(lyric)) : print('write')
