def handle(self, *args, **kwargs): self.stdout.write('Import picture and bio for artists') artists = Artist.objects.filter(picture=None) metadata_grabber = MetadataGrabber() for artist in artists: try: infos = metadata_grabber.get_and_save_artist(artist.name, "%s/%s" % (settings.STATIC_PATH, 'images/artists/'), "%s.jpg" % artist.slug) if infos is not None: if 'infos' in infos.keys() and 'text' in infos['infos'].keys() and infos['infos']['text'] is not None: artist.text = infos['infos']['text'] else: artist.text = "" if artist.slug is not None: artist.picture = 'images/artists/%s.jpg' % artist.slug else: artist.picture = 'images/no_band.jpg' artist.save() self.stdout.write('+ %s' % artist.name) except: artist.picture = 'images/no_band.jpg' artist.text = "" artist.save() self.stdout.write('- %s' % artist.name) self.stdout.write('Import finished')
def handle(self, *args, **kwargs): self.stdout.write("Import covers for albums") albums = Album.objects.filter(picture=None) metadata_grabber = MetadataGrabber() for album in albums: image = metadata_grabber.get_and_save_cover( "%s" % album.name, "%s/%s" % (settings.STATIC_PATH, "images/covers/"), "%s.jpg" % album.slug ) if image is not None: path = "%s%s.jpg" % ("images/covers/", album.slug) else: path = "images/no_cover.gif" album.picture = path album.save() self.stdout.write("+ %s" % album.name) self.stdout.write("Import finished")