2014-05-01 19:51:21 +02:00
|
|
|
# ex:ts=4:sw=4:sts=4:et
|
|
|
|
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
2016-11-06 15:25:49 +01:00
|
|
|
import copy
|
|
|
|
import hashlib
|
2018-11-18 12:47:19 +01:00
|
|
|
import logging
|
2019-08-25 00:40:39 +02:00
|
|
|
import re
|
|
|
|
from urllib.parse import parse_qs
|
|
|
|
from urllib.parse import urlparse
|
2018-01-30 22:07:21 +01:00
|
|
|
|
2016-11-06 15:25:49 +01:00
|
|
|
from svtplay_dl.error import ServiceError
|
2019-08-25 00:40:39 +02:00
|
|
|
from svtplay_dl.fetcher.dash import dashparse
|
2016-11-06 15:25:49 +01:00
|
|
|
from svtplay_dl.fetcher.hls import hlsparse
|
2019-08-25 00:40:39 +02:00
|
|
|
from svtplay_dl.service import OpenGraphThumbMixin
|
|
|
|
from svtplay_dl.service import Service
|
2022-12-10 14:05:56 +01:00
|
|
|
from svtplay_dl.subtitle import subtitle_probe
|
2019-08-25 00:40:39 +02:00
|
|
|
from svtplay_dl.utils.text import decode_html_entities
|
2014-05-01 19:51:21 +02:00
|
|
|
|
2015-09-15 20:10:32 +02:00
|
|
|
|
2016-11-06 15:25:49 +01:00
|
|
|
class OppetArkiv(Service, OpenGraphThumbMixin):
|
2019-08-25 00:27:31 +02:00
|
|
|
supported_domains = ["oppetarkiv.se"]
|
2014-05-01 19:51:21 +02:00
|
|
|
|
2016-11-06 15:25:49 +01:00
|
|
|
def get(self):
|
|
|
|
vid = self.find_video_id()
|
|
|
|
if vid is None:
|
|
|
|
yield ServiceError("Cant find video id for this video")
|
|
|
|
return
|
|
|
|
|
2021-02-28 22:05:15 +01:00
|
|
|
url = f"http://api.svt.se/videoplayer-api/video/{vid}"
|
2016-11-06 15:25:49 +01:00
|
|
|
data = self.http.request("get", url)
|
|
|
|
if data.status_code == 404:
|
2021-02-28 22:05:15 +01:00
|
|
|
yield ServiceError(f"Can't get the json file for {url}")
|
2016-11-06 15:25:49 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
data = data.json()
|
|
|
|
if "live" in data:
|
2018-05-13 13:06:45 +02:00
|
|
|
self.config.set("live", data["live"])
|
2016-11-06 15:25:49 +01:00
|
|
|
|
2018-06-03 00:12:45 +02:00
|
|
|
self.outputfilename(data)
|
2016-11-06 15:25:49 +01:00
|
|
|
|
|
|
|
if "subtitleReferences" in data:
|
|
|
|
for i in data["subtitleReferences"]:
|
2022-12-10 14:05:56 +01:00
|
|
|
yield from subtitle_probe(copy.copy(self.config), i["url"], output=self.output)
|
2016-11-06 15:25:49 +01:00
|
|
|
|
|
|
|
if len(data["videoReferences"]) == 0:
|
|
|
|
yield ServiceError("Media doesn't have any associated videos (yet?)")
|
|
|
|
return
|
|
|
|
|
|
|
|
for i in data["videoReferences"]:
|
|
|
|
parse = urlparse(i["url"])
|
|
|
|
query = parse_qs(parse.query)
|
|
|
|
if i["format"] == "hls" or i["format"] == "ios":
|
2021-05-16 02:22:37 +02:00
|
|
|
yield from hlsparse(self.config, self.http.request("get", i["url"]), i["url"], output=self.output)
|
2016-11-06 15:25:49 +01:00
|
|
|
if "alt" in query and len(query["alt"]) > 0:
|
|
|
|
alt = self.http.get(query["alt"][0])
|
|
|
|
if alt:
|
2021-05-16 02:22:37 +02:00
|
|
|
yield from hlsparse(self.config, self.http.request("get", alt.request.url), alt.request.url, output=self.output)
|
2016-11-06 15:25:49 +01:00
|
|
|
if i["format"] == "dash264" or i["format"] == "dashhbbtv":
|
2021-05-16 02:22:37 +02:00
|
|
|
yield from dashparse(self.config, self.http.request("get", i["url"]), i["url"], output=self.output)
|
2016-11-06 15:25:49 +01:00
|
|
|
if "alt" in query and len(query["alt"]) > 0:
|
|
|
|
alt = self.http.get(query["alt"][0])
|
|
|
|
if alt:
|
2021-05-16 02:22:37 +02:00
|
|
|
yield from dashparse(self.config, self.http.request("get", alt.request.url), alt.request.url, output=self.output)
|
2016-11-06 15:25:49 +01:00
|
|
|
|
|
|
|
def find_video_id(self):
|
|
|
|
match = re.search('data-video-id="([^"]+)"', self.get_urldata())
|
|
|
|
if match:
|
|
|
|
return match.group(1)
|
|
|
|
return None
|
|
|
|
|
2018-05-13 13:06:45 +02:00
|
|
|
def find_all_episodes(self, config):
|
2021-12-18 20:18:25 +01:00
|
|
|
episodes = []
|
2014-05-01 19:51:21 +02:00
|
|
|
page = 1
|
2015-08-31 17:14:31 +02:00
|
|
|
data = self.get_urldata()
|
2015-06-28 16:45:43 +02:00
|
|
|
match = re.search(r'"/etikett/titel/([^"/]+)', data)
|
2014-05-01 19:51:21 +02:00
|
|
|
if match is None:
|
2019-09-06 22:49:49 +02:00
|
|
|
match = re.search(r'"http://www.oppetarkiv.se/etikett/titel/([^/]+)/', self.url)
|
2014-05-01 19:51:21 +02:00
|
|
|
if match is None:
|
2018-11-18 12:47:19 +01:00
|
|
|
logging.error("Couldn't find title")
|
2021-12-18 20:18:25 +01:00
|
|
|
return episodes
|
2014-05-01 19:51:21 +02:00
|
|
|
program = match.group(1)
|
2014-12-21 13:10:26 +01:00
|
|
|
|
|
|
|
n = 0
|
2021-12-18 21:37:09 +01:00
|
|
|
if config.get("all_last") > 0:
|
2014-12-21 13:10:26 +01:00
|
|
|
sort = "tid_fallande"
|
|
|
|
else:
|
|
|
|
sort = "tid_stigande"
|
|
|
|
|
2015-09-30 00:47:49 +02:00
|
|
|
while True:
|
2021-02-28 22:05:15 +01:00
|
|
|
url = f"http://www.oppetarkiv.se/etikett/titel/{program}/?sida={page}&sort={sort}&embed=true"
|
2015-09-30 00:47:49 +02:00
|
|
|
data = self.http.request("get", url)
|
|
|
|
if data.status_code == 404:
|
|
|
|
break
|
|
|
|
|
|
|
|
data = data.text
|
2015-06-28 16:45:43 +02:00
|
|
|
regex = re.compile(r'href="(/video/[^"]+)"')
|
2014-05-01 19:51:21 +02:00
|
|
|
for match in regex.finditer(data):
|
2018-05-13 13:06:45 +02:00
|
|
|
if n == self.config.get("all_last"):
|
2014-12-21 13:10:26 +01:00
|
|
|
break
|
2021-04-27 19:44:09 +02:00
|
|
|
episodes.append(f"http://www.oppetarkiv.se{match.group(1)}")
|
2014-12-21 13:10:26 +01:00
|
|
|
n += 1
|
2014-05-01 19:51:21 +02:00
|
|
|
page += 1
|
|
|
|
|
|
|
|
return episodes
|
2016-11-06 15:25:49 +01:00
|
|
|
|
2018-05-13 13:06:45 +02:00
|
|
|
def outputfilename(self, data):
|
2021-12-18 21:37:09 +01:00
|
|
|
vid = hashlib.sha256(data["programVersionId"].encode("utf-8")).hexdigest()[:7]
|
|
|
|
self.output["id"] = vid
|
2017-04-21 22:00:53 +02:00
|
|
|
|
|
|
|
datatitle = re.search('data-title="([^"]+)"', self.get_urldata())
|
|
|
|
if not datatitle:
|
2021-12-18 20:18:25 +01:00
|
|
|
return
|
2017-04-21 22:00:53 +02:00
|
|
|
datat = decode_html_entities(datatitle.group(1))
|
2018-05-13 13:06:45 +02:00
|
|
|
self.output["title"] = self.name(datat)
|
|
|
|
self.seasoninfo(datat)
|
2016-11-06 15:25:49 +01:00
|
|
|
|
|
|
|
def seasoninfo(self, data):
|
2018-10-28 23:16:00 +01:00
|
|
|
match = re.search(r"S.song (\d+) - Avsnitt (\d+)", data)
|
2016-11-06 15:25:49 +01:00
|
|
|
if match:
|
2018-05-13 13:06:45 +02:00
|
|
|
self.output["season"] = int(match.group(1))
|
|
|
|
self.output["episode"] = int(match.group(2))
|
2016-11-06 15:25:49 +01:00
|
|
|
else:
|
2018-10-28 23:16:00 +01:00
|
|
|
match = re.search(r"Avsnitt (\d+)", data)
|
2016-11-06 15:25:49 +01:00
|
|
|
if match:
|
2018-05-13 13:06:45 +02:00
|
|
|
self.output["episode"] = int(match.group(1))
|
2016-11-06 15:25:49 +01:00
|
|
|
|
2020-12-26 13:10:56 +01:00
|
|
|
def name(self, data):
|
2017-04-21 22:00:53 +02:00
|
|
|
if data.find(" - S.song") > 0:
|
2019-08-25 00:27:31 +02:00
|
|
|
title = data[: data.find(" - S.song")]
|
2016-11-06 15:25:49 +01:00
|
|
|
else:
|
2017-04-21 22:00:53 +02:00
|
|
|
if data.find(" - Avsnitt") > 0:
|
2019-08-25 00:27:31 +02:00
|
|
|
title = data[: data.find(" - Avsnitt")]
|
2017-04-21 22:00:53 +02:00
|
|
|
else:
|
|
|
|
title = data
|
|
|
|
return title
|