Skip to content

Instantly share code, notes, and snippets.

@sunoru
Last active August 2, 2019 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunoru/e85a38e20f6437ffebf56fb18ff8561e to your computer and use it in GitHub Desktop.
Save sunoru/e85a38e20f6437ffebf56fb18ff8561e to your computer and use it in GitHub Desktop.
import json
import glob
import os
import subprocess
import sys
DATA_FILE = './data.json'
VLC_PATH = 'C:/Program Files (x86)/VideoLAN/VLC/vlc.exe'
TYPE_IGNORED = 'ignored'
TYPE_OTHERS = 'others'
def load():
if os.path.exists(DATA_FILE):
with open(DATA_FILE) as fi:
return json.load(fi)
return {'videos': {}}
def get_video_list():
return glob.glob('../*/*/*/*.mp4')
def save(data):
with open(DATA_FILE, 'w') as fo:
json.dump(data, fo)
def play(filename):
subprocess.Popen([VLC_PATH, '--one-instance', 'file:///%s' % filename])
def export_main():
data = load()
result_files = {}
for name in data['videos']:
video = data['videos'][name]
video_type = video['type']
if video_type == TYPE_IGNORED:
continue
print('%s: %s', video_type, name)
output_file = result_files.get(video_type, open('./list_%s.txt' % video_type, 'w'))
output_file.write("file './%s'\n" % video['file'])
output_file.write('inpoint %s\noutpoint %s\n' % video['range'])
for f in result_files:
f.close()
def process_main():
data = load()
video_list = get_video_list()
print('%d files.' % len(video_list))
print('Input format: start end type remarks')
for filename in video_list:
name = filename.split(os.sep)[-1].split('-')[0]
print("%s: " % name, end='')
video = data['videos'].get(name, {
'file': filename
})
video_type = video.get('type')
if video_type is not None:
start, end = video.get('range', (None, None))
remarks = video.get('remarks', '')
print("%s %s %s %s" % (start, end, video_type, remarks))
continue
play(filename)
tmp = input().split()
l = len(tmp)
if l == 1:
video['type'] = TYPE_OTHERS
video['remarks'] = tmp[0]
elif l >= 3:
start, end, video_type = tmp[:3]
video['range'] = [float(start), float(end)]
video['type'] = video_type
if l == 4:
video['remarks'] = tmp[3]
else:
video['type'] = TYPE_IGNORED
data['videos'][name] = video
save(data)
def main():
if len(sys.argv) > 1 and sys.argv[1] == 'export':
export_main()
else:
process_main()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment