2 from __future__
import unicode_literals
4 from .common
import InfoExtractor
12 class SverigesRadioBaseIE(InfoExtractor
):
13 _BASE_URL
= 'https://sverigesradio.se/sida/playerajax/'
14 _QUALITIES
= ['low', 'medium', 'high']
19 _CODING_FORMAT_TO_ABR_MAP
= {
26 def _real_extract(self
, url
):
27 audio_id
= self
._match
_id
(url
)
30 'type': self
._AUDIO
_TYPE
,
33 item
= self
._download
_json
(
34 self
._BASE
_URL
+ 'audiometadata', audio_id
,
35 'Downloading audio JSON metadata', query
=query
)['items'][0]
36 title
= item
['subtitle']
38 query
['format'] = 'iis'
41 for quality
in self
._QUALITIES
:
42 query
['quality'] = quality
43 audio_url_data
= self
._download
_json
(
44 self
._BASE
_URL
+ 'getaudiourl', audio_id
,
45 'Downloading %s format JSON metadata' % quality
,
46 fatal
=False, query
=query
) or {}
47 audio_url
= audio_url_data
.get('audioUrl')
48 if not audio_url
or audio_url
in urls
:
50 urls
.append(audio_url
)
51 ext
= determine_ext(audio_url
)
52 coding_format
= audio_url_data
.get('codingFormat')
53 abr
= int_or_none(self
._search
_regex
(
54 r
'_a(\d+)\.m4a', audio_url
, 'audio bitrate',
55 default
=None)) or self
._CODING
_FORMAT
_TO
_ABR
_MAP
.get(coding_format
)
58 'acodec': self
._EXT
_TO
_CODEC
_MAP
.get(ext
),
60 'format_id': str_or_none(coding_format
),
64 self
._sort
_formats
(formats
)
70 'series': item
.get('title'),
71 'duration': int_or_none(item
.get('duration')),
72 'thumbnail': item
.get('displayimageurl'),
73 'description': item
.get('description'),
77 class SverigesRadioPublicationIE(SverigesRadioBaseIE
):
78 IE_NAME
= 'sverigesradio:publication'
79 _VALID_URL
= r
'https?://(?:www\.)?sverigesradio\.se/sida/(?:artikel|gruppsida)\.aspx\?.*?\bartikel=(?P<id>[0-9]+)'
81 'url': 'https://sverigesradio.se/sida/artikel.aspx?programid=83&artikel=7038546',
82 'md5': '6a4917e1923fccb080e5a206a5afa542',
87 'series': 'Nyheter (Ekot)',
88 'title': 'Esa Teittinen: Sanningen har inte kommit fram',
89 'description': 'md5:daf7ce66a8f0a53d5465a5984d3839df',
90 'thumbnail': r
're:^https?://.*\.jpg',
93 'url': 'https://sverigesradio.se/sida/gruppsida.aspx?programid=3304&grupp=6247&artikel=7146887',
94 'only_matching': True,
96 _AUDIO_TYPE
= 'publication'
99 class SverigesRadioEpisodeIE(SverigesRadioBaseIE
):
100 IE_NAME
= 'sverigesradio:episode'
101 _VALID_URL
= r
'https?://(?:www\.)?sverigesradio\.se/(?:sida/)?avsnitt/(?P<id>[0-9]+)'
103 'url': 'https://sverigesradio.se/avsnitt/1140922?programid=1300',
104 'md5': '20dc4d8db24228f846be390b0c59a07c',
109 'series': 'Konflikt',
110 'title': 'Metoo och valen',
111 'description': 'md5:fcb5c1f667f00badcc702b196f10a27e',
112 'thumbnail': r
're:^https?://.*\.jpg',
115 _AUDIO_TYPE
= 'episode'