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(
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_tags" % cls.prefix: F("%s_tags" % cls.prefix),
+ "%s_tags" % cls.prefix: 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):
'parts_count': audiobook.parts_count,
'source_sha1': audiobook.source_sha1,
}
'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)
self.set_status(aid, status.ENCODING)
def run(self, uid, aid, publish=True):
aid = int(aid)
audiobook = Audiobook.objects.get(id=aid)
self.set_status(aid, status.ENCODING)
- 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)
self.set_status(aid, status.TAGGING)
self.set_tags(audiobook, out_file.name)
self.set_status(aid, status.SENDING)
self.set_status(aid, status.TAGGING)
self.set_tags(audiobook, out_file.name)
self.set_status(aid, status.SENDING)
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'),
- 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'),