fix bilibili.py download audio error when lrc file length is less than 0.

This commit is contained in:
gr.zhu 2021-07-31 19:28:28 +08:00
parent 63a7662be4
commit 52e63a43ab
2 changed files with 3 additions and 60 deletions

View File

@ -436,7 +436,9 @@ class Bilibili(VideoExtractor):
self.title = song_info['data']['title'] self.title = song_info['data']['title']
# get lyrics # get lyrics
self.lyrics = get_content(song_info['data']['lyric']) lrc = song_info['data']['lyric']
if lrc is not None and len(lrc) > 0:
self.lyrics = get_content(lrc)
api_url = self.bilibili_audio_api(sid) api_url = self.bilibili_audio_api(sid)
api_content = get_content(api_url, headers=self.bilibili_headers()) api_content = get_content(api_url, headers=self.bilibili_headers())

View File

@ -1,59 +0,0 @@
import traceback
import sys
from you_get import common as you_get
import io
import os
url = "https://www.bilibili.com/video/BV1GV411p7P9"
path = os.path.dirname(os.path.realpath(__file__))
def getJson(url):
from you_get import common as you
try:
__console__ = sys.stdout
f = io.StringIO()
sys.stdout = f
sys.argv = ['you-get', url, '--json']
you.main()
text = f.getvalue()
sys.stdout = __console__
print(text)
except:
traceback.print_exc()
def getDefaultDownloadInfo(url):
try:
__console__ = sys.stdout
f = io.StringIO()
sys.stdout = f
sys.argv = ['you-get', url, '-u']
you_get.main()
text = f.getvalue()
sys.stdout = __console__
print(text)
except:
traceback.print_exc()
def download(url, path):
try:
sys.argv = ['you-get', url, '-o', path, '--no-caption', '--debug']
you_get.main()
except:
traceback.print_exc()
if __name__ == '__main__':
# only use one sentence, they all ok (使用如下的单条语句,都是可以正常打印的, 并且可以下载视频)
# both are cant download video with combine (但是将语句组合使用,打印出的结果就有问题了, 并且无法下载视频)
# use these lines, print double json text (使用如下语句,将会打印出两次 json 解析数据)
getDefaultDownloadInfo(url)
getJson(url)
download(url, path)
# or use these lines, print triple json text (使用如下语句,仅仅改变排序,将会打印出三次 json 解析数据)
# getJson(url)
# getDefaultDownloadInfo(url)
# download(url, "save path")