Skip to content

Commit

Permalink
Fix related videos
Browse files Browse the repository at this point in the history
  • Loading branch information
user234683 committed Aug 28, 2019
1 parent 1ce500b commit 0c22835
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions youtube_dl/extractor/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -1703,18 +1703,22 @@ def extract_token(v_info):
# 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
Expand Down

0 comments on commit 0c22835

Please sign in to comment.