2015-10-04 14:40:00 +02: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
|
2015-10-29 19:32:38 +01:00
|
|
|
import os
|
2018-02-22 03:30:36 +01:00
|
|
|
import hashlib
|
|
|
|
import random
|
2018-01-30 22:07:21 +01:00
|
|
|
from urllib.parse import urlparse
|
2015-10-04 14:40:00 +02:00
|
|
|
|
|
|
|
from svtplay_dl.service import Service
|
|
|
|
from svtplay_dl.fetcher.hls import hlsparse
|
|
|
|
from svtplay_dl.error import ServiceError
|
2018-01-13 20:27:40 +01:00
|
|
|
from svtplay_dl.utils import filenamify
|
2015-10-30 00:29:48 +01:00
|
|
|
from svtplay_dl.log import log
|
2015-10-04 14:40:00 +02:00
|
|
|
|
2018-01-30 20:11:37 +01:00
|
|
|
|
2015-10-04 14:40:00 +02:00
|
|
|
class Dplay(Service):
|
2016-02-07 20:41:21 +01:00
|
|
|
supported_domains = ['dplay.se', 'dplay.dk', "dplay.no"]
|
2015-10-04 14:40:00 +02:00
|
|
|
|
2015-12-26 11:46:14 +01:00
|
|
|
def get(self):
|
2016-02-07 20:41:21 +01:00
|
|
|
parse = urlparse(self.url)
|
2018-02-22 03:30:36 +01:00
|
|
|
self.domain = re.search(r"(dplay\.\w\w)", parse.netloc).group(1)
|
2015-10-04 14:40:00 +02:00
|
|
|
|
2018-02-22 03:30:36 +01:00
|
|
|
if not self._token():
|
|
|
|
log.error("Something went wrong getting token for requests")
|
2015-10-29 22:42:27 +01:00
|
|
|
|
2018-02-25 21:20:54 +01:00
|
|
|
if self.options.username and self.options.password:
|
|
|
|
premium = self._login()
|
|
|
|
if not premium:
|
|
|
|
log.warning("Wrong username/password.")
|
|
|
|
|
|
|
|
channel = False
|
|
|
|
if "kanaler" in parse.path:
|
|
|
|
match = re.search("kanaler/([^/]+)$", parse.path)
|
|
|
|
path = "/channels/{}".format(match.group(1))
|
|
|
|
url = "https://disco-api.{}/content{}".format(self.domain, path)
|
|
|
|
channel = True
|
|
|
|
self.options.live = True
|
2018-03-04 15:06:47 +01:00
|
|
|
elif "program" in parse.path:
|
|
|
|
match = re.search("(programmer|program)/([^/]+)$", parse.path)
|
|
|
|
path = "/shows/{}".format(match.group(2))
|
|
|
|
url = "https://disco-api.{}/content{}".format(self.domain, path)
|
|
|
|
res = self.http.get(url, headers={"x-disco-client": "WEB:UNKNOWN:dplay-client:0.0.1"})
|
|
|
|
programid = res.json()["data"]["id"]
|
|
|
|
qyerystring = "include=primaryChannel,show&filter[videoType]=EPISODE&filter[show.id]={}&" \
|
|
|
|
"page[size]=100&sort=seasonNumber,episodeNumber,-earliestPlayableStart".format(programid)
|
|
|
|
res = self.http.get("https://disco-api.{}/content/videos?{}".format(self.domain, qyerystring))
|
|
|
|
janson = res.json()
|
|
|
|
vid = 0
|
|
|
|
slug = None
|
|
|
|
for i in janson["data"]:
|
|
|
|
if int(i["id"]) > vid:
|
|
|
|
vid = int(i["id"])
|
|
|
|
slug = i["attributes"]["path"]
|
|
|
|
if slug:
|
|
|
|
url = "https://disco-api.{}/content/videos/{}".format(self.domain, slug)
|
|
|
|
else:
|
|
|
|
yield ServiceError("Cant find latest video on program url")
|
|
|
|
return
|
2018-02-25 21:20:54 +01:00
|
|
|
else:
|
2018-02-26 00:34:58 +01:00
|
|
|
match = re.search("(videos|videoer)/(.*)$", parse.path)
|
|
|
|
url = "https://disco-api.{}/content/videos/{}".format(self.domain, match.group(2))
|
2018-02-22 03:30:36 +01:00
|
|
|
res = self.http.get(url, headers={"x-disco-client": "WEB:UNKNOWN:dplay-client:0.0.1"})
|
|
|
|
janson = res.json()
|
2018-02-25 21:22:59 +01:00
|
|
|
if "errors" in janson:
|
|
|
|
yield ServiceError("Cant find any videos on this url")
|
|
|
|
return
|
2018-01-09 00:40:24 +01:00
|
|
|
|
2018-02-22 03:30:36 +01:00
|
|
|
if self.options.output_auto:
|
|
|
|
directory = os.path.dirname(self.options.output)
|
|
|
|
self.options.service = "dplay"
|
2018-02-25 21:20:54 +01:00
|
|
|
if channel:
|
|
|
|
name = filenamify(janson["data"]["attributes"]["name"])
|
|
|
|
else:
|
|
|
|
name = self._autoname(janson)
|
2018-02-22 03:30:36 +01:00
|
|
|
if name is None:
|
|
|
|
yield ServiceError("Cant find vid id for autonaming")
|
|
|
|
return
|
|
|
|
title = "{0}-{1}-{2}".format(name, janson["data"]["id"], self.options.service)
|
|
|
|
if len(directory):
|
|
|
|
self.options.output = os.path.join(directory, title)
|
|
|
|
else:
|
|
|
|
self.options.output = title
|
|
|
|
|
2018-02-24 20:59:23 +01:00
|
|
|
if self.exclude():
|
|
|
|
yield ServiceError("Excluding video")
|
|
|
|
return
|
|
|
|
|
2018-02-22 03:30:36 +01:00
|
|
|
api = "https://disco-api.{}/playback/videoPlaybackInfo/{}".format(self.domain, janson["data"]["id"])
|
|
|
|
res = self.http.get(api)
|
|
|
|
if res.status_code > 400:
|
2018-02-25 21:20:54 +01:00
|
|
|
yield ServiceError("You dont have permission to watch this")
|
2016-02-07 20:43:00 +01:00
|
|
|
return
|
2018-02-22 03:30:36 +01:00
|
|
|
streams = hlsparse(self.options, self.http.request("get", res.json()["data"]["attributes"]["streaming"]["hls"]["url"]),
|
|
|
|
res.json()["data"]["attributes"]["streaming"]["hls"]["url"], httpobject=self.http)
|
|
|
|
if streams:
|
|
|
|
for n in list(streams.keys()):
|
|
|
|
yield streams[n]
|
2015-10-29 19:32:38 +01:00
|
|
|
|
|
|
|
def _autoname(self, jsondata):
|
2018-02-22 03:30:36 +01:00
|
|
|
match = re.search('^([^/]+)/', jsondata["data"]["attributes"]["path"])
|
|
|
|
show = match.group(1)
|
|
|
|
season = jsondata["data"]["attributes"]["seasonNumber"]
|
|
|
|
episode = jsondata["data"]["attributes"]["episodeNumber"]
|
2018-02-25 00:09:08 +01:00
|
|
|
name = jsondata["data"]["attributes"]["name"]
|
2018-01-13 20:27:40 +01:00
|
|
|
show = filenamify(show)
|
2018-02-25 00:09:08 +01:00
|
|
|
return filenamify("{0}.s{1:02d}e{2:02d}.{3}".format(show, int(season), int(episode), name))
|
2015-10-30 00:29:48 +01:00
|
|
|
|
|
|
|
def find_all_episodes(self, options):
|
2016-02-07 20:41:21 +01:00
|
|
|
parse = urlparse(self.url)
|
2018-02-22 03:30:36 +01:00
|
|
|
self.domain = re.search(r"(dplay\.\w\w)", parse.netloc).group(1)
|
|
|
|
|
2018-02-26 00:34:58 +01:00
|
|
|
match = re.search("^/(program|programmer|videos|videoer)/([^/]+)", parse.path)
|
2015-10-30 00:29:48 +01:00
|
|
|
if not match:
|
2018-02-22 03:30:36 +01:00
|
|
|
log.error("Can't find show name")
|
2015-10-30 00:29:48 +01:00
|
|
|
return None
|
|
|
|
|
2018-02-22 03:30:36 +01:00
|
|
|
if not self._token():
|
|
|
|
log.error("Something went wrong getting token for requests")
|
2015-10-30 00:29:48 +01:00
|
|
|
|
2018-02-22 03:30:36 +01:00
|
|
|
premium = False
|
|
|
|
if self.options.username and self.options.password:
|
2018-02-25 21:20:54 +01:00
|
|
|
premium = self._login()
|
2018-02-22 03:30:36 +01:00
|
|
|
if not premium:
|
|
|
|
log.warning("Wrong username/password.")
|
|
|
|
|
|
|
|
url = "https://disco-api.{}/content/shows/{}".format(self.domain, match.group(2))
|
|
|
|
res = self.http.get(url)
|
|
|
|
programid = res.json()["data"]["id"]
|
|
|
|
seasons = res.json()["data"]["attributes"]["seasonNumbers"]
|
2015-10-30 00:29:48 +01:00
|
|
|
episodes = []
|
2018-02-22 03:30:36 +01:00
|
|
|
for season in seasons:
|
|
|
|
qyerystring = "include=primaryChannel,show&filter[videoType]=EPISODE&filter[show.id]={}&filter[seasonNumber]={}&" \
|
|
|
|
"page[size]=100&sort=seasonNumber,episodeNumber,-earliestPlayableStart".format(programid, season)
|
|
|
|
res = self.http.get("https://disco-api.{}/content/videos?{}".format(self.domain, qyerystring))
|
|
|
|
janson = res.json()
|
|
|
|
for i in janson["data"]:
|
|
|
|
if not premium and not "Free" in i["attributes"]["packages"]:
|
|
|
|
continue
|
|
|
|
episodes.append("https://www.{}/videos/{}".format(self.domain, i["attributes"]["path"]))
|
2015-10-30 00:29:48 +01:00
|
|
|
if len(episodes) == 0:
|
|
|
|
log.error("Cant find any playable files")
|
2016-02-07 22:16:45 +01:00
|
|
|
if options.all_last > 0:
|
|
|
|
return episodes[:options.all_last]
|
2015-10-30 00:29:48 +01:00
|
|
|
return episodes
|
2018-02-22 03:30:36 +01:00
|
|
|
|
2018-02-25 21:20:54 +01:00
|
|
|
def _login(self):
|
2018-02-22 03:30:36 +01:00
|
|
|
url = "https://disco-api.{}/login".format(self.domain)
|
|
|
|
login = {"credentials": {"username": self.options.username, "password": self.options.password}}
|
|
|
|
res = self.http.post(url, json=login)
|
|
|
|
if res.status_code > 400:
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
def _token(self):
|
|
|
|
# random device id for cookietoken
|
|
|
|
deviceid = hashlib.sha256(bytes(int(random.random()*1000))).hexdigest()
|
|
|
|
url = "https://disco-api.{}/token?realm={}&deviceId={}&shortlived=true".format(self.domain, self.domain.replace(".", ""), deviceid)
|
|
|
|
res = self.http.get(url)
|
|
|
|
if res.status_code > 400:
|
|
|
|
return False
|
|
|
|
return True
|