def run(self, obj): log = logging.getLogger('util.importer.Importer.run') # map it = obj.import_tag print '*****************************' print it print '*****************************' if 'mb_track_id' in it: log.info('mb_track_id: %s' % (it['mb_track_id'])) m = Media(name=it['name']) # get/create release # lookup by mb_id r = None if 'mb_release_id' in it: lrs = lookup.release_by_mb_id(it['mb_release_id']) #print 'LRS!:' #print lrs if lrs.count() > 0: r = lrs[0] if not r: r, created = Release.objects.get_or_create(name=it['release']) # assign mb_relation if 'mb_release_id' in it: url = 'http://musicbrainz.org/release/%s' % it['mb_release_id'] print 'musicbrainz_url: %s' % url rel = Relation(content_object=r, url=url) rel.save() # complete medatata self.complete_release_meta(r, it) try: if r: m.release = r except Exception, e: print e
def run(self, obj): log = logging.getLogger('util.importer.run') it = obj.import_tag rt = obj.results_tag print '*****************************' self.pp.pprint(it) self.pp.pprint(rt) print '*****************************' """ get import settings """ # media name = None tracknumber = None alibrary_media_id = None mb_track_id = None if 'name' in it and it['name']: name = it['name'] if 'media_tracknumber' in rt and rt['media_tracknumber']: tracknumber = rt['media_tracknumber'] if 'alibrary_media_id' in it and it['alibrary_media_id']: alibrary_media_id = it['alibrary_media_id'] if 'mb_track_id' in it and it['mb_track_id']: mb_track_id = it['mb_track_id'] # release release = None alibrary_release_id = None mb_release_id = None force_release = False if 'release' in it and it['release']: release = it['release'] if 'alibrary_release_id' in it and it['alibrary_release_id']: alibrary_release_id = it['alibrary_release_id'] if 'mb_release_id' in it and it['mb_release_id']: mb_release_id = it['mb_release_id'] if 'force_release' in it and it['force_release']: force_release = it['force_release'] # artist artist = None alibrary_artist_id = None mb_artist_id = None force_artist = False if 'artist' in it and it['artist']: artist = it['artist'] if 'alibrary_artist_id' in it and it['alibrary_artist_id']: alibrary_artist_id = it['alibrary_artist_id'] if 'mb_artist_id' in it and it['mb_artist_id']: mb_artist_id = it['mb_artist_id'] if 'force_artist' in it and it['force_artist']: force_artist = it['force_artist'] # label label = None alibrary_label_id = None mb_label_id = None force_label = False if 'label' in it and it['label']: label = it['label'] if 'alibrary_label_id' in it and it['alibrary_label_id']: alibrary_label_id = it['alibrary_label_id'] if 'mb_label_id' in it and it['mb_label_id']: mb_label_id = it['mb_label_id'] if 'force_label' in it and it['force_label']: force_label = it['force_label'] print print '***************************************************************' print '* import settings *' print '***************************************************************' print print '* media *******************************************************' print print ' name: %s' % name print ' tracknumber: %s' % tracknumber print ' alibrary_media_id: %s' % alibrary_media_id print ' mb_track_id: %s' % mb_track_id print print '* release *****************************************************' print print ' release: %s' % release print ' alibrary_release_id: %s' % alibrary_release_id print ' mb_release_id: %s' % mb_release_id print ' force_release: %s' % force_release print print '* artist *****************************************************' print print ' artist: %s' % artist print ' alibrary_artist_id: %s' % alibrary_artist_id print ' mb_artist_id: %s' % mb_artist_id print ' force_artist: %s' % force_artist print print '* label *****************************************************' print print ' label: %s' % label print ' alibrary_label_id: %s' % alibrary_label_id print ' mb_label_id: %s' % mb_label_id print ' force_label: %s' % force_label print print '***************************************************************' time.sleep(1.1) #raw_input("Press Enter to continue...") """ create media always executed, as duplicates are handled before this step """ m = None m_created = False log.info('media, force creation: %s' % name) m = Media(name=name) if tracknumber: m.tracknumber = tracknumber m.save() m_created = True """ get or create release get release by: - mb_id - internal_id - or force creation """ """ Section to search / create / lookup release information """ r = None r_created = False # look in imports importitems if release is already here # (case where same item is 'forced' several times - so we have to avoid recreation) try: ctype = ContentType.objects.get(app_label="alibrary", model="release") ii_ids = obj.import_session.get_importitem_ids(ctype) print 'ii_ids: ' print ii_ids ir = Release.objects.filter(pk__in=ii_ids, name=release) print ir log.info('found release in import session: %s' % ir) except: ir = None if ir and ir.count > 0: r = ir[0] # create release if forced if force_release and not r: log.info('release, force creation: %s' % release) r = Release(name=release) r.save() r_created = True # try to get release by alibrary_id if alibrary_release_id and not r: log.debug('release, lookup by alibrary_release_id: %s' % alibrary_release_id) try: r = Release.objects.get(pk=alibrary_release_id) log.debug('got release: %s by alibrary_release_id: %s' % (r.pk, alibrary_release_id)) except Exception, e: # print e log.debug('could not get release by alibrary_release_id: %s' % alibrary_release_id)