bilibili手机缓存视频转换为mp4

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下路径识别有点问题需要改一下

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值