add manage.py command to extract derivatives, fixes #783

This commit is contained in:
j 2012-05-29 17:02:59 +02:00
parent 55992dd834
commit 76aa590bbb
3 changed files with 39 additions and 2 deletions

View file

@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
from django.core.management.base import BaseCommand
from django.conf import settings
import os
import monkey_patch.models
from ... import models
from ...tasks import extract_derivatives
class Command(BaseCommand):
"""
"""
help = 'extract derivatives, run this to recreate all derivatives. i.e after adding new resolutions'
args = ''
option_list = BaseCommand.option_list + (
make_option('--rebuild', action='store_true', dest='rebuild',
default=False, help='reencode all derivatives again'),
make_option('--forground', action='store_true', dest='forground',
default=False, help='dont dispatch encoding to celery but run in forground'),
)
def handle(self, **options):
for s in models.Stream.objects.filter(source=None):
if options['forground']:
extract_derivatives(s.item.id, options['rebuild'])
else:
extract_derivatives.delay(s.item.id, options['rebuild'])

View file

@ -409,7 +409,7 @@ class Stream(models.Model):
def path(self, name=''): def path(self, name=''):
return self.file.get_path(name) return self.file.get_path(name)
def extract_derivatives(self): def extract_derivatives(self, rebuild=False):
config = settings.CONFIG['video'] config = settings.CONFIG['video']
for resolution in config['resolutions']: for resolution in config['resolutions']:
for f in config['formats']: for f in config['formats']:
@ -422,6 +422,8 @@ class Stream(models.Model):
derivative.video.name = os.path.join(os.path.dirname(self.video.name), name) derivative.video.name = os.path.join(os.path.dirname(self.video.name), name)
derivative.encode() derivative.encode()
derivative.save() derivative.save()
else if rebuild or not derivative.available:
derivative.encode()
return True return True
def encode(self): def encode(self):

View file

@ -104,6 +104,14 @@ def process_stream(fileId):
file.item.update_timeline() file.item.update_timeline()
return True return True
@task(queue="encoding")
def extract_derivatives(fileId, rebuild=False):
file = models.File.objects.get(id=fileId)
streams = file.streams.filter(source=None)
if streams.count() > 0:
stream[0].extract_derivatives(rebuild)
return True
@task(queue="encoding") @task(queue="encoding")
def update_stream(id): def update_stream(id):
s = models.Stream.objects.get(pk=id) s = models.Stream.objects.get(pk=id)