Max fixes, disable insecure request warning
This commit is contained in:
parent
4443e0fe11
commit
91b146ca5b
@ -7,6 +7,8 @@ import subprocess
|
||||
import sys
|
||||
import traceback
|
||||
from http.cookiejar import MozillaCookieJar
|
||||
import urllib3
|
||||
|
||||
|
||||
import time
|
||||
import click
|
||||
@ -355,6 +357,8 @@ def result(ctx, service, quality, closest_resolution, range_, wanted, alang, sla
|
||||
|
||||
service_name = service.__class__.__name__
|
||||
|
||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) # Disable insecure request warnings
|
||||
|
||||
if service_name in ["DisneyPlus", "Hulu"]: # Always retrieve fresh keys for DSNP so that content_keys variable has 2 kid:key pairs, change this to fetch all keys for title from cache
|
||||
global content_keys
|
||||
no_cache = True
|
||||
|
||||
@ -14,6 +14,10 @@ import requests
|
||||
import xmltodict
|
||||
from langcodes import Language
|
||||
|
||||
# Import urllib3 and disable insecure request warnings
|
||||
import urllib3
|
||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||
|
||||
from vinetrimmer.objects import TextTrack, Title, Tracks, VideoTrack
|
||||
from vinetrimmer.objects.tracks import AudioTrack, MenuTrack
|
||||
from vinetrimmer.services.BaseService import BaseService
|
||||
@ -83,19 +87,54 @@ class Max(BaseService):
|
||||
external_id = self.title['id']
|
||||
|
||||
response = self.session.get(
|
||||
f"https://default.any-any.prd.api.max.com/cms/routes/{content_type}/{external_id}?include=default",
|
||||
f"https://default.prd.api.max.com/cms/routes/{content_type}/{external_id}?include=default",
|
||||
)
|
||||
|
||||
content_data = [x for x in response.json()["included"] if "attributes" in x and "title" in
|
||||
x["attributes"] and x["attributes"]["alias"] == "generic-%s-blueprint-page" % (re.sub(r"-", "", content_type))][0]["attributes"]
|
||||
content_title = content_data["title"]
|
||||
try:
|
||||
content_data = [x for x in response.json()["included"] if "attributes" in x and "title" in
|
||||
x["attributes"] and x["attributes"]["alias"] == "generic-%s-blueprint-page" % (re.sub(r"-", "", content_type))][0]["attributes"]
|
||||
content_title = content_data["title"]
|
||||
except:
|
||||
content_data = [x for x in response.json()["included"] if "attributes" in x and "alternateId" in
|
||||
x["attributes"] and x["attributes"]["alternateId"] == external_id and x["attributes"].get("originalName")][0]["attributes"]
|
||||
content_title = content_data["originalName"]
|
||||
|
||||
|
||||
if content_type == "sport":
|
||||
included_dt = response.json()["included"]
|
||||
|
||||
for included in included_dt:
|
||||
for key, data in included.items():
|
||||
if key == "attributes":
|
||||
for k,d in data.items():
|
||||
if d == "VOD":
|
||||
event_data = included
|
||||
|
||||
release_date = event_data["attributes"].get("airDate") or event_data["attributes"].get("firstAvailableDate")
|
||||
year = datetime.strptime(release_date, '%Y-%m-%dT%H:%M:%SZ').year
|
||||
|
||||
return Title(
|
||||
id_=external_id,
|
||||
type_=Title.Types.MOVIE,
|
||||
name=content_title.title(),
|
||||
year=year,
|
||||
# original_lang=,
|
||||
source=self.ALIASES[0],
|
||||
service_data=event_data,
|
||||
)
|
||||
|
||||
#if content_type == "movie":
|
||||
if content_type == "movie" or content_type == "standalone":
|
||||
metadata = self.session.get(
|
||||
url=f"https://default.any-any.prd.api.max.com/content/videos/{external_id}/activeVideoForShow?&include=edit"
|
||||
url=f"https://default.prd.api.max.com/content/videos/{external_id}/activeVideoForShow?&include=edit"
|
||||
).json()['data']
|
||||
|
||||
try:
|
||||
edit_id = metadata['relationships']['edit']['data']['id']
|
||||
except:
|
||||
for x in response.json()["included"]:
|
||||
if x.get("type") == "video" and x.get("relationships", {}).get("show", {}).get("data", {}).get("id") == external_id:
|
||||
metadata = x
|
||||
|
||||
release_date = metadata["attributes"].get("airDate") or metadata["attributes"].get("firstAvailableDate")
|
||||
year = datetime.strptime(release_date, '%Y-%m-%dT%H:%M:%SZ').year
|
||||
return Title(
|
||||
@ -113,39 +152,37 @@ class Max(BaseService):
|
||||
if content_type == "mini-series":
|
||||
alias = "generic-miniseries-page-rail-episodes"
|
||||
else:
|
||||
alias = "generic-%s-page-rail-episodes-tabbed-content" % (content_type)
|
||||
|
||||
alias = "-%s-page-rail-episodes-tabbed-content" % (content_type)
|
||||
included_dt = response.json()["included"]
|
||||
season_data = [data for included in included_dt for key, data in included.items()
|
||||
if key == "attributes" for k,d in data.items() if d == alias][0]
|
||||
season_data = [data for included in included_dt for key, data in
|
||||
included.items() if key == "attributes" for k,d in data.items() if alias in str(d).lower()][0]
|
||||
season_data = season_data["component"]["filters"][0]
|
||||
|
||||
seasons = [int(season["value"]) for season in season_data["options"]]
|
||||
|
||||
season_parameters = [(int(season["id"]), season["parameter"]) for season in season_data["options"]] #[(int(season["value"]), season["parameter"]) for season in season_data["options"] for season_number in seasons if int(season["id"]) == int(season_number)]
|
||||
season_parameters = [(int(season["value"]), season["parameter"]) for season in season_data["options"]
|
||||
for season_number in seasons if int(season["value"]) == int(season_number)]
|
||||
|
||||
if not season_parameters:
|
||||
raise self.log.exit("season(s) %s not found")
|
||||
|
||||
data_paginas = self.session.get(url="https://default.any-any.prd.api.max.com/cms/collections/generic-show-page-rail-episodes-tabbed-content?include=default&pf[show.id]=%s" % (external_id)).json()
|
||||
total_pages = data_paginas['data']['meta']['itemsTotalPages']
|
||||
for (value, parameter) in season_parameters:
|
||||
data = self.session.get(url="https://default.prd.api.max.com/cms/collections/generic-show-page-rail-episodes-tabbed-content?include=default&pf[show.id]=%s&%s" % (external_id, parameter)).json()
|
||||
try:
|
||||
episodes_dt = sorted([dt for dt in data["included"] if "attributes" in dt and "videoType" in
|
||||
dt["attributes"] and dt["attributes"]["videoType"] == "EPISODE"
|
||||
and int(dt["attributes"]["seasonNumber"]) == int(value)], key=lambda x: x["attributes"]["episodeNumber"])
|
||||
except KeyError:
|
||||
raise self.log.exit("season episodes were not found")
|
||||
|
||||
for pagina in range(1, total_pages + 1):
|
||||
for (value, parameter) in season_parameters:
|
||||
data = self.session.get(url="https://default.any-any.prd.api.max.com/cms/collections/generic-show-page-rail-episodes-tabbed-content?include=default&pf[show.id]=%s&%s&page[items.number]=%s" % (external_id, parameter, pagina)).json()
|
||||
try:
|
||||
episodes_dt = sorted([dt for dt in data["included"] if "attributes" in dt and "videoType" in
|
||||
dt["attributes"] and dt["attributes"]["videoType"] == "EPISODE"
|
||||
and int(dt["attributes"]["seasonNumber"]) == int(value)], key=lambda x: x["attributes"]["episodeNumber"])
|
||||
except KeyError:
|
||||
raise self.log.exit("season episodes were not found")
|
||||
|
||||
episodes.extend(episodes_dt)
|
||||
episodes.extend(episodes_dt)
|
||||
|
||||
titles = []
|
||||
release_date = episodes[0]["attributes"].get("airDate") or episodes[0]["attributes"].get("firstAvailableDate")
|
||||
year = datetime.strptime(release_date, '%Y-%m-%dT%H:%M:%SZ').year
|
||||
|
||||
season_map = {int(item[1].split("=")[-1]): item[0] for item in season_parameters}
|
||||
|
||||
for episode in episodes:
|
||||
titles.append(
|
||||
Title(
|
||||
@ -153,7 +190,7 @@ class Max(BaseService):
|
||||
type_=Title.Types.TV,
|
||||
name=content_title,
|
||||
year=year,
|
||||
season=episode['attributes']['seasonNumber'],
|
||||
season=season_map.get(episode['attributes'].get('seasonNumber')),
|
||||
episode=episode['attributes']['episodeNumber'],
|
||||
episode_name=episode['attributes']['name'],
|
||||
# original_lang=edit.get('originalAudioLanguage'),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user