def urls(artist): """Retrieves all possibly correct urls for specified :artist:. :artist: Artist to search for. :returns: List of urls. """ artist_ = urllib2.quote(artist.replace(u'/', u'').encode( u'utf-8')).replace(u'%20', u'+') return reqread( u'http://search.musicbrainz.org/ws/2/artist/?query=artist:' + artist_ + u'*&fmt=json')
def sense(url, releases): """Retrieves releases for specified band id. Injected into Bandsensor. :url: ID of the current band. :releases: Types of releases to search for. :returns: Tuple in form of (url, [(album, year)]). """ soup = reqread(u'http://www.metal-archives.com/band/discography/id/' + url + u'/tab/all').decode(u'utf-8') return (url, __getalbums(soup, releases))
def init(): res = reqread( u'http://www.progarchives.com/bands-alpha.asp?letter=*' ).decode(u'latin-1').encode(u'utf-8') def __internal(context, artist, url): glob[str(url[0])[14:]] = artist[0].text return False root = etree.HTML(res) ns = etree.FunctionNamespace(u'http://fake.gayeogi/functions') ns.prefix = u'pa' ns[u'test'] = __internal root.xpath(u'//td/a[pa:test(strong, @href)]')
def urls(artist): """Retrieves all possibly correct urls for specified :artist:. :artist: Artist to search for. :returns: List of urls. """ artist_ = urllib2.quote( artist.replace(u'&', u'and').replace(u'/', u'').encode(u'utf-8') ).replace(u'%20', u'+') json = reqread( u"http://www.metal-archives.com/search/ajax-band-search" u"/?field=name&query={0}&sEcho=1&iColumns=3&sColumns=&" u"iDisplayStart=0&iDisplayLength=100&sNames=%2C%2C".format(artist_) ) return JParse(artist).decode(json)
def sense(url, releases): """Retrieves releases for specified band id. Injected into Bandsensor. :url: ID of the current band (it is mbid format here). :releases: Types of releases to search for. :returns: Tuple in form of (url, [(album, year)]). """ result = dict() offset = 0 count = 100 partial = dict() while count > 0: soup = reqread( u'http://www.musicbrainz.org/ws/2/release?artist=' + url + u'&type=' + u'|'.join(releases).lower() + u'&offset=' + unicode(offset) + u'&limit=100') (partial, n) = __getalbums(soup, partial) result.update(partial) count = n - count - offset offset += 100 return (url, list(result.iteritems()))
def sense(url, releases): """Retrieves releases for specified band id. Injected into Bandsensor. :url: ID of the current band (it is mbid format here). :releases: Types of releases to search for. :returns: Tuple in form of (url, [(album, year)]). """ res = reqread( u'http://www.progarchives.com/artist.asp?id=' + url ).decode(u'latin-1').encode(u'utf-8') artist = glob[url] def __enabled(context, element): for release in releases: if element[0].text.lower().startswith( artist.lower() + u' ' + di[release].lower() ): return True return False result = list() def __internal(context, albums, years): result.append((albums[0].text.strip(), years[0].text.strip())) return False root = etree.HTML(res) ns = etree.FunctionNamespace(u'http://fake.gayeogi/functions') ns.prefix = u'pa' ns[u'test'] = __internal ns[u'enabled'] = __enabled root.xpath( u"//h3[pa:enabled(.)]/following-sibling::*[1]" u"//td[pa:test(a[2]/strong, span[3])]" ) return (url, result)