1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-30 23:24:16 +01:00
svtplay-dl/lib/svtplay_dl/service/sr.py

32 lines
1.0 KiB
Python
Raw Normal View History

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
import json
import re
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 Sr(Service, OpenGraphThumbMixin):
2019-08-25 00:27:31 +02:00
supported_domains = ["sverigesradio.se"]
def get(self):
2015-08-30 11:27:31 +02:00
data = self.get_urldata()
match = re.search(r'data-audio-id="(\d+)"', data)
match2 = re.search(r'data-audio-type="(\w+)"', data)
if match and match2:
aid = match.group(1)
type = match2.group(1)
2016-10-17 23:58:23 +02:00
else:
yield ServiceError("Can't find audio info")
return
2016-10-17 23:58:23 +02:00
2021-12-18 19:52:08 +01:00
dataurl = f"https://sverigesradio.se/sida/playerajax/getaudiourl?id={aid}&type={type}&quality=high&format=iis"
2015-09-07 19:03:31 +02:00
data = self.http.request("get", dataurl).text
2016-10-17 23:58:23 +02:00
playerinfo = json.loads(data)
yield HTTP(copy.copy(self.config), playerinfo["audioUrl"], 128, output=self.output)