]> git.0d.be Git - django-panik-nonstop.git/commitdiff
skip 60 seconds when producing track extract
authorFrédéric Péters <fpeters@0d.be>
Wed, 5 Aug 2020 12:23:24 +0000 (14:23 +0200)
committerFrédéric Péters <fpeters@0d.be>
Wed, 5 Aug 2020 12:23:48 +0000 (14:23 +0200)
nonstop/views.py

index 82f1f00bd58342246b719b21dba68695151c846d..0db85e9a29032703d0beb06c2e486232260a85ce 100644 (file)
@@ -106,7 +106,7 @@ def track_sound(request, pk):
         # local user
         return FileResponse(open(file_path, 'rb'))
     # remote user, transcode and serve first minute
-    cmd = subprocess.run([
+    cmdline = [
         'ffmpeg',
         '-loglevel', 'quiet',
         '-t', '60',  # 60 seconds
@@ -115,7 +115,10 @@ def track_sound(request, pk):
         '-f', 'opus',
         '-b:a', '64000',
         '-',  # send to stdout
-        ], capture_output=True)
+    ]
+    if track.duration and track.duration.total_seconds() > 60:
+        cmdline[1:1] = ['-ss', '60']
+    cmd = subprocess.run(cmdline, capture_output=True)
     return HttpResponse(cmd.stdout, content_type='audio/opus')