Django 1.5
[audio.git] / apps / archive / tasks.py
old mode 100755 (executable)
new mode 100644 (file)
index e8ce4fb..1b2be74
@@ -4,6 +4,7 @@ import mimetypes
 import os
 import os.path
 import pipes
 import os
 import os.path
 import pipes
+import stat
 import subprocess
 from tempfile import NamedTemporaryFile
 from time import sleep
 import subprocess
 from tempfile import NamedTemporaryFile
 from time import sleep
@@ -58,6 +59,7 @@ class AudioFormatTask(Task):
             ExistingFile(file_name),
             save=False
             )
             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)})
 
         Audiobook.objects.filter(pk=audiobook.pk).update(
             **{field: getattr(audiobook, field)})
 
@@ -91,7 +93,7 @@ class AudioFormatTask(Task):
         except SystemExit, e:
             raise cls.RemoteOperationError
 
         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)
         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.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.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]
 
     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', 
     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',
             '-ar', '44100',
             '-ab', '64k',
             '-ac', '1',
             '-y',
-            out_path
+            '-acodec', 'libmp3lame',
+            out_path.encode('utf-8')
             ])
 
     @classmethod
             ])
 
     @classmethod
@@ -188,11 +194,12 @@ class OggTask(AudioFormatTask):
     @staticmethod
     def encode(in_path, out_path):
         # 44.1kHz 64kbps mono Ogg Vorbis
     @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')
             ])
             ])