Skip to content

Commit

Permalink
Make search case-insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
johnwmillr committed Feb 28, 2018
1 parent 0179ff0 commit 832edd8
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# OSX
# macOS
*.DS_Store

# API credentials
Expand All @@ -21,4 +21,5 @@
# Python cache stuff
*.egg-info
__pycache__
dist
dist
README.rst
10 changes: 5 additions & 5 deletions lyricsgenius/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def _scrape_song_lyrics_from_url(self, URL):
return lyrics.strip('\n')

def _clean(self, s):
return s.translate(str.maketrans('','',punctuation)).replace('\u200b', " ").strip()
return s.translate(str.maketrans('','',punctuation)).replace('\u200b', " ").strip().lower()

class Genius(_API):
"""User-level interface with the Genius.com API. User can search for songs (getting lyrics) and artists (getting songs)"""
Expand Down Expand Up @@ -252,12 +252,12 @@ def save_artists(self, artists, filename="artist_lyrics", overwrite=False):

# Extract each artist's lyrics in json format
all_lyrics = {'artists': []}
for n, art in enumerate(artists):
if isinstance(art, Artist):
for n, artist in enumerate(artists):
if isinstance(artist, Artist):
all_lyrics['artists'].append({})
tmp_file = "./{dir}/tmp_{num}_{name}".format(dir=tmp_dir, num=n, name=art.name.replace(" ",""))
tmp_file = "./{dir}/tmp_{num}_{name}".format(dir=tmp_dir, num=n, name=artist.name.replace(" ",""))
print(tmp_file)
all_lyrics['artists'][-1] = art.save_lyrics(filename=tmp_file, overwrite=True)
all_lyrics['artists'][-1] = artist.save_lyrics(filename=tmp_file, overwrite=True)
else:
warn("Item #{} was not of type Artist. Skipping.".format(n))

Expand Down
2 changes: 1 addition & 1 deletion lyricsgenius/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def songInArtist(new_song):
lyrics_to_write['songs'][-1]['lyrics'] = song.lyrics
lyrics_to_write['songs'][-1]['image'] = song.song_art_image_url
lyrics_to_write['songs'][-1]['artist'] = self.name
lyrics_to_write['songs'][-1]['json'] = song._body
lyrics_to_write['songs'][-1]['raw'] = song._body
else:
print("SKIPPING \"{}\" -- already found in artist collection.".format(song.title))
else:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

setup(
name='lyricsgenius',
version='0.4',
version='0.4.1',
description='Download lyrics and metadata from Genius.com',
long_description=README,
classifiers=[
Expand Down
4 changes: 2 additions & 2 deletions tests/test_genius.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class TestSong(unittest.TestCase):
def setUpClass(cls):
print("\n---------------------\nSetting up Song tests...\n")
cls.artist_name = 'Andy Shauf'
cls.song_title = 'Begin Again'
cls.song_title = 'begin again' # Lowercase is intentional
cls.album = 'The Party'
cls.year = '2016-05-20'
cls.song = api.search_song(cls.song_title,cls.artist_name)
Expand All @@ -100,7 +100,7 @@ def test_song(self):

def test_title(self):
msg = "The returned song title does not match the title of the requested song."
self.assertEqual(self.song.title, self.song_title, msg)
self.assertEqual(api._clean(self.song.title), api._clean(self.song_title), msg)

def test_artist(self):
msg = "The returned artist name does not match the artist of the requested song."
Expand Down

0 comments on commit 832edd8

Please sign in to comment.