婆罗门
精华
|
战斗力 鹅
|
回帖 0
注册时间 2016-1-9
|
之前缓存大量番剧 写过一个脚本合并
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- import json
- import os
- import re
- import subprocess
- def get_output(output_path):
- result = {}
- for root, dirs, files in os.walk(output_path):
- if not dirs:
- entry_file = os.path.join(os.path.split(root)[0], 'entry.json')
- if os.path.isfile(entry_file):
- with open(entry_file, 'r', encoding='utf8') as f:
- flv_json = json.loads(f.read())
- if 'ep' in flv_json:
- output = '{}_{}_{}.mp4'.format(
- flv_json['title'],
- flv_json['ep']['index'],
- flv_json['ep']['index_title']
- )
- elif 'page_data' in flv_json:
- output = '{}_{}_{}.mp4'.format(
- flv_json['title'],
- flv_json['page_data']['page'],
- flv_json['page_data']['part']
- )
- else:
- output = flv_json['title'] + '.mp4'
- output = re.sub(r'[\/:*?"<>:|]', ' ', output)
- output = os.path.join(output_path, output)
- flvs = sorted([flv for flv in files if flv.endswith('.blv')],
- key=lambda a: int(a.split('.')[0]))
- result[output] = [os.path.join(root, flv) for flv in flvs]
- return result
- def create_concat_file(files, output):
- concat_file = output + '.txt'
- with open(concat_file, 'w', encoding='utf8') as f:
- for file in files:
- f.write("file '%s'\n" % file)
- return concat_file
- def concat_flv(files, output):
- concat_file = create_concat_file(files, output)
- params = ['ffmpeg', '-f', 'concat', '-safe', '-1',
- '-i', concat_file, '-c', 'copy',
- '-bsf:a', 'aac_adtstoasc', output]
- subprocess.call(params)
- os.remove(concat_file)
- def main():
- output_path = os.path.dirname(os.path.realpath(__file__))
- files = get_output(output_path)
- for output, flvs in files.items():
- concat_flv(flvs, output)
- if __name__ == '__main__':
- main()
复制代码 |
|