Python Genius Lyric Collector - TypeError

74 Views Asked by At

I am extremely new to coding so I am following a tutorial to find and collect lyrics from Genius (https://www.storybench.org/download-song-lyrics-genius-using-python/). This tutorial uses LyricsGenius(https://github.com/johnwmillr/LyricsGenius).

from __future__ import print_function
import lyricsgenius as genius
import csv


# Insert client ID
api = genius.Genius('xxxxxxxxxxxxxxxxxxxxxxx')

with open('lyricaldata.csv', encoding='mac_roman') as csv_file:
    csv_reader = csv.reader(csv_file, delimiter=',')
    line_count = 0
    for row in csv_reader:
        if line_count == 0:
            line_count += 1
        else:
            item_year = row[0]
            item_artist = row[1]
            item_song = row[2]
            # print(f'\t{row[0]}\t{row[1]}\t{row[2]}')
            song = api.search_song(item_song,item_artist)
            filename = item_song.replace("/","_") + "|" + item_artist.replace("/","_")
            if song is not None:
                song.save_lyrics(filename='lyrics/txt/'+filename+'.json', format='txt')
                song.save_lyrics(filename='lyrics/json/'+filename+'.json', format='json')

            line_count += 1

    print('Processed {line_count} lines.')

I've followed the tutorial step by step but whenever I run the script I receive the following TypeError.

Searching for "Mudd Baby" by Icewear Vezzo...
Done.
Traceback (most recent call last):
  File "./test.py", line 23, in <module>
    song.save_lyrics(filename='lyrics/txt/'+filename+'.json', format='txt')
TypeError: save_lyrics() got an unexpected keyword argument 'format'

How do I prevent this TypeError from occurring?

1

There are 1 best solutions below

0
On

Either because the the needed keyword is format_ with an underscore _


or depending on the version the call is:

    def save_lyrics(self,
                    filename=None,
                    extension='json',
                    overwrite=False,
                    ensure_ascii=True,
                    sanitize=True,
                    verbose=True):

Replace it with extension in that case