lyrics.py
| 1 | 
      import lyricsgenius # https://github.com/johnwmillr/LyricsGenius  | 
  
|---|---|
| 2 | 
      import sys  | 
  
| 3 | 
      import os.path  | 
  
| 4 | 
      # 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"
     | 
  
| 5 | 
      fullpath = sys.argv[3]
     | 
  
| 6 | 
      title = sys.argv[2]
     | 
  
| 7 | 
      artist = sys.argv[1]
     | 
  
| 8 | 
      title = title.split(" ")
     | 
  
| 9 | 
      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)))  | 
  
| 10 | 
      pad = fullpath.rstrip('.mp3') + '.lrc'  | 
  
| 11 | 
      print(pad)  | 
  
| 12 | 
      if os.path.exists(pad) :
     | 
  
| 13 | 
          print("exists")
     | 
  
| 14 | 
          ##if os.path.getsize(pad) > 8 : sys.exit()
     | 
  
| 15 | 
      file = open(pad, "w")  | 
  
| 16 | 
      genius = lyricsgenius.Genius('zTxO8rZchsFENu4LqXVLC2gbPLveJro33Y3LK_0fsWfJp5y_nSEs8FWW6HNUVRet',
     | 
  
| 17 | 
      skip_non_songs=True, excluded_terms=["(Remix)", "instrumental"], remove_section_headers=True)  | 
  
| 18 | 
      song = genius.search_song(title, artist)  | 
  
| 19 | 
      lyric = song.lyrics  | 
  
| 20 | 
      lyric = lyric.replace('EmbedShare URLCopyEmbedCopy', '')  | 
  
| 21 | 
      if lyric == '' : lyric = 'not found'  | 
  
| 22 | 
      lyric = lyric + '\n\n' + '~ ' + fullpath  | 
  
| 23 | 
      if (file.write(lyric)) : print('write')  | 
  
