1 from .common
import InfoExtractor
6 get_element_html_by_class
,
14 class SverigesRadioBaseIE(InfoExtractor
):
15 _BASE_URL
= 'https://sverigesradio.se/sida/playerajax/'
16 _QUALITIES
= ['low', 'medium', 'high']
21 _CODING_FORMAT_TO_ABR_MAP
= {
28 def _real_extract(self
, url
):
29 audio_id
, display_id
= self
._match
_valid
_url
(url
).group('id', 'slug')
31 webpage
= self
._download
_webpage
(url
, display_id
)
34 get_element_html_by_class('audio-button', webpage
),
35 ({extract_attributes}
, ('data-audio-id', 'data-publication-id')), get_all
=False)
36 or self
._parse
_json
(get_element_by_id('gtm-metadata', webpage
), display_id
)['pageId'])
40 'type': self
._AUDIO
_TYPE
,
43 item
= self
._download
_json
(
44 self
._BASE
_URL
+ 'audiometadata', audio_id
,
45 'Downloading audio JSON metadata', query
=query
)['items'][0]
47 query
['format'] = 'iis'
50 for quality
in self
._QUALITIES
:
51 query
['quality'] = quality
52 audio_url_data
= self
._download
_json
(
53 self
._BASE
_URL
+ 'getaudiourl', audio_id
,
54 f
'Downloading {quality} format JSON metadata',
55 fatal
=False, query
=query
) or {}
56 audio_url
= audio_url_data
.get('audioUrl')
57 if not audio_url
or audio_url
in urls
:
59 urls
.append(audio_url
)
60 ext
= determine_ext(audio_url
)
61 coding_format
= audio_url_data
.get('codingFormat')
62 abr
= int_or_none(self
._search
_regex
(
63 r
'_a(\d+)\.m4a', audio_url
, 'audio bitrate',
64 default
=None)) or self
._CODING
_FORMAT
_TO
_ABR
_MAP
.get(coding_format
)
67 'acodec': self
._EXT
_TO
_CODEC
_MAP
.get(ext
),
69 'format_id': str_or_none(coding_format
),
77 **traverse_obj(item
, {
80 'duration': ('duration', {int_or_none}
),
81 'thumbnail': ('displayimageurl', {url_or_none}
),
82 'description': 'description',
87 class SverigesRadioPublicationIE(SverigesRadioBaseIE
):
88 IE_NAME
= 'sverigesradio:publication'
89 _VALID_URL
= r
'https?://(?:www\.)?sverigesradio\.se/(?:sida/)?(?:artikel|gruppsida)(?:\.aspx\?.*?\bartikel=(?P<id>[0-9]+)|/(?P<slug>[\w-]+))'
91 'url': 'https://sverigesradio.se/sida/artikel.aspx?programid=83&artikel=7038546',
92 'md5': '6a4917e1923fccb080e5a206a5afa542',
97 'series': 'Nyheter (Ekot)',
98 'title': 'Esa Teittinen: Sanningen har inte kommit fram',
99 'description': 'md5:daf7ce66a8f0a53d5465a5984d3839df',
100 'thumbnail': r
're:^https?://.*\.jpg',
103 'url': 'https://sverigesradio.se/artikel/tysk-fotbollsfeber-bayern-munchens-10-ariga-segersvit-kan-brytas',
104 'md5': 'f8a914ad50f491bb74eed403ab4bfef6',
108 'title': 'Tysk fotbollsfeber när Bayern Münchens 10-åriga segersvit kan brytas',
109 'series': 'Radiosporten',
110 'description': 'md5:5254610e20ce527ecb3a6102a06dcc5f',
112 'thumbnail': r
're:^https?://.*\.jpg',
115 'url': 'https://sverigesradio.se/sida/gruppsida.aspx?programid=3304&grupp=6247&artikel=7146887',
116 'only_matching': True,
118 _AUDIO_TYPE
= 'publication'
121 class SverigesRadioEpisodeIE(SverigesRadioBaseIE
):
122 IE_NAME
= 'sverigesradio:episode'
123 _VALID_URL
= r
'https?://(?:www\.)?sverigesradio\.se/(?:sida/)?avsnitt/(?:(?P<id>\d+)|(?P<slug>[\w-]+))(?:$|[#?])'
125 'url': 'https://sverigesradio.se/avsnitt/1140922?programid=1300',
126 'md5': '20dc4d8db24228f846be390b0c59a07c',
131 'series': 'Konflikt',
132 'title': 'Metoo och valen',
133 'description': 'md5:fcb5c1f667f00badcc702b196f10a27e',
134 'thumbnail': r
're:^https?://.*\.jpg',
137 'url': 'https://sverigesradio.se/avsnitt/p4-live-med-first-aid-kit-scandinavium-mars-2023',
138 'md5': 'ce17fb82520a8033dbb846993d5589fe',
142 'title': 'P4 Live med First Aid Kit',
143 'description': 'md5:6d5b78eed3d2b65f6de04daa45e9285d',
144 'thumbnail': r
're:^https?://.*\.jpg',
149 _AUDIO_TYPE
= 'episode'