From e09f58b3bc3af6ce1e541fb7d034fe869fba6e82 Mon Sep 17 00:00:00 2001 From: remitamine Date: Wed, 14 Oct 2015 10:40:54 +0100 Subject: [PATCH] [srgssr] change the url chortcut, fix image extraction ,add a test and extract format id --- youtube_dl/extractor/srgssr.py | 35 ++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/youtube_dl/extractor/srgssr.py b/youtube_dl/extractor/srgssr.py index 3b5dcc503..f759e5600 100644 --- a/youtube_dl/extractor/srgssr.py +++ b/youtube_dl/extractor/srgssr.py @@ -12,7 +12,7 @@ class SRGSSRIE(InfoExtractor): - _VALID_URL = r'(?:https?://tp\.srgssr\.ch/p(?:/[^/]+)+\?urn=)?urn:(?Psrf|rts|rsi|rtr|swi):(?:[^:]+:)?(?Pvideo|audio):(?P[0-9a-f\-]{36}|\d+)' + _VALID_URL = r'(?:https?://tp\.srgssr\.ch/p(?:/[^/]+)+\?urn=urn|srgssr):(?Psrf|rts|rsi|rtr|swi):(?:[^:]+:)?(?Pvideo|audio):(?P[0-9a-f\-]{36}|\d+)' _ERRORS = { 'AGERATING12': 'To protect children under the age of 12, this video is only available between 8 p.m. and 6 a.m.', @@ -44,11 +44,12 @@ def _real_extract(self, url): timestamp = parse_iso8601(created_date) thumbnails = [] - for image in media_data['Image']['ImageRepresentations']['ImageRepresentation']: - thumbnails.append({ - 'id': image.get('id'), - 'url': image['url'], - }) + if 'Image' in media_data: + for image in media_data['Image']['ImageRepresentations']['ImageRepresentation']: + thumbnails.append({ + 'id': image.get('id'), + 'url': image['url'], + }) preference = qualities(['LQ', 'MQ', 'SD', 'HQ', 'HD']) formats = [] @@ -70,16 +71,17 @@ def _real_extract(self, url): if asset_url.startswith('rtmp'): ext = self._search_regex(r'([a-z0-9]+):[^/]+', asset_url, 'ext') formats.append({ + 'format_id': asset['@quality'], 'url': asset_url, 'preference': preference(asset['@quality']), 'ext': ext, }) - downloads = media_data.get('Downloads') - if downloads: - for source in downloads['Download']: + if 'Downloads' in media_data: + for source in media_data['Downloads']['Download']: for asset in source['url']: formats.append({ + 'format_id': asset['@quality'], 'url': asset['text'], 'preference': preference(asset['@quality']) }) @@ -120,8 +122,21 @@ class SRGSSRPlayIE(InfoExtractor): 'description': 'md5:88604432b60d5a38787f152dec89cd56', 'timestamp': 1373493600, }, + },{ + 'url': 'http://www.rtr.ch/play/radio/actualitad/audio/saira-tujetsch-tuttina-cuntinuar-cun-sedrun-muster-turissem?id=63cb0778-27f8-49af-9284-8c7a8c6d15fc', + 'info_dict': { + 'id': '63cb0778-27f8-49af-9284-8c7a8c6d15fc', + 'ext': 'mp3', + 'upload_date': '20151013', + 'title': 'Saira: Tujetsch - tuttina cuntinuar cun Sedrun Mustér Turissem', + 'timestamp': 1444750398, + }, + 'params': { + # rtmp download + 'skip_download': True, + }, }] def _real_extract(self, url): bu, media_type, media_id = re.match(self._VALID_URL, url).groups() - return self.url_result('urn:%s:%s:%s' % (bu[:3], media_type, media_id), 'SRGSSR') + return self.url_result('srgssr:%s:%s:%s' % (bu[:3], media_type, media_id), 'SRGSSR')