import os,sys,re
import pathlib,json
def mager(dir_path):
if dir_path[-1] != r'/':
dir_path +=r'/'
path_list = list()
for root,dirs,files in os.walk(dir_path): #路径遍历
if "entry.json" in files:
path_list.append(str(root))
if path_list == []:
return 0
for x in path_list:
str_c = ""
print("dir:"+x)
with open(x+"/entry.json","r") as load_f:
config_file = json.load(load_f)
try:
format_list = ["unknown",".blv",".m4s"]
try: #格式判断
file_format = format_list[config_file["media_type"]]
except:
file_format = format_list[0]
try:
if config_file["title"] not in config_file["page_data"]["download_subtitle"]:
str_c = config_file["title"]
except:
pass
str_c += str(config_file["page_data"]["page"])
try:
if config_file["page_data"]["part"] not in config_file["page_data"]["download_subtitle"]:
str_c += config_file["page_data"]["part"]
except:
pass
str_c += config_file["page_data"]["download_subtitle"]
except:
pass
if file_format != format_list[0]:
file_path = x+"/"+str(config_file["type_tag"])
for root_f,dirs_f,files_f in os.walk(file_path):
meger_comand = r"ffmpeg "
for file_b in files_f:
if file_format in file_b:
meger_comand += " -i " +file_path+"/"+file_b
meger_comand += ' "'+dir_path+clean_file_name(str_c + ".mp4")+'"'
print(meger_comand)
os.system(meger_comand)
def clean_file_name(filename:str):
invalid_chars='[\\\/:*?"<>|]'
replace_char='-'
return re.sub(invalid_chars,replace_char,filename)
if __name__ == "__main__":
for path_t in sys.argv:
if pathlib.Path(path_t).is_dir(): #目录是否存在
mager(path_t)
运行命令 参数跟需要转换的视频缓存目录
python bilimeger.py /e/down/*
在/e/down/*目录下合成视频
识别json文件合成视频音频分离的缓存文件到mp4
在msys2下使用
在powersheel下路径识别有点问题需要改一下