[bilibili] support audio lyrics

This commit is contained in:
Mort Yao 2019-02-20 15:07:53 +01:00
parent 11184c2552
commit 96a25273a1
No known key found for this signature in database
GPG Key ID: 07DA00CB78203251
2 changed files with 12 additions and 2 deletions

View File

@ -34,6 +34,7 @@ class VideoExtractor():
self.ua = None
self.referer = None
self.danmaku = None
self.lyrics = None
if args:
self.url = args[0]
@ -238,9 +239,11 @@ class VideoExtractor():
output_dir=kwargs['output_dir'],
merge=kwargs['merge'],
av=stream_id in self.dash_streams)
if 'caption' not in kwargs or not kwargs['caption']:
print('Skipping captions or danmaku.')
return
for lang in self.caption_tracks:
filename = '%s.%s.srt' % (get_filename(self.title), lang)
print('Saving %s ... ' % filename, end="", flush=True)
@ -249,12 +252,19 @@ class VideoExtractor():
'w', encoding='utf-8') as x:
x.write(srt)
print('Done.')
if self.danmaku is not None and not dry_run:
filename = '{}.cmt.xml'.format(get_filename(self.title))
print('Downloading {} ...\n'.format(filename))
with open(os.path.join(kwargs['output_dir'], filename), 'w', encoding='utf8') as fp:
fp.write(self.danmaku)
if self.lyrics is not None and not dry_run:
filename = '{}.lrc'.format(get_filename(self.title))
print('Downloading {} ...\n'.format(filename))
with open(os.path.join(kwargs['output_dir'], filename), 'w', encoding='utf8') as fp:
fp.write(self.lyrics)
# For main_dev()
#download_urls(urls, self.title, self.streams[stream_id]['container'], self.streams[stream_id]['size'])
keep_obj = kwargs.get('keep_obj', False)

View File

@ -399,8 +399,8 @@ class Bilibili(VideoExtractor):
# set audio title
self.title = song_info['data']['title']
lyric = song_info['data']['lyric']
# TODO: download lyrics
# get lyrics
self.lyrics = get_content(song_info['data']['lyric'])
api_url = self.bilibili_audio_api(sid)
api_content = get_content(api_url, headers=self.bilibili_headers())