mirror of
https://github.com/spaam/svtplay-dl.git
synced 2024-11-30 15:14:14 +01:00
dplay: fix so it works with the updated website
This commit is contained in:
parent
1e32678ba9
commit
5fc7750e17
@ -25,10 +25,9 @@ class Dplay(Service):
|
|||||||
if not self._token():
|
if not self._token():
|
||||||
logging.error("Something went wrong getting token for requests")
|
logging.error("Something went wrong getting token for requests")
|
||||||
|
|
||||||
if self.config.get("username") and self.config.get("password"):
|
if not self._login():
|
||||||
premium = self._login()
|
yield ServiceError("Need the 'st' cookie to work")
|
||||||
if not premium:
|
return
|
||||||
logging.warning("Wrong username/password. no support for recaptcha.")
|
|
||||||
|
|
||||||
channel = False
|
channel = False
|
||||||
if "kanaler" in parse.path:
|
if "kanaler" in parse.path:
|
||||||
@ -112,52 +111,62 @@ class Dplay(Service):
|
|||||||
def find_all_episodes(self, config):
|
def find_all_episodes(self, config):
|
||||||
parse = urlparse(self.url)
|
parse = urlparse(self.url)
|
||||||
self.domain = re.search(r"(dplay\.\w\w)", parse.netloc).group(1)
|
self.domain = re.search(r"(dplay\.\w\w)", parse.netloc).group(1)
|
||||||
|
programid = None
|
||||||
|
seasons = []
|
||||||
match = re.search("^/(program|programmer|videos|videoer)/([^/]+)", parse.path)
|
match = re.search("^/(program|programmer|videos|videoer)/([^/]+)", parse.path)
|
||||||
if not match:
|
if not match:
|
||||||
logging.error("Can't find show name")
|
logging.error("Can't find show name")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
if not self._login():
|
||||||
|
logging.error("Need the 'st' cookie to work")
|
||||||
|
return None
|
||||||
|
|
||||||
if not self._token():
|
if not self._token():
|
||||||
logging.error("Something went wrong getting token for requests")
|
logging.error("Something went wrong getting token for requests")
|
||||||
|
|
||||||
premium = False
|
premium = self._checkpremium()
|
||||||
if self.config.get("username") and self.config.get("password"):
|
url = "http://disco-api.{}/cms/routes/program/{}?decorators=viewingHistory&include=default".format(self.domain, match.group(2))
|
||||||
premium = self._login()
|
|
||||||
if not premium:
|
|
||||||
logging.warning("Wrong username/password.")
|
|
||||||
|
|
||||||
url = "https://disco-api.{}/content/shows/{}".format(self.domain, match.group(2))
|
|
||||||
res = self.http.get(url)
|
res = self.http.get(url)
|
||||||
programid = res.json()["data"]["id"]
|
for what in res.json()["included"]:
|
||||||
seasons = res.json()["data"]["attributes"]["seasonNumbers"]
|
if "attributes" in what and "alias" in what["attributes"] and "season" in what["attributes"]["alias"]:
|
||||||
|
programid = what["id"]
|
||||||
|
for ses in what["attributes"]["component"]["filters"]:
|
||||||
|
if ses["id"] == "seasonNumber":
|
||||||
|
for opt in ses["options"]:
|
||||||
|
seasons.append(opt["value"])
|
||||||
episodes = []
|
episodes = []
|
||||||
for season in seasons:
|
|
||||||
qyerystring = (
|
if programid:
|
||||||
"include=primaryChannel,show&filter[videoType]=EPISODE&filter[show.id]={}&filter[seasonNumber]={}&"
|
for season in seasons:
|
||||||
"page[size]=100&sort=seasonNumber,episodeNumber,-earliestPlayableStart".format(programid, season)
|
page = 1
|
||||||
)
|
totalpages = 1
|
||||||
res = self.http.get("https://disco-api.{}/content/videos?{}".format(self.domain, qyerystring))
|
while page <= totalpages:
|
||||||
janson = res.json()
|
qyerystring = "decorators=viewingHistory&include=default&page[items.number]={}&&pf[seasonNumber]={}".format(page, season)
|
||||||
for i in janson["data"]:
|
res = self.http.get("https://disco-api.{}/cms/collections/{}?{}".format(self.domain, programid, qyerystring))
|
||||||
if not premium and "Free" not in i["attributes"]["packages"]:
|
janson = res.json()
|
||||||
continue
|
totalpages = janson["data"]["meta"]["itemsTotalPages"]
|
||||||
episodes.append("https://www.{}/videos/{}".format(self.domain, i["attributes"]["path"]))
|
for i in janson["included"]:
|
||||||
if len(episodes) == 0:
|
if i["type"] != "video":
|
||||||
|
continue
|
||||||
|
if i["attributes"]["videoType"] == "EPISODE":
|
||||||
|
if not premium and "Free" not in i["attributes"]["packages"]:
|
||||||
|
continue
|
||||||
|
episodes.append("https://www.{}/videos/{}".format(self.domain, i["attributes"]["path"]))
|
||||||
|
page += 1
|
||||||
|
if not episodes:
|
||||||
logging.error("Cant find any playable files")
|
logging.error("Cant find any playable files")
|
||||||
if config.get("all_last") > 0:
|
if config.get("all_last") > 0:
|
||||||
return episodes[: config.get("all_last")]
|
return episodes[: config.get("all_last")]
|
||||||
return episodes
|
return episodes
|
||||||
|
|
||||||
def _login(self):
|
def _login(self):
|
||||||
url = "https://disco-api.{}/login".format(self.domain)
|
res = self.http.get("https://disco-api.{}/users/me".format(self.domain), headers={"authority": "disco-api.{}".format(self.domain)})
|
||||||
login = {"credentials": {"username": self.config.get("username"), "password": self.config.get("password")}}
|
if not res.json()["data"]["attributes"]["anonymous"]:
|
||||||
res = self.http.post(url, json=login)
|
return True
|
||||||
if res.status_code >= 400:
|
return False
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
def _token(self):
|
def _token(self) -> bool:
|
||||||
# random device id for cookietoken
|
# random device id for cookietoken
|
||||||
deviceid = hashlib.sha256(bytes(int(random.random() * 1000))).hexdigest()
|
deviceid = hashlib.sha256(bytes(int(random.random() * 1000))).hexdigest()
|
||||||
url = "https://disco-api.{}/token?realm={}&deviceId={}&shortlived=true".format(self.domain, self.domain.replace(".", ""), deviceid)
|
url = "https://disco-api.{}/token?realm={}&deviceId={}&shortlived=true".format(self.domain, self.domain.replace(".", ""), deviceid)
|
||||||
@ -165,3 +174,10 @@ class Dplay(Service):
|
|||||||
if res.status_code >= 400:
|
if res.status_code >= 400:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def _checkpremium(self) -> bool:
|
||||||
|
res = self.http.get("https://disco-api.{}/users/me".format(self.domain), headers={"authority": "disco-api.{}".format(self.domain)})
|
||||||
|
if res.status_code < 400:
|
||||||
|
if "premium" in res.json()["data"]["attributes"]["products"]:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
Loading…
Reference in New Issue
Block a user