use default options instead of passing all over the place
This commit is contained in:
parent
ce51e8c2c4
commit
2a5d741ccf
3 changed files with 14 additions and 3 deletions
|
|
@ -7,9 +7,7 @@ class Command(BaseCommand):
|
||||||
help = 'generate symlinks to clips and clips.json'
|
help = 'generate symlinks to clips and clips.json'
|
||||||
|
|
||||||
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('--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):
|
||||||
return generate_clips(options)
|
return generate_clips(options)
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ class Command(BaseCommand):
|
||||||
def add_arguments(self, parser):
|
def add_arguments(self, parser):
|
||||||
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('--offset', action='store', dest='offset', default="1024", help='inital offset in pi')
|
parser.add_argument('--offset', action='store', dest='offset', default="1024", help='inital offset in pi')
|
||||||
parser.add_argument('--lang', action='store', dest='lang', default=None, help='subtitle language')
|
|
||||||
|
|
||||||
def handle(self, **options):
|
def handle(self, **options):
|
||||||
update_subtitles(options)
|
update_subtitles(options)
|
||||||
|
|
|
||||||
14
render.py
14
render.py
|
|
@ -506,6 +506,7 @@ def parse_lang(lang):
|
||||||
|
|
||||||
|
|
||||||
def render_all(options):
|
def render_all(options):
|
||||||
|
options = load_defaults(options)
|
||||||
prefix = options['prefix']
|
prefix = options['prefix']
|
||||||
duration = int(options['duration'])
|
duration = int(options['duration'])
|
||||||
base = int(options['offset'])
|
base = int(options['offset'])
|
||||||
|
|
@ -897,9 +898,22 @@ def scene_subtitles(scene, options):
|
||||||
offset += clip['duration']
|
offset += clip['duration']
|
||||||
return subs
|
return subs
|
||||||
|
|
||||||
|
|
||||||
|
def load_defaults(options):
|
||||||
|
path = os.path.join(options["prefix"], "options.json")
|
||||||
|
if os.path.exists(path):
|
||||||
|
with open(path) as fd:
|
||||||
|
defaults = json.loads(fd)
|
||||||
|
for key in defaults:
|
||||||
|
if key not in options:
|
||||||
|
options[key] = defaults[key]
|
||||||
|
return options
|
||||||
|
|
||||||
|
|
||||||
def update_subtitles(options):
|
def update_subtitles(options):
|
||||||
import item.models
|
import item.models
|
||||||
|
|
||||||
|
options = load_defaults(options)
|
||||||
prefix = Path(options['prefix'])
|
prefix = Path(options['prefix'])
|
||||||
base = int(options['offset'])
|
base = int(options['offset'])
|
||||||
lang, tlang = parse_lang(options["lang"])
|
lang, tlang = parse_lang(options["lang"])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue