mirror of
https://github.com/spaam/svtplay-dl.git
synced 2024-11-30 15:14:14 +01:00
37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
# ex:ts=4:sw=4:sts=4:et
|
|
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
|
import copy
|
|
import re
|
|
|
|
from svtplay_dl.error import ServiceError
|
|
from svtplay_dl.fetcher.http import HTTP
|
|
from svtplay_dl.service import OpenGraphThumbMixin
|
|
from svtplay_dl.service import Service
|
|
|
|
|
|
class Sr(Service, OpenGraphThumbMixin):
|
|
supported_domains = ["sverigesradio.se"]
|
|
|
|
def get(self):
|
|
data = self.get_urldata()
|
|
|
|
match = re.search(r'data-audio-id="(\d+)"', data)
|
|
match2 = re.search(r'data-publication-id="(\w+)"', data)
|
|
if match and match2:
|
|
aid = match.group(1)
|
|
pubid = match2.group(1)
|
|
else:
|
|
yield ServiceError("Can't find audio info")
|
|
return
|
|
|
|
for what in ["episode", "secondary"]:
|
|
language = ""
|
|
apiurl = f"https://sverigesradio.se/playerajax/audio?id={aid}&type={what}&publicationid={pubid}&quality=high"
|
|
resp = self.http.request("get", apiurl)
|
|
if resp.status_code > 400:
|
|
continue
|
|
playerinfo = resp.json()
|
|
if what == "secondary":
|
|
language = "musik"
|
|
yield HTTP(copy.copy(self.config), playerinfo["audioUrl"], 128, output=self.output, language=language)
|