-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmerge_flv.py
More file actions
54 lines (45 loc) · 1.54 KB
/
merge_flv.py
File metadata and controls
54 lines (45 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# -*- encoding: utf-8 -*-
# @Author: RZH
from re import findall
from os import system, listdir, rename, remove
def rename_all():
"""
ffmpeg doesn't support Chinese characters in filename
:return: None
"""
for file in listdir('.'):
rename(file, ''.join(findall('[\x00-\xff]', file)).replace(' ', ''))
return None
def group_files() -> dict:
"""
:return: {title: [flv_file_1, flv_file_2, ...], ...}
"""
groups = {}
ass_files = filter(lambda x: x[-3:] == 'ass', listdir('.'))
flv_files = sorted(list(filter(lambda x: x[-3:] == 'flv', listdir('.'))))
for ass_file in ass_files:
title = ass_file[:-4]
groups[title] = []
for flv_file in flv_files:
if findall(r'^%s' % title, flv_file):
groups[title].append(flv_file)
return groups
def merge_all(src: dict, delete_ori: bool = False):
"""
:param src: {title: [flv_file_1, flv_file_2, ...], ...}
:param delete_ori: delete the old file (after merging them) or not
:return: None
"""
for title, files in src.items():
with open('merge.txt', 'w', encoding='utf-8') as f:
f.write("file '" + "'\nfile '".join(files) + "'")
system('ffmpeg -f concat -i merge.txt -c copy %s' % title + '.flv')
if delete_ori:
for file in files:
remove(file)
remove('merge.txt')
return None
if __name__ == '__main__':
rename_all()
merge_all(group_files(), delete_ori=True)
pass