diff options
author | Qijiang Fan <fqj1994@gmail.com> | 2015-08-24 00:31:30 +0800 |
---|---|---|
committer | Sergey M․ <dstftw@gmail.com> | 2015-09-26 20:21:27 +0600 |
commit | b65e5bb72f48c57316ac0166141810bd1e7b2de8 (patch) | |
tree | 8b546054c3c7c3987d9e455ff9ae436a4fb67505 /youtube_dl/extractor | |
parent | 54914380c04ac7b52fa6dc69d49576fb7afe5f27 (diff) |
[qqmusic] Add subtitles for QQMusic
Use .lrc lyrics as subtitles if lyrics in lrc format exist.
Diffstat (limited to 'youtube_dl/extractor')
-rw-r--r-- | youtube_dl/extractor/qqmusic.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/youtube_dl/extractor/qqmusic.py b/youtube_dl/extractor/qqmusic.py index 1654a641f..8ead04606 100644 --- a/youtube_dl/extractor/qqmusic.py +++ b/youtube_dl/extractor/qqmusic.py @@ -58,6 +58,11 @@ class QQMusicIE(InfoExtractor): curMs = int(time.time() * 1000) % 1000 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): mid = self._match_id(url) @@ -112,15 +117,25 @@ class QQMusicIE(InfoExtractor): self._check_formats(formats, mid) self._sort_formats(formats) - return { + actual_lrc_lyrics = self._filter_lrc(lrc_content) + + info_dict = { 'id': mid, 'formats': formats, 'title': song_name, 'upload_date': publish_time, 'creator': singer, '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): |