Example #1
0
def work(artist, element, urls, releases):
    """Retrieves new or updated info for specified artist.

    Also fetches a list of all bands and urls if it doesn't exist yet.

    Args:
        artist: artist to check against
        element: db element containing existing info (it is db[<artist_name>])
        urls: urls previously retrieved for given artist
        releases: types of releases to check for

    Note: Should be threaded in real application.

    """
    if urls and u'progarchives.com' in urls.keys():
        (url, albums) = __sense(urls[u'progarchives'], releases)
        return {
            u'choice': url,
            u'result': albums,
            u'errors': set(),
            u'artist': artist
        }
    artists = list()
    for (url, a) in glob.iteritems():
        if a.lower().startswith(artist.lower()):
            artists.append(url)
    if not artists:
        raise NoBandError()
    sensor = Bandsensor(__sense, artists, element, releases)
    data = sensor.run()
    if not data:
        raise NoBandError()
    return {
        u'choice': data[0],
        u'result': data[1],
        u'errors': sensor.errors
    }
Example #2
0
def work(artist, element, urls, releases):
    """Retrieves new or updated info for specified artist.

    Args:
        artist: artist to check against
        element: db element containing existing info (it is db[<artist_name>])
        urls: urls previously retrieved for given artist
        releases: types of releases to check for

    Note: Should be threaded in real application.

    """
    if urls and u'musicbrainz' in urls.keys():
        (url, albums) = __sense(urls[u'musicbrainz'], releases)
        return {
            u'choice': url,
            u'result': albums,
            u'errors': set(),
            u'artist': artist
        }
    artist_ = urllib2.quote(artist.replace(u'/', u'').encode(
                u'utf-8')).replace(u'%20', u'+')
    urls_ = reqread(
            u'http://search.musicbrainz.org/ws/2/artist/?query=artist:'
            + artist_ + u'*&fmt=json')
    if not urls_:
        raise NoBandError()
    sensor = Bandsensor(__sense, JParse(artist).decode(urls_),
            element, releases)
    data = sensor.run()
    if not data:
        raise NoBandError()
    return {
        u'choice': data[0],
        u'result': data[1],
        u'errors': sensor.errors
    }
Example #3
0
def __parse2(json, artist, element, releases):
    """Retrieves info on an new release for a list of results.

    Args:
        json: Actually, a string retrieved from metal-archives JSON search
        artist: artist to check against
        element: db element containing existing info (it is db[<artist_name>])
        releases: types of releases to check for

    Note: It is meant for internal usage only!

    """
    urls = JParse(artist).decode(json)
    if not urls:
        raise NoBandError()
    sensor = Bandsensor(__sense, urls, element, releases)
    data = sensor.run()
    if not data:
        raise NoBandError()
    return {
        u'choice': data[0],
        u'result': data[1],
        u'errors': sensor.errors
    }