B站上傳字幕問題解決

博客:blog.shinelee.me | 博客園 | CSDNpython

B站上傳字幕時,若是srt文件中出現以下空行,則會報錯,僅上傳了空行前的部分
srt file
因而寫了個python腳本,以下:git

import pysrt
import glob

srt_files = glob.glob('./*.srt')

for f in srt_files:
    subs = pysrt.open(f)
    for sub in subs:
        if sub.text == '':
            sub.text = ' '
    subs.save(f, encoding='utf-8')

解析srt文本,對象化爲subs,判斷當前字幕的文本是否是空串,若是是空串,變爲空格,再保存文件。github

這樣上傳字幕就不會出問題了。.net

pysrt github地址:https://github.com/byroot/pysrtcode

經過pip install pysrt安裝。對象

相關文章
相關標籤/搜索