From 25ea769bc3ef453e950d83e73cd47adab4495c2c Mon Sep 17 00:00:00 2001 From: Johan Andersson Date: Sun, 14 Mar 2021 18:36:20 +0100 Subject: [PATCH] svtplay: improve detection of season and episode numbers fixes: #1342 --- lib/svtplay_dl/service/svtplay.py | 46 ++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/lib/svtplay_dl/service/svtplay.py b/lib/svtplay_dl/service/svtplay.py index ddcbb43..e6ccbeb 100644 --- a/lib/svtplay_dl/service/svtplay.py +++ b/lib/svtplay_dl/service/svtplay.py @@ -236,15 +236,53 @@ class Svtplay(Service, MetadataThumbMixin): def seasoninfo(self, data): season, episode = None, None - match = re.search(r"/säsong (\d+)/avsnitt (\d+)", data["analyticsIdentifiers"]["viewId"]) - if not match: + season_nr = self._find_season(data) + episode_nr = self._find_episode(data) + + if season_nr is None or episode_nr is None: return season, episode - season = "{:02d}".format(int(match.group(1))) - episode = "{:02d}".format(int(match.group(2))) + season = "{:02d}".format(int(season_nr)) + episode = "{:02d}".format(int(episode_nr)) return season, episode + def _find_season(self, data): + match = re.search(r"/säsong (\d+)/", data["analyticsIdentifiers"]["viewId"]) + if match: + return match.group(1) + + match = re.search(r"-sasong-(\d+)-", data["item"]["urls"]["svtplay"]) + if match: + return match.group(1) + + vid = data["video"]["svtId"] + for seasons in data["associatedContent"]: + for i in seasons["items"]: + if i["item"]["videoSvtId"] == vid: + match = re.search(r"S.song (\d+)", i["item"]["positionInSeason"]) + if match: + return match.group(1) + return None + + def _find_episode(self, data): + match = re.search(r"/avsnitt (\d+)", data["analyticsIdentifiers"]["viewId"]) + if match: + return match.group(1) + + match = re.search(r"Avsnitt (\d+)", data["item"]["name"]) + if match: + return match.group(1) + + vid = data["video"]["svtId"] + for seasons in data["associatedContent"]: + for i in seasons["items"]: + if i["item"]["videoSvtId"] == vid: + match = re.search(r"Avsnitt (\d+)", i["item"]["positionInSeason"]) + if match: + return match.group(1) + return None + def extrametadata(self, episode): self.output["tvshow"] = self.output["season"] is not None and self.output["episode"] is not None if "validFrom" in episode: