generate clips
This commit is contained in:
parent
c48f227dfc
commit
21283e38ac
1 changed files with 40 additions and 0 deletions
40
management/commands/generate_clips.py
Normal file
40
management/commands/generate_clips.py
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
import item.models
|
||||||
|
import itemlist.models
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = 'generate symlinks to clips and clips.json'
|
||||||
|
|
||||||
|
def add_arguments(self, parser):
|
||||||
|
parser.add_argument('--prefix', action='store_', dest='prefix', default="/srv/t_for_time", help='prefix to build clips in')
|
||||||
|
|
||||||
|
def handle(self, **options):
|
||||||
|
prefix = options['prefix']
|
||||||
|
clips = []
|
||||||
|
for i in item.models.Item.objects.filter(data__type__contains="Original"):
|
||||||
|
qs = item.models.Item.objects.filter(data__title=i.data['title']).exclude(id=i.id)
|
||||||
|
if qs.count() == 2:
|
||||||
|
clip = {}
|
||||||
|
durations = []
|
||||||
|
for e in item.models.Item.objects.filter(data__title=i.data['title']):
|
||||||
|
source = i.files.all()[0].data.path
|
||||||
|
ext = os.path.splitext(source)[1]
|
||||||
|
type_ = e.data['type'][0].lower()
|
||||||
|
target = os.path.join(prefix, type_, i.data['title'] + ext)
|
||||||
|
os.makedirs(os.path.dirname(target), exist_ok=True)
|
||||||
|
if os.path.exists(target):
|
||||||
|
os.unlink(target)
|
||||||
|
os.symlink(source, target)
|
||||||
|
clip[type_] = target
|
||||||
|
durations.append(e.files.all()[0].duration)
|
||||||
|
clip["duration"] = min(durations)
|
||||||
|
clip['tags'] = i.data.get('tags', [])
|
||||||
|
clips.append(clip)
|
||||||
|
|
||||||
|
with open(os.path.join(prefix, 'clips.json'), 'w') as fd:
|
||||||
|
json.dump(clips, fd, indent=2, ensure_ascii=False)
|
Loading…
Reference in a new issue