fix(iP): Set default version for UHD
This commit is contained in:
parent
fea45c5ed6
commit
3095165f8c
@ -143,21 +143,29 @@ class iP(Service):
|
||||
def get_tracks(self, title: Union[Movie, Episode]) -> Tracks:
|
||||
r = self.session.get(url=self.config["endpoints"]["playlist"].format(pid=title.id))
|
||||
r.raise_for_status()
|
||||
playlist = r.json()
|
||||
|
||||
versions = r.json().get("allAvailableVersions")
|
||||
versions = playlist.get("allAvailableVersions")
|
||||
if not versions:
|
||||
# If API returns no versions, try to fetch from site source code
|
||||
r = self.session.get(self.config["base_url"].format(type="episode", pid=title.id))
|
||||
redux = re.search("window.__IPLAYER_REDUX_STATE__ = (.*?);</script>", r.text).group(1)
|
||||
data = json.loads(redux)
|
||||
versions = [{"pid": x.get("id") for x in data["versions"] if not x.get("kind") == "audio-described"}]
|
||||
versions = [{"pid": x.get("id") for x in data.get("versions", {}) if not x.get("kind") == "audio-described"}]
|
||||
|
||||
if self.vcodec == "H.265":
|
||||
versions = [{"pid": playlist.get("defaultAvailableVersion", {}).get("pid")}]
|
||||
|
||||
if not versions:
|
||||
self.log.error(" - No available versions for this title was found")
|
||||
sys.exit(1)
|
||||
|
||||
connections = [self.check_all_versions(version) for version in (x.get("pid") for x in versions)]
|
||||
quality = [connection.get("height") for i in connections for connection in i if connection.get("height")]
|
||||
max_quality = max((h for h in quality if h < "1080"), default=None)
|
||||
|
||||
media = next(
|
||||
(i for i in connections if any(connection.get("height") == max_quality or "2160" for connection in i)),
|
||||
(i for i in connections if any(connection.get("height") == max_quality for connection in i)),
|
||||
None,
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user