1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-24 04:05:39 +01:00
svtplay-dl/lib/svtplay_dl/service/youplay.py

46 lines
1.7 KiB
Python
Raw Normal View History

# ex:ts=4:sw=4:sts=4:et
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
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 unquote_plus
from svtplay_dl.error import ServiceError
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
2015-09-15 20:10:32 +02:00
class Youplay(Service, OpenGraphThumbMixin):
2019-08-25 00:27:31 +02:00
supported_domains = ["www.affarsvarlden.se"]
def get(self):
data = self.get_urldata()
match = re.search(r'script async defer src="(//content.youplay.se[^"]+)"', data)
if not match:
2021-02-28 22:05:15 +01:00
yield ServiceError(f"Cant find video info for {self.url}")
return
2021-04-27 19:44:09 +02:00
data = self.http.request("get", f"http:{match.group(1)}".content)
2014-12-22 10:20:37 +01:00
match = re.search(r'decodeURIComponent\("([^"]+)"\)\)', data)
if not match:
yield ServiceError("Can't decode video info")
return
data = unquote_plus(match.group(1))
2014-12-22 10:20:37 +01:00
match = re.search(r"videoData = ({[^;]+});", data)
if not match:
2021-02-28 22:05:15 +01:00
yield ServiceError(f"Cant find video info for {self.url}")
return
# fix broken json.
2014-12-22 10:20:37 +01:00
regex = re.compile(r"\s(\w+):")
data = regex.sub(r"'\1':", match.group(1))
2019-08-25 00:27:31 +02:00
data = data.replace("'", '"')
j = re.sub(r"{\s*(\w)", r'{"\1', data)
2014-12-26 02:04:29 +01:00
j = j.replace("\n", "")
j = re.sub(r'",\s*}', '"}', j)
2014-12-26 02:04:29 +01:00
jsondata = json.loads(j)
for i in jsondata["episode"]["sources"]:
match = re.search(r"mp4_(\d+)", i)
if match:
yield HTTP(copy.copy(self.config), jsondata["episode"]["sources"][i], match.group(1), output=self.output)