def test_that_stripping_works(self): self.assertEqual(stripper('River (feat. Ed Sheeran)', 'Eminem'), 'Eminem-River') self.assertEqual( stripper( 'CAN\'T STOP THE FEELING!' ' (Original Song from DreamWorks Animation\'s \"TROLLS\")', 'Justin Timberlake'), 'Justin-Timberlake-CANT-STOP-THE-FEELING') self.assertEqual( stripper('Ain\'t My Fault - R3hab Remix', 'Zara Larsson'), 'Zara-Larsson-Aint-My-Fault') self.assertEqual(stripper('1800-273-8255', 'Logic'), 'Logic-1800-273-8255') self.assertEqual(stripper('Scream & Shout', 'will.i.am'), 'william-Scream-and-Shout')
def test_that_stripping_works(self): """ Test that stripping works """ self.assertEqual(stripper('River (feat. Ed Sheeran)', 'Eminem'), 'Eminem-River') self.assertEqual(stripper('Ain\'t My Fault - R3hab Remix', 'Zara Larsson'), 'Zara-Larsson-Aint-My-Fault') self.assertEqual(stripper('1800-273-8255', 'Logic'), 'Logic-1800-273-8255') self.assertEqual(stripper('Scream & Shout', 'will.i.am'), 'william-Scream-and-Shout') self.assertEqual(stripper('Heebiejeebies - Bonus', 'Aminé'), 'Amine-Heebiejeebies') self.assertEqual(stripper('FRÜHLING IN PARIS', 'Rammstein'), 'Rammstein-FRUHLING-IN-PARIS') self.assertEqual(stripper( 'Chanel (Go Get It) [feat. Gunna & Lil Baby]', 'Young Thug'), 'Young-Thug-Chanel-Go-Get-It') self.assertEqual(stripper( 'MONOPOLY (with Victoria Monét)', 'Ariana Grande'), 'Ariana-Grande-and-Victoria-Monet-MONOPOLY') self.assertEqual(stripper('Seasons (with Sjava & Reason)', 'Mozzy'), 'Mozzy-Sjava-and-Reason-Seasons') self.assertEqual(stripper( '거품 안 넘치게 따라줘 [Life Is Good] (feat. Crush, Dj Friz)', 'Dynamic Duo'), 'Dynamic-Duo-Life-Is-Good')
async def get_lyrics(song, artist, session): """ doc: https://github.com/SwagLyrics/SwagLyrics-For-Spotify/blob/master/swaglyrics/cli.py#L75 Get lyrics from Genius given the song and artist. Formats the URL with the stripped url path to fetch the lyrics. :param session: the aiohttp session :param song: currently playing song :param artist: song artist :return: song lyrics or None if lyrics unavailable """ url_data = stripper(song, artist) # generate url path using stripper() if url_data.startswith('-') or url_data.endswith('-'): return None # url path had either song in non-latin, artist in non-latin, or both url = f'https://genius.com/{url_data}-lyrics' # format the url with the url path try: page = await fetch(session, url, raise_for_status=True) except aiohttp.ClientResponseError: url_data = await fetch(session, f'{backend_url}/stripper', data={ 'song': song, 'artist': artist }) if not url_data: raise LyricsNotFound( f"Lyrics for {song} by {artist} not found on Genius.") url = f'https://genius.com/{url_data}-lyrics' page = await fetch(session, url) html = BeautifulSoup(page, "html.parser") lyrics_path = html.find( "div", class_="lyrics") # finding div on Genius containing the lyrics if lyrics_path: lyrics = UnicodeDammit(lyrics_path.get_text().strip()).unicode_markup else: # hotfix! lyrics_path = html.find_all("div", class_=re.compile("^Lyrics__Container")) lyrics_data = [] for x in lyrics_path: lyrics_data.append( UnicodeDammit( re.sub("<.*?>", "", str(x).replace("<br/>", "\n"))).unicode_markup) lyrics = "\n".join(lyrics_data) return lyrics
def update(): if request.method == 'POST': song = request.form['song'] artist = request.form['artist'] stripped = stripper(song, artist) try: version = request.form['version'] except KeyError: return update_text print(song, artist, stripped, version) if version < '1.1.1': return update_text with open('unsupported.txt', 'r', encoding='utf-8') as f: data = f.read() if f'{song} by {artist}' in data: return 'Issue already exists on the GitHub repo. \n' \ 'https://github.com/SwagLyrics/SwagLyrics-For-Spotify/issues' # check if song, artist trivial (all letters and spaces) if re.fullmatch(asrg, song) and re.fullmatch(asrg, artist): return f'Lyrics for {song} by {artist} may not exist on Genius.\n' + gh_issue_text # check if song exists on spotify and does not have lyrics on genius if check_song(song, artist): with open('unsupported.txt', 'a', encoding='utf-8') as f: f.write(f'{song} by {artist}\n') issue = create_issue(song, artist, version, stripped) if issue['status_code'] == 201: print( f'Created issue on the GitHub repo for {song} by {artist}.' ) return 'Lyrics for that song may not exist on Genius. ' \ 'Created issue on the GitHub repo for {song} by {artist} to investigate ' \ 'further. \n{link}'.format(song=song, artist=artist, link=issue['link']) else: return f'Logged {song} by {artist} in the server.' return "That's a fishy request, that song doesn't seem to exist on Spotify. \n" + gh_issue_text
def update(): song = request.form['song'] artist = request.form['artist'] stripped = stripper(song, artist) try: version = request.form['version'] except KeyError: return update_text logging.info(f"{song=}, {artist=}, {stripped=}, {version=}") if version < '1.2.0': return update_text with open('unsupported.txt', 'r', encoding='utf-8') as f: data = f.read() if f'{song} by {artist}' in data: return 'Issue already exists on the GitHub repo. \n' \ 'https://github.com/SwagLyrics/SwagLyrics-For-Spotify/issues' # check if song, artist trivial (all letters, spaces and common symbols) # if re.fullmatch(asrg, unidecode(f"{song} {artist}")): # check if song exists on spotify and does not have lyrics on genius if check_song(song, artist) and not check_stripper(song, artist): return f'Lyrics for {song} by {artist} may not exist on Genius.\n' + gh_issue_text # with open('unsupported.txt', 'a', encoding='utf-8') as f: # f.write(f'{song} by {artist}\n') # issue = create_issue(song, artist, version, stripped) # if issue['status_code'] == 201: # logging.info(f'Created issue on the GitHub repo for {song} by {artist}.') # return 'Lyrics for that song may not exist on Genius. ' \ # f'Created issue on the GitHub repo for {song} by {artist} to investigate ' \ # f'further. \n{issue["link"]}' # else: # return f'Logged {song} by {artist} in the server.' return "That song doesn't seem to exist on Spotify or is instrumental. \n" + gh_issue_text
""" large scale stripper test suite """ import csv from pathlib import Path from swaglyrics.cli import stripper dataset = Path(__file__).parent / 'lssts_dataset.tsv' with open(dataset.resolve(), newline='', encoding="utf-8") as csvfile: f = csv.reader(csvfile, delimiter="\t") for row in f: # print(row) assert stripper(row[0], row[1]) == row[2]