From 82ea1051b54134150f290d3d9f259a4baf54faf4 Mon Sep 17 00:00:00 2001 From: George Brighton Date: Sat, 27 Jun 2015 05:11:23 +0100 Subject: [PATCH 01/13] [moviefap] Add new extractor --- youtube_dl/extractor/__init__.py | 1 + youtube_dl/extractor/moviefap.py | 117 +++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 youtube_dl/extractor/moviefap.py diff --git a/youtube_dl/extractor/__init__.py b/youtube_dl/extractor/__init__.py index 7e74a971d8..b70c1b57ed 100644 --- a/youtube_dl/extractor/__init__.py +++ b/youtube_dl/extractor/__init__.py @@ -311,6 +311,7 @@ from .morningstar import MorningstarIE from .motherless import MotherlessIE from .motorsport import MotorsportIE from .movieclips import MovieClipsIE +from .moviefap import MovieFapIE from .moviezine import MoviezineIE from .movshare import MovShareIE from .mtv import ( diff --git a/youtube_dl/extractor/moviefap.py b/youtube_dl/extractor/moviefap.py new file mode 100644 index 0000000000..49b8ab7d9f --- /dev/null +++ b/youtube_dl/extractor/moviefap.py @@ -0,0 +1,117 @@ +from __future__ import unicode_literals + +import re + +from .common import InfoExtractor +from ..utils import str_to_int + + +class MovieFapIE(InfoExtractor): + _VALID_URL = r'https?://(?:www\.)?moviefap\.com/videos/(?P[0-9a-f]+)/(?P[a-z-_]+)' + _TESTS = [{ + 'url': 'http://www.moviefap.com/videos/e5da0d3edce5404418f5/jeune-couple-russe.html', + 'md5': 'fa56683e291fc80635907168a743c9ad', + 'info_dict': { + 'id': 'e5da0d3edce5404418f5', + 'ext': 'flv', + 'title': 'Jeune Couple Russe', + 'description': 'Amateur', + 'thumbnail': 'http://pic.moviefap.com/thumbs/e5/949-18l.jpg', + 'uploader_id': 'whiskeyjar', + 'display_id': 'jeune-couple-russe' + } + }, { + 'url': 'http://www.moviefap.com/videos/3080837f6712355015c2/busty-british-blonde-takes-backdoor-in-fake-taxi.html', + 'md5': 'bedef72cb23d27a20755fc430a6d7a0e', + 'info_dict': { + 'id': '3080837f6712355015c2', + 'ext': 'mp4', + 'title': 'Busty British blonde takes backdoor in fake taxi', + 'description': 'Big boobs British blonde flashing in fake taxi then giving titsjob and rimjob in the back seat before getting big cock up her tight ass', + 'thumbnail': 'http://img.moviefap.com/a16:9w990r/thumbs/30/322021-18l.jpg', + 'uploader_id': 'momcikoper', + 'display_id': 'busty-british-blonde-takes-backdoor-in-fake-taxi' + } + }] + + @staticmethod + def __get_thumbnail_data(xml): + + """ + Constructs a list of video thumbnails from timeline preview images. + :param xml: the information XML document to parse + """ + + timeline = xml.find('timeline') + if timeline is None: + # not all videos have the data - ah well + return [] + + # get the required information from the XML + attrs = {attr: str_to_int(timeline.find(attr).text) + for attr in ['imageWidth', 'imageHeight', 'imageFirst', 'imageLast']} + pattern = timeline.find('imagePattern').text + + # generate the list of thumbnail information dicts + thumbnails = [] + for i in range(attrs['imageFirst'], attrs['imageLast'] + 1): + thumbnails.append({ + 'url': pattern.replace('#', str(i)), + 'width': attrs['imageWidth'], + 'height': attrs['imageHeight'] + }) + return thumbnails + + def _real_extract(self, url): + + # find the video ID + video_id = self._match_id(url) + + # retrieve the page HTML + webpage = self._download_webpage(url, video_id) + + # find the URL of the XML document detailing video download URLs + info_url = self._html_search_regex(r'flashvars\.config = escape\("(.+?)"', webpage, 'player parameters') + + # download that XML + xml = self._download_xml(info_url, video_id) + + # create dictionary of properties we know so far, or can find easily + info = { + 'id': video_id, + 'title': self._html_search_regex(r'

(.*?)

', webpage, 'title'), + 'display_id': re.compile(self._VALID_URL).match(url).group('name'), + 'thumbnails': self.__get_thumbnail_data(xml), + 'thumbnail': xml.find('startThumb').text, + 'description': self._html_search_regex(r'name="description" value="(.*?)"', webpage, 'description'), + 'uploader_id': self._html_search_regex(r'name="username" value="(.*?)"', webpage, 'uploader_id'), + 'view_count': str_to_int(self._html_search_regex(r'
Views ([0-9]+)', webpage, 'view_count')), + 'average_rating': float(self._html_search_regex(r'Current Rating
(.*?)', webpage, 'average_rating')), + 'comment_count': str_to_int(self._html_search_regex(r'([0-9]+)', webpage, 'comment_count')), + 'age_limit': 18, + 'webpage_url': self._html_search_regex(r'name="link" value="(.*?)"', webpage, 'webpage_url'), + 'categories': self._html_search_regex(r'
\s*(.*?)\s*
', webpage, 'categories').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'] = xml.find('videoLink').text + else: + # multiple formats available + info['formats'] = [] + + # N.B. formats are already in ascending order of quality + for item in xml.find('quality').findall('item'): + info['formats'].append({ + 'url': item.find('videoLink').text, + 'resolution': item.find('res').text # 480p etc. + }) + + return info From 71f9e49e67bfe62c9f1a6d8f74b7d81ab820ba84 Mon Sep 17 00:00:00 2001 From: George Brighton Date: Sat, 27 Jun 2015 05:22:35 +0100 Subject: [PATCH 02/13] [moviefap] Fix dictionary comprehension syntax incompatible with Python 2.6 --- youtube_dl/extractor/moviefap.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/youtube_dl/extractor/moviefap.py b/youtube_dl/extractor/moviefap.py index 49b8ab7d9f..88f9dab6ff 100644 --- a/youtube_dl/extractor/moviefap.py +++ b/youtube_dl/extractor/moviefap.py @@ -48,17 +48,19 @@ class MovieFapIE(InfoExtractor): return [] # get the required information from the XML - attrs = {attr: str_to_int(timeline.find(attr).text) - for attr in ['imageWidth', 'imageHeight', 'imageFirst', 'imageLast']} + width = str_to_int(timeline.find('imageWidth').text) + height = str_to_int(timeline.find('imageHeight').text) + first = str_to_int(timeline.find('imageFirst').text) + last = str_to_int(timeline.find('imageLast').text) pattern = timeline.find('imagePattern').text # generate the list of thumbnail information dicts thumbnails = [] - for i in range(attrs['imageFirst'], attrs['imageLast'] + 1): + for i in range(first, last + 1): thumbnails.append({ 'url': pattern.replace('#', str(i)), - 'width': attrs['imageWidth'], - 'height': attrs['imageHeight'] + 'width': width, + 'height': height }) return thumbnails From 802d74aa6ba2613f95d19c3be6c2480b9a2ebe5b Mon Sep 17 00:00:00 2001 From: George Brighton Date: Sat, 27 Jun 2015 20:01:27 +0100 Subject: [PATCH 03/13] [moviefap] Swap test for an alternative non-copyrighted video --- youtube_dl/extractor/moviefap.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/youtube_dl/extractor/moviefap.py b/youtube_dl/extractor/moviefap.py index 88f9dab6ff..880ea22476 100644 --- a/youtube_dl/extractor/moviefap.py +++ b/youtube_dl/extractor/moviefap.py @@ -21,16 +21,16 @@ class MovieFapIE(InfoExtractor): 'display_id': 'jeune-couple-russe' } }, { - 'url': 'http://www.moviefap.com/videos/3080837f6712355015c2/busty-british-blonde-takes-backdoor-in-fake-taxi.html', - 'md5': 'bedef72cb23d27a20755fc430a6d7a0e', + 'url': 'http://www.moviefap.com/videos/be9867c9416c19f54a4a/experienced-milf-amazing-handjob.html', + 'md5': '26624b4e2523051b550067d547615906', 'info_dict': { - 'id': '3080837f6712355015c2', + 'id': 'be9867c9416c19f54a4a', 'ext': 'mp4', - 'title': 'Busty British blonde takes backdoor in fake taxi', - 'description': 'Big boobs British blonde flashing in fake taxi then giving titsjob and rimjob in the back seat before getting big cock up her tight ass', - 'thumbnail': 'http://img.moviefap.com/a16:9w990r/thumbs/30/322021-18l.jpg', - 'uploader_id': 'momcikoper', - 'display_id': 'busty-british-blonde-takes-backdoor-in-fake-taxi' + 'title': 'Experienced MILF Amazing Handjob', + 'description': 'Experienced MILF giving an Amazing Handjob', + 'thumbnail': 'http://img.moviefap.com/a16:9w990r/thumbs/be/322032-20l.jpg', + 'uploader_id': 'darvinfred06', + 'display_id': 'experienced-milf-amazing-handjob' } }] From 9c494108983c2a951780217014c26d8f3b081682 Mon Sep 17 00:00:00 2001 From: George Brighton Date: Sat, 27 Jun 2015 20:06:44 +0100 Subject: [PATCH 04/13] [moviefap] Add categories to tests --- youtube_dl/extractor/moviefap.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/youtube_dl/extractor/moviefap.py b/youtube_dl/extractor/moviefap.py index 880ea22476..6b79183c75 100644 --- a/youtube_dl/extractor/moviefap.py +++ b/youtube_dl/extractor/moviefap.py @@ -18,7 +18,8 @@ class MovieFapIE(InfoExtractor): 'description': 'Amateur', 'thumbnail': 'http://pic.moviefap.com/thumbs/e5/949-18l.jpg', 'uploader_id': 'whiskeyjar', - 'display_id': 'jeune-couple-russe' + 'display_id': 'jeune-couple-russe', + 'categories': ['Amateur', 'Teen'] } }, { 'url': 'http://www.moviefap.com/videos/be9867c9416c19f54a4a/experienced-milf-amazing-handjob.html', @@ -30,7 +31,8 @@ class MovieFapIE(InfoExtractor): 'description': 'Experienced MILF giving an Amazing Handjob', 'thumbnail': 'http://img.moviefap.com/a16:9w990r/thumbs/be/322032-20l.jpg', 'uploader_id': 'darvinfred06', - 'display_id': 'experienced-milf-amazing-handjob' + 'display_id': 'experienced-milf-amazing-handjob', + 'categories': ['Amateur', 'Masturbation', 'Mature', 'Flashing'] } }] From a8e6f30d8ed13209f2e9815ae97b3edccd38561b Mon Sep 17 00:00:00 2001 From: George Brighton Date: Sat, 27 Jun 2015 20:14:15 +0100 Subject: [PATCH 05/13] [moviefap] Swap and justify tests --- youtube_dl/extractor/moviefap.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/youtube_dl/extractor/moviefap.py b/youtube_dl/extractor/moviefap.py index 6b79183c75..1985c53c00 100644 --- a/youtube_dl/extractor/moviefap.py +++ b/youtube_dl/extractor/moviefap.py @@ -9,19 +9,7 @@ from ..utils import str_to_int class MovieFapIE(InfoExtractor): _VALID_URL = r'https?://(?:www\.)?moviefap\.com/videos/(?P[0-9a-f]+)/(?P[a-z-_]+)' _TESTS = [{ - 'url': 'http://www.moviefap.com/videos/e5da0d3edce5404418f5/jeune-couple-russe.html', - 'md5': 'fa56683e291fc80635907168a743c9ad', - 'info_dict': { - 'id': 'e5da0d3edce5404418f5', - 'ext': 'flv', - 'title': 'Jeune Couple Russe', - 'description': 'Amateur', - 'thumbnail': 'http://pic.moviefap.com/thumbs/e5/949-18l.jpg', - 'uploader_id': 'whiskeyjar', - 'display_id': 'jeune-couple-russe', - 'categories': ['Amateur', 'Teen'] - } - }, { + # normal, multi-format video 'url': 'http://www.moviefap.com/videos/be9867c9416c19f54a4a/experienced-milf-amazing-handjob.html', 'md5': '26624b4e2523051b550067d547615906', 'info_dict': { @@ -34,6 +22,20 @@ class MovieFapIE(InfoExtractor): 'display_id': 'experienced-milf-amazing-handjob', 'categories': ['Amateur', 'Masturbation', 'Mature', 'Flashing'] } + }, { + # quirky single-format case where the extension is given as fid, but the video is really an flv + 'url': 'http://www.moviefap.com/videos/e5da0d3edce5404418f5/jeune-couple-russe.html', + 'md5': 'fa56683e291fc80635907168a743c9ad', + 'info_dict': { + 'id': 'e5da0d3edce5404418f5', + 'ext': 'flv', + 'title': 'Jeune Couple Russe', + 'description': 'Amateur', + 'thumbnail': 'http://pic.moviefap.com/thumbs/e5/949-18l.jpg', + 'uploader_id': 'whiskeyjar', + 'display_id': 'jeune-couple-russe', + 'categories': ['Amateur', 'Teen'] + } }] @staticmethod From d16ef949ca94ffb998c4db5a8367f0b367d659e3 Mon Sep 17 00:00:00 2001 From: George Brighton Date: Sat, 27 Jun 2015 20:36:46 +0100 Subject: [PATCH 06/13] [moviefap] Allow non-critical fields to change without breaking extraction --- youtube_dl/extractor/moviefap.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/youtube_dl/extractor/moviefap.py b/youtube_dl/extractor/moviefap.py index 1985c53c00..23575d30a8 100644 --- a/youtube_dl/extractor/moviefap.py +++ b/youtube_dl/extractor/moviefap.py @@ -89,14 +89,14 @@ class MovieFapIE(InfoExtractor): 'display_id': re.compile(self._VALID_URL).match(url).group('name'), 'thumbnails': self.__get_thumbnail_data(xml), 'thumbnail': xml.find('startThumb').text, - 'description': self._html_search_regex(r'name="description" value="(.*?)"', webpage, 'description'), - 'uploader_id': self._html_search_regex(r'name="username" value="(.*?)"', webpage, 'uploader_id'), - 'view_count': str_to_int(self._html_search_regex(r'
Views ([0-9]+)', webpage, 'view_count')), - 'average_rating': float(self._html_search_regex(r'Current Rating
(.*?)', webpage, 'average_rating')), - 'comment_count': str_to_int(self._html_search_regex(r'([0-9]+)', webpage, 'comment_count')), + 'description': self._html_search_regex(r'name="description" value="(.*?)"', webpage, 'description', fatal=False), + 'uploader_id': self._html_search_regex(r'name="username" value="(.*?)"', webpage, 'uploader_id', fatal=False), + 'view_count': str_to_int(self._html_search_regex(r'
Views ([0-9]+)', webpage, 'view_count, fatal=False')), + 'average_rating': float(self._html_search_regex(r'Current Rating
(.*?)', webpage, 'average_rating', fatal=False)), + 'comment_count': str_to_int(self._html_search_regex(r'([0-9]+)', webpage, 'comment_count', fatal=False)), 'age_limit': 18, - 'webpage_url': self._html_search_regex(r'name="link" value="(.*?)"', webpage, 'webpage_url'), - 'categories': self._html_search_regex(r'\s*(.*?)\s*
', webpage, 'categories').split(', ') + 'webpage_url': self._html_search_regex(r'name="link" value="(.*?)"', webpage, 'webpage_url', fatal=False), + 'categories': self._html_search_regex(r'\s*(.*?)\s*
', webpage, 'categories', fatal=False).split(', ') } # find and add the format From 62b742ece3ec6c7d7fd24898b5413b6b98a4ae8f Mon Sep 17 00:00:00 2001 From: George Brighton Date: Sat, 27 Jun 2015 20:51:11 +0100 Subject: [PATCH 07/13] [moviefap] Remove redundant comments --- youtube_dl/extractor/moviefap.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/youtube_dl/extractor/moviefap.py b/youtube_dl/extractor/moviefap.py index 23575d30a8..b38a8e71ff 100644 --- a/youtube_dl/extractor/moviefap.py +++ b/youtube_dl/extractor/moviefap.py @@ -70,19 +70,13 @@ class MovieFapIE(InfoExtractor): def _real_extract(self, url): - # find the video ID video_id = self._match_id(url) - - # retrieve the page HTML webpage = self._download_webpage(url, video_id) - # find the URL of the XML document detailing video download URLs + # find and retrieve the XML document detailing video download URLs info_url = self._html_search_regex(r'flashvars\.config = escape\("(.+?)"', webpage, 'player parameters') - - # download that XML xml = self._download_xml(info_url, video_id) - # create dictionary of properties we know so far, or can find easily info = { 'id': video_id, 'title': self._html_search_regex(r'

(.*?)

', webpage, 'title'), From 43b925ce74efd0a011f7880dcdcc90f4cf3b8f4b Mon Sep 17 00:00:00 2001 From: George Brighton Date: Sat, 27 Jun 2015 20:52:12 +0100 Subject: [PATCH 08/13] [moviefap] Replace calls to `find()` with `util.xpath_text()`. --- youtube_dl/extractor/moviefap.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/youtube_dl/extractor/moviefap.py b/youtube_dl/extractor/moviefap.py index b38a8e71ff..6da93dbc9b 100644 --- a/youtube_dl/extractor/moviefap.py +++ b/youtube_dl/extractor/moviefap.py @@ -3,7 +3,10 @@ from __future__ import unicode_literals import re from .common import InfoExtractor -from ..utils import str_to_int +from ..utils import ( + xpath_text, + str_to_int +) class MovieFapIE(InfoExtractor): @@ -82,7 +85,7 @@ class MovieFapIE(InfoExtractor): 'title': self._html_search_regex(r'

(.*?)

', webpage, 'title'), 'display_id': re.compile(self._VALID_URL).match(url).group('name'), 'thumbnails': self.__get_thumbnail_data(xml), - 'thumbnail': xml.find('startThumb').text, + 'thumbnail': xpath_text(xml, 'startThumb', 'thumbnail'), 'description': self._html_search_regex(r'name="description" value="(.*?)"', webpage, 'description', fatal=False), 'uploader_id': self._html_search_regex(r'name="username" value="(.*?)"', webpage, 'uploader_id', fatal=False), 'view_count': str_to_int(self._html_search_regex(r'
Views ([0-9]+)', webpage, 'view_count, fatal=False')), @@ -102,7 +105,7 @@ class MovieFapIE(InfoExtractor): # work out the video URL(s) if xml.find('videoLink') is not None: # single format available - info['url'] = xml.find('videoLink').text + info['url'] = xpath_text(xml, 'videoLink', 'url', True) else: # multiple formats available info['formats'] = [] @@ -110,8 +113,8 @@ class MovieFapIE(InfoExtractor): # N.B. formats are already in ascending order of quality for item in xml.find('quality').findall('item'): info['formats'].append({ - 'url': item.find('videoLink').text, - 'resolution': item.find('res').text # 480p etc. + 'url': xpath_text(item, 'videoLink', 'url', True), + 'resolution': xpath_text(item, 'res', 'resolution', True) # 480p etc. }) return info From b971abe897ee17fed7e36868fdc8880f6b145d7b Mon Sep 17 00:00:00 2001 From: George Brighton Date: Sat, 27 Jun 2015 21:04:53 +0100 Subject: [PATCH 09/13] [moviefap] Replace call to `str()` with `compat.compat_str()` --- youtube_dl/extractor/moviefap.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/youtube_dl/extractor/moviefap.py b/youtube_dl/extractor/moviefap.py index 6da93dbc9b..20a78f3b2b 100644 --- a/youtube_dl/extractor/moviefap.py +++ b/youtube_dl/extractor/moviefap.py @@ -7,6 +7,7 @@ from ..utils import ( xpath_text, str_to_int ) +from ..compat import compat_str class MovieFapIE(InfoExtractor): @@ -65,7 +66,7 @@ class MovieFapIE(InfoExtractor): thumbnails = [] for i in range(first, last + 1): thumbnails.append({ - 'url': pattern.replace('#', str(i)), + 'url': pattern.replace('#', compat_str(i)), 'width': width, 'height': height }) From 8a1b49ff19a8a1fdc2c30cf10cc0598ac9bc8819 Mon Sep 17 00:00:00 2001 From: George Brighton Date: Sat, 27 Jun 2015 22:27:06 +0100 Subject: [PATCH 10/13] [moviefap] Explicitly sort formats to handle possible site changes --- youtube_dl/extractor/moviefap.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/youtube_dl/extractor/moviefap.py b/youtube_dl/extractor/moviefap.py index 20a78f3b2b..295bfe3f02 100644 --- a/youtube_dl/extractor/moviefap.py +++ b/youtube_dl/extractor/moviefap.py @@ -111,11 +111,14 @@ class MovieFapIE(InfoExtractor): # multiple formats available info['formats'] = [] - # N.B. formats are already in ascending order of quality 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': xpath_text(item, 'res', 'resolution', True) # 480p etc. + 'resolution': resolution, + 'height': int(re.findall(r'\d+', resolution)[0]) }) + self._sort_formats(info['formats']) + return info From 1a5fd4eebc2717b5173df50d65007f90cb05ee30 Mon Sep 17 00:00:00 2001 From: George Brighton Date: Sat, 27 Jun 2015 22:32:56 +0100 Subject: [PATCH 11/13] [moviefap] Wrap long lines --- youtube_dl/extractor/moviefap.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/youtube_dl/extractor/moviefap.py b/youtube_dl/extractor/moviefap.py index 295bfe3f02..9de052a998 100644 --- a/youtube_dl/extractor/moviefap.py +++ b/youtube_dl/extractor/moviefap.py @@ -78,23 +78,32 @@ class MovieFapIE(InfoExtractor): webpage = self._download_webpage(url, video_id) # find and retrieve the XML document detailing video download URLs - info_url = self._html_search_regex(r'flashvars\.config = escape\("(.+?)"', webpage, 'player parameters') + info_url = self._html_search_regex( \ + r'flashvars\.config = escape\("(.+?)"', webpage, 'player parameters') xml = self._download_xml(info_url, video_id) info = { 'id': video_id, - 'title': self._html_search_regex(r'

(.*?)

', webpage, 'title'), + 'title': self._html_search_regex( \ + r'

(.*?)

', webpage, 'title'), 'display_id': re.compile(self._VALID_URL).match(url).group('name'), 'thumbnails': self.__get_thumbnail_data(xml), 'thumbnail': xpath_text(xml, 'startThumb', 'thumbnail'), - 'description': self._html_search_regex(r'name="description" value="(.*?)"', webpage, 'description', fatal=False), - 'uploader_id': self._html_search_regex(r'name="username" value="(.*?)"', webpage, 'uploader_id', fatal=False), - 'view_count': str_to_int(self._html_search_regex(r'
Views ([0-9]+)', webpage, 'view_count, fatal=False')), - 'average_rating': float(self._html_search_regex(r'Current Rating
(.*?)', webpage, 'average_rating', fatal=False)), - 'comment_count': str_to_int(self._html_search_regex(r'([0-9]+)', webpage, 'comment_count', fatal=False)), + 'description': self._html_search_regex( \ + r'name="description" value="(.*?)"', webpage, 'description', fatal=False), + 'uploader_id': self._html_search_regex( \ + r'name="username" value="(.*?)"', webpage, 'uploader_id', fatal=False), + 'view_count': str_to_int(self._html_search_regex( \ + r'
Views ([0-9]+)', webpage, 'view_count, fatal=False')), + 'average_rating': float(self._html_search_regex( \ + r'Current Rating
(.*?)', webpage, 'average_rating', fatal=False)), + 'comment_count': str_to_int(self._html_search_regex( \ + r'([0-9]+)', webpage, 'comment_count', fatal=False)), 'age_limit': 18, - 'webpage_url': self._html_search_regex(r'name="link" value="(.*?)"', webpage, 'webpage_url', fatal=False), - 'categories': self._html_search_regex(r'
\s*(.*?)\s*
', webpage, 'categories', fatal=False).split(', ') + 'webpage_url': self._html_search_regex( \ + r'name="link" value="(.*?)"', webpage, 'webpage_url', fatal=False), + 'categories': self._html_search_regex( \ + r'
\s*(.*?)\s*
', webpage, 'categories', fatal=False).split(', ') } # find and add the format From 5a9cc19972fb3aae7a67470f65ec5cd30918f4e1 Mon Sep 17 00:00:00 2001 From: George Brighton Date: Sat, 27 Jun 2015 23:03:06 +0100 Subject: [PATCH 12/13] [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 9de052a998..5e0c701d4e 100644 --- a/youtube_dl/extractor/moviefap.py +++ b/youtube_dl/extractor/moviefap.py @@ -82,8 +82,36 @@ class MovieFapIE(InfoExtractor): 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 @@ class MovieFapIE(InfoExtractor): '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 From db652ea186586e3eda5006ee096161b1a867c0d0 Mon Sep 17 00:00:00 2001 From: George Brighton Date: Sat, 27 Jun 2015 23:04:55 +0100 Subject: [PATCH 13/13] [moviefap] Fix `flake8` warnings introduced in 1a5fd4e --- youtube_dl/extractor/moviefap.py | 36 ++++++++++++++++---------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/youtube_dl/extractor/moviefap.py b/youtube_dl/extractor/moviefap.py index 5e0c701d4e..82b8635390 100644 --- a/youtube_dl/extractor/moviefap.py +++ b/youtube_dl/extractor/moviefap.py @@ -78,8 +78,8 @@ class MovieFapIE(InfoExtractor): webpage = self._download_webpage(url, video_id) # find and retrieve the XML document detailing video download URLs - info_url = self._html_search_regex( \ - r'flashvars\.config = escape\("(.+?)"', webpage, 'player parameters') + info_url = self._html_search_regex( + r'flashvars\.config = escape\("(.+?)"', webpage, 'player parameters') xml = self._download_xml(info_url, video_id) # find the video container @@ -112,24 +112,24 @@ class MovieFapIE(InfoExtractor): return { 'id': video_id, 'formats': formats, - 'title': self._html_search_regex( \ - r'

(.*?)

', webpage, 'title'), + 'title': self._html_search_regex( + r'

(.*?)

', webpage, 'title'), 'display_id': re.compile(self._VALID_URL).match(url).group('name'), 'thumbnails': self.__get_thumbnail_data(xml), 'thumbnail': xpath_text(xml, 'startThumb', 'thumbnail'), - 'description': self._html_search_regex( \ - r'name="description" value="(.*?)"', webpage, 'description', fatal=False), - 'uploader_id': self._html_search_regex( \ - r'name="username" value="(.*?)"', webpage, 'uploader_id', fatal=False), - 'view_count': str_to_int(self._html_search_regex( \ - r'
Views ([0-9]+)', webpage, 'view_count, fatal=False')), - 'average_rating': float(self._html_search_regex( \ - r'Current Rating
(.*?)', webpage, 'average_rating', fatal=False)), - 'comment_count': str_to_int(self._html_search_regex( \ - r'([0-9]+)', webpage, 'comment_count', fatal=False)), + 'description': self._html_search_regex( + r'name="description" value="(.*?)"', webpage, 'description', fatal=False), + 'uploader_id': self._html_search_regex( + r'name="username" value="(.*?)"', webpage, 'uploader_id', fatal=False), + 'view_count': str_to_int(self._html_search_regex( + r'
Views ([0-9]+)', webpage, 'view_count, fatal=False')), + 'average_rating': float(self._html_search_regex( + r'Current Rating
(.*?)', webpage, 'average_rating', fatal=False)), + 'comment_count': str_to_int(self._html_search_regex( + r'([0-9]+)', webpage, 'comment_count', fatal=False)), 'age_limit': 18, - 'webpage_url': self._html_search_regex( \ - r'name="link" value="(.*?)"', webpage, 'webpage_url', fatal=False), - 'categories': self._html_search_regex( \ - r'
\s*(.*?)\s*
', webpage, 'categories', fatal=False).split(', ') + 'webpage_url': self._html_search_regex( + r'name="link" value="(.*?)"', webpage, 'webpage_url', fatal=False), + 'categories': self._html_search_regex( + r'
\s*(.*?)\s*
', webpage, 'categories', fatal=False).split(', ') }