From a3406c8c53cfc5c776d4ef4100e07f2de82c43a2 Mon Sep 17 00:00:00 2001 From: Johan Andersson Date: Sat, 24 Feb 2018 17:39:26 +0100 Subject: [PATCH] cmore: add support for .dk/fi/no fixes: #815 --- lib/svtplay_dl/service/cmore.py | 48 +++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/lib/svtplay_dl/service/cmore.py b/lib/svtplay_dl/service/cmore.py index c2f7bee..16db5cd 100644 --- a/lib/svtplay_dl/service/cmore.py +++ b/lib/svtplay_dl/service/cmore.py @@ -9,29 +9,36 @@ from svtplay_dl.log import log from svtplay_dl.fetcher.dash import dashparse from svtplay_dl.subtitle import subtitle from svtplay_dl.utils import filenamify -from svtplay_dl.utils.urllib import urljoin +from svtplay_dl.utils.urllib import urljoin, urlparse from svtplay_dl.error import ServiceError class Cmore(Service): - supported_domains = ['www.cmore.se'] + supported_domains = ['www.cmore.se', 'www.cmore.dk', 'www.cmore.no', 'www.cmore.fi'] def get(self): if not self.options.username or not self.options.password: yield ServiceError("You need username and password to download things from this site.") return + token, message = self._login() if not token: yield ServiceError(message) return + res = self.http.get(self.url) match = re.search('data-asset-id="([^"]+)"', res.text) if not match: yield ServiceError("Can't find video id") return - url = "https://restapi.cmore.se/api/tve_web/asset/{0}/play.json?protocol=VUDASH".format(match.group(1)) + + tld = self._gettld() + url = "https://restapi.cmore.{0}/api/tve_web/asset/{1}/play.json?protocol=VUDASH".format(tld, match.group(1)) res = self.http.get(url, headers={"authorization": "Bearer {0}".format(token)}) janson = res.json() + if "error" in janson: + yield ServiceError("This video is geoblocked") + return if self.options.output_auto: directory = os.path.dirname(self.options.output) @@ -74,13 +81,23 @@ class Cmore(Service): yield streams[n] def _autoname(self, vid): - url = "https://restapi.cmore.se/api/tve_web/asset/{0}.json?expand=metadata".format(vid) + url = "https://restapi.cmore.{0}/api/tve_web/asset/{1}.json?expand=metadata".format(self._gettld(), vid) res = self.http.get(url) janson = res.json()["asset"]["metadata"] if isinstance(janson["title"], list): for i in janson["title"]: - if i["@xml:lang"] == "sv_SE": # if we add other .tld, we might need to change this. - name = i["$"] + if self._gettld() == "se": + if i["@xml:lang"] == "sv_SE": + name = i["$"] + elif self._gettld() == "dk": + if i["@xml:lang"] == "da_DK": + name = i["$"] + elif self._gettld() == "no": + if i["@xml:lang"] == "nb_NO": + name = i["$"] + elif self._gettld() == "fi": + if i["@xml:lang"] == "fi_FI": + name = i["$"] else: name = janson["title"]["$"] @@ -99,7 +116,7 @@ class Cmore(Service): res = self.http.get(self.url) tags = re.findall('= 400: return None, "Wrong username or password" janson = res.json() @@ -123,6 +149,6 @@ class Cmore(Service): return token, None def operatorlist(self): - res = self.http.get("https://tve.cmore.se/country/se/operator?client=cmore-web") + res = self.http.get("https://tve.cmore.se/country/{0}/operator?client=cmore-web".format(self._gettld())) for i in res.json()["data"]["operators"]: print("operator: '{0}'".format(i["name"].lower()))