def get_details_spotify(song_name):
    '''
    Tries finding metadata through Spotify
    '''

    song_name = improvename.songname(song_name)

    spotify = spotipy.Spotify()
    results = spotify.search(song_name, limit=1)  # Find top result

    log.log_indented('* Finding metadata from Spotify.')

    try:
        album = (results['tracks']['items'][0]['album']
                 ['name'])  # Parse json dictionary
        artist = (results['tracks']['items'][0]['album']['artists'][0]['name'])
        song_title = (results['tracks']['items'][0]['name'])
        try:
            log_indented("* Finding lyrics from Genius.com")
            lyrics = get_lyrics_genius(song_title)
        except:
            log_error("* Could not find lyrics from Genius.com, trying something else")
            lyrics = get_lyrics_letssingit(song_title)

        match_bool, score = matching_details(song_name, song_title, artist)
        if match_bool:
            return artist, album, song_title, lyrics, match_bool, score
        else:
            return None

    except IndexError:
        log.log_error(
            '* Could not find metadata from spotify, trying something else.', indented=True)
        return None
Example #2
0
def get_details_letssingit(song_name):
    """
    Gets the song details if song details not found through spotify
    """

    song_name = improvename.songname(song_name)

    letssingit_search_url = 'http://search.letssingit.com/cgi-exe/am.cgi' \
                            '?a=search&artist_id=&l=archive&s='
    url = "{}{}".format(letssingit_search_url, quote(song_name.encode('utf-8')))
    html = urlopen(url).read()
    soup = BeautifulSoup(html, 'html.parser')
    link = soup.find('a', {'class': 'high_profile'})
    try:
        link = link.get('href')
        link = urlopen(link).read()

        soup = BeautifulSoup(link, 'html.parser')

        album_div = soup.find('div', {'id': 'albums'})
        title_div = soup.find('div', {'id': 'content_artist'}).find('h1')

        try:
            lyrics = soup.find('div', {'id': 'lyrics'}).text
            lyrics = lyrics[3:]
        except AttributeError:
            lyrics = ''
            log.log_error('* Couldn\'t find lyrics', indented=True)

        try:
            song_title = title_div.contents[0]
            song_title = song_title[1:-8]
        except AttributeError:
            log.log_error('* Couldn\'t reset song title', indented=True)
            song_title = song_name

        try:
            artist = title_div.contents[1].getText()
        except AttributeError:
            log.log_error('* Couldn\'t find artist name', indented=True)
            artist = 'Unknown'

        try:
            album = album_div.find('a').contents[0]
            album = album[:-7]
        except AttributeError:
            log.log_error('* Couldn\'t find the album name', indented=True)
            album = artist

    except AttributeError:
        log.log_error('* Couldn\'t find song details', indented=True)

        album = song_name
        song_title = song_name
        artist = 'Unknown'
        lyrics = ''

    match_bool, score = matching_details(song_name, song_title, artist)

    return artist, album, song_title, lyrics, match_bool, score
def get_details_letssingit(song_name):
    '''
    Gets the song details if song details not found through spotify
    '''

    song_name = improvename.songname(song_name)

    url = "http://search.letssingit.com/cgi-exe/am.cgi?a=search&artist_id=&l=archive&s=" + \
        quote(song_name.encode('utf-8'))
    html = urlopen(url).read()
    soup = BeautifulSoup(html, "html.parser")
    link = soup.find('a', {'class': 'high_profile'})
    try:
        link = link.get('href')
        link = urlopen(link).read()

        soup = BeautifulSoup(link, "html.parser")

        album_div = soup.find('div', {'id': 'albums'})
        title_div = soup.find('div', {'id': 'content_artist'}).find('h1')

        try:
            lyrics = soup.find('div', {'id': 'lyrics'}).text
            lyrics = lyrics[3:]
        except AttributeError:
            lyrics = ""
            log.log_error("* Couldn't find lyrics", indented=True)

        try:
            song_title = title_div.contents[0]
            song_title = song_title[1:-8]
        except AttributeError:
            log.log_error("* Couldn't reset song title", indented=True)
            song_title = song_name

        try:
            artist = title_div.contents[1].getText()
        except AttributeError:
            log.log_error("* Couldn't find artist name", indented=True)
            artist = "Unknown"

        try:
            album = album_div.find('a').contents[0]
            album = album[:-7]
        except AttributeError:
            log.log_error("* Couldn't find the album name", indented=True)
            album = artist

    except AttributeError:
        log.log_error("* Couldn't find song details", indented=True)

        album = song_name
        song_title = song_name
        artist = "Unknown"
        lyrics = ""

    match_bool, score = matching_details(song_name, song_title, artist)

    return artist, album, song_title, lyrics, match_bool, score
Example #4
0
def get_details_spotify(song_name):
    """
    Use Spotipy to send an API call to Spotify to fetch the details of a track
    """

    #Remove useless words such as - 'lyrics', 'HD', 'audio' from file name
    song_name = improvename.songname(song_name)
    spotify = spotipy.Spotify()
    #Choose top result
    results = spotify.search(song_name, limit=1)

    log.log_indented('* Finding metadata from Spotify.')

    try:
        album = (results['tracks']['items'][0]['album']['name'])
        artist = (results['tracks']['items'][0]['album']['artists'][0]['name'])
        song_title = (results['tracks']['items'][0]['name'])
    except IndexError:
        log.log_error(
            '* Could not find metadata from spotify, trying something else.',
            indented=True)
        return None

    try:
        log.log_indented("* Finding lyrics from Genius.com")
        lyrics = get_lyrics_genius(artist + ' ' + song_title)
    except:
        lyrics = ''
        log.log_error("* Could not find lyrics from Genius.com", indented=True)

    match_bool, score = matching_details(song_name, song_title, artist)

    if match_bool:
        log.log("Match score: %s/10.0" % round(score * 10, 1))
        return artist, album, song_title, lyrics
    else:
        return None
Example #5
0
def get_details_spotify(song_name):
    '''
    Tries finding metadata through Spotify
    '''

    song_name = improvename.songname(song_name)

    spotify = spotipy.Spotify()
    results = spotify.search(song_name, limit=1)  # Find top result

    log.log_indented('* Finding metadata from Spotify.')

    try:
        album = (results['tracks']['items'][0]['album']['name']
                 )  # Parse json dictionary
        artist = (results['tracks']['items'][0]['album']['artists'][0]['name'])
        song_title = (results['tracks']['items'][0]['name'])
        try:
            log_indented("* Finding lyrics from Genius.com")
            lyrics = get_lyrics_genius(song_title)
        except:
            log_error(
                "* Could not find lyrics from Genius.com, trying something else"
            )
            lyrics = get_lyrics_letssingit(song_title)

        match_bool, score = matching_details(song_name, song_title, artist)
        if match_bool:
            return artist, album, song_title, lyrics, match_bool, score
        else:
            return None

    except IndexError:
        log.log_error(
            '* Could not find metadata from spotify, trying something else.',
            indented=True)
        return None