added youtube music cookies to settings

This commit is contained in:
Hellow 2023-09-11 21:19:50 +02:00
parent 2900f4696a
commit 151cdf7831
2 changed files with 25 additions and 20 deletions

View File

@ -59,25 +59,13 @@ class YoutubeMusicConnection(Connection):
) )
# cookie consent for youtube # cookie consent for youtube
# https://stackoverflow.com/a/66940841/16804841 # https://stackoverflow.com/a/66940841/16804841 doesn't work
""" for cookie_key, cookie_value in youtube_settings["youtube_music_consent_cookies"].items():
self.session.cookies.set( self.session.cookies.set(
name='CONSENT', name=cookie_key,
value='YES+cb.20250328-17-p0.en-GB+FX+{}'.format(random.randint(100, 999)), value=cookie_value,
path='/', domain='.youtube.com' path='/', domain='.youtube.com'
) )
self.session.cookies.set(
name='CONSENT',
value='YES+cb.20250328-17-p0.en-GB+FX+{}'.format(random.randint(100, 999)),
path='/', domain='.youtube.com'
)
"""
self.session.cookies.set(
name='CONSENT',
value='PENDING+258',
path='/', domain='.youtube.com'
)
# self.start_hearthbeat() # self.start_hearthbeat()
def hearthbeat(self): def hearthbeat(self):
@ -112,7 +100,7 @@ class YoutubeMusic(SuperYouTube):
LOGGER = logging_settings["youtube_music_logger"] LOGGER = logging_settings["youtube_music_logger"]
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.connection: YoutubeMusicConnection = YoutubeMusicConnection(logger=self.LOGGER, accept_language="en-US,en;q=0.5") self.connection: YoutubeMusicConnection = YoutubeMusicConnection(logger=self.LOGGER, accept_language="en-US,en;q=0.5")
self.credentials: YouTubeMusicCredentials = YouTubeMusicCredentials( self.credentials: YouTubeMusicCredentials = YouTubeMusicCredentials(
api_key=youtube_settings["youtube_music_api_key"], api_key=youtube_settings["youtube_music_api_key"],
ctoken="", ctoken="",
@ -139,6 +127,7 @@ class YoutubeMusic(SuperYouTube):
return return
if urlparse(r.url).netloc == "consent.youtube.com": if urlparse(r.url).netloc == "consent.youtube.com":
self.LOGGER.info(f"Making cookie consent request for {type(self).__name__}.")
r = self.connection.post("https://consent.youtube.com/save", data={ r = self.connection.post("https://consent.youtube.com/save", data={
'gl': 'DE', 'gl': 'DE',
'm': '0', 'm': '0',
@ -156,6 +145,17 @@ class YoutubeMusic(SuperYouTube):
}) })
if r is None: if r is None:
return return
# load cookie dict from settings
cookie_dict = youtube_settings["youtube_music_consent_cookies"]
for cookie in r.cookies:
cookie_dict[cookie.name] = cookie.value
for cookie in self.connection.session.cookies:
cookie_dict[cookie.name] = cookie.value
# save cookies in settings
youtube_settings["youtube_music_consent_cookies"] = cookie_dict
r = self.connection.get("https://music.youtube.com/") r = self.connection.get("https://music.youtube.com/")
if r is None: if r is None:

View File

@ -32,6 +32,10 @@ Dw. if it is empty, Rachel will fetch it automatically for you <333
If any instance seems to be missing, run music kraken with the -f flag."""), If any instance seems to be missing, run music kraken with the -f flag."""),
Attribute(name="use_sponsor_block", default_value=True, description="Use sponsor block to remove adds or simmilar from the youtube videos."), Attribute(name="use_sponsor_block", default_value=True, description="Use sponsor block to remove adds or simmilar from the youtube videos."),
Attribute(name="youtube_music_consent_cookies", default_value={
"CONSENT": "PENDING+258"
}, description="The cookie with the key CONSENT says to what stuff you agree. Per default you decline all cookies, but it honestly doesn't matter."),
Attribute(name="youtube_music_innertube_context", default_value={ Attribute(name="youtube_music_innertube_context", default_value={
"client": { "client": {
"hl": "en", "hl": "en",
@ -96,3 +100,4 @@ class SettingsStructure(TypedDict):
youtube_url: List[ParseResult] youtube_url: List[ParseResult]
use_sponsor_block: bool use_sponsor_block: bool
youtube_music_innertube_context: dict youtube_music_innertube_context: dict
youtube_music_consent_cookies: dict