1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-24 12:15:40 +01:00
svtplay-dl/lib/svtplay_dl/service/vg.py

39 lines
1.4 KiB
Python
Raw Normal View History

2014-08-17 10:55:05 +02:00
import copy
2019-08-25 00:40:39 +02:00
import json
import re
2018-01-30 22:07:21 +01:00
from urllib.parse import urlparse
2014-08-17 10:55:05 +02:00
2019-08-25 00:40:39 +02:00
from svtplay_dl.error import ServiceError
2016-02-07 10:41:43 +01:00
from svtplay_dl.fetcher.hls import hlsparse
2019-08-25 00:40:39 +02:00
from svtplay_dl.fetcher.http import HTTP
from svtplay_dl.service import OpenGraphThumbMixin
from svtplay_dl.service import Service
2014-08-17 10:55:05 +02:00
2015-09-15 20:10:32 +02:00
2014-08-17 10:55:05 +02:00
class Vg(Service, OpenGraphThumbMixin):
2019-08-25 00:27:31 +02:00
supported_domains = ["vg.no", "vgtv.no"]
2014-08-17 10:55:05 +02:00
def get(self):
data = self.get_urldata()
2014-12-08 23:07:02 +01:00
match = re.search(r'data-videoid="([^"]+)"', data)
2014-08-17 10:55:05 +02:00
if not match:
2014-08-18 22:21:44 +02:00
parse = urlparse(self.url)
2019-08-25 00:27:31 +02:00
match = re.search(r"video/(\d+)/", parse.fragment)
2014-08-18 22:21:44 +02:00
if not match:
2021-02-28 22:05:15 +01:00
yield ServiceError(f"Can't find video file for: {self.url}")
2014-10-06 23:21:43 +02:00
return
2014-08-17 10:55:05 +02:00
videoid = match.group(1)
2021-02-28 22:05:15 +01:00
data = self.http.request("get", f"http://svp.vg.no/svp/api/v1/vgtv/assets/{videoid}?appName=vgtv-website").text
2014-08-17 10:55:05 +02:00
jsondata = json.loads(data)
2018-05-13 13:06:45 +02:00
self.output["title"] = jsondata["title"]
2014-08-17 10:55:05 +02:00
if "hls" in jsondata["streamUrls"]:
yield from hlsparse(
2020-12-26 13:10:56 +01:00
self.config,
self.http.request("get", jsondata["streamUrls"]["hls"]),
jsondata["streamUrls"]["hls"],
output=self.output,
2019-08-25 00:27:31 +02:00
)
2014-08-17 10:55:05 +02:00
if "mp4" in jsondata["streamUrls"]:
yield HTTP(copy.copy(self.config), jsondata["streamUrls"]["mp4"], output=self.output)