~cadence/tube-devel

NewLeaf: Fix EU consent page workaround not accepting our PENDING cookie value anymore v1 SUPERSEDED

~lomanic
~lomanic: 1
 Fix EU consent page workaround not accepting our PENDING cookie value anymore

 2 files changed, 4 insertions(+), 2 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~cadence/tube-devel/patches/22701/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH NewLeaf] Fix EU consent page workaround not accepting our PENDING cookie value anymore Export this patch

~lomanic
From: Lomanic <lomanic@hotmail.fr>

See https://github.com/benbusby/whoogle-search/issues/311 for some context
We're now implementing https://github.com/ytdl-org/youtube-dl/blob/a7260099873acc6dc7d76cafad2f6b139087afd0/youtube_dl/extractor/youtube.py#L263-L264
---
 extractors/channel.py | 3 ++-
 extractors/search.py  | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/extractors/channel.py b/extractors/channel.py
index fb8ccea..44ed272 100644
--- a/extractors/channel.py
+++ b/extractors/channel.py
@@ -6,6 +6,7 @@ from tools.converters import *
from tools.extractors import extract_yt_initial_data
from threading import Lock
from cachetools import TTLCache
import random

channel_cache = TTLCache(maxsize=50, ttl=300)
channel_cache_lock = Lock()
@@ -18,7 +19,7 @@ def extract_channel(ucid):
			return channel_cache[ucid]

	channel_type = "channel" if len(ucid) == 24 and ucid[:2] == "UC" else "user"
	with requests.get("https://www.youtube.com/{}/{}/videos?hl=en".format(channel_type, ucid), cookies={"CONSENT": "PENDING+999"}) as r:
	with requests.get("https://www.youtube.com/{}/{}/videos?hl=en".format(channel_type, ucid), cookies={"CONSENT": 'YES+cb.20210509-17-p0.en+F+%s' % random.randint(100, 999)}) as r:
		r.raise_for_status()
		yt_initial_data = extract_yt_initial_data(r.content.decode("utf8"))

diff --git a/extractors/search.py b/extractors/search.py
index 487ccf8..bba92ed 100644
--- a/extractors/search.py
+++ b/extractors/search.py
@@ -4,6 +4,7 @@ import yt_dlp
from tools.converters import *
from tools.extractors import extract_yt_initial_data
from cachetools import TTLCache
import random

search_cache = TTLCache(maxsize=50, ttl=300)

@@ -17,7 +18,7 @@ ytdl = yt_dlp.YoutubeDL(ytdl_opts)

def extract_search(q):
	try:
		with requests.get("https://www.youtube.com/results", params={"q": q, "hl": "en"}, cookies={"CONSENT": "PENDING+999"}) as r:
		with requests.get("https://www.youtube.com/results", params={"q": q, "hl": "en"}, cookies={"CONSENT": 'YES+cb.20210509-17-p0.en+F+%s' % random.randint(100, 999)}) as r:
			r.raise_for_status()
			content = r.content.decode("utf8")
			yt_initial_data = extract_yt_initial_data(content)
-- 
2.30.2