Skip to content

Commit

Permalink
Fix can't summon Login csrf
Browse files Browse the repository at this point in the history
- ...?
  • Loading branch information
NyaShinn1204 committed Dec 28, 2024
1 parent 511cdd6 commit 0f7a415
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
12 changes: 7 additions & 5 deletions ext/amazon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -99,17 +97,21 @@ 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"})
raise

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']}"
})
Expand Down
3 changes: 2 additions & 1 deletion ext/utils/amazon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion test_amazon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
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")

0 comments on commit 0f7a415

Please sign in to comment.