trakt-tools / universal-trakt-scrobbler

MIT License
551 stars 54 forks source link

Use alternative endpoints for Prime Brazil #274

Closed Throne3d closed 1 year ago

Throne3d commented 1 year ago

Hi there! I was having issues syncing Amazon Prime in Brazil, possibly similar to the issues in #211, and I found the Account menu on the site was using a different set of endpoints to retrieve data here from my region. I'm not entirely sure what-all countries this might affect, or even if this is only relevant when region === 'na', so I'm not expecting this PR to be ready in the current state, but I wanted to open it and see what kinds of paths forward there might be.

I was previously receiving 4xxs or redirects to the main storefront for the /gp endpoints. Weirdly enough, I've just gone back and tested the previous endpoints and they're now working for me, so I don't have copies of the specific errors handy - I did have to log back in to Amazon a few different times while trying to set up the debugging environment for the extension, so maybe there's a situation where a cookie is only partially set or something, and only some endpoints work?

These new endpoints all seemed to work for me out of the box anyway, and are the ones Prime used on the Account page - here's some example data, which seems structurally identical to what the code is expecting:

Sample data ``` GET https://www.primevideo.com/region/na/api/getProfiles [etc] { "__type":"atv.wps#GetProfilesOutput", "canCreate":true, "canEdit":true, "isProfileImplicitlySelectedOrLocked":false, "links":{"preEditProfile":"/region/na/profiles/ref=...?step=edit",...}, "metadata":{...}, "profiles":[...], "strings":{"DV_PROFILES_CANCEL":"Cancel",...} } ``` ``` GET https://www.primevideo.com/region/na/api/getWatchHistorySettingsPage?widgetArgs={} { "__type": "atv.wps#SettingsOutput", "metadata": {...}, "notifications": [...], "widgets": [ {...,"widgetType": "page-title"}, {...,"widgetType": "navigation-tabs" }, { "content": { "__type": "atv.wps#ActivityHistoryOutput", "content": { "__type": "atv.wps#ActivityHistoryItems", "nextToken": "...", "seeMoreLink": { "href": "/region/na/settings/watch-history/...", "text": "Load more" }, "strings": {...}, "titles": [ { "date": "January 21, 2023", "titles": [ { "actions": {...}, "children": [...], "gti": "...", "imageSrc": "...", "time": ..., "title": { "href": "/region/na/detail/...", "text": "American Gods, Season 3" } } ] }, ... ] } }, "widgetType": "watch-history" } ] } ``` ``` GET https://www.primevideo.com/region/na/api/enrichItemMetadata?metadataToEnrich={"playback":true}&titleIDsToEnrich=["amzn1.dv.gti.bebbba29-32ef-f78d-62c1-8d091d35f1c8"] { "__type": "atv.wps#StorefrontEnrichItemsOutput", "enrichments": { "amzn1.dv.gti.bebbba29-32ef-f78d-62c1-8d091d35f1c8": { "cardBundle": {...}, "degradations": [], "entitlements": [], "filterEntitled": false, "hasSubtitles": false, "messages": {...}, "playbackActions": [ { "appFallbackUrl": "https://www.microsoft.com/store/apps/9P6RC76MSMMJ", "disableJs": false, "fallbackUrl": "/region/na/detail/0QG47KI9CRBKFY19NDP5JJH808/ref=...?autoplay=1&t=0", "label": "Play S3 E10", "legacyOfferASIN": "...", "playbackExperienceMetadata": {}, "playbackStatus": "FEATURE_IN_PROGRESS", "refMarker": "...", "resumeTime": 0, "sessionID": "...", "titleID": "amzn1.dv.gti.bebbba29-32ef-f78d-62c1-8d091d35f1c8", "videoMaterialType": "Feature" } ], "progress": { "isLive": false, "percentage": 100.0 }, "properties": {} } }, "isTrailerAutoplayEnabled": true, "metadata": { "availability": { "description": "Fatal Count: 0, Error Count: 0, Warning Count: 0", "severity": "NoDegradation" } } } ```

Is there some process to test this more thoroughly among more users, to make sure this doesn't break anything? Given the old endpoints are working again for me now, maybe it would be better to validate a "200 OK" response from the original ones before falling back to these ones - WDYT? I'd appreciate any guidance on how to validate this so we can determine if a change to use these new endpoints would be helpful.

rafaelgomesxyz commented 1 year ago

Thanks for the PR! Closing in favor of #286.