def get_data(artist,d=False, I=False): logging.error("getting data of %s"%artist) data=get_ndbArtist(artist) if data != []: logging.error("mbid from ndb or memcache get_data") return data url=tools.get_url('musicbrainz','artist',artist) xml=tools.get_xml(url) parsed=xml.getElementsByTagName("artist") disambiguation=" " mbid=[] if xml.getElementsByTagName("artist-list")[0].attributes.get("count").value == '1' : mbidId=parsed[0].attributes.get("id").value url="http://musicbrainz.org/ws/2/artist/"+mbidId+"?inc=releases" x=tools.get_xml(url) name=xml.getElementsByTagName("name")[0].childNodes[0].nodeValue disambiguation=" " ar=Artist(artist=name, mbid=mbidId, disambiguation=disambiguation, letter=name[0]) mbid.append(ar) memcache.set("select * from Artist where artist='%s'"%name,[ar]) else: for a in parsed: mbidId=a.attributes.get("id").value name=a.getElementsByTagName("name")[0].childNodes[0].nodeValue try: disambiguation=a.getElementsByTagName("disambiguation")[0].childNodes[0].nodeValue if d==False: continue except: disambiguation=" " ar=Artist(artist=name, mbid=mbidId, disambiguation=disambiguation, letter=name[0]) mbid.append(ar) memcache.set("select * from Artist where artist='%s'"%name,[ar]) logging.error(mbid) return mbid
def get_artist_mb(mbid): data=memcache.get("%s artist="%mbid) if data is not None: return data try: data=list(ndb.gql("select artist from Artist where mbid='%s'"%mbid)) if data != []: memcache.set("%s artist="%mbid, data[0].artist) return data[0].artist except: pass url="http://www.musicbrainz.org/ws/2/artist/?query=arid:"+mbid xml=tools.get_xml(url) if xml.getElementsByTagName("artist-list")[0].attributes.get("count").value == '1': name= xml.getElementsByTagName("name")[0].childNodes[0].nodeValue memcache.set("%s artist="%mbid, name) a=Artist(artist=name, mbid=mbid,disambiguation=" ",letter=name[0]) try: a.put() logging.error("Artist inserted in ndb") except: pass return name
def get_artist_albums(artist_mbid): logging.error("START OF Artist_ALBUMS") url=tools.get_url("musicbrainz","artist_mbid",artist_mbid) xml=tools.get_xml(url) artist_name= xml.getElementsByTagName("name")[0].childNodes[0].nodeValue logo=image.get_image(artist_mbid," ",'artist') background=image.get_image(artist_mbid,"artist_name",'bg') artist=Artists(artist_name=artist_name, artist_mbid=artist_mbid,disambiguation=" ",letter=artist_name[0], key=ndb.Key('Artists',artist_mbid)) artist.logo=logo artist.background=background artist_key=artist.put() logging.error(artist) releases=xml.getElementsByTagName("release-group") albums=[] for rg in releases: try: if rg.getElementsByTagName("primary-type")[0].childNodes[0].nodeValue != "Album": continue error=rg.getElementsByTagName("secondary-type")[0] continue except: try: if rg.attributes.get("type").value == "Album": album_mbid=rg.attributes.get("id").value b=Albums(key=ndb.Key(Albums,album_mbid,parent=ndb.Key(Artist,artist_mbid))) b.album_mbid=album_mbid b.album_name=rg.getElementsByTagName("title")[0].childNodes[0].nodeValue b.album_date=rg.getElementsByTagName("first-release-date")[0].childNodes[0].nodeValue b.album_image=image.get_image(album_mbid,b.album_name,key="album") albums.append(b) logging.error(b) except: continue albums.sort(key=lambda tup: tup.album_date) test=ndb.put_multi(albums) logging.error("END OF Artist_ALBUMS") return artist,albums
def search_artist(artist_name): logging.error("getting data of %s"%artist_name) data = None #data=memcache.get("search %s"%artist_name) if data is not None: logging.error("mbid from ndb or memcache get_data") return data url=tools.get_url('musicbrainz','artist',artist_name) logging.error(url) xml=tools.get_xml(url) parsed=xml.getElementsByTagName("artist") disambiguation=" " artists=[] if xml.getElementsByTagName("artist-list")[0].attributes.get("count").value == '1' : artist={} artist["mbid"]=parsed[0].attributes.get("id").value artist["name"]=parsed[0].getElementsByTagName("name")[0].childNodes[0].nodeValue artists.append(artist) else: for a in parsed: artist={} artist["mbid"]=a.attributes.get("id").value artist["name"]=a.getElementsByTagName("name")[0].childNodes[0].nodeValue try: artist["country"]=a.getElementsByTagName("area")[0].getElementsByTagName("name")[0].childNodes[0].nodeValue except: artist["country"]="" try: disambiguation=a.getElementsByTagName("disambiguation")[0].childNodes[0].nodeValue except: disambiguation=" " artists.append(artist) memcache.set("search %s"%artist_name, artists) return artists
def post(self): j=self.request.body track=json.loads(j) id=memcache.get("7digital of %s"%track) if id is None: url=tools.get_url("7digital", "buytrack", track) logging.error(url) xml=tools.get_xml(url) tracka=xml.getElementsByTagName("track") id=tracka[0].attributes.get("id").value memcache.set("7digital of %s"%track,id) self.response.out.write(json.dumps(id))