from apiclient import api_call
from archive.constants import status
from archive.models import Audiobook
from apiclient import api_call
from archive.constants import status
from archive.models import Audiobook
@classmethod
def set_status(cls, aid, status):
Audiobook.objects.filter(pk=aid).update(
@classmethod
def set_status(cls, aid, status):
Audiobook.objects.filter(pk=aid).update(
- def set_tags(cls, audiobook, file_name):
- tags = getattr(audiobook, "get_%s_tags" % cls.ext)()['tags']
- if not tags.get('flac_sha1'):
- tags['flac_sha1'] = audiobook.get_source_sha1()
+ def set_tags(cls, tags, file_name):
getattr(audiobook, field).save(
"%d.%s" % (audiobook.pk, cls.ext),
ExistingFile(file_name),
getattr(audiobook, field).save(
"%d.%s" % (audiobook.pk, cls.ext),
ExistingFile(file_name),
- "%s_published_tags" % cls.ext: F("%s_tags" % cls.ext),
- "%s_tags" % cls.ext: None,
- "%s_published" % cls.ext: datetime.now(),
- '%s_status' % cls.ext: None,
+ "%s_published" % cls.prefix: datetime.now(),
+ '%s_status' % cls.prefix: None,
}
Audiobook.objects.filter(pk=aid).update(**kwargs)
@classmethod
def put(cls, user, audiobook, path):
}
Audiobook.objects.filter(pk=aid).update(**kwargs)
@classmethod
def put(cls, user, audiobook, path):
'part_name': audiobook.part_name,
'part_index': audiobook.index,
'parts_count': audiobook.parts_count,
'source_sha1': audiobook.source_sha1,
'part_name': audiobook.part_name,
'part_index': audiobook.index,
'parts_count': audiobook.parts_count,
'source_sha1': audiobook.source_sha1,
}
with open(path, 'rb') as f:
api_call(user, UPLOAD_URL, data=data, files={
}
with open(path, 'rb') as f:
api_call(user, UPLOAD_URL, data=data, files={
def run(self, uid, aid, publish=True):
aid = int(aid)
audiobook = Audiobook.objects.get(id=aid)
def run(self, uid, aid, publish=True):
aid = int(aid)
audiobook = Audiobook.objects.get(id=aid)
- out_file = NamedTemporaryFile(delete=False, prefix='%d-' % aid, suffix='.%s' % self.ext, dir=BUILD_PATH)
+ out_file = NamedTemporaryFile(
+ delete=False, prefix='%d-' % aid, suffix='.%s' % self.ext,
+ dir=settings.FILE_UPLOAD_TEMP_DIR
+ )
self.set_status(aid, status.SENDING)
if publish:
self.put(user, audiobook, out_file.name)
self.set_status(aid, status.SENDING)
if publish:
self.put(user, audiobook, out_file.name)
else:
self.set_status(aid, None)
self.save(audiobook, out_file.name)
else:
self.set_status(aid, None)
self.save(audiobook, out_file.name)
def on_failure(self, exc, task_id, args, kwargs, einfo):
aid = (args[0], kwargs.get('aid'))[0]
self.set_status(aid, None)
class Mp3Task(AudioFormatTask):
def on_failure(self, exc, task_id, args, kwargs, einfo):
aid = (args[0], kwargs.get('aid'))[0]
self.set_status(aid, None)
class Mp3Task(AudioFormatTask):
# 44.1kHz 64kbps mono MP3
subprocess.check_call(['ffmpeg',
'-i', in_path.encode('utf-8'),
# 44.1kHz 64kbps mono MP3
subprocess.check_call(['ffmpeg',
'-i', in_path.encode('utf-8'),
- def set_tags(cls, audiobook, file_name):
- mp3_tags = audiobook.get_mp3_tags()['tags']
- if not mp3_tags.get('flac_sha1'):
- mp3_tags['flac_sha1'] = audiobook.get_source_sha1()
+ def set_tags(cls, tags, file_name):
factory_tuple = cls.TAG_MAP[k]
factory, tagtype = factory_tuple[:2]
audio.add(factory(tagtype, v, *factory_tuple[2:]))
factory_tuple = cls.TAG_MAP[k]
factory, tagtype = factory_tuple[:2]
audio.add(factory(tagtype, v, *factory_tuple[2:]))
# 44.1kHz 64kbps mono Ogg Vorbis
subprocess.check_call(['ffmpeg',
'-i', in_path.encode('utf-8'),
# 44.1kHz 64kbps mono Ogg Vorbis
subprocess.check_call(['ffmpeg',
'-i', in_path.encode('utf-8'),