057 B站缓存视频重命名

B站更改了视频音频的存储方式:在使用手机下载以后怎么进行合并以及重命名呢?

使用下面程序的前提是安装了ffmpeg并且添加了环境变量

  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
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
# -*- coding: utf-8 -*-
"""
Created on Wed Apr  1 18:33:10 2020

@author: zangz
"""


import ctypes
import time
import random
import tkinter as tk
from tkinter import filedialog
import os
import json
import os.path
import re






def myCMDmainf2(path1,path2,name):
    ver=os.popen("ffmpeg -i "+path1+" -i "+path2+" -c:v copy -c:a aac -strict experimental "+name)
    ver.close()


def get_file(path):
    list1=[]#用于存储递归查找到的所有文件,传递给函数
    fileList = os.listdir(path)  # 获取path目录下所有文件
    for filename in fileList:
        pathTmp = os.path.join(path,filename) # 获取path与filename组合后的路径
        if os.path.isdir(pathTmp):  # 如果是目录
            a=get_file(pathTmp) # 则递归查找(注意一定要有接受变量,不然就出错了)
            for i in a:
                list1.append(i)
        else: 
            list1.append(pathTmp)
    return list1


#筛选后缀函数,传入包含所有后缀名的列表,以及需要筛选的后缀(默认筛选txt文件)
def shai_xuan_hou_zhui(file_path_list,hou_zhui='.txt'):

    list2=[]  #用于储存筛选好的文件的路径
    for filepath in file_path_list:
        # os.path.splitext():分离文件名与扩展名
        if os.path.splitext(filepath)[1] == hou_zhui:
            list2.append(filepath)
    #        print(filepath +'\n')

    return list2
#



while True:
    root = tk.Tk()
    root.withdraw()
    path = filedialog.askdirectory()
    file_path_list=get_file(path)
    json_list=shai_xuan_hou_zhui(file_path_list,'.json')  #筛选出json文件的路径
    for path_json in json_list:
        if path_json.endswith("entry.json"):  #只要包含这个文件信息的json文件
            with open(path_json,'r',encoding='utf-8') as f:
                load_dict=json.load(f)    #将json文件转换成字典
                list_split=path_json.split('\\') #将路径进行切分
                number = int(list_split[1]) #这个是文件夹编号的名字,为了把全部视频按编号进行排序
                str1=''
                if number < 10:
                    str1='00'+str(number)
                elif number < 100 :
                    str1='0'+str(number)
                else:
                    str1=str(number)
                # file_num = load_dict['page_data']['page']
                title=load_dict['page_data']['download_subtitle'] #获取本来应该的文件名
                title= title.replace("/","")
                type_tag = str(load_dict['type_tag'])
            if type_tag[0:3] == "lua":
                ret = re.sub(r"entry.json", '', path_json) #获取取出json文件名的路径
                ret = ret.replace("\\","/")
                old_name_origin=ret+type_tag #得到原始的路径
                file_path_list1=get_file(old_name_origin)
                for qq in range(0,(len(file_path_list1)-1)):
                    old_name=old_name_origin+'/'+ str(qq)+'.blv'     #得到原始的路径
                    new_name=ret+ type_tag + '/'+str1+'_'+ title+'_'+str(qq)+'.mp4' #新的文件名
                    os.rename(old_name,new_name) #进行重命名操作
                    num.append(ret)
                    result.append(title)
            else:
                ret = re.sub(r"entry.json", '', path_json) #获取取出json文件名的路径
                old_name_origin=ret + type_tag+'/' #得到原始的路径
                path1=old_name_origin+"video.m4s"
                path2=old_name_origin+"audio.m4s"
                new_name=old_name_origin+str1+'_'+ title+'.mp4' #新的文件名
                name = old_name_origin+str1+'_'+'output.mp4'
                # print(path1,path2,new_name)
                myCMDmainf2(path1,path2,name)
                print(name)
                print(new_name)
                os.rename(name,new_name) #进行重命名操作

最后使用搜索将后缀为mp4的文件给保存到一个新的文件夹中就好了 image.png

exe 打包链接:

链接:https://pan.baidu.com/s/1H8SB58VFyvBpb-8ilRiDsg 提取码:cjhd