add prefix
This commit is contained in:
parent
8defb3da5a
commit
714a29015e
3 changed files with 44 additions and 20 deletions
27
encode.py
27
encode.py
|
@ -1,7 +1,8 @@
|
|||
#!/usr/bin/python3
|
||||
from argparse import ArgumentParser
|
||||
from glob import glob
|
||||
import os
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
|
@ -34,7 +35,7 @@ def is_new(xml, mp4):
|
|||
)
|
||||
return vtime < xtime
|
||||
|
||||
def encode(xml, force=False):
|
||||
def encode(xml, force=False, prefix='.'):
|
||||
item_json = xml.replace('.xml', '.json')
|
||||
audio_xml = xml.replace('.xml', '.audio.xml')
|
||||
vocals_xml = xml.replace('.xml', '.vocals.xml')
|
||||
|
@ -48,7 +49,7 @@ def encode(xml, force=False):
|
|||
left = video + '_left.wav'
|
||||
right = video + '_right.wav'
|
||||
|
||||
public_mp4 = 'public/' + mp4.split('/')[-1][0].lower() + mp4.split('/')[-2] + '.1080p.mp4'
|
||||
public_mp4 = os.path.join(prefix, 'public', mp4.split('/')[-1][0].lower() + mp4.split('/')[-2] + '.1080p.mp4')
|
||||
public_mp4_480p = public_mp4.replace('.1080p.mp4', '.480p.mp4')
|
||||
|
||||
if force or is_new(xml, public_mp4):
|
||||
|
@ -127,12 +128,13 @@ def encode(xml, force=False):
|
|||
shutil.move(mp4_480p, public_mp4_480p)
|
||||
cmd = [
|
||||
'./subtitles.py',
|
||||
'--prefix', prefix
|
||||
item_json
|
||||
]
|
||||
subprocess.call(cmd)
|
||||
|
||||
def encode_all():
|
||||
for xml in sorted(glob('output/*/*.xml')):
|
||||
def encode_all(prefix):
|
||||
for xml in sorted(glob(os.path.join(prefix, 'output/*/*.xml'))):
|
||||
parts = xml.split('.')
|
||||
if len(parts) > 2 and parts[-2] in (
|
||||
'audio',
|
||||
|
@ -142,10 +144,17 @@ def encode_all():
|
|||
'vocals',
|
||||
):
|
||||
continue
|
||||
encode(xml)
|
||||
encode(xml, prefix=prefix)
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) == 2:
|
||||
encode(sys.argv[1], True)
|
||||
usage = "usage: %(prog)s [options] xml"
|
||||
parser = ArgumentParser(usage=usage)
|
||||
parser.add_argument('-p', '--prefix', dest='prefix',
|
||||
help='version prefix', default='.')
|
||||
parser.add_argument('files', metavar='path', type=str, nargs='*', help='xml files')
|
||||
opts = parser.parse_args()
|
||||
if opts.files:
|
||||
for xml in opts.files:
|
||||
encode(xml, True, prefix=opts.prefix)
|
||||
else:
|
||||
encode_all()
|
||||
encode_all(prefix=opts.prefix)
|
||||
|
|
22
render.py
22
render.py
|
@ -1,11 +1,12 @@
|
|||
#!/usr/bin/python3
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import subprocess
|
||||
from argparse import ArgumentParser
|
||||
from collections import defaultdict
|
||||
import string
|
||||
from glob import glob
|
||||
import json
|
||||
import os
|
||||
import string
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from pi import random
|
||||
from keywords import KEYWORDS
|
||||
|
@ -427,13 +428,20 @@ def sequence(seq, letter):
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
render_xml = len(sys.argv) < 2 or sys.argv[1] != 'json'
|
||||
usage = "usage: %(prog)s [options] xml"
|
||||
parser = ArgumentParser(usage=usage)
|
||||
parser.add_argument('-p', '--prefix', dest='prefix',
|
||||
help='version prefix', default='.')
|
||||
parser.add_argument('files', metavar='path', type=str, nargs='*', help='json files')
|
||||
opts = parser.parse_args()
|
||||
|
||||
render_xml = opts.files != ['json']
|
||||
for n in range(10):
|
||||
seq = random(n * 1000)
|
||||
#for letter in ('T', 'W'):
|
||||
for letter in string.ascii_uppercase:
|
||||
r = sequence(seq, letter)
|
||||
tjson = 'output/%02d/%s.json' % (n, letter)
|
||||
tjson = os.path.join(opts.prefix, 'output/%02d/%s.json' % (n, letter))
|
||||
folder = os.path.dirname(tjson)
|
||||
if not os.path.exists(folder):
|
||||
ox.makedirs(folder)
|
||||
|
|
15
subtitles.py
15
subtitles.py
|
@ -216,6 +216,13 @@ def overlaps(src, other):
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
usage = "usage: %(prog)s [options] json"
|
||||
parser = ArgumentParser(usage=usage)
|
||||
parser.add_argument('-p', '--prefix', dest='prefix',
|
||||
help='version prefix', default='.')
|
||||
parser.add_argument('files', metavar='path', type=str, nargs='*', help='json files')
|
||||
opts = parser.parse_args()
|
||||
|
||||
if os.path.exists('subtitles.json'):
|
||||
items = json.load(open('subtitles.json'))
|
||||
else:
|
||||
|
@ -223,12 +230,12 @@ if __name__ == '__main__':
|
|||
with open('subtitles.json', 'w') as fd:
|
||||
json.dump(items, fd, indent=4, ensure_ascii=False, sort_keys=True)
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
files = sys.argv[1:]
|
||||
else:
|
||||
files = glob('output/*/*.json')
|
||||
files = opts.files
|
||||
if not files:
|
||||
files = glob(os.path.join(opts.prefix, 'output/*/*.json'))
|
||||
for item_json in files:
|
||||
prefix = 'public/' + item_json.split('/')[-1][0].lower() + item_json.split('/')[-2] + '.'
|
||||
prefix = os.path.join(opts.prefix, prefix)
|
||||
output_json = prefix + '1080p.json'
|
||||
output_srt = prefix + '1080p.srt'
|
||||
render_subtitles(item_json, output_json, output_srt, ['ko', 'en'])
|
||||
|
|
Loading…
Reference in a new issue