From 5a9cc19972fb3aae7a67470f65ec5cd30918f4e1 Mon Sep 17 00:00:00 2001 From: George Brighton Date: Sat, 27 Jun 2015 23:03:06 +0100 Subject: [PATCH] [moviefap] Move flv videos to formats in the metadata --- youtube_dl/extractor/moviefap.py | 56 +++++++++++++++++--------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/youtube_dl/extractor/moviefap.py b/youtube_dl/extractor/moviefap.py index 9de052a99..5e0c701d4 100644 --- a/youtube_dl/extractor/moviefap.py +++ b/youtube_dl/extractor/moviefap.py @@ -82,8 +82,36 @@ def _real_extract(self, url): r'flashvars\.config = escape\("(.+?)"', webpage, 'player parameters') xml = self._download_xml(info_url, video_id) - info = { + # find the video container + if xml.find('videoConfig') is not None: + ext = xml.find('videoConfig').find('type').text + else: + ext = 'flv' # guess... + + # work out the video URL(s) + formats = [] + if xml.find('videoLink') is not None: + # single format available + formats.append({ + 'url': xpath_text(xml, 'videoLink', 'url', True), + 'ext': ext + }) + else: + # multiple formats available + for item in xml.find('quality').findall('item'): + resolution = xpath_text(item, 'res', 'resolution', True) # 480p etc. + formats.append({ + 'url': xpath_text(item, 'videoLink', 'url', True), + 'ext': ext, + 'resolution': resolution, + 'height': int(re.findall(r'\d+', resolution)[0]) + }) + + self._sort_formats(formats) + + return { 'id': video_id, + 'formats': formats, 'title': self._html_search_regex( \ r'

(.*?)

', webpage, 'title'), 'display_id': re.compile(self._VALID_URL).match(url).group('name'), @@ -105,29 +133,3 @@ def _real_extract(self, url): 'categories': self._html_search_regex( \ r'
\s*(.*?)\s*
', webpage, 'categories', fatal=False).split(', ') } - - # find and add the format - if xml.find('videoConfig') is not None: - info['ext'] = xml.find('videoConfig').find('type').text - else: - info['ext'] = 'flv' # guess... - - # work out the video URL(s) - if xml.find('videoLink') is not None: - # single format available - info['url'] = xpath_text(xml, 'videoLink', 'url', True) - else: - # multiple formats available - info['formats'] = [] - - for item in xml.find('quality').findall('item'): - resolution = xpath_text(item, 'res', 'resolution', True) # 480p etc. - info['formats'].append({ - 'url': xpath_text(item, 'videoLink', 'url', True), - 'resolution': resolution, - 'height': int(re.findall(r'\d+', resolution)[0]) - }) - - self._sort_formats(info['formats']) - - return info