1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-28 06:04:17 +01:00
svtplay-dl/lib/svtplay_dl/service/atg.py

41 lines
1.3 KiB
Python
Raw Normal View History

2018-01-27 20:10:30 +01:00
# ex:ts=4:sw=4:sts=4:et
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
import json
from datetime import datetime
2018-01-30 22:07:21 +01:00
from urllib.parse import urlparse
2018-01-27 20:10:30 +01:00
from svtplay_dl.error import ServiceError
from svtplay_dl.fetcher.hls import hlsparse
2019-08-25 00:40:39 +02:00
from svtplay_dl.service import Service
2018-01-27 20:10:30 +01:00
class Atg(Service):
supported_domains = ["atgplay.se"]
def get(self):
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)
2018-01-27 20:10:30 +01:00
2021-02-28 22:05:15 +01:00
api_url = f"https://www.atgplay.se/api/{current_time}/video/{wanted_id}"
2018-01-27 20:10:30 +01:00
video_assets = self.http.request("get", api_url)
try:
janson = json.loads(video_assets.text)
except json.decoder.JSONDecodeError:
2021-02-28 22:05:15 +01:00
yield ServiceError(f"Can't decode api request: {video_assets.text}")
2018-01-27 20:10:30 +01:00
return
if "title" in janson:
2018-05-13 13:06:45 +02:00
self.output["title"] = janson["title"]
2018-01-27 20:10:30 +01:00
if "urls" in janson:
for i in janson["urls"]:
if "m3u" == i:
yield from hlsparse(self.config, self.http.request("get", janson["urls"]["m3u"]), janson["urls"]["m3u"], output=self.output)