]> git.0d.be Git - django-panik-emissions.git/commitdiff
create-sound-files: add --link option
authorFrédéric Péters <fpeters@0d.be>
Fri, 27 Dec 2019 08:34:20 +0000 (09:34 +0100)
committerFrédéric Péters <fpeters@0d.be>
Fri, 27 Dec 2019 08:36:10 +0000 (09:36 +0100)
emissions/management/commands/create-sound-files.py

index 21df5a25baeffc6362b8dbc0246d1f712e9cf78b..ac1548b298154ca9d39cd3194d1675fb6edca719 100644 (file)
@@ -45,10 +45,16 @@ class Command(BaseCommand):
             dest='copy',
             default=False,
             help='Copy initial file')
+        parser.add_argument('--link',
+            action='store_true',
+            dest='link',
+            default=False,
+            help='Link initial file')
 
-    def handle(self, force, reset_metadata, copy, emission, episode, verbosity, formats, **kwargs):
+    def handle(self, force, reset_metadata, copy, link, emission, episode, verbosity, formats, **kwargs):
         self.verbose = (verbosity > 1)
         self.copy = copy
+        self.link = link
 
         for soundfile in SoundFile.objects.select_related().exclude(podcastable=False):
             if emission and soundfile.episode.emission.slug != emission:
@@ -78,12 +84,15 @@ class Command(BaseCommand):
         if not os.path.exists(os.path.dirname(file_path)):
             os.mkdir(os.path.dirname(file_path))
 
-        cmd = ['ffmpeg', '-y', '-i', soundfile.file.path]
-
         if self.copy and os.path.splitext(soundfile.file.path)[-1].strip('.') == format:
             shutil.copy(soundfile.file.path, file_path)
             return
 
+        if self.link and os.path.splitext(soundfile.file.path)[-1].strip('.') == format:
+            os.symlink(soundfile.file.path, file_path)
+            return
+
+        cmd = ['ffmpeg', '-y', '-i', soundfile.file.path]
         if format == 'ogg':
             cmd.extend(['-q:a', '5'])
         elif format == 'mp3':