Commit d948f3ff authored by fred's avatar fred

use mediainfo (and soxi if it fails) to get durations

parent d8258994
import datetime
import os
import mutagen
import mutagen.aiff
import mutagen.mp4
import mutagen.asf
import re
import subprocess
from django.core.management.base import BaseCommand, CommandError
......@@ -12,19 +9,18 @@ from ...models import NonstopFile, Track
def get_duration(filename):
klasses = {'.m4a': mutagen.mp4.MP4,
'.wma': mutagen.asf.ASF,
'.wav': None,
'.WAV': None,
}
klass = klasses.get(os.path.splitext(filename)[-1], mutagen.File)
if klass:
try:
return klass(filename).info.length
except (AttributeError, mutagen.aiff.InvalidChunk):
# fallback on soxi
pass
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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment