2 from __future__
import unicode_literals
6 from .srgssr
import SRGSSRIE
9 compat_urllib_parse_urlparse
,
20 class RTSIE(SRGSSRIE
):
22 _VALID_URL
= r
'rts:(?P<rts_id>\d+)|https?://(?:www\.)?rts\.ch/(?:[^/]+/){2,}(?P<id>[0-9]+)-(?P<display_id>.+?)\.html'
26 'url': 'http://www.rts.ch/archives/tv/divers/3449373-les-enfants-terribles.html',
27 'md5': 'f254c4b26fb1d3c183793d52bc40d3e7',
30 'display_id': 'les-enfants-terribles',
33 'title': 'Les Enfants Terribles',
34 'description': 'France Pommier et sa soeur Luce Feral, les deux filles de ce groupe de 5.',
36 'upload_date': '19680921',
37 'timestamp': -40280400,
38 'thumbnail': 're:^https?://.*\.image',
43 'url': 'http://www.rts.ch/emissions/passe-moi-les-jumelles/5624067-entre-ciel-et-mer.html',
44 'md5': 'f1077ac5af686c76528dc8d7c5df29ba',
47 'display_id': '5742494',
50 'title': 'Les yeux dans les cieux - Mon homard au Canada',
51 'description': 'md5:d22ee46f5cc5bac0912e5a0c6d44a9f7',
52 'uploader': 'Passe-moi les jumelles',
53 'upload_date': '20140404',
54 'timestamp': 1396635300,
55 'thumbnail': 're:^https?://.*\.image',
60 'url': 'http://www.rts.ch/video/sport/hockey/5745975-1-2-kloten-fribourg-5-2-second-but-pour-gotteron-par-kwiatowski.html',
61 'md5': 'b4326fecd3eb64a458ba73c73e91299d',
64 'display_id': '1-2-kloten-fribourg-5-2-second-but-pour-gotteron-par-kwiatowski',
67 'title': '1/2, Kloten - Fribourg (5-2): second but pour Gottéron par Kwiatowski',
68 'description': 'Hockey - Playoff',
70 'upload_date': '20140403',
71 'timestamp': 1396556882,
72 'thumbnail': 're:^https?://.*\.image',
75 'skip': 'Blocked outside Switzerland',
78 'url': 'http://www.rts.ch/video/info/journal-continu/5745356-londres-cachee-par-un-epais-smog.html',
79 'md5': '9f713382f15322181bb366cc8c3a4ff0',
82 'display_id': 'londres-cachee-par-un-epais-smog',
85 'title': 'Londres cachée par un épais smog',
86 'description': 'Un important voile de smog recouvre Londres depuis mercredi, provoqué par la pollution et du sable du Sahara.',
87 'uploader': 'Le Journal en continu',
88 'upload_date': '20140403',
89 'timestamp': 1396537322,
90 'thumbnail': 're:^https?://.*\.image',
95 'url': 'http://www.rts.ch/audio/couleur3/programmes/la-belle-video-de-stephane-laurenceau/5706148-urban-hippie-de-damien-krisl-03-04-2014.html',
96 'md5': 'dd8ef6a22dff163d063e2a52bc8adcae',
99 'display_id': 'urban-hippie-de-damien-krisl-03-04-2014',
102 'title': '"Urban Hippie", de Damien Krisl',
103 'description': 'Des Hippies super glam.',
104 'upload_date': '20140403',
105 'timestamp': 1396551600,
109 # article with videos on rhs
110 'url': 'http://www.rts.ch/sport/hockey/6693917-hockey-davos-decroche-son-31e-titre-de-champion-de-suisse.html',
113 'title': 'Hockey: Davos décroche son 31e titre de champion de Suisse',
115 'playlist_mincount': 5,
119 def _real_extract(self
, url
):
120 m
= re
.match(self
._VALID
_URL
, url
)
121 media_id
= m
.group('rts_id') or m
.group('id')
122 display_id
= m
.group('display_id') or media_id
124 def download_json(internal_id
):
125 return self
._download
_json
(
126 'http://www.rts.ch/a/%s.html?f=json/article' % internal_id
,
129 all_info
= download_json(media_id
)
131 # media_id extracted out of URL is not always a real id
132 if 'video' not in all_info
and 'audio' not in all_info
:
133 page
= self
._download
_webpage
(url
, display_id
)
135 # article with videos on rhs
137 r
'<article[^>]+class="content-item"[^>]*>\s*<a[^>]+data-video-urn="urn:([^"]+)"',
141 r
'(?s)<iframe[^>]+class="srg-player"[^>]+src="[^"]+urn:([^"]+)"',
144 entries
= [self
.url_result('srgssr:%s' % video_urn
, 'SRGSSR') for video_urn
in videos
]
145 return self
.playlist_result(entries
, media_id
, self
._og
_search
_title
(page
))
147 internal_id
= self
._html
_search
_regex
(
148 r
'<(?:video|audio) data-id="([0-9]+)"', page
,
150 all_info
= download_json(internal_id
)
152 media_type
= 'video' if 'video' in all_info
else 'audio'
155 self
.get_media_data('rts', media_type
, media_id
)
157 info
= all_info
['video']['JSONinfo'] if 'video' in all_info
else all_info
['audio']
159 upload_timestamp
= parse_iso8601(info
.get('broadcast_date'))
160 duration
= info
.get('duration') or info
.get('cutout') or info
.get('cutduration')
161 if isinstance(duration
, compat_str
):
162 duration
= parse_duration(duration
)
163 view_count
= info
.get('plays')
164 thumbnail
= unescapeHTML(info
.get('preview_image_url'))
166 def extract_bitrate(url
):
167 return int_or_none(self
._search
_regex
(
168 r
'-([0-9]+)k\.', url
, 'bitrate', default
=None))
171 for format_id
, format_url
in info
['streams'].items():
172 if format_id
== 'hds_sd' and 'hds' in info
['streams']:
174 if format_id
== 'hls_sd' and 'hls' in info
['streams']:
176 if format_url
.endswith('.f4m'):
177 token
= self
._download
_xml
(
178 'http://tp.srgssr.ch/token/akahd.xml?stream=%s/*' % compat_urllib_parse_urlparse(format_url
).path
,
179 media_id
, 'Downloading %s token' % format_id
)
180 auth_params
= xpath_text(token
, './/authparams', 'auth params')
183 f4m_formats
= self
._extract
_f
4m
_formats
(
184 '%s?%s&hdcore=3.4.0&plugin=aasp-3.4.0.132.66' % (format_url
, auth_params
),
185 media_id
, f4m_id
=format_id
, fatal
=False)
187 formats
.extend(f4m_formats
)
188 elif format_url
.endswith('.m3u8'):
189 m3u8_formats
= self
._extract
_m
3u8_formats
(
190 format_url
, media_id
, 'mp4', m3u8_id
=format_id
, fatal
=False)
192 formats
.extend(m3u8_formats
)
195 'format_id': format_id
,
197 'tbr': extract_bitrate(format_url
),
202 'format_id': '%s-%sk' % (media
['ext'], media
['rate']),
203 'url': 'http://download-video.rts.ch/%s' % media
['url'],
204 'tbr': media
['rate'] or extract_bitrate(media
['url']),
205 } for media
in info
['media'] if media
.get('rate')])
207 self
._check
_formats
(formats
, media_id
)
208 self
._sort
_formats
(formats
)
212 'display_id': display_id
,
214 'title': info
['title'],
215 'description': info
.get('intro'),
216 'duration': duration
,
217 'view_count': view_count
,
218 'uploader': info
.get('programName'),
219 'timestamp': upload_timestamp
,
220 'thumbnail': thumbnail
,