Skip to content

plugins.youtube: fix consent dialog #3672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 3, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
plugins.youtube: moved 'consent' into '_find_video_id'
  • Loading branch information
back-to committed Apr 3, 2021
commit 3b2c2718d3e857b6f1bfdbee0cd76b5d265f646a
19 changes: 9 additions & 10 deletions src/streamlink/plugins/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,21 @@ def _create_adaptive_streams(self, info, streams):
return streams

def _find_video_id(self, url):

m = _url_re.match(url)
if m.group("video_id"):
log.debug("Video ID from URL")
return m.group("video_id")

res = self.session.http.get(url)
if urlparse(res.url).netloc == "consent.youtube.com":
c_data = {}
for _i in itertags(res.text, "input"):
if _i.attributes.get("type") == "hidden":
c_data[_i.attributes.get("name")] = _i.attributes.get("value")
log.debug(f"c_data_keys: {', '.join(c_data.keys())}")
self.session.http.post("https://consent.youtube.com/s", data=c_data)
res = self.session.http.get(url)

datam = _ytdata_re.search(res.text)
if datam:
data = parse_json(datam.group(1))
Expand Down Expand Up @@ -296,15 +304,6 @@ def _get_stream_info(self, video_id):
return info_parsed

def _get_streams(self):
res = self.session.http.get(self.url)
if "consent.youtube" in res.url:
c_data = {}
for _i in itertags(res.text, "input"):
if _i.attributes.get("type") == "hidden":
c_data[_i.attributes.get("name")] = _i.attributes.get("value")
log.debug(f"c_data_keys: {', '.join(c_data.keys())}")
self.session.http.post("https://consent.youtube.com/s", data=c_data)

is_live = False

self.video_id = self._find_video_id(self.url)
Expand Down