欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python批量合成bilibili的m4s緩存文件為MP4格式 ver2.5

 更新時(shí)間:2020年12月01日 08:31:51   作者:偃笙  
這篇文章主要介紹了python批量合成bilibili的m4s緩存文件為MP4格式 ver2.5的相關(guān)知識(shí),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

相對(duì)之前版本更新內(nèi)容:

※ 根據(jù)UP主分類存放導(dǎo)出的視頻。

※ 新增一種標(biāo)題格式

注意:需要安裝ffmpeg才可使用
ffmpeg下載地址: https://ffmpeg.zeranoe.com/builds/
ffmpeg安裝方法:
解壓好下載的壓縮包后,再將bin目錄加入Path環(huán)境變量中 按Win+R 運(yùn)行 輸入cmd 在彈出的框框中輸入 ffmpeg ,如果沒(méi)有出現(xiàn)"既不是內(nèi)部或外部命令"之類的話就是安裝成功了
參考鏈接: http://www.dbjr.com.cn/article/153806.htm
運(yùn)行截圖

 

工具源碼

import os
import json
import random
import time
import requests

# 清除所有空格
def clearSpace(str):
 return str.replace(" ", "").replace(" ", "");


# 獲取指定Uid的Up主名
def getUpNameByUid(uid):
 try:
 url = 'https://space.bilibili.com/' + str(uid)
 html = requests.get(url)
 html.encoding = 'UTF-8'
 html = html.text
 index1 = html.find("<title>") + len("<title>")
 index2 = html.find("的個(gè)人空間", index1)
 result = html[index1:index2]
 if (result != ""):
  return result
 else:
  return uid
 except Exception:
 return uid

# 獲取時(shí)間戳
def getTimeStamp():
 t = time.localtime(time.time())
 return str(t.tm_year) + '_' + str(t.tm_mon) + '_' + str(t.tm_mday) + '_' + str(t.tm_hour) + \
  str(t.tm_min) + str(t.tm_sec) + str(random.randint(10, 99))


# 更正文件名
def correctFileName(name):
 n_list = list(name)
 for i in range(0, len(n_list)):
 index = 0
 for i in n_list:
  if (
   i == '\\' or i == '/' or i == ':' or i == '*' or i == '?' or i == '\"' or i == '<' or i == '>' or i == '|'):
  n_list.pop(index)
  index = index + 1
 return ''.join(n_list)

# 讀取json文件
def getVideoName(path):
 f = open(path, encoding='utf-8')
 setting = json.load(f)
 try:
 result = setting['page_data']['download_subtitle'] # 注意多重結(jié)構(gòu)的讀取語(yǔ)法
 except KeyError:
 try:
  result = setting['title'] + ' 第' + setting['ep']['index'] + '話 ' + setting['ep']['index_title']
 except KeyError:
  try:
  result = setting['title']
  except KeyError:
  result = getTimeStamp()
 return result


def getVideoOwner(path):
 try:
 f = open(path, encoding='utf-8')
 setting = json.load(f)
 return clearSpace(getUpNameByUid(setting['owner_id']))
 except Exception:
 return ""

# 獲取文件列表
def getFileList(file_dir):
 # 定義四個(gè)列表
 title = []
 owner = []
 videoPath = []
 audioPath = []
 # 遍歷文件目錄
 for root, dirs, files in os.walk(file_dir):
 if ('entry.json' in files):
  title.append(getVideoName(str(root) + '\\entry.json'))
  owner.append(getVideoOwner(str(root) + '\\entry.json'))
 if ('video.m4s' in files and 'audio.m4s' in files):
  videoPath.append(str(root) + '\\video.m4s')
  audioPath.append(str(root) + '\\audio.m4s')
 if (len(title) < len(videoPath)):
  title.append(getTimeStamp())
 if ('0.blv' in files):
  title.pop()
 return [title, owner, videoPath, audioPath]


# 輸出mp4文件
def getMP4(title, owner, video_path, audio_path):
 # 生成輸出目錄
 if not os.path.exists("./output"):
 os.mkdir("./output")
 # 循環(huán)生成MP4文件
 for i in title:
 reName = correctFileName(i)
 # 開始生成MP4文件
 if not os.path.exists("./output/" + reName + ".mp4"):
  # 獲取臨時(shí)文件時(shí)間戳
  t_stamp = getTimeStamp()
  # 開始合成
  os.system(
  "ffmpeg -i " + video_path[title.index(i)] + " -i " + audio_path[
   title.index(i)] + " -codec copy ./output/" + t_stamp + ".mp4")
  # 設(shè)置所屬Up主
  curOwner = owner[title.index(i)]
  if curOwner != "":
  if not os.path.exists("./output/" + curOwner):
   os.mkdir("./output/" + curOwner)
  os.rename("./output/" + t_stamp + ".mp4", "./output/" + curOwner + "/" + reName + ".mp4")
  else:
  # 將臨時(shí)文件時(shí)間戳改為標(biāo)題名
  os.rename("./output/" + t_stamp + ".mp4", "./output/" + reName + ".mp4")
  print("正在合成...")
  print("標(biāo)題:" + reName)
  print("UP主:" + curOwner)
  print("視頻源:" + video_path[title.index(i)])
  print("音頻源:" + audio_path[title.index(i)])
  time.sleep(1)

print("歡迎使用批量合成M4S工具 ver2.5")
fileDir = str(input("請(qǐng)輸入含M4S文件的目錄:"))
f = getFileList(fileDir)
getMP4(f[0], f[1], f[2], f[3])
print("合成完畢")

已編譯好的可執(zhí)行文件(EXE):

鏈接: https://pan.baidu.com/s/1bLOg6GGJ5Wp7gcW73sXzvg

提取碼: yqvm

到此這篇關(guān)于python批量合成bilibili的m4s緩存文件為MP4格式 ver2.5的文章就介紹到這了,更多相關(guān)python批量合成bilibili緩存文件內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論