2018-01-08 20:38:20 +01:00
|
|
|
# ex:ts=4:sw=4:sts=4:et
|
|
|
|
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
|
|
|
from __future__ import absolute_import
|
|
|
|
import re
|
|
|
|
import json
|
2018-01-30 22:07:21 +01:00
|
|
|
from urllib.parse import urljoin, urlparse, parse_qs
|
2018-01-13 20:08:52 +01:00
|
|
|
|
2018-01-08 20:38:20 +01:00
|
|
|
|
|
|
|
from svtplay_dl.log import log
|
2018-01-08 22:06:17 +01:00
|
|
|
from svtplay_dl.service.svtplay import Svtplay
|
2018-01-08 20:38:20 +01:00
|
|
|
from svtplay_dl.error import ServiceError
|
|
|
|
|
|
|
|
|
2018-01-08 22:06:17 +01:00
|
|
|
class Barnkanalen(Svtplay):
|
2018-01-08 20:38:20 +01:00
|
|
|
supported_domains = ['svt.se']
|
|
|
|
supported_path = "/barnkanalen"
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def handles(cls, url):
|
|
|
|
urlp = urlparse(url)
|
|
|
|
|
|
|
|
correctpath = urlp.path.startswith(cls.supported_path)
|
|
|
|
if urlp.netloc in cls.supported_domains and correctpath:
|
|
|
|
return True
|
|
|
|
|
|
|
|
# For every listed domain, try with www. subdomain as well.
|
2018-01-30 20:11:37 +01:00
|
|
|
if urlp.netloc in ['www.' + x for x in cls.supported_domains] and correctpath:
|
2018-01-08 20:38:20 +01:00
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
def get(self):
|
|
|
|
parse = urlparse(self.url)
|
|
|
|
|
|
|
|
query = parse_qs(parse.query)
|
|
|
|
self.access = None
|
|
|
|
if "accessService" in query:
|
|
|
|
self.access = query["accessService"]
|
|
|
|
|
|
|
|
match = re.search("__barnplay'] = ({.*});", self.get_urldata())
|
|
|
|
if not match:
|
|
|
|
yield ServiceError("Can't find video info.")
|
|
|
|
return
|
|
|
|
|
|
|
|
janson = json.loads(match.group(1))["context"]["dispatcher"]["stores"]["ApplicationStateStore"]["data"]
|
|
|
|
janson["video"] = janson["categoryStateCache"]["karaktarer"]["episodeModel"]
|
|
|
|
|
|
|
|
if "title" not in janson["video"]:
|
|
|
|
yield ServiceError("Can't find any video on that page.")
|
|
|
|
return
|
|
|
|
|
|
|
|
if "live" in janson["video"]:
|
2018-05-13 13:06:45 +02:00
|
|
|
self.config.set("live", janson["video"]["live"])
|
2018-01-08 20:38:20 +01:00
|
|
|
|
2018-05-08 22:51:27 +02:00
|
|
|
self.outputfilename(janson["video"])
|
2018-01-08 20:38:20 +01:00
|
|
|
|
|
|
|
if "programVersionId" in janson["video"]:
|
|
|
|
vid = janson["video"]["programVersionId"]
|
|
|
|
else:
|
|
|
|
vid = janson["video"]["id"]
|
|
|
|
res = self.http.get("http://api.svt.se/videoplayer-api/video/{0}".format(vid))
|
|
|
|
try:
|
|
|
|
janson = res.json()
|
|
|
|
except json.decoder.JSONDecodeError:
|
|
|
|
yield ServiceError("Can't decode api request: {0}".format(res.request.url))
|
|
|
|
return
|
|
|
|
videos = self._get_video(janson)
|
|
|
|
for i in videos:
|
|
|
|
yield i
|
|
|
|
|
|
|
|
def find_all_episodes(self, options):
|
|
|
|
videos = []
|
|
|
|
match = re.search("__barnplay'] = ({.*});", self.get_urldata())
|
|
|
|
if not match:
|
|
|
|
log.error("Couldn't retrieve episode list.")
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
dataj = json.loads(match.group(1))
|
2018-01-09 21:14:01 +01:00
|
|
|
dataj = dataj["context"]["dispatcher"]["stores"]["EpisodesStore"]
|
|
|
|
showId = list(dataj["data"].keys())[0]
|
|
|
|
items = dataj["data"][showId]["episodes"]
|
|
|
|
for i in items:
|
|
|
|
program = i
|
|
|
|
videos = self.videos_to_list(program, videos)
|
|
|
|
videos.reverse()
|
2018-01-08 20:38:20 +01:00
|
|
|
|
|
|
|
episodes = [urljoin("http://www.svt.se", x) for x in videos]
|
|
|
|
|
|
|
|
if options.all_last > 0:
|
2018-01-09 21:14:01 +01:00
|
|
|
return episodes[-options.all_last:]
|
|
|
|
return episodes
|
2018-01-08 20:38:20 +01:00
|
|
|
|
|
|
|
def videos_to_list(self, lvideos, videos):
|
|
|
|
url = self.url + "/" + str(lvideos["id"])
|
|
|
|
parse = urlparse(url)
|
|
|
|
if parse.path not in videos:
|
|
|
|
filename = self.outputfilename(lvideos, self.options.output)
|
|
|
|
if not self.exclude2(filename):
|
|
|
|
videos.append(parse.path)
|
|
|
|
|
|
|
|
return videos
|