From 0f7a4153957c619998edfe1994c5a0d29a8aacb2 Mon Sep 17 00:00:00 2001 From: NyaShinn1204 Date: Sat, 28 Dec 2024 18:06:56 +0900 Subject: [PATCH] Fix can't summon Login csrf - ...? --- ext/amazon.py | 12 +++++++----- ext/utils/amazon.py | 3 ++- test_amazon.py | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/ext/amazon.py b/ext/amazon.py index 410ffb6..ecb0c1a 100644 --- a/ext/amazon.py +++ b/ext/amazon.py @@ -53,9 +53,7 @@ def set_variable(session, LOG_LEVEL): with open('config.yml', 'r') as yml: config = yaml.safe_load(yml) - - session.headers.update({"User-Agent": config["headers"]["User-Agent"]}) - + def main_command(session, url, email, password, LOG_LEVEL, quality, vrange): try: #global media_code, playtoken @@ -99,7 +97,7 @@ def main_command(session, url, email, password, LOG_LEVEL, quality, vrange): logger.debug(f"Get cookies: {len(cookies)}", extra={"service_name": "Amazon"}) logger.info("Getting Account Region", extra={"service_name": "Amazon"}) - get_region, error_msg = amazon_downloader.get_region() + get_region, error_msg, cookie = amazon_downloader.get_region() if not get_region: logger.error("Failed to get Amazon Account Region", extra={"service_name": "Amazon"}) logger.error(error_msg, extra={"service_name": "Amazon"}) @@ -107,9 +105,13 @@ def main_command(session, url, email, password, LOG_LEVEL, quality, vrange): logger.info(f" + Region: {get_region['code']}", extra={"service_name": "Amazon"}) + logger.info("Update Session", extra={"service_name": "Amazon"}) + session.headers.update({"User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0'}) + session.cookies.update(cookies or {}) + # Update Region, Endpoints endpoints = amazon_downloader.prepare_endpoints(get_region) - + session.headers.update({ "Origin": f"https://{get_region['base']}" }) diff --git a/ext/utils/amazon.py b/ext/utils/amazon.py index c2d9bdf..c9dcdc6 100644 --- a/ext/utils/amazon.py +++ b/ext/utils/amazon.py @@ -173,7 +173,7 @@ def get_region(self) -> dict: region["base_manifest"] = f"{pv_region}.primevideo.com" region["base"] = "www.primevideo.com" - return region, None + return region, None, self.cookies def prepare_endpoint(self, name: str, uri: str, region: dict) -> str: if name in ("browse", "playback", "licence", "xray"): return f"https://{(region['base_manifest'])}{uri}" @@ -343,6 +343,7 @@ def get_csrf_token(self) -> str: prop = prop.get("props", {}).get("codeEntry", {}).get("token") if prop: return prop + #print(response) raise self.log.error("Unable to get ontv CSRF token", extra={"service_name": "Amazon"}) ## OK FUCKING ERROR; ... why not match..??? Fucking Amazon def get_code_pair(self, device: dict) -> dict: diff --git a/test_amazon.py b/test_amazon.py index fe6ed37..a686348 100644 --- a/test_amazon.py +++ b/test_amazon.py @@ -5,4 +5,4 @@ # 1080の時は SDR # 2160の時は HDR -amazon_dl.main_command(requests.session(), "https://www.amazon.co.jp/gp/video/detail/B0CHHPLWM5/ref=atv_hm_hom_c_lW5Kly_brws_2_1?jic=8%7CEgRzdm9k", "", "", "DEBUG", 1080, "SDR") \ No newline at end of file +amazon_dl.main_command(requests.Session(), "https://www.amazon.co.jp/gp/video/detail/B0CHHPLWM5/ref=atv_hm_hom_c_lW5Kly_brws_2_1?jic=8%7CEgRzdm9k", "", "", "DEBUG", 1080, "SDR") \ No newline at end of file