B站缓存整理工具

python:

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
#make by 纯白 2020.4.6
import os
import json
videopath = os.path.abspath('.')
episodes = os.listdir(videopath)
episodes.remove(os.path.basename(__file__))
for episode in episodes:
episodePath = videopath+'\\%s\\' % episode
contents = os.listdir(episodePath)
for c in contents:
if(os.path.isdir(episodePath+c)):
blvPath = c
elif c == 'entry.json':
with open(episodePath+c, encoding='UTF-8') as jsonf:
temp = json.load(jsonf)
titletemp = temp['page_data']['part']
title = titletemp
blvs = os.listdir(episodePath+blvPath)
with open(episodePath + blvPath + '\\list.txt', 'w', encoding='utf-8') as f:
# 创建list.txt,用于依次存取每个视频的文件名
isblv = True
for blv in blvs:
if blv == 'audio.m4s':
isblv = False
break
elif os.path.splitext(blv)[1] == '.blv': # 依次寻找blv文件
f.write("file '%s'\n" % blv) # list.txt 以“file '文件名'”的格式一行行存储
if isblv:
cmd = r'%s && cd %s && ffmpeg -f concat -i list.txt -c copy "%s.mp4"' % (
videopath[0:2], episodePath + blvPath, videopath+'\\'+title)
else:
cmd = r'%s && cd %s && ffmpeg -i video.m4s -i audio.m4s -c copy "%s.mp4"' % (
videopath[0:2], episodePath + blvPath, videopath+'\\'+title)
# 首先定位到视频所在盘,然后cd到视频片段所在的目录,
# 最后运行ffmpeg的命令
os.system(cmd) # 执行命
# print(cmd)
-------------end-------------