From 7b2fd0f5b2e58c2b9beab1531d19f3e7dd0ab03a Mon Sep 17 00:00:00 2001 From: Alex Seiler Date: Tue, 17 Jan 2017 18:15:20 +0100 Subject: [PATCH] [twentymin] Removed default values in regular expression search and avoided code duplication for video formats. --- youtube_dl/extractor/twentymin.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/youtube_dl/extractor/twentymin.py b/youtube_dl/extractor/twentymin.py index d7fc4c4b5..68d5a0cb5 100644 --- a/youtube_dl/extractor/twentymin.py +++ b/youtube_dl/extractor/twentymin.py @@ -91,28 +91,29 @@ class TwentyMinutenIE(InfoExtractor): if not video_id: params = self._html_search_regex( r']+src="(?:https?:)?//www\.20min\.ch/videoplayer/videoplayer\.html\?params=(.+?[^"])"', - webpage, '20min embed URL', default='') + webpage, '20min embed URL') video_id = self._search_regex( r'.*videoId@(\d+)', - params, 'Video Id', default='') + params, 'Video Id') description = self._html_search_meta( 'description', webpage, 'description') thumbnail = self._og_search_thumbnail(webpage) + formats = [] + format_preferences = [('sd', ''), ('hd', 'h')] + for format_id, url_extension in format_preferences: + format_url = 'http://podcast.20min-tv.ch/podcast/20min/%s%s.mp4' % (video_id, url_extension) + formats.append({ + 'format_id': format_id, + 'url': format_url, + }) + return { 'id': video_id, 'display_id': display_id, 'title': title, 'description': description, 'thumbnail': thumbnail, - 'formats': [{ - 'format_id': 'sd', - 'url': 'http://podcast.20min-tv.ch/podcast/20min/%s.mp4' % video_id, - 'preference': -2 - }, { - 'format_id': 'hd', - 'url': 'http://podcast.20min-tv.ch/podcast/20min/%sh.mp4' % video_id, - 'preference': -1 - }] + 'formats': formats, }