2013-03-02 21:26:28 +01:00
|
|
|
# ex:ts=4:sw=4:sts=4:et
|
|
|
|
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
2019-08-25 00:40:39 +02:00
|
|
|
import copy
|
2013-02-12 19:43:37 +01:00
|
|
|
import re
|
|
|
|
|
2015-09-06 14:19:10 +02:00
|
|
|
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
|
2013-02-12 19:43:37 +01:00
|
|
|
|
2015-09-15 20:10:32 +02:00
|
|
|
|
2014-02-05 21:34:41 +01:00
|
|
|
class Sr(Service, OpenGraphThumbMixin):
|
2019-08-25 00:27:31 +02:00
|
|
|
supported_domains = ["sverigesradio.se"]
|
2013-01-17 00:21:47 +01:00
|
|
|
|
2015-12-26 11:46:14 +01:00
|
|
|
def get(self):
|
2015-08-30 11:27:31 +02:00
|
|
|
data = self.get_urldata()
|
2014-12-22 17:41:40 +01:00
|
|
|
|
2019-01-09 21:35:12 +01:00
|
|
|
match = re.search(r'data-audio-id="(\d+)"', data)
|
2024-07-28 16:25:57 +02:00
|
|
|
match2 = re.search(r'data-publication-id="(\w+)"', data)
|
2019-01-09 21:35:12 +01:00
|
|
|
if match and match2:
|
|
|
|
aid = match.group(1)
|
2024-07-28 16:25:57 +02:00
|
|
|
pubid = match2.group(1)
|
2016-10-17 23:58:23 +02:00
|
|
|
else:
|
2019-01-09 21:35:12 +01:00
|
|
|
yield ServiceError("Can't find audio info")
|
|
|
|
return
|
2016-10-17 23:58:23 +02:00
|
|
|
|
2024-07-28 16:25:57 +02:00
|
|
|
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)
|