From cf7f8c1da8d86077cbf24109346c02ba28943a0b Mon Sep 17 00:00:00 2001 From: dalgr Date: Sat, 27 Jan 2018 20:10:30 +0100 Subject: [PATCH] Add support for service ATG --- lib/svtplay_dl/__init__.py | 2 ++ lib/svtplay_dl/service/atg.py | 56 +++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 lib/svtplay_dl/service/atg.py diff --git a/lib/svtplay_dl/__init__.py b/lib/svtplay_dl/__init__.py index 5500eec..b6e2e91 100644 --- a/lib/svtplay_dl/__init__.py +++ b/lib/svtplay_dl/__init__.py @@ -19,6 +19,7 @@ from svtplay_dl.output import filename from svtplay_dl.postprocess import postprocess from svtplay_dl.service.aftonbladet import Aftonbladet, Aftonbladettv +from svtplay_dl.service.atg import Atg from svtplay_dl.service.bambuser import Bambuser from svtplay_dl.service.bigbrother import Bigbrother from svtplay_dl.service.cmore import Cmore @@ -67,6 +68,7 @@ __version__ = "1.9.7" sites = [ Aftonbladet, Aftonbladettv, + Atg, Bambuser, Barnkanalen, Bigbrother, diff --git a/lib/svtplay_dl/service/atg.py b/lib/svtplay_dl/service/atg.py new file mode 100644 index 0000000..35b0a64 --- /dev/null +++ b/lib/svtplay_dl/service/atg.py @@ -0,0 +1,56 @@ +# 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 json +import os +import re +import unicodedata +from datetime import datetime + +from svtplay_dl.service import Service +from svtplay_dl.error import ServiceError +from svtplay_dl.fetcher.hls import hlsparse +from svtplay_dl.utils.urllib import urlparse + + +class Atg(Service): + supported_domains = ["atgplay.se"] + + def get(self): + + if self.exclude(): + yield ServiceError("Excluding video") + return + + parse = urlparse(self.url) + + if not parse.path.startswith("/video"): + yield ServiceError("Can't find video info") + return + + wanted_id = parse.path[7:] + current_time = int((datetime.utcnow() - datetime.utcfromtimestamp(0)).total_seconds() * 1000) + + api_url = "https://www.atgplay.se/api/{0}/video/{1}".format(current_time, wanted_id) + video_assets = self.http.request("get", api_url) + + try: + janson = json.loads(video_assets.text) + except json.decoder.JSONDecodeError: + yield ServiceError("Can't decode api request: {0}".format(video_assets.text)) + return + + if "title" in janson: + directory = os.path.dirname(self.options.output) + title = re.sub(r"[^\S\n\t]+|\\|/", "_", janson["title"]) + self.options.output = os.path.join(directory, title) + + if "urls" in janson: + for i in janson["urls"]: + stream = None + if "m3u" == i: + stream = hlsparse(self.options, self.http.request("get", janson["urls"]["m3u"]), janson["urls"]["m3u"]) + + if stream: + for key in list(stream.keys()): + yield stream[key]