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 -*-
|
2013-04-27 13:17:00 +02:00
|
|
|
|
2013-03-01 23:39:42 +01:00
|
|
|
from __future__ import absolute_import
|
2014-02-05 21:34:41 +01:00
|
|
|
import json
|
2013-02-12 19:43:37 +01:00
|
|
|
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
|
2013-02-12 19:43:37 +01:00
|
|
|
|
2014-02-05 21:34:41 +01:00
|
|
|
from svtplay_dl.service import Service, OpenGraphThumbMixin
|
2014-04-21 17:33:44 +02:00
|
|
|
from svtplay_dl.fetcher.http import HTTP
|
2015-09-06 14:19:10 +02:00
|
|
|
from svtplay_dl.error import ServiceError
|
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):
|
2014-01-01 14:57:17 +01: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
|
|
|
|
2016-05-14 22:54:30 +02:00
|
|
|
if self.exclude():
|
2015-09-06 23:04:48 +02:00
|
|
|
yield ServiceError("Excluding video")
|
2014-12-22 17:41:40 +01:00
|
|
|
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:
|
2017-06-26 00:09:00 +02:00
|
|
|
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)
|
2017-06-26 00:09:00 +02:00
|
|
|
type = "episode"
|
2016-10-17 23:58:23 +02:00
|
|
|
elif match2:
|
|
|
|
aid = match2.group(1)
|
2017-06-26 00:09:00 +02:00
|
|
|
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)
|