add manage.py command to extract derivatives, fixes #783
This commit is contained in:
parent
55992dd834
commit
76aa590bbb
3 changed files with 39 additions and 2 deletions
27
pandora/archive/management/commands/extract_derivatives.py
Normal file
27
pandora/archive/management/commands/extract_derivatives.py
Normal 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'])
|
|
@ -409,7 +409,7 @@ class Stream(models.Model):
|
|||
def path(self, name=''):
|
||||
return self.file.get_path(name)
|
||||
|
||||
def extract_derivatives(self):
|
||||
def extract_derivatives(self, rebuild=False):
|
||||
config = settings.CONFIG['video']
|
||||
for resolution in config['resolutions']:
|
||||
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.encode()
|
||||
derivative.save()
|
||||
else if rebuild or not derivative.available:
|
||||
derivative.encode()
|
||||
return True
|
||||
|
||||
def encode(self):
|
||||
|
|
|
@ -104,6 +104,14 @@ def process_stream(fileId):
|
|||
file.item.update_timeline()
|
||||
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")
|
||||
def update_stream(id):
|
||||
s = models.Stream.objects.get(pk=id)
|
||||
|
|
Loading…
Reference in a new issue