3 from .common
import InfoExtractor
4 from ..networking
.exceptions
import HTTPError
9 get_element_html_by_class
,
10 get_element_text_and_html_by_tag
,
11 get_elements_html_by_class
,
19 from ..utils
.traversal
import traverse_obj
22 class RadioComercialIE(InfoExtractor
):
23 _VALID_URL
= r
'https?://(?:www\.)?radiocomercial\.pt/podcasts/[^/?#]+/t?(?P<season>\d+)/(?P<id>[\w-]+)'
25 'url': 'https://radiocomercial.pt/podcasts/o-homem-que-mordeu-o-cao/t6/taylor-swift-entranhando-se-que-nem-uma-espada-no-ventre-dos-fas#page-content-wrapper',
26 'md5': '5f4fe8e485b29d2e8fd495605bc2c7e4',
28 'id': 'taylor-swift-entranhando-se-que-nem-uma-espada-no-ventre-dos-fas',
30 'title': 'Taylor Swift entranhando-se que nem uma espada no ventre dos fãs.',
31 'release_date': '20231025',
32 'thumbnail': r
're:https://radiocomercial.pt/upload/[^.]+.jpg',
36 'url': 'https://radiocomercial.pt/podcasts/convenca-me-num-minuto/t3/convenca-me-num-minuto-que-os-lobisomens-existem',
37 'md5': '47e96c273aef96a8eb160cd6cf46d782',
39 'id': 'convenca-me-num-minuto-que-os-lobisomens-existem',
41 'title': 'Convença-me num minuto que os lobisomens existem',
42 'release_date': '20231026',
43 'thumbnail': r
're:https://radiocomercial.pt/upload/[^.]+.jpg',
47 'url': 'https://radiocomercial.pt/podcasts/inacreditavel-by-ines-castel-branco/t2/o-desastre-de-aviao',
48 'md5': '69be64255420fec23b7259955d771e54',
50 'id': 'o-desastre-de-aviao',
52 'title': 'O desastre de avião',
53 'description': 'md5:8a82beeb372641614772baab7246245f',
54 'release_date': '20231101',
55 'thumbnail': r
're:https://radiocomercial.pt/upload/[^.]+.jpg',
60 'skip_download': True,
63 'url': 'https://radiocomercial.pt/podcasts/tnt-todos-no-top/2023/t-n-t-29-de-outubro',
64 'md5': '91d32d4d4b1407272068b102730fc9fa',
66 'id': 't-n-t-29-de-outubro',
68 'title': 'T.N.T 29 de outubro',
69 'release_date': '20231029',
70 'thumbnail': r
're:https://radiocomercial.pt/upload/[^.]+.jpg',
75 def _real_extract(self
, url
):
76 video_id
, season
= self
._match
_valid
_url
(url
).group('id', 'season')
77 webpage
= self
._download
_webpage
(url
, video_id
)
80 'title': self
._html
_extract
_title
(webpage
),
81 'description': self
._og
_search
_description
(webpage
, default
=None),
82 'release_date': unified_strdate(get_element_by_class(
83 'date', get_element_html_by_class('descriptions', webpage
) or '')),
84 'thumbnail': self
._og
_search
_thumbnail
(webpage
),
85 'season': int_or_none(season
),
86 'url': extract_attributes(get_element_html_by_class('audiofile', webpage
) or '').get('href'),
90 class RadioComercialPlaylistIE(InfoExtractor
):
91 _VALID_URL
= r
'https?://(?:www\.)?radiocomercial\.pt/podcasts/(?P<id>[\w-]+)(?:/t?(?P<season>\d+))?/?(?:$|[?#])'
93 'url': 'https://radiocomercial.pt/podcasts/convenca-me-num-minuto/t3',
95 'id': 'convenca-me-num-minuto_t3',
96 'title': 'Convença-me num Minuto - Temporada 3',
98 'playlist_mincount': 32
100 'url': 'https://radiocomercial.pt/podcasts/o-homem-que-mordeu-o-cao',
102 'id': 'o-homem-que-mordeu-o-cao',
103 'title': 'O Homem Que Mordeu o Cão',
105 'playlist_mincount': 19
107 'url': 'https://radiocomercial.pt/podcasts/as-minhas-coisas-favoritas',
109 'id': 'as-minhas-coisas-favoritas',
110 'title': 'As Minhas Coisas Favoritas',
112 'playlist_mincount': 131
114 'url': 'https://radiocomercial.pt/podcasts/tnt-todos-no-top/t2023',
116 'id': 'tnt-todos-no-top_t2023',
117 'title': 'TNT - Todos No Top - Temporada 2023',
119 'playlist_mincount': 39
122 def _entries(self
, url
, playlist_id
):
123 for page
in itertools
.count(1):
125 webpage
= self
._download
_webpage
(
126 f
'{url}/{page}', playlist_id
, f
'Downloading page {page}')
127 except ExtractorError
as e
:
128 if isinstance(e
.cause
, HTTPError
) and e
.cause
.status
== 404:
132 episodes
= get_elements_html_by_class('tm-ouvir-podcast', webpage
)
135 for url_path
in traverse_obj(episodes
, (..., {extract_attributes}
, 'href')):
136 episode_url
= urljoin(url
, url_path
)
137 if RadioComercialIE
.suitable(episode_url
):
140 def _real_extract(self
, url
):
141 podcast
, season
= self
._match
_valid
_url
(url
).group('id', 'season')
142 playlist_id
= join_nonempty(podcast
, season
, delim
='_t')
143 url
= update_url(url
, query
=None, fragment
=None)
144 webpage
= self
._download
_webpage
(url
, playlist_id
)
146 name
= try_call(lambda: get_element_text_and_html_by_tag('h1', webpage
)[0])
147 title
= name
if name
== season
else join_nonempty(name
, season
, delim
=' - Temporada ')
149 return self
.playlist_from_matches(
150 self
._entries
(url
, playlist_id
), playlist_id
, title
, ie
=RadioComercialIE
)