-
Notifications
You must be signed in to change notification settings - Fork 0
/
bilibili_v2.py
48 lines (43 loc) · 1.65 KB
/
bilibili_v2.py
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
import sys
import os
import json
# convert invalided character in name of file to chinese character
def file_format(str):
lt="\\/:*?\"<>|"
for i in lt:
if str.find(i) != -1:
str=str.replace(i,chr(ord(i)+65248))
return str
def run(path):
output="" # ouput path
videoName=""
videoId=0
idWidth=len(str(len(os.listdir(path))))
if os.path.exists(path):
for root, dirs, files in os.walk(path):
if 'entry.json' in files:
with open(root+'\\'+'entry.json', encoding='utf8') as f:
entry=json.load(f)
output=file_format(entry['title'])
if os.path.exists(output) is False:
os.makedirs(output)
videoName=file_format(entry['page_data']['part'])
videoId=entry['page_data']['page']
elif 'index.json' in files:
fileList=list(filter(lambda file:file.endswith('.blv'), files))
sorted(fileList)
tempFile=r'filelist'
with open(tempFile, 'w') as f:
for file in fileList:
f.write('file \'%s\\%s\'\n' % (root, file))
cmd='ffmpeg -v warning -f concat -safe 0 -i \"%s\" -c copy \"%s\\%0*d.%s.mkv\" -hide_banner' % (tempFile, output, idWidth, videoId, videoName)
os.system(cmd)
os.remove(tempFile)
def main():
if len(sys.argv)==2:
run(sys.argv[1])
else:
for dir in os.listdir('.'):
if os.path.isdir(dir):
run(dir)
main()