Example #1
0
def _run_query(provider, canvas, options, expect):
    'Do the actual plyr work'
    draw_string = 'X'

    # Only block realted to plyr.
    qry = plyr.Query(**options)
    qry.providers = [provider]
    results = qry.commit()

    # Write results to results/ folder
    ctr = 0
    for item in results:
        item.write(
            os.path.join(
                'results', '{art}_{alb}_{tit}_{typ}_{prv}_{nbr}'.format(
                    art=options.get('artist', ''),
                    alb=options.get('album', ''),
                    tit=options.get('title', ''),
                    typ=options.get('get_type', ''),
                    prv=provider,
                    nbr=str(ctr))))
        ctr += 1

    if expect(results):
        draw_string = 'Y'

    # Make sure no add() is done in parallel
    DRAW_LOCK.acquire()
    canvas.add(options['artist'], provider, draw_string)
    DRAW_LOCK.release()
Example #2
0
    def do_process(self, artist_title):
        artist, title = artist_title
        LOGGER.debug('artist={a} title={t} ({v})'.format(
            a=artist, t=title, v=plyr.version()
        ))

        qry = plyr.Query(
            get_type='lyrics',
            artist=artist,
            title=title,
            database=self.database,
            parallel=4,
            timeout=5
        )
        items = qry.commit()

        if items:
            first = items[0]

            # This item was cached on failure:
            if first.rating is -1:
                return None

            try:
                return (first.data.decode('utf-8'), )
            except UnicodeDecodeError:
                pass

        if self._cache_failures:
            dummy = self.database.make_dummy()
            self.database.insert(qry, dummy)
        return None
Example #3
0
    def delete(self, type, artist, title, album):
        """Delete metadata from the cache.

        Keyword arguments:
        type -- type of the metadata
        artist -- artist tag
        title -- title tag
        album -- album tag
        """
        if artist and title and album:
            self.cache.delete(plyr.Query(get_type=type, artist=artist, title=title, album=album))
Example #4
0
def fetch_track_lyrics(artist, title):
    query = plyr.Query(artist=artist, title=title, get_type="lyrics")
    items = query.commit()
    if not items:
        print("ERROR: {} - {} has no lyrics".format(artist, title))
        return None
    decoded = items[0].data.decode("utf-8")
    if decoded == "Instrumental" or decoded == "[ INSTRUMENTAL ]":
        print("{} - {} is instrumental".format(artist, title))
        return None
    return decoded
Example #5
0
def getLyrics(artist,track,vendor):
    if vendor == 'plyr':
        query = plyr.Query(artist=artist, title=track, get_type='lyrics',timeout=1,verbosity=3,parallel=40,useragent=userAgent)
        items = query.commit()
        lyrics = items[0].data
    elif vendor == 'lyricsdotcom':
        artistF = filter(checkName, artist.replace(' ','_')).replace('_','-')
        trackF = filter(checkName, track.replace(' ','_')).replace('_','-')
        artistF = re.sub('-+','-',artistF).lower()
        trackF = re.sub('-+','-',trackF).lower()
        lyricsdotcom = 'http://www.lyrics.com/'
        lyriclink = lyricsdotcom+trackF + '-lyrics-' +artistF + '.html'
        req = requests.get(lyriclink)
        lyricsoup = BeautifulSoup(req.content)
        lyrics = lyricsoup.find_all('div',{'id':re.compile('lyric_space|lyrics')})[0].text
    elif vendor == 'pylyrics':
        lyrics = PyLyrics.getLyrics(artist,track)
    return lyrics
Example #6
0
def download_album_art(disc_number, artist, album, replace_existing):
    disc_number_string = format_disc_number_string(disc_number)
    art_file_path = os.path.join(ART_DIR,
                                 disc_number_string + '.' + IMAGE_FORMAT)
    if replace_existing or not os.path.isfile(art_file_path):
        if DEBUG:
            print("Downloading art for " + art_file_path)
        qry = plyr.Query(artist=artist,
                         album=album,
                         get_type='cover',
                         allowed_formats=[IMAGE_FORMAT])
        qry.useragent = USER_AGENT
        items = qry.commit()
        if len(items) > 0:
            items[0].write(art_file_path)
        else:
            print("Couldn't find art for disc " + disc_number_string + ' (' +
                  artist + ' - ' + album + ')')
Example #7
0
    def _query(self, type, normalize=True):
        """Return the list containing results from the glyr.Query,
        or None if some tags are missing.

        Keyword arguments:
        type -- type of the metadata
        normalize -- whether the search strings should be normalized by glyr
        """
        try:
            query = plyr.Query(get_type=type, artist=self.artist, title=self.title, album=self.album)
        except AttributeError:
            # Missing tags?
            return None
        else:
            query.useragent = lyvi.USERAGENT
            query.database = self.cache
            if not normalize:
                query.normalize = ('none', 'artist', 'album', 'title')
            return query.commit()