1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-28 06:04:17 +01:00
svtplay-dl/lib/svtplay_dl/service/sr.py

53 lines
2.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 -*-
from __future__ import absolute_import
import json
import re
2014-06-07 20:43:40 +02:00
import copy
2018-01-30 22:07:21 +01:00
from urllib.parse import urljoin
from svtplay_dl.service import Service, OpenGraphThumbMixin
2014-04-21 17:33:44 +02:00
from svtplay_dl.fetcher.http import HTTP
from svtplay_dl.error import ServiceError
2015-09-15 20:10:32 +02:00
class Sr(Service, OpenGraphThumbMixin):
supported_domains = ['sverigesradio.se']
def get(self):
2015-08-30 11:27:31 +02:00
data = self.get_urldata()
2016-05-14 22:54:30 +02:00
if self.exclude():
2015-09-06 23:04:48 +02:00
yield ServiceError("Excluding video")
return
2016-10-17 23:58:23 +02:00
match = re.search('data-audio-type="publication" data-audio-id="(\d+)">', data) # Nyheter
if match:
2017-02-12 09:01:40 +01:00
dataurl = "https://sverigesradio.se/sida/playerajax/getaudiourl?id={0}&type={1}&quality=high&format=iis".format(match.group(1), "publication")
2016-10-17 23:58:23 +02:00
data = self.http.request("get", dataurl).text
playerinfo = json.loads(data)
yield HTTP(copy.copy(self.options), playerinfo["audioUrl"], 128)
2014-10-06 23:21:43 +02:00
return
2016-10-17 23:58:23 +02:00
match = re.search(r'href="(/topsy/ljudfil/\d+-mp3)"', data) # Ladda ner
if match:
yield HTTP(copy.copy(self.options), urljoin("https://sverigesradio.se", match.group(1)), 128)
return
else:
match = re.search('data-audio-type="episode" data-audio-id="(\d+)"', data) # Ladda ner med musik
match2 = re.search('data-audio-type="secondary" data-audio-id="(\d+)"', data) # Ladda ner utan musik
2016-10-17 23:58:23 +02:00
if match:
aid = match.group(1)
type = "episode"
2016-10-17 23:58:23 +02:00
elif match2:
aid = match2.group(1)
type = "secondary"
2016-10-17 23:58:23 +02:00
else:
yield ServiceError("Can't find audio info")
return
2017-02-12 09:01:40 +01:00
dataurl = "https://sverigesradio.se/sida/playerajax/getaudiourl?id={0}&type={1}&quality=high&format=iis".format(aid, type)
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.options), playerinfo["audioUrl"], 128)