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,
- api_call(user, UPLOAD_URL, data=data, files={
- "file": open(path, 'rb'),
- })
+ with open(path, 'rb') as f:
+ api_call(user, UPLOAD_URL, data=data, files={
+ "file": f,
+ })
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):
- def id3_comment(tag, text, lang=u'pol'):
- return tag(encoding=1, lang=lang, desc=u'', text=text)
- def id3_priv(tag, text, what=u''):
+ def id3_comment(tag, text, lang='pol'):
+ return tag(encoding=3, lang=lang, desc='', text=text)
+ def id3_priv(tag, text, what=''):
# 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:]))
if COVER_IMAGE:
mime = mimetypes.guess_type(COVER_IMAGE)
factory_tuple = cls.TAG_MAP[k]
factory, tagtype = factory_tuple[:2]
audio.add(factory(tagtype, v, *factory_tuple[2:]))
if COVER_IMAGE:
mime = mimetypes.guess_type(COVER_IMAGE)
- f = open(COVER_IMAGE)
- audio.add(id3.APIC(encoding=0, mime=mime, type=3, desc=u'', data=f.read()))
- f.close()
+ with open(COVER_IMAGE, 'rb') as f:
+ audio.add(id3.APIC(encoding=0, mime=mime, type=3, desc='', data=f.read()))
# 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'),