mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-11-23 02:32:16 +00:00
[qqmusic] Add subtitles for QQMusic
Use .lrc lyrics as subtitles if lyrics in lrc format exist.
This commit is contained in:
parent
54914380c0
commit
b65e5bb72f
1 changed files with 17 additions and 2 deletions
|
@ -58,6 +58,11 @@ class QQMusicIE(InfoExtractor):
|
||||||
curMs = int(time.time() * 1000) % 1000
|
curMs = int(time.time() * 1000) % 1000
|
||||||
return int(round(random.random() * 2147483647) * curMs % 1E10)
|
return int(round(random.random() * 2147483647) * curMs % 1E10)
|
||||||
|
|
||||||
|
def _filter_lrc(self, data):
|
||||||
|
lyrics_expr = r'(\[[0-9]{2}:[0-9]{2}\.[0-9]{2,}\][^\n]*|\[[^\]]*\])'
|
||||||
|
texts = re.findall(lyrics_expr, data)
|
||||||
|
return ''.join(i + "\n" for i in texts)
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
mid = self._match_id(url)
|
mid = self._match_id(url)
|
||||||
|
|
||||||
|
@ -112,15 +117,25 @@ class QQMusicIE(InfoExtractor):
|
||||||
self._check_formats(formats, mid)
|
self._check_formats(formats, mid)
|
||||||
self._sort_formats(formats)
|
self._sort_formats(formats)
|
||||||
|
|
||||||
return {
|
actual_lrc_lyrics = self._filter_lrc(lrc_content)
|
||||||
|
|
||||||
|
info_dict = {
|
||||||
'id': mid,
|
'id': mid,
|
||||||
'formats': formats,
|
'formats': formats,
|
||||||
'title': song_name,
|
'title': song_name,
|
||||||
'upload_date': publish_time,
|
'upload_date': publish_time,
|
||||||
'creator': singer,
|
'creator': singer,
|
||||||
'description': lrc_content,
|
'description': lrc_content,
|
||||||
'thumbnail': thumbnail_url,
|
'thumbnail': thumbnail_url
|
||||||
}
|
}
|
||||||
|
if actual_lrc_lyrics:
|
||||||
|
info_dict['subtitles'] = {
|
||||||
|
'origin': [{
|
||||||
|
'ext': 'lrc',
|
||||||
|
'data': actual_lrc_lyrics,
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
return info_dict
|
||||||
|
|
||||||
|
|
||||||
class QQPlaylistBaseIE(InfoExtractor):
|
class QQPlaylistBaseIE(InfoExtractor):
|
||||||
|
|
Loading…
Reference in a new issue