def reassign_items(request, *args, **kwargs): media_ids = kwargs.get('media_ids', []) name = kwargs.get('name', None) release_id = kwargs.get('release_id', None) if media_ids and (release_id or name): log.debug(u'reassigning items: %s to %s' % ((',').join(media_ids), release_id)) if release_id: r = Release.objects.get(pk=int(release_id)) else: r = Release(name=name.strip()) r.creator = r.last_editor = request.user r.save() for id in media_ids: m = Media.objects.get(pk=int(id)) m.release = r m.save() data = {'status': True, 'error': None, 'next': r.get_absolute_url()} else: data = { 'status': False, 'error': 'missing data', } return json.dumps(data)
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)
# try to get release by mb_id if mb_release_id and not r: log.debug('release, lookup by mb_release_id: %s' % mb_release_id) try: lrs = lookup.release_by_mb_id(mb_release_id) r = lrs[0] log.debug('got release: %s by mb_release_id: %s' % (r.pk, mb_release_id)) except Exception, e: # print e log.debug('could not get release by mb_release_id: %s' % mb_release_id) # no luck yet, so create the release if not r: log.info('no release yet, so create it: %s' % release) r = Release(name=release) r.save() r_created = True # attach item to current import if r: log.info('release here, add it to importitems: %s' % r) ii = obj.import_session.add_importitem(r) log.info('importitem created: %s' % ii) # assign m.release = r
if mb_release_id and not r: log.debug('release, lookup by mb_release_id: %s' % mb_release_id) try: lrs = lookup.release_by_mb_id(mb_release_id) r = lrs[0] log.debug('got release: %s by mb_release_id: %s' % (r.pk, mb_release_id)) except Exception, e: # print e log.debug('could not get release by mb_release_id: %s' % mb_release_id) # no luck yet, so create the release if not r: log.info('no release yet, so create it: %s' % release) r = Release(name=release) r.save() r_created = True # attach item to current import if r: log.info('release here, add it to importitems: %s' % r) ii = obj.import_session.add_importitem(r) log.info('importitem created: %s' % ii) # assign m.release = r """ Section to search / create / lookup artist information """