def process_task(obj): target = 'download' from atracker.util import create_event process = Process() status, result, messages = process.run(instance=obj, format=obj.fileformat) if target == 'download': if result: obj.filesize = os.path.getsize(result) obj.file = DjangoFile(open(result), u'archive') # update status obj.status = 1 obj.save() process.clear_cache() else: obj.status = 99 obj.status_msg = messages obj.save() process.clear_cache()
def process_task(obj): processor = Process() metadata = processor.extract_metadata(obj.file) #time.sleep(1) obj.results_tag = metadata print "DONE!!!" print metadata obj.status = 3 obj.save() obj.results_acoustid = processor.get_aid(obj.file) obj.save()
def process_task(obj): from atracker.util import create_event process = Process() log = logging.getLogger('exporter.models.process_task') archive_dir = create_archive_dir(obj) archive_cache_dir = os.path.join(archive_dir, 'cache/') archive_path = os.path.join( archive_dir, 'archive') # .zip appended by 'make_archive' #archive_file = ZipFile(archive_path, "w") log.debug('archive_dir: %s' % (archive_dir)) log.debug('archive_cache_dir: %s' % (archive_cache_dir)) log.debug('archive_path: %s' % (archive_path)) # do shizzle for item in obj.export_items.all(): print print 'item: %s' % item.content_type print 'pk: %s' % item.object_id # maybe not too elegant.. switching processing for different types if item.content_type.name.lower() == 'release': t_item = item.content_object filename_format = '%s - %s - %s.%s' print 'GOT RELEAZE!' for media in t_item.media_release.all(): print 'Media: %s' % media.name if obj.fileformat == 'mp3': filename = filename_format % (media.tracknumber, media.name, media.artist.name, 'mp3') filepath = os.path.join(archive_cache_dir, filename) shutil.copyfile(media.get_cache_file('mp3', 'base'), filepath) process.incect_metadata(filepath, media) # just dummy - not possible... if obj.fileformat == 'flac': filename = filename_format % (media.tracknumber, media.name, media.artist.name, 'mp3') filepath = os.path.join(archive_cache_dir, filename) shutil.copyfile(media.get_cache_file('mp3', 'base'), filepath) process.incect_metadata(filepath, media) create_event(obj.user, media, None, 'download') if t_item.main_image: pass #archive_file.write(t_item.main_image.path, 'cover.jpg') print shutil.make_archive(archive_path, 'zip', archive_cache_dir) obj.file = DjangoFile(open(archive_path + '.zip'), u'archive.zip') obj.filesize = os.path.getsize(archive_path + '.zip') # get filesize obj.filename = generate_export_filename(obj.export_items) #obj.filename = 'asdasdas' # update status obj.status = 1 obj.save()
def process_task(obj): # to prevent circular import errors from util.process import Process processor = Process() # duplicate check by sha1 media_id = processor.id_by_sha1(obj.file) # duplicate check by echoprint if not media_id: media_id = processor.id_by_echoprint(obj.file) metadata = processor.extract_metadata(obj.file) # try to get media by id returned from fingerprinter media = None if media_id: try: media = Media.objects.get(pk=media_id) except: pass if media: obj.results_tag = metadata obj.media = media print "DUPLICATE!!!" # obj.results_tag_status = True # obj.status = 5 # obj.save() else: pass #time.sleep(1) obj.results_tag = metadata print "DONE!!!" print metadata print obj.status = 3 obj.results_tag_status = True obj.save() obj.results_acoustid = processor.get_aid(obj.file) obj.results_acoustid_status = True obj.save() obj.results_musicbrainz = processor.get_musicbrainz(obj) obj.results_discogs_status = True obj.save() # requeue if no results yet print 'MB YET!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' if len(obj.results_musicbrainz) < 1: s = {'skip_tracknumber': True} obj.settings = s obj.save() obj.results_musicbrainz = processor.get_musicbrainz(obj) obj.save() obj.status = 2 if media: obj.status = 5 # add to session obj.import_session.add_importitem(obj) obj.results_tag_status = True obj.save()