]> git.0d.be Git - django-panik-nonstop.git/commitdiff
get duration using function from django-panik-emissions
authorFrédéric Péters <fpeters@0d.be>
Sat, 16 May 2020 13:37:30 +0000 (15:37 +0200)
committerFrédéric Péters <fpeters@0d.be>
Sat, 16 May 2020 13:37:30 +0000 (15:37 +0200)
nonstop/management/commands/compute_durations.py

index 057101be7c14520fc18cc14f0b0d8c662545949d..1fe11e384186a48ff755c919f6f7e4b479d36a31 100644 (file)
@@ -6,39 +6,10 @@ import subprocess
 from django.core.management.base import BaseCommand
 from django.utils.encoding import force_text
 
+from emissions.utils import get_duration
 from ...models import Track
 
 
-def get_duration(filename):
-    p = subprocess.Popen(['mediainfo', '--Inform=Audio;%Duration%', filename],
-                         close_fds=True,
-                         stdin=subprocess.PIPE,
-                         stdout=subprocess.PIPE,
-                         stderr=subprocess.PIPE)
-    stdout, stderr = p.communicate()
-    try:
-        return int(stdout) / 1000
-    except ValueError:
-        pass
-
-    # fallback on soxi
-    p = subprocess.Popen(['soxi', filename], close_fds=True,
-                         stdin=subprocess.PIPE,
-                         stdout=subprocess.PIPE,
-                         stderr=subprocess.PIPE)
-    stdout, stderr = p.communicate()
-    for line in stdout.splitlines():
-        line = force_text(line)
-        if not line.startswith('Duration'):
-            continue
-        try:
-            hours, minutes, seconds = re.findall(r'(\d\d):(\d\d):(\d\d)', line)[0]
-        except IndexError:
-            continue
-        return int(hours) * 3600 + int(minutes) * 60 + int(seconds)
-    return None
-
-
 class Command(BaseCommand):
     def add_arguments(self, parser):
         parser.add_argument(