1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-24 04:05:39 +01:00

cmore: fix --all-episodes work again and dash strems support

This commit is contained in:
Johan Andersson 2021-06-04 00:39:18 +02:00
parent 9ebb2e9c01
commit d32bc0280d

View File

@ -1,9 +1,9 @@
import logging import logging
import re import re
from urllib.parse import urljoin
from urllib.parse import urlparse from urllib.parse import urlparse
from svtplay_dl.error import ServiceError from svtplay_dl.error import ServiceError
from svtplay_dl.fetcher.dash import dashparse
from svtplay_dl.fetcher.hls import hlsparse from svtplay_dl.fetcher.hls import hlsparse
from svtplay_dl.service import Service from svtplay_dl.service import Service
@ -46,27 +46,61 @@ class Cmore(Service):
yield ServiceError("Can't play this because the video is geoblocked.") yield ServiceError("Can't play this because the video is geoblocked.")
return return
if res.json()["playbackItem"]["type"] == "hls": jansson = res.json()
if jansson["playbackItem"]["type"] == "hls":
yield from hlsparse( yield from hlsparse(
self.config, self.config,
self.http.request("get", res.json()["playbackItem"]["manifestUrl"]), self.http.request("get", jansson["playbackItem"]["manifestUrl"]),
res.json()["playbackItem"]["manifestUrl"], jansson["playbackItem"]["manifestUrl"],
output=self.output, output=self.output,
httpobject=self.http,
)
yield from dashparse(
self.config,
self.http.request("get", jansson["playbackItem"]["manifestUrl"].replace(".m3u8", ".mpd")),
jansson["playbackItem"]["manifestUrl"].replace(".m3u8", ".mpd"),
output=self.output,
httpobject=self.http,
) )
def find_all_episodes(self, config): def find_all_episodes(self, config):
episodes = [] episodes = []
seasons = []
token, message = self._login() token, message = self._login()
if not token: if not token:
logging.error(message) logging.error(message)
return return
res = self.http.get(self.url)
tags = re.findall('<a class="card__link" href="([^"]+)"', res.text) parse = urlparse(self.url)
for i in tags: url = f"https://www.cmore.{self._gettld()}/page-data{parse.path}/page-data.json"
url = urljoin(f"https://www.cmore.{self._gettld()}/", i) res = self.http.get(url)
if url not in episodes: if res.status_code > 400:
episodes.append(url) logging.warning("Bad url? it only work with series")
return seasons
janson = res.json()
if "mutualSeasonData" in janson["result"]["pageContext"]:
path = janson["result"]["pageContext"]["mutualSeasonData"]["serieRelativeUrl"]
seasons = janson["result"]["pageContext"]["mutualSeasonData"]["seasonNumbers"]
elif "mutualEpisodeData" in janson["result"]["pageContext"]:
path = janson["result"]["pageContext"]["mutualEpisodeData"]["serieRelativeUrl"]
seasons = janson["result"]["pageContext"]["mutualEpisodeData"]["seasonNumbers"]
elif "serie" in janson["result"]["pageContext"]:
path = janson["result"]["pageContext"]["serie"]["relativeUrl"]
seasons = janson["result"]["pageContext"]["serie"]["seasonNumbers"]
else:
logging.warning("Can't find info needed to find episodes")
for season in seasons:
url = f"https://www.cmore.se/page-data{path}/sasong-{season}/page-data.json"
res = self.http.get(url)
janson = res.json()
for episode in janson["result"]["pageContext"]["season"]["selectedEpisodes"]:
episode_url = f'https://www.cmore.{self._gettld()}{episode["relativeUrl"]}'
if episode_url not in episodes:
episodes.append(episode_url)
if config.get("all_last") > 0: if config.get("all_last") > 0:
return sorted(episodes[-config.get("all_last") :]) return sorted(episodes[-config.get("all_last") :])