mirror of
https://github.com/spaam/svtplay-dl.git
synced 2024-11-24 04:05:39 +01:00
cmore: new site, new update
This commit is contained in:
parent
a72d8e4e3c
commit
41cee01ab3
@ -1,12 +1,10 @@
|
|||||||
from __future__ import absolute_import, unicode_literals
|
from __future__ import absolute_import, unicode_literals
|
||||||
import re
|
import re
|
||||||
import copy
|
|
||||||
from urllib.parse import urljoin, urlparse
|
from urllib.parse import urljoin, urlparse
|
||||||
|
|
||||||
from svtplay_dl.service import Service
|
from svtplay_dl.service import Service
|
||||||
from svtplay_dl.log import log
|
from svtplay_dl.log import log
|
||||||
from svtplay_dl.fetcher.dash import dashparse
|
from svtplay_dl.fetcher.hls import hlsparse
|
||||||
from svtplay_dl.subtitle import subtitle
|
|
||||||
from svtplay_dl.error import ServiceError
|
from svtplay_dl.error import ServiceError
|
||||||
|
|
||||||
|
|
||||||
@ -23,73 +21,34 @@ class Cmore(Service):
|
|||||||
yield ServiceError(message)
|
yield ServiceError(message)
|
||||||
return
|
return
|
||||||
|
|
||||||
res = self.http.get(self.url)
|
vid = self._get_vid()
|
||||||
match = re.search('data-asset-id="([^"]+)"', res.text)
|
if not vid:
|
||||||
if not match:
|
|
||||||
yield ServiceError("Can't find video id")
|
yield ServiceError("Can't find video id")
|
||||||
return
|
return
|
||||||
|
|
||||||
tld = self._gettld()
|
tld = self._gettld()
|
||||||
url = "https://restapi.cmore.{0}/api/tve_web/asset/{1}/play.json?protocol=VUDASH".format(tld, match.group(1))
|
self.output["id"] = vid
|
||||||
res = self.http.get(url, headers={"authorization": "Bearer {0}".format(token)})
|
|
||||||
|
metaurl = "https://playback-api.b17g.net/asset/{}?service=cmore.{}" \
|
||||||
|
"&device=browser&drm=widevine&protocol=dash%2Chls".format(self.output["id"], tld)
|
||||||
|
res = self.http.get(metaurl)
|
||||||
janson = res.json()
|
janson = res.json()
|
||||||
if "error" in janson:
|
self._autoname(janson)
|
||||||
yield ServiceError("This video is geoblocked")
|
if janson["metadata"]["isDrmProtected"]:
|
||||||
|
yield ServiceError("Can't play this because the video got drm.")
|
||||||
return
|
return
|
||||||
|
|
||||||
basename = self._autoname(match.group(1))
|
url = "https://playback-api.b17g.net/media/{}?service=cmore.{}&device=browser&protocol=hls%2Cdash&drm=widevine".format(self.output["id"], tld)
|
||||||
self.output["id"] = match.group(1)
|
res = self.http.request("get", url, cookies=self.cookies, headers={"authorization": "Bearer {0}".format(token)})
|
||||||
if basename is None:
|
if res.status_code > 200:
|
||||||
yield ServiceError("Cant find vid id for autonaming")
|
yield ServiceError("Can't play this because the video is geoblocked.")
|
||||||
return
|
return
|
||||||
|
|
||||||
if "drmProtected" in janson["playback"]:
|
if res.json()["playbackItem"]["type"] == "hls":
|
||||||
if janson["playback"]["drmProtected"]:
|
streams = hlsparse(self.config, self.http.request("get", res.json()["playbackItem"]["manifestUrl"]),
|
||||||
yield ServiceError("DRM protected. Can't do anything")
|
res.json()["playbackItem"]["manifestUrl"], output=self.output)
|
||||||
return
|
for n in list(streams.keys()):
|
||||||
|
yield streams[n]
|
||||||
if isinstance(janson["playback"]["items"]["item"], list):
|
|
||||||
for i in janson["playback"]["items"]["item"]:
|
|
||||||
if i["mediaFormat"] == "ism":
|
|
||||||
streams = dashparse(self.config, self.http.request("get", i["url"]), i["url"], output=self.output)
|
|
||||||
if streams:
|
|
||||||
for n in list(streams.keys()):
|
|
||||||
yield streams[n]
|
|
||||||
if i["mediaFormat"] == "webvtt":
|
|
||||||
yield subtitle(copy.copy(self.config), "wrst", i["url"])
|
|
||||||
else:
|
|
||||||
i = janson["playback"]["items"]["item"]
|
|
||||||
if i["mediaFormat"] == "ism":
|
|
||||||
streams = dashparse(self.config, self.http.request("get", i["url"]), i["url"], output=self.output)
|
|
||||||
for n in list(streams.keys()):
|
|
||||||
yield streams[n]
|
|
||||||
|
|
||||||
def _autoname(self, 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 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"]["$"]
|
|
||||||
|
|
||||||
if "season" in janson:
|
|
||||||
self.output["season"] = int(janson["season"]["$"])
|
|
||||||
self.output["episode"] = int(janson["episode"]["$"])
|
|
||||||
self.output["title"] = name
|
|
||||||
return self.output["title"]
|
|
||||||
|
|
||||||
def find_all_episodes(self, config):
|
def find_all_episodes(self, config):
|
||||||
episodes = []
|
episodes = []
|
||||||
@ -136,3 +95,27 @@ class Cmore(Service):
|
|||||||
res = self.http.get("https://tve.cmore.se/country/{0}/operator?client=cmore-web".format(self._gettld()))
|
res = self.http.get("https://tve.cmore.se/country/{0}/operator?client=cmore-web".format(self._gettld()))
|
||||||
for i in res.json()["data"]["operators"]:
|
for i in res.json()["data"]["operators"]:
|
||||||
print("operator: '{0}'".format(i["name"].lower()))
|
print("operator: '{0}'".format(i["name"].lower()))
|
||||||
|
|
||||||
|
def _get_vid(self):
|
||||||
|
res = self.http.get(self.url)
|
||||||
|
match = re.search('data-asset-id="([^"]+)"', res.text)
|
||||||
|
if match:
|
||||||
|
return match.group(1)
|
||||||
|
|
||||||
|
parse = urlparse(self.url)
|
||||||
|
match = re.search(r"/(\d+)-[\w-]+$", parse.path)
|
||||||
|
if match:
|
||||||
|
return match.group(1)
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
def _autoname(self, janson):
|
||||||
|
if "seriesTitle" in janson["metadata"]:
|
||||||
|
self.output["title"] = janson["metadata"]["seriesTitle"]
|
||||||
|
self.output["episodename"] = janson["metadata"]["episodeTitle"]
|
||||||
|
|
||||||
|
else:
|
||||||
|
self.output["title"] = janson["metadata"]["title"]
|
||||||
|
self.output["season"] = janson["metadata"]["seasonNumber"]
|
||||||
|
self.output["episode"] = janson["metadata"]["episodeNumber"]
|
||||||
|
self.config.set("live", janson["metadata"]["isLive"])
|
||||||
|
Loading…
Reference in New Issue
Block a user