censored version

This commit is contained in:
j 2025-10-08 13:25:22 +01:00
commit a7816225a5

View file

@ -1,6 +1,7 @@
import json import json
import os import os
import re import re
import subprocess
from collections import defaultdict from collections import defaultdict
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
@ -33,6 +34,7 @@ class Command(BaseCommand):
def add_arguments(self, parser): def add_arguments(self, parser):
parser.add_argument('--lang', action='store', dest='lang', default=None, help='subtitle language') parser.add_argument('--lang', action='store', dest='lang', default=None, help='subtitle language')
parser.add_argument('--prefix', action='store', dest='prefix', default="/srv/t_for_time", help='prefix to build clips in') parser.add_argument('--prefix', action='store', dest='prefix', default="/srv/t_for_time", help='prefix to build clips in')
parser.add_argument('--censored', action='store', dest='censored', default=None, help='censor items from list')
def handle(self, **options): def handle(self, **options):
prefix = options['prefix'] prefix = options['prefix']
@ -45,8 +47,12 @@ class Command(BaseCommand):
tlang = None tlang = None
if lang == "en": if lang == "en":
lang = None lang = None
if options['censored']:
censored_list = itemlist.models.List.get(options["censored"])
censored = list(censored_list.get_items(censored_list.user).all().values_list('public_id', flat=True))
clips = [] clips = []
for i in item.models.Item.objects.filter(sort__type='original'): for i in item.models.Item.objects.filter(sort__type='original'):
original_target = ""
qs = item.models.Item.objects.filter(data__title=i.data['title']).exclude(id=i.id) qs = item.models.Item.objects.filter(data__title=i.data['title']).exclude(id=i.id)
if qs.count() >= 1: if qs.count() >= 1:
clip = {} clip = {}
@ -65,6 +71,10 @@ class Command(BaseCommand):
if os.path.islink(target): if os.path.islink(target):
os.unlink(target) os.unlink(target)
os.symlink(source, target) os.symlink(source, target)
if type_ == "original":
original_target = target
if options['censored'] and e.public_id in censored:
target = '/srv/t_for_time/censored.mp4'
clip[type_] = target clip[type_] = target
durations.append(e.files.filter(selected=True)[0].duration) durations.append(e.files.filter(selected=True)[0].duration)
clip["duration"] = min(durations) clip["duration"] = min(durations)
@ -77,8 +87,7 @@ class Command(BaseCommand):
clip["duration"] = cd clip["duration"] = cd
clip['tags'] = i.data.get('tags', []) clip['tags'] = i.data.get('tags', [])
clip['editingtags'] = i.data.get('editingtags', []) clip['editingtags'] = i.data.get('editingtags', [])
name = os.path.basename(clip['original']) name = os.path.basename(original_target)
seqid = re.sub("Hotel Aporia_(\d+)", "S\\1_", name) seqid = re.sub("Hotel Aporia_(\d+)", "S\\1_", name)
seqid = re.sub("Night March_(\d+)", "S\\1_", seqid) seqid = re.sub("Night March_(\d+)", "S\\1_", seqid)
seqid = re.sub("_(\d+)H_(\d+)", "_S\\1\\2_", seqid) seqid = re.sub("_(\d+)H_(\d+)", "_S\\1\\2_", seqid)
@ -129,3 +138,18 @@ class Command(BaseCommand):
} }
with open(os.path.join(prefix, 'voice_over.json'), 'w') as fd: with open(os.path.join(prefix, 'voice_over.json'), 'w') as fd:
json.dump(voice_over, fd, indent=2, ensure_ascii=False) json.dump(voice_over, fd, indent=2, ensure_ascii=False)
if options['censored']:
censored_mp4 = '/srv/t_for_time/censored.mp4'
if not os.path.exists(censored_mp4):
cmd = [
"ffmpeg",
"-nostats", "-loglevel", "error",
"-f", "lavfi",
"-i", "color=color=white:size=1920x1080:rate=24",
"-t", "3600",
"-c:v", "libx264",
"-pix_fmt", "yuv420p",
censored_mp4
]
subprocess.call(cmd)