X-Git-Url: https://git.mdrn.pl/audio.git/blobdiff_plain/c64903445bdf2294335b43d464d8147f2fdf41c4..3bb77aad08a5558125b1cc80a599135d0e68eeda:/apps/archive/tasks.py diff --git a/apps/archive/tasks.py b/apps/archive/tasks.py old mode 100755 new mode 100644 index e8ce4fb..1b2be74 --- a/apps/archive/tasks.py +++ b/apps/archive/tasks.py @@ -4,6 +4,7 @@ import mimetypes import os import os.path import pipes +import stat import subprocess from tempfile import NamedTemporaryFile from time import sleep @@ -58,6 +59,7 @@ class AudioFormatTask(Task): ExistingFile(file_name), save=False ) + os.chmod(getattr(audiobook, field).path, stat.S_IREAD|stat.S_IWRITE|stat.S_IRGRP|stat.S_IROTH) Audiobook.objects.filter(pk=audiobook.pk).update( **{field: getattr(audiobook, field)}) @@ -91,7 +93,7 @@ class AudioFormatTask(Task): except SystemExit, e: raise cls.RemoteOperationError - def run(self, aid): + def run(self, aid, publish=True): aid = int(aid) audiobook = Audiobook.objects.get(id=aid) self.set_status(aid, status.ENCODING) @@ -111,10 +113,13 @@ class AudioFormatTask(Task): self.set_tags(audiobook, out_file.name) self.set_status(aid, status.SENDING) - self.put(audiobook, out_file.name) + if publish: + self.put(audiobook, out_file.name) + self.published(aid) + else: + self.set_status(aid, None) self.save(audiobook, out_file.name) - self.published(aid) def on_failure(self, exc, task_id, args, kwargs, einfo): aid = (args[0], kwargs.get('aid'))[0] @@ -157,12 +162,13 @@ class Mp3Task(AudioFormatTask): def encode(in_path, out_path): # 44.1kHz 64kbps mono MP3 subprocess.check_call(['ffmpeg', - '-i', in_path, + '-i', in_path.encode('utf-8'), '-ar', '44100', '-ab', '64k', '-ac', '1', '-y', - out_path + '-acodec', 'libmp3lame', + out_path.encode('utf-8') ]) @classmethod @@ -188,11 +194,12 @@ class OggTask(AudioFormatTask): @staticmethod def encode(in_path, out_path): # 44.1kHz 64kbps mono Ogg Vorbis - subprocess.check_call(['oggenc', - in_path, - '--discard-comments', - '--resample', '44100', - '--downmix', - '-b', '64', - '-o', out_path + subprocess.check_call(['ffmpeg', + '-i', in_path.encode('utf-8'), + '-ar', '44100', + '-ab', '64k', + '-ac', '1', + '-y', + '-acodec', 'libvorbis', + out_path.encode('utf-8') ])