def import_artist_bio(a, overwrite): artist = kutcheris.search_artist(a.name) additional_urls = [] if not len(artist): print "Looing for data on wikipedia" i, iurl, b, u = wikipedia.get_artist_details(a.name) if u: additional_urls.append(u) #if not b: # newname = wikipedia.search(a.name) # mx = max(len(a.name), len(newname)) # mn = min(len(a.name), len(newname)) # # Only accept the wikipedia search result if it's # if newname and mn + 3 < mx: # i, b, u = wikipedia.get_artist_details(newname) if b: sn = data.models.SourceName.objects.get(name="Wikipedia") else: print "Found data on kutcheris.com" aid = artist.values()[0] i, b, u = kutcheris.get_artist_details(aid) u = "http://kutcheris.com/artist.php?id=%s" % aid if b: sn = data.models.SourceName.objects.get(name="kutcheris.com") if b: source, created = data.models.Source.objects.get_or_create( source_name=sn, uri=u, defaults={"title": a.name}) description = data.models.Description.objects.create(description=b, source=source) a.description = description if i: print "Found image" try: existingimg = a.images.get(image__contains="%s" % a.mbid) # TODO: If the image doesn't exist on disk this is an error. fix it. #if existingimg.image.size != len(i) or overwrite: if overwrite: # If the imagesize has changed, or overwrite is set, remove the image existingimg.delete() except data.models.Image.DoesNotExist: pass im = data.models.Image() im.image.save("artist-%s.jpg" % a.mbid, ContentFile(i)) a.images.add(im) if additional_urls: for u in additional_urls: # Currently we only have wikipedia additionals, but this may change sn = data.models.SourceName.objects.get(name="Wikipedia") title = u.split("/")[-1].replace("_", " ") source, created = data.models.Source.objects.get_or_create( source_name=sn, uri=u, defaults={"title": title}) a.references.add(source) a.save()
def import_artist_bio(a, overwrite): artist = kutcheris.search_artist(a.name) additional_urls = [] if not len(artist): print "Looing for data on wikipedia" i, iurl, b, u = wikipedia.get_artist_details(a.name) if u: additional_urls.append(u) #if not b: # newname = wikipedia.search(a.name) # mx = max(len(a.name), len(newname)) # mn = min(len(a.name), len(newname)) # # Only accept the wikipedia search result if it's # if newname and mn + 3 < mx: # i, b, u = wikipedia.get_artist_details(newname) if b: sn = data.models.SourceName.objects.get(name="Wikipedia") else: print "Found data on kutcheris.com" aid = artist.values()[0] i, b, u = kutcheris.get_artist_details(aid) u = "http://kutcheris.com/artist.php?id=%s" % aid if b: sn = data.models.SourceName.objects.get(name="kutcheris.com") if b: source, created = data.models.Source.objects.get_or_create(source_name=sn, uri=u, defaults={"title": a.name}) description = data.models.Description.objects.create(description=b, source=source) a.description = description if i: print "Found image" try: existingimg = a.images.get(image__contains="%s" % a.mbid) # TODO: If the image doesn't exist on disk this is an error. fix it. #if existingimg.image.size != len(i) or overwrite: if overwrite: # If the imagesize has changed, or overwrite is set, remove the image existingimg.delete() except data.models.Image.DoesNotExist: pass im = data.models.Image() im.image.save("artist-%s.jpg" % a.mbid, ContentFile(i)) a.images.add(im) if additional_urls: for u in additional_urls: # Currently we only have wikipedia additionals, but this may change sn = data.models.SourceName.objects.get(name="Wikipedia") title = u.split("/")[-1].replace("_", " ") source, created = data.models.Source.objects.get_or_create(source_name=sn, uri=u, defaults={"title": title}) a.references.add(source) a.save()
def handle(self, *args, **options): for did, kid in themap.items(): a = models.Artist.objects.get(pk=did) print "* got", a.name, a.mbid imgcontent, bio, wpurl = kutcheris.get_artist_details(kid) if bio: print "got bio" u = "http://kutcheris.com/artist.php?id=%s" % kid sn = data.models.SourceName.objects.get(name="kutcheris.com") source, created = data.models.Source.objects.get_or_create( source_name=sn, uri=u, defaults={"title": a.name}) description = data.models.Description.objects.create( description=bio, source=source) a.description = description if imgcontent: print "got image" a.images.remove() im = data.models.Image() im.image.save("%s.jpg" % a.mbid, ContentFile(imgcontent)) a.images.add(im) a.save() # Check if they're on musicbrainz->wikipedia too print "looking up wikipedia" mba = mb.mb.get_artist_by_id(a.mbid, includes="url-rels") mba = mba["artist"] wikipedia = None for rel in mba.get("url-relation-list", []): if rel["type"] == "wikipedia": wikipedia = rel["target"] print "got wikipedia url", wikipedia theurl = None if wikipedia or wpurl: if wikipedia == wpurl: theurl = wikipedia elif wikipedia and not wpurl: theurl = wikipedia elif not wikipedia and wpurl: theurl = wpurl else: print "musicbrainz wp", wikipedia, "and kutcheris wp", wpurl, "are differnt. using mb" theurl = wikipedia if theurl: print "adding wikipedia reference" sn = data.models.SourceName.objects.get(name="Wikipedia") title = theurl.split("/")[-1].replace("_", " ") source, created = data.models.Source.objects.get_or_create( source_name=sn, uri=theurl, defaults={"title": title}) a.references.add(source)
def import_artist_kutcheris(a): artist = kutcheris.search_artist(a.name) if artist: print "Found data on kutcheris.com" aid = artist.values()[0] i, b, u = kutcheris.get_artist_details(aid) u = "http://kutcheris.com/artist.php?id=%s" % aid if b: sn = data.models.SourceName.objects.get(name="kutcheris.com") if b: source, created = data.models.Source.objects.get_or_create(source_name=sn, uri=u, defaults={"title": a.name}) description = data.models.Description.objects.create(description=b, source=source) a.description = description a.save()
def handle(self, *args, **options): for did, kid in themap.items(): a = models.Artist.objects.get(pk=did) print "* got", a.name, a.mbid imgcontent, bio, wpurl = kutcheris.get_artist_details(kid) if bio: print "got bio" u = "http://kutcheris.com/artist.php?id=%s" % kid sn = data.models.SourceName.objects.get(name="kutcheris.com") source, created = data.models.Source.objects.get_or_create(source_name=sn, uri=u, defaults={"title": a.name}) description = data.models.Description.objects.create(description=bio, source=source) a.description = description if imgcontent: print "got image" a.images.remove() im = data.models.Image() im.image.save("%s.jpg" % a.mbid, ContentFile(imgcontent)) a.images.add(im) a.save() # Check if they're on musicbrainz->wikipedia too print "looking up wikipedia" mba = mb.mb.get_artist_by_id(a.mbid, includes="url-rels") mba = mba["artist"] wikipedia = None for rel in mba.get("url-relation-list", []): if rel["type"] == "wikipedia": wikipedia = rel["target"] print "got wikipedia url", wikipedia theurl = None if wikipedia or wpurl: if wikipedia == wpurl: theurl = wikipedia elif wikipedia and not wpurl: theurl = wikipedia elif not wikipedia and wpurl: theurl = wpurl else: print "musicbrainz wp", wikipedia, "and kutcheris wp", wpurl, "are differnt. using mb" theurl = wikipedia if theurl: print "adding wikipedia reference" sn = data.models.SourceName.objects.get(name="Wikipedia") title = theurl.split("/")[-1].replace("_", " ") source, created = data.models.Source.objects.get_or_create(source_name=sn, uri=theurl, defaults={"title": title}) a.references.add(source)
def handle(self, *args, **options): for did, kid in themap.items(): a = models.Artist.objects.get(pk=did) print("* got %s %s" % (a.name, a.mbid)) imgcontent, bio, wpurl = kutcheris.get_artist_details(kid) if bio: print("got bio") u = "http://kutcheris.com/artist.php?id=%s" % kid sn = data.models.SourceName.objects.get(name="kutcheris.com") source, created = data.models.Source.objects.get_or_create( source_name=sn, uri=u, defaults={"title": a.name}) description = data.models.Description.objects.create( description=bio, source=source) a.description = description if imgcontent: print("got image") im = data.models.Image() im.image.save("%s.jpg" % a.mbid, ContentFile(imgcontent)) a.image = im a.save() # Check if they're on musicbrainz->wikipedia too print("looking up wikipedia") mba = mb.mb.get_artist_by_id(a.mbid, includes="url-rels") mba = mba["artist"] wikipedia = None for rel in mba.get("url-relation-list", []): if rel["type"] == "wikipedia": wikipedia = rel["target"] print("got wikipedia url %s" % wikipedia) theurl = None if wikipedia or wpurl: if wikipedia == wpurl: theurl = wikipedia elif wikipedia and not wpurl: theurl = wikipedia elif not wikipedia and wpurl: theurl = wpurl else: print( "musicbrainz wp %s and kutcheris wp % are differnt. using mb" % (wikipedia, wpurl)) theurl = wikipedia
def handle(self, *args, **options): for did, kid in themap.items(): a = models.Artist.objects.get(pk=did) print("* got %s %s" % (a.name, a.mbid)) imgcontent, bio, wpurl = kutcheris.get_artist_details(kid) if bio: print("got bio") u = "http://kutcheris.com/artist.php?id=%s" % kid sn = data.models.SourceName.objects.get(name="kutcheris.com") source, created = data.models.Source.objects.get_or_create(source_name=sn, uri=u, defaults={"title": a.name}) description = data.models.Description.objects.create(description=bio, source=source) a.description = description if imgcontent: print("got image") im = data.models.Image() im.image.save("%s.jpg" % a.mbid, ContentFile(imgcontent)) a.image = im a.save() # Check if they're on musicbrainz->wikipedia too print("looking up wikipedia") mba = mb.mb.get_artist_by_id(a.mbid, includes="url-rels") mba = mba["artist"] wikipedia = None for rel in mba.get("url-relation-list", []): if rel["type"] == "wikipedia": wikipedia = rel["target"] print("got wikipedia url %s" % wikipedia) theurl = None if wikipedia or wpurl: if wikipedia == wpurl: theurl = wikipedia elif wikipedia and not wpurl: theurl = wikipedia elif not wikipedia and wpurl: theurl = wpurl else: print("musicbrainz wp %s and kutcheris wp % are differnt. using mb" % (wikipedia, wpurl)) theurl = wikipedia