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(