]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/rts.py
3 from .srgssr
import SRGSSRIE
4 from ..compat
import compat_str
15 class RTSIE(SRGSSRIE
): # XXX: Do not subclass from concrete IE
18 _VALID_URL
= r
'rts:(?P<rts_id>\d+)|https?://(?:.+?\.)?rts\.ch/(?:[^/]+/){2,}(?P<id>[0-9]+)-(?P<display_id>.+?)\.html'
22 'url': 'http://www.rts.ch/archives/tv/divers/3449373-les-enfants-terribles.html',
23 'md5': '753b877968ad8afaeddccc374d4256a5',
26 'display_id': 'les-enfants-terribles',
29 'title': 'Les Enfants Terribles',
30 'description': 'France Pommier et sa soeur Luce Feral, les deux filles de ce groupe de 5.',
32 'upload_date': '19680921',
33 'timestamp': -40280400,
34 'thumbnail': r
're:^https?://.*\.image',
37 'expected_warnings': ['Unable to download f4m manifest', 'Failed to download m3u8 information'],
40 'url': 'http://www.rts.ch/emissions/passe-moi-les-jumelles/5624067-entre-ciel-et-mer.html',
43 'title': 'Passe-moi les jumelles',
45 'playlist_mincount': 4,
48 'url': 'http://www.rts.ch/video/sport/hockey/5745975-1-2-kloten-fribourg-5-2-second-but-pour-gotteron-par-kwiatowski.html',
51 'display_id': '1-2-kloten-fribourg-5-2-second-but-pour-gotteron-par-kwiatowski',
54 'title': '1/2, Kloten - Fribourg (5-2): second but pour Gottéron par Kwiatowski',
55 'description': 'Hockey - Playoff',
57 'upload_date': '20140403',
58 'timestamp': 1396556882,
59 'thumbnail': r
're:^https?://.*\.image',
64 'skip_download': True,
66 'expected_warnings': ['Unable to download f4m manifest', 'Failed to download m3u8 information'],
67 'skip': 'Blocked outside Switzerland',
70 'url': 'http://www.rts.ch/video/info/journal-continu/5745356-londres-cachee-par-un-epais-smog.html',
71 'md5': '9bb06503773c07ce83d3cbd793cebb91',
74 'display_id': 'londres-cachee-par-un-epais-smog',
77 'title': 'Londres cachée par un épais smog',
78 'description': 'Un important voile de smog recouvre Londres depuis mercredi, provoqué par la pollution et du sable du Sahara.',
79 'uploader': 'L\'actu en vidéo',
80 'upload_date': '20140403',
81 'timestamp': 1396537322,
82 'thumbnail': r
're:^https?://.*\.image',
85 'expected_warnings': ['Unable to download f4m manifest', 'Failed to download m3u8 information'],
88 'url': 'http://www.rts.ch/audio/couleur3/programmes/la-belle-video-de-stephane-laurenceau/5706148-urban-hippie-de-damien-krisl-03-04-2014.html',
89 'md5': 'dd8ef6a22dff163d063e2a52bc8adcae',
92 'display_id': 'urban-hippie-de-damien-krisl-03-04-2014',
95 'title': '"Urban Hippie", de Damien Krisl',
96 'description': 'Des Hippies super glam.',
97 'upload_date': '20140403',
98 'timestamp': 1396551600,
102 # article with videos on rhs
103 'url': 'http://www.rts.ch/sport/hockey/6693917-hockey-davos-decroche-son-31e-titre-de-champion-de-suisse.html',
106 'title': 'Hockey: Davos décroche son 31e titre de champion de Suisse',
108 'playlist_mincount': 5,
111 'url': 'http://pages.rts.ch/emissions/passe-moi-les-jumelles/5624065-entre-ciel-et-mer.html',
112 'only_matching': True,
116 def _real_extract(self
, url
):
117 m
= self
._match
_valid
_url
(url
)
118 media_id
= m
.group('rts_id') or m
.group('id')
119 display_id
= m
.group('display_id') or media_id
121 def download_json(internal_id
):
122 return self
._download
_json
(
123 'http://www.rts.ch/a/%s.html?f=json/article' % internal_id
,
126 all_info
= download_json(media_id
)
128 # media_id extracted out of URL is not always a real id
129 if 'video' not in all_info
and 'audio' not in all_info
:
132 for item
in all_info
.get('items', []):
133 item_url
= item
.get('url')
136 entries
.append(self
.url_result(item_url
, 'RTS'))
139 page
, urlh
= self
._download
_webpage
_handle
(url
, display_id
)
140 if re
.match(self
._VALID
_URL
, urlh
.url
).group('id') != media_id
:
141 return self
.url_result(urlh
.url
, 'RTS')
143 # article with videos on rhs
145 r
'<article[^>]+class="content-item"[^>]*>\s*<a[^>]+data-video-urn="urn:([^"]+)"',
149 r
'(?s)<iframe[^>]+class="srg-player"[^>]+src="[^"]+urn:([^"]+)"',
152 entries
= [self
.url_result('srgssr:%s' % video_urn
, 'SRGSSR') for video_urn
in videos
]
155 return self
.playlist_result(entries
, media_id
, all_info
.get('title'))
157 internal_id
= self
._html
_search
_regex
(
158 r
'<(?:video|audio) data-id="([0-9]+)"', page
,
160 all_info
= download_json(internal_id
)
162 media_type
= 'video' if 'video' in all_info
else 'audio'
165 self
._get
_media
_data
('rts', media_type
, media_id
)
167 info
= all_info
['video']['JSONinfo'] if 'video' in all_info
else all_info
['audio']
169 title
= info
['title']
171 def extract_bitrate(url
):
172 return int_or_none(self
._search
_regex
(
173 r
'-([0-9]+)k\.', url
, 'bitrate', default
=None))
176 streams
= info
.get('streams', {})
177 for format_id
, format_url
in streams
.items():
178 if format_id
== 'hds_sd' and 'hds' in streams
:
180 if format_id
== 'hls_sd' and 'hls' in streams
:
182 ext
= determine_ext(format_url
)
183 if ext
in ('m3u8', 'f4m'):
184 format_url
= self
._get
_tokenized
_src
(format_url
, media_id
, format_id
)
186 formats
.extend(self
._extract
_f
4m
_formats
(
187 format_url
+ ('?' if '?' not in format_url
else '&') + 'hdcore=3.4.0',
188 media_id
, f4m_id
=format_id
, fatal
=False))
190 formats
.extend(self
._extract
_m
3u8_formats
(
191 format_url
, media_id
, 'mp4', 'm3u8_native', m3u8_id
=format_id
, fatal
=False))
194 'format_id': format_id
,
196 'tbr': extract_bitrate(format_url
),
199 download_base
= 'http://rtsww%s-d.rts.ch/' % ('-a' if media_type
== 'audio' else '')
200 for media
in info
.get('media', []):
201 media_url
= media
.get('url')
202 if not media_url
or re
.match(r
'https?://', media_url
):
204 rate
= media
.get('rate')
205 ext
= media
.get('ext') or determine_ext(media_url
, 'mp4')
208 format_id
+= '-%dk' % rate
210 'format_id': format_id
,
211 'url': urljoin(download_base
, media_url
),
212 'tbr': rate
or extract_bitrate(media_url
),
215 self
._check
_formats
(formats
, media_id
)
217 duration
= info
.get('duration') or info
.get('cutout') or info
.get('cutduration')
218 if isinstance(duration
, compat_str
):
219 duration
= parse_duration(duration
)
223 'display_id': display_id
,
226 'description': info
.get('intro'),
227 'duration': duration
,
228 'view_count': int_or_none(info
.get('plays')),
229 'uploader': info
.get('programName'),
230 'timestamp': parse_iso8601(info
.get('broadcast_date')),
231 'thumbnail': unescapeHTML(info
.get('preview_image_url')),