diff options
author | James Taylor <user234683@users.noreply.github.com> | 2019-08-27 18:04:44 -0700 |
---|---|---|
committer | James Taylor <user234683@users.noreply.github.com> | 2019-08-27 18:04:44 -0700 |
commit | 0c22835dd214dc71e5cd085c5549ffe8dcf7f657 (patch) | |
tree | 8f39e207ce491479f2b3a76b67dbef49a8bf03f3 | |
parent | 1ce500b8a22619b4205596024cf7cbb50af7ae42 (diff) | |
download | yt-local-0c22835dd214dc71e5cd085c5549ffe8dcf7f657.tar.lz yt-local-0c22835dd214dc71e5cd085c5549ffe8dcf7f657.tar.xz yt-local-0c22835dd214dc71e5cd085c5549ffe8dcf7f657.zip |
Fix related videos
-rw-r--r-- | youtube_dl/extractor/youtube.py | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/youtube_dl/extractor/youtube.py b/youtube_dl/extractor/youtube.py index 18b240a..85be28d 100644 --- a/youtube_dl/extractor/youtube.py +++ b/youtube_dl/extractor/youtube.py @@ -1703,18 +1703,22 @@ class YoutubeIE(YoutubeBaseInfoExtractor): # Is it unlisted? unlisted = ('<span id="watch-privacy-icon"' in video_webpage) - # Related videos - related_vid_info = self._search_regex(r"""'RELATED_PLAYER_ARGS':\s*(\{.*?\})""", video_webpage, "related_player_args", default='') - if related_vid_info == '': - related_vids = [] - else: - related_vid_info = json.loads(related_vid_info)['rvs'] - if related_vid_info == '': - related_vids = [] + # Related videos + related_vids = [] + try: + rvs_match = re.search(r'"rvs":"(.*?)[^\\]"', video_webpage) + if rvs_match is not None: + rvs = json.loads('"' + rvs_match.group(1) + '"') # unescape json string (\u0026 for example) + related_vid_parts = (compat_parse_qs(related_item) for related_item in rvs.split(",")) + related_vids = [{key : value[0] for key,value in vid.items()} for vid in related_vid_parts] else: - related_vids = (compat_parse_qs(related_item) for related_item in related_vid_info.split(",")) - related_vids = [{key : value[0] for key,value in vid.items()} for vid in related_vids] + print('Failed to extract related videos: no rvs') + + except Exception: + print('Error while extracting related videos:') + traceback.print_exc() + # Music list # Test case: https://www.youtube.com/watch?v=jbkZdRglnKY |