def video_info_url(video_id, watch_url, watch_html): """Contruct the video_info url. :param str video_id: A YouTube video identifer. :param str watch_url: A YouTube watch url. :param str watch_html: The html contents of the watch page. :rtype: str :returns: :samp:`https://youtube.com/get_video_info` with necessary GET parameters. """ # I'm not entirely sure what ``t`` represents. Looks to represent a # boolean. t = regex_search(r'\W[\'"]?t[\'"]?: ?[\'"](.+?)[\'"]', watch_html, group=0) # Here we use ``OrderedDict`` so that the output is consistant between # Python 2.7+. params = OrderedDict([ ('video_id', video_id), ('el', '$el'), ('ps', 'default'), ('eurl', quote(watch_url)), ('hl', 'en_US'), ('t', quote(t)), ]) return 'https://youtube.com/get_video_info?' + urlencode(params)
def video_info_url( video_id, watch_url, watch_html, embed_html, age_restricted, ): """Construct the video_info url. :param str video_id: A YouTube video identifier. :param str watch_url: A YouTube watch url. :param str watch_html: The html contents of the watch page. :param str embed_html: The html contents of the embed page (for age restricted videos). :param bool age_restricted: Is video age restricted. :rtype: str :returns: :samp:`https://youtube.com/get_video_info` with necessary GET parameters. """ if age_restricted: sts = regex_search(r'"sts"\s*:\s*(\d+)', embed_html, group=1) # Here we use ``OrderedDict`` so that the output is consistent between # Python 2.7+. params = OrderedDict([ ('video_id', video_id), ('eurl', eurl(video_id)), ('sts', sts), ]) else: # I'm not entirely sure what ``t`` represents. Looks to represent a # boolean. t = regex_search( r'\W[\'"]?t[\'"]?: ?[\'"](.+?)[\'"]', watch_html, group=0, ) params = OrderedDict([ ('video_id', video_id), ('el', '$el'), ('ps', 'default'), ('eurl', quote(watch_url)), ('hl', 'en_US'), ('t', quote(t)), ]) return 'https://youtube.com/get_video_info?' + urlencode(params)
def video_info_url( video_id, watch_url, watch_html, embed_html, age_restricted, ): """Construct the video_info url. :param str video_id: A YouTube video identifier. :param str watch_url: A YouTube watch url. :param str watch_html: The html contents of the watch page. :param str embed_html: The html contents of the embed page (for age restricted videos). :param bool age_restricted: Is video age restricted. :rtype: str :returns: :samp:`https://youtube.com/get_video_info` with necessary GET parameters. """ if age_restricted: sts = regex_search(r'"sts"\s*:\s*(\d+)', embed_html, group=1) # Here we use ``OrderedDict`` so that the output is consistent between # Python 2.7+. params = OrderedDict([("video_id", video_id), ("eurl", eurl(video_id)), ("sts", sts)]) else: params = OrderedDict([ ("video_id", video_id), ("el", "$el"), ("ps", "default"), ("eurl", quote(watch_url)), ("hl", "en_US"), ]) return "https://youtube.com/get_video_info?" + urlencode(params)