Fix vbitrate == "min"

This commit is contained in:
chu23465 2025-04-11 06:26:41 +05:30
parent ca46bd4906
commit 5290850dc6
4 changed files with 57 additions and 67 deletions

View File

@ -395,7 +395,7 @@ def result(ctx, service, quality, closest_resolution, range_, wanted, alang, sla
# Modified video track selection to choose closest resolution if exact match not found # Modified video track selection to choose closest resolution if exact match not found
if quality and closest_resolution: if quality and closest_resolution:
available_resolutions = [int(track.height) for track in title.tracks.videos] available_resolutions = [int(track.height) for track in title.tracks.videos]
if not available_resolutions: if available_resolutions == []:
log.error(" - No video tracks available") log.error(" - No video tracks available")
continue continue
if quality not in available_resolutions: if quality not in available_resolutions:
@ -405,11 +405,13 @@ def result(ctx, service, quality, closest_resolution, range_, wanted, alang, sla
# Modified video track selection to choose lowest bitrate if vbitrate == min # Modified video track selection to choose lowest bitrate if vbitrate == min
if vbitrate and vbitrate.lower() == "min": if vbitrate and vbitrate.lower() == "min":
available_bitrate = [int(track.bitrate) for track in title.tracks.videos] if not quality:
if not available_resolutions: quality = 1080
available_bitrate = [int(track.bitrate) for track in title.tracks.videos if track.height == quality]
if available_bitrate == []:
log.error(" - No video tracks available") log.error(" - No video tracks available")
continue continue
vbitrate = min(available_bitrate) vbitrate = min(available_bitrate) / 1000
log.warning(f" - Choosing minimum bitrate: {vbitrate}") log.warning(f" - Choosing minimum bitrate: {vbitrate}")
elif vbitrate: elif vbitrate:
vbitrate = int(vbitrate) vbitrate = int(vbitrate)
@ -528,9 +530,6 @@ def result(ctx, service, quality, closest_resolution, range_, wanted, alang, sla
session_id=session_id session_id=session_id
) )
assert license assert license
# Convert bytes to string if necessary
if isinstance(license, bytes):
license = license.decode('utf-8')
ctx.obj.cdm.parse_license( ctx.obj.cdm.parse_license(
session_id, session_id,
license license

Binary file not shown.

View File

@ -636,10 +636,10 @@ class Amazon(BaseService):
"marketplaceID": self.region["marketplace_id"], "marketplaceID": self.region["marketplace_id"],
"resourceUsage": "ImmediateConsumption", "resourceUsage": "ImmediateConsumption",
"videoMaterialType": "Feature", "videoMaterialType": "Feature",
"operatingSystemName": "Linux" if self.vquality == "SD" else "Windows", "operatingSystemName": "Windows",
"operatingSystemVersion": "unknown" if self.vquality == "SD" else "10.0", "operatingSystemVersion": "10.0",
"customerID": self.customer_id, "customerID": self.customer_id,
"deviceDrmOverride": "Playready", #CENC or Playready both work "deviceDrmOverride": "CENC", #CENC or Playready both work
"deviceStreamingTechnologyOverride": "DASH", # or SmoothStreaming "deviceStreamingTechnologyOverride": "DASH", # or SmoothStreaming
"deviceVideoQualityOverride": self.vquality, "deviceVideoQualityOverride": self.vquality,
"deviceHdrFormatsOverride": self.VIDEO_RANGE_MAP.get(self.range, "None"), "deviceHdrFormatsOverride": self.VIDEO_RANGE_MAP.get(self.range, "None"),
@ -661,6 +661,7 @@ class Amazon(BaseService):
).json() ).json()
lic_list.append(lic) lic_list.append(lic)
params["deviceStreamingTechnologyOverride"] = "SmoothStreaming" params["deviceStreamingTechnologyOverride"] = "SmoothStreaming"
params["deviceDrmOverride"] = "Playready"
lic = self.session.post( lic = self.session.post(
url=self.endpoints["licence"], url=self.endpoints["licence"],
params=params, params=params,
@ -1161,42 +1162,43 @@ class Amazon(BaseService):
return bearer["access_token"] return bearer["access_token"]
def refresh(self, device: dict, refresh_token: str, access_token: str) -> dict: def refresh(self, device: dict, refresh_token: str, access_token: str) -> dict:
# https://gitlab.com/keatontaylor/alexapy/-/commit/540b6333d973177bbc98e6ef39b00134f80ef0bb # using the refresh token get the cookies needed for making calls to *.amazon.com
response = requests.post(
cookies = { url=self.endpoints["token"],
'at-main': access_token,
}
headers={ headers={
'User-Agent': 'AmazonWebView/Amazon Alexa/2.2.223830.0/iOS/11.4.1/iPhone', 'User-Agent': 'AmazonWebView/Amazon Alexa/2.2.223830.0/iOS/11.4.1/iPhone', # https://gitlab.com/keatontaylor/alexapy/-/commit/540b6333d973177bbc98e6ef39b00134f80ef0bb
'Accept-Language': 'en-US', 'Accept-Language': 'en-US',
'Accept-Charset': 'utf-8', 'Accept-Charset': 'utf-8',
'Connection': 'keep-alive', 'Connection': 'keep-alive',
'Content-Type': 'application/x-www-form-urlencoded', 'Content-Type': 'application/x-www-form-urlencoded',
'Accept': '*/*' 'Accept': '*/*'
} },
data2 = { cookies={
'at-main': access_token,
},
data={
**device, **device,
'domain': '.' + self.endpoints["token"].split("/")[-3], 'domain': '.' + self.endpoints["token"].split("/")[-3],
'source_token': refresh_token, 'source_token': str(refresh_token),
'requested_token_type': 'auth_cookies', 'requested_token_type': 'auth_cookies',
'source_token_type': 'refresh_token', 'source_token_type': 'refresh_token',
} }
)
# using the refresh token get the cookies needed for making calls to alexa.amazon.com response_json = response.json()
response = requests.post(url=self.endpoints["token"], headers=headers, cookies=cookies, data=data2)
cookies = {} cookies = {}
self.log.debug(response_json)
if response.status_code == 200: if response.status_code == 200:
# Extract the cookies from the response # Extract the cookies from the response
raw_cookies = response.json()['response']['tokens']['cookies']['.amazon.com'] raw_cookies = response_json['response']['tokens']['cookies']['.amazon.com']
for cookie in raw_cookies: for cookie in raw_cookies:
cookies[cookie['Name']] = cookie['Value'] cookies[cookie['Name']] = cookie['Value']
else: else:
error = response.json()['response']["error"] error = response_json['response']["error"]
self.cache_path.unlink(missing_ok=True) self.cache_path.unlink(missing_ok=True)
raise self.log.exit(f"Error when refreshing cookies: {error['message']} [{error['code']}]") raise self.log.exit(f"Error when refreshing cookies: {error['message']} [{error['code']}]")
# Create a new cookies object to be used with requsts. response = requests.post(
url=self.endpoints["token"],
headers={ headers={
'Content-Type': 'application/json; charset=utf-8', 'Content-Type': 'application/json; charset=utf-8',
'Accept-Encoding': 'gzip, deflate, br', 'Accept-Encoding': 'gzip, deflate, br',
@ -1206,31 +1208,20 @@ class Amazon(BaseService):
'Accept-Language': 'en-US,en-US;q=1.0', 'Accept-Language': 'en-US,en-US;q=1.0',
'x-amzn-identity-auth-domain': self.endpoints["token"].split("/")[-3], 'x-amzn-identity-auth-domain': self.endpoints["token"].split("/")[-3],
'x-amzn-requestid': str(uuid4()).replace('-', '') 'x-amzn-requestid': str(uuid4()).replace('-', '')
} },
json_data = { json={
**device, **device,
'requested_token_type': 'access_token', 'requested_token_type': 'access_token',
'source_token_type': 'refresh_token', 'source_token_type': 'refresh_token',
'source_token': str(refresh_token), 'source_token': str(refresh_token),
}, # https://github.com/Sandmann79/xbmc/blob/dab17d913ee877d96115e6f799623bca158f3f24/plugin.video.amazon-test/resources/lib/login.py#L593
} # https://github.com/Sandmann79/xbmc/blob/dab17d913ee877d96115e6f799623bca158f3f24/plugin.video.amazon-test/resources/lib/login.py#L593 cookies=cookies
)
# Add cookies to session
#if cookies != {}:
# for k,v in cookies.iteritems():
# if not isinstance(v, str):
# v = str(v)
# self.session.cookies.set(k,v)
# make the call and print the response.
response = requests.post(url=self.endpoints["token"], headers=headers, json=json_data, cookies=cookies)
response_json = response.json() response_json = response.json()
if response.status_code != 200 or "error" in response_json: if response.status_code != 200 or "error" in response_json:
self.cache_path.unlink(missing_ok=True) # Remove the cached device as its tokens have expired self.cache_path.unlink(missing_ok=True) # Remove the cached device as its tokens have expired
raise self.log.exit( raise self.log.exit(f"Failed to refresh device token -> {response_json['error_description']} [{response_json['error']}]")
f"Failed to refresh device token -> {response_json['error_description']} [{response_json['error']}]"
)
self.log.debug(response_json) self.log.debug(response_json)
if response_json["token_type"] != "bearer": if response_json["token_type"] != "bearer":
raise self.log.exit("Unexpected returned refreshed token type") raise self.log.exit("Unexpected returned refreshed token type")