1
0
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:
Johan Andersson 2020-09-15 23:44:08 +02:00
parent 1e32678ba9
commit 5fc7750e17

View File

@ -25,10 +25,9 @@ class Dplay(Service):
if not self._token():
logging.error("Something went wrong getting token for requests")
if self.config.get("username") and self.config.get("password"):
premium = self._login()
if not premium:
logging.warning("Wrong username/password. no support for recaptcha.")
if not self._login():
yield ServiceError("Need the 'st' cookie to work")
return
channel = False
if "kanaler" in parse.path:
@ -112,52 +111,62 @@ class Dplay(Service):
def find_all_episodes(self, config):
parse = urlparse(self.url)
self.domain = re.search(r"(dplay\.\w\w)", parse.netloc).group(1)
programid = None
seasons = []
match = re.search("^/(program|programmer|videos|videoer)/([^/]+)", parse.path)
if not match:
logging.error("Can't find show name")
return None
if not self._login():
logging.error("Need the 'st' cookie to work")
return None
if not self._token():
logging.error("Something went wrong getting token for requests")
premium = False
if self.config.get("username") and self.config.get("password"):
premium = self._login()
if not premium:
logging.warning("Wrong username/password.")
url = "https://disco-api.{}/content/shows/{}".format(self.domain, match.group(2))
premium = self._checkpremium()
url = "http://disco-api.{}/cms/routes/program/{}?decorators=viewingHistory&include=default".format(self.domain, match.group(2))
res = self.http.get(url)
programid = res.json()["data"]["id"]
seasons = res.json()["data"]["attributes"]["seasonNumbers"]
for what in res.json()["included"]:
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 = []
for season in seasons:
qyerystring = (
"include=primaryChannel,show&filter[videoType]=EPISODE&filter[show.id]={}&filter[seasonNumber]={}&"
"page[size]=100&sort=seasonNumber,episodeNumber,-earliestPlayableStart".format(programid, season)
)
res = self.http.get("https://disco-api.{}/content/videos?{}".format(self.domain, qyerystring))
janson = res.json()
for i in janson["data"]:
if not premium and "Free" not in i["attributes"]["packages"]:
continue
episodes.append("https://www.{}/videos/{}".format(self.domain, i["attributes"]["path"]))
if len(episodes) == 0:
if programid:
for season in seasons:
page = 1
totalpages = 1
while page <= totalpages:
qyerystring = "decorators=viewingHistory&include=default&page[items.number]={}&&pf[seasonNumber]={}".format(page, season)
res = self.http.get("https://disco-api.{}/cms/collections/{}?{}".format(self.domain, programid, qyerystring))
janson = res.json()
totalpages = janson["data"]["meta"]["itemsTotalPages"]
for i in janson["included"]:
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")
if config.get("all_last") > 0:
return episodes[: config.get("all_last")]
return episodes
def _login(self):
url = "https://disco-api.{}/login".format(self.domain)
login = {"credentials": {"username": self.config.get("username"), "password": self.config.get("password")}}
res = self.http.post(url, json=login)
if res.status_code >= 400:
return False
return True
res = self.http.get("https://disco-api.{}/users/me".format(self.domain), headers={"authority": "disco-api.{}".format(self.domain)})
if not res.json()["data"]["attributes"]["anonymous"]:
return True
return False
def _token(self):
def _token(self) -> bool:
# random device id for cookietoken
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)
@ -165,3 +174,10 @@ class Dplay(Service):
if res.status_code >= 400:
return False
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