From 82ea1051b54134150f290d3d9f259a4baf54faf4 Mon Sep 17 00:00:00 2001 From: George Brighton Date: Sat, 27 Jun 2015 05:11:23 +0100 Subject: [PATCH 01/17] [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 7e74a971d..b70c1b57e 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 000000000..49b8ab7d9 --- /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/17] [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 49b8ab7d9..88f9dab6f 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/17] [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 88f9dab6f..880ea2247 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/17] [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 880ea2247..6b79183c7 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/17] [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 6b79183c7..1985c53c0 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/17] [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 1985c53c0..23575d30a 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/17] [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 23575d30a..b38a8e71f 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/17] [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 b38a8e71f..6da93dbc9 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/17] [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 6da93dbc9..20a78f3b2 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/17] [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 20a78f3b2..295bfe3f0 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/17] [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 295bfe3f0..9de052a99 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/17] [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 @@ 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/17] [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 5e0c701d4..82b863539 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(', ') } From 9603e8a7d998615d3da1af47461ec9c353ec4e7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergey=20M=E2=80=A4?= Date: Sun, 28 Jun 2015 22:55:28 +0600 Subject: [PATCH 14/17] [YoutubeDL] Handle None width and height similarly to formats --- youtube_dl/YoutubeDL.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index ef0f71bad..411de9ac9 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -1008,7 +1008,7 @@ class YoutubeDL(object): t.get('preference'), t.get('width'), t.get('height'), t.get('id'), t.get('url'))) for i, t in enumerate(thumbnails): - if 'width' in t and 'height' in t: + if t.get('width') and t.get('height'): t['resolution'] = '%dx%d' % (t['width'], t['height']) if t.get('id') is None: t['id'] = '%d' % i From bf42a9906d9a066d32f1cc50e1b033e6676744ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergey=20M=E2=80=A4?= Date: Sun, 28 Jun 2015 22:56:07 +0600 Subject: [PATCH 15/17] [utils] Add default value for xpath_text --- youtube_dl/utils.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 96490f112..942f76d24 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -62,6 +62,8 @@ std_headers = { } +NO_DEFAULT = object() + ENGLISH_MONTH_NAMES = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] @@ -171,13 +173,15 @@ def xpath_with_ns(path, ns_map): return '/'.join(replaced) -def xpath_text(node, xpath, name=None, fatal=False): +def xpath_text(node, xpath, name=None, fatal=False, default=NO_DEFAULT): if sys.version_info < (2, 7): # Crazy 2.6 xpath = xpath.encode('ascii') n = node.find(xpath) if n is None or n.text is None: - if fatal: + if default is not NO_DEFAULT: + return default + elif fatal: name = xpath if name is None else name raise ExtractorError('Could not find XML element %s' % name) else: From c342041fba9283ba5f05f48427aabf79adcf8647 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergey=20M=E2=80=A4?= Date: Sun, 28 Jun 2015 22:56:45 +0600 Subject: [PATCH 16/17] [extractor/common] Use NO_DEFAULT from utils --- youtube_dl/extractor/common.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/youtube_dl/extractor/common.py b/youtube_dl/extractor/common.py index 49e4dc710..7fa46d295 100644 --- a/youtube_dl/extractor/common.py +++ b/youtube_dl/extractor/common.py @@ -22,6 +22,7 @@ from ..compat import ( compat_str, ) from ..utils import ( + NO_DEFAULT, age_restricted, bug_reports_message, clean_html, @@ -33,7 +34,7 @@ from ..utils import ( sanitize_filename, unescapeHTML, ) -_NO_DEFAULT = object() + class InfoExtractor(object): @@ -523,7 +524,7 @@ class InfoExtractor(object): video_info['description'] = playlist_description return video_info - def _search_regex(self, pattern, string, name, default=_NO_DEFAULT, fatal=True, flags=0, group=None): + def _search_regex(self, pattern, string, name, default=NO_DEFAULT, fatal=True, flags=0, group=None): """ Perform a regex search on the given string, using a single or a list of patterns returning the first matching group. @@ -549,7 +550,7 @@ class InfoExtractor(object): return next(g for g in mobj.groups() if g is not None) else: return mobj.group(group) - elif default is not _NO_DEFAULT: + elif default is not NO_DEFAULT: return default elif fatal: raise RegexNotFoundError('Unable to extract %s' % _name) @@ -557,7 +558,7 @@ class InfoExtractor(object): self._downloader.report_warning('unable to extract %s' % _name + bug_reports_message()) return None - def _html_search_regex(self, pattern, string, name, default=_NO_DEFAULT, fatal=True, flags=0, group=None): + def _html_search_regex(self, pattern, string, name, default=NO_DEFAULT, fatal=True, flags=0, group=None): """ Like _search_regex, but strips HTML tags and unescapes entities. """ From d16154d16327907279eff48a4018c495726d401a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergey=20M=E2=80=A4?= Date: Sun, 28 Jun 2015 23:05:09 +0600 Subject: [PATCH 17/17] [tnaflix] Generalize tnaflix extractors --- youtube_dl/extractor/__init__.py | 8 +- youtube_dl/extractor/empflix.py | 31 ---- youtube_dl/extractor/moviefap.py | 135 --------------- youtube_dl/extractor/tnaflix.py | 279 +++++++++++++++++++++++++------ 4 files changed, 234 insertions(+), 219 deletions(-) delete mode 100644 youtube_dl/extractor/empflix.py delete mode 100644 youtube_dl/extractor/moviefap.py diff --git a/youtube_dl/extractor/__init__.py b/youtube_dl/extractor/__init__.py index d41d277c9..d44339200 100644 --- a/youtube_dl/extractor/__init__.py +++ b/youtube_dl/extractor/__init__.py @@ -144,7 +144,6 @@ from .ellentv import ( ) from .elpais import ElPaisIE from .embedly import EmbedlyIE -from .empflix import EMPFlixIE from .engadget import EngadgetIE from .eporner import EpornerIE from .eroprofile import EroProfileIE @@ -311,7 +310,6 @@ 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 ( @@ -578,7 +576,11 @@ from .tmz import ( TMZIE, TMZArticleIE, ) -from .tnaflix import TNAFlixIE +from .tnaflix import ( + TNAFlixIE, + EMPFlixIE, + MovieFapIE, +) from .thvideo import ( THVideoIE, THVideoPlaylistIE diff --git a/youtube_dl/extractor/empflix.py b/youtube_dl/extractor/empflix.py deleted file mode 100644 index 4827022e0..000000000 --- a/youtube_dl/extractor/empflix.py +++ /dev/null @@ -1,31 +0,0 @@ -from __future__ import unicode_literals - -from .tnaflix import TNAFlixIE - - -class EMPFlixIE(TNAFlixIE): - _VALID_URL = r'https?://(?:www\.)?empflix\.com/videos/(?P.+?)-(?P[0-9]+)\.html' - - _TITLE_REGEX = r'name="title" value="(?P[^"]*)"' - _DESCRIPTION_REGEX = r'name="description" value="([^"]*)"' - _CONFIG_REGEX = r'flashvars\.config\s*=\s*escape\("([^"]+)"' - - _TESTS = [ - { - 'url': 'http://www.empflix.com/videos/Amateur-Finger-Fuck-33051.html', - 'md5': 'b1bc15b6412d33902d6e5952035fcabc', - 'info_dict': { - 'id': '33051', - 'display_id': 'Amateur-Finger-Fuck', - 'ext': 'mp4', - 'title': 'Amateur Finger Fuck', - 'description': 'Amateur solo finger fucking.', - 'thumbnail': 're:https?://.*\.jpg$', - 'age_limit': 18, - } - }, - { - 'url': 'http://www.empflix.com/videos/[AROMA][ARMD-718]-Aoi-Yoshino-Sawa-25826.html', - 'only_matching': True, - } - ] diff --git a/youtube_dl/extractor/moviefap.py b/youtube_dl/extractor/moviefap.py deleted file mode 100644 index 82b863539..000000000 --- a/youtube_dl/extractor/moviefap.py +++ /dev/null @@ -1,135 +0,0 @@ -from __future__ import unicode_literals - -import re - -from .common import InfoExtractor -from ..utils import ( - xpath_text, - str_to_int -) -from ..compat import compat_str - - -class MovieFapIE(InfoExtractor): - _VALID_URL = r'https?://(?:www\.)?moviefap\.com/videos/(?P<id>[0-9a-f]+)/(?P<name>[a-z-_]+)' - _TESTS = [{ - # normal, multi-format video - 'url': 'http://www.moviefap.com/videos/be9867c9416c19f54a4a/experienced-milf-amazing-handjob.html', - 'md5': '26624b4e2523051b550067d547615906', - 'info_dict': { - 'id': 'be9867c9416c19f54a4a', - 'ext': 'mp4', - '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', - '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 - 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 - 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(first, last + 1): - thumbnails.append({ - 'url': pattern.replace('#', compat_str(i)), - 'width': width, - 'height': height - }) - return thumbnails - - def _real_extract(self, url): - - video_id = self._match_id(url) - 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') - xml = self._download_xml(info_url, video_id) - - # 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'<div id="view_title"><h1>(.*?)</h1>', 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'<br>Views <strong>([0-9]+)</strong>', webpage, 'view_count, fatal=False')), - 'average_rating': float(self._html_search_regex( - r'Current Rating<br> <strong>(.*?)</strong>', webpage, 'average_rating', fatal=False)), - 'comment_count': str_to_int(self._html_search_regex( - r'<span id="comCount">([0-9]+)</span>', 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'</div>\s*(.*?)\s*<br>', webpage, 'categories', fatal=False).split(', ') - } diff --git a/youtube_dl/extractor/tnaflix.py b/youtube_dl/extractor/tnaflix.py index c282865b2..49516abca 100644 --- a/youtube_dl/extractor/tnaflix.py +++ b/youtube_dl/extractor/tnaflix.py @@ -3,39 +3,70 @@ from __future__ import unicode_literals import re from .common import InfoExtractor +from ..compat import compat_str from ..utils import ( - parse_duration, fix_xml_ampersands, + float_or_none, + int_or_none, + parse_duration, + str_to_int, + xpath_text, ) -class TNAFlixIE(InfoExtractor): - _VALID_URL = r'https?://(?:www\.)?tnaflix\.com/[^/]+/(?P<display_id>[^/]+)/video(?P<id>\d+)' - - _TITLE_REGEX = r'<title>(.+?) - TNAFlix Porn Videos' - _DESCRIPTION_REGEX = r'

([^<]+)

' - _CONFIG_REGEX = r'flashvars\.config\s*=\s*escape\("([^"]+)"' - - _TESTS = [ - { - 'url': 'http://www.tnaflix.com/porn-stars/Carmella-Decesare-striptease/video553878', - 'md5': 'ecf3498417d09216374fc5907f9c6ec0', - 'info_dict': { - 'id': '553878', - 'display_id': 'Carmella-Decesare-striptease', - 'ext': 'mp4', - 'title': 'Carmella Decesare - striptease', - 'description': '', - 'thumbnail': 're:https?://.*\.jpg$', - 'duration': 91, - 'age_limit': 18, - } - }, - { - 'url': 'https://www.tnaflix.com/amateur-porn/bunzHD-Ms.Donk/video358632', - 'only_matching': True, - } +class TNAFlixNetworkBaseIE(InfoExtractor): + # May be overridden in descendants if necessary + _CONFIG_REGEX = [ + r'flashvars\.config\s*=\s*escape\("([^"]+)"', + r']+name="config\d?" value="([^"]+)"', ] + _TITLE_REGEX = r']+name="title" value="([^"]+)"' + _DESCRIPTION_REGEX = r']+name="description" value="([^"]+)"' + _UPLOADER_REGEX = r']+name="username" value="([^"]+)"' + _VIEW_COUNT_REGEX = None + _COMMENT_COUNT_REGEX = None + _AVERAGE_RATING_REGEX = None + _CATEGORIES_REGEX = r']*>\s*]+class="infoTitle"[^>]*>Categories:\s*]+class="listView"[^>]*>(.+?)\s*' + + def _extract_thumbnails(self, flix_xml): + + def get_child(elem, names): + for name in names: + child = elem.find(name) + if child is not None: + return child + + timeline = get_child(flix_xml, ['timeline', 'rolloverBarImage']) + if timeline is None: + return + + pattern_el = get_child(timeline, ['imagePattern', 'pattern']) + if pattern_el is None or not pattern_el.text: + return + + first_el = get_child(timeline, ['imageFirst', 'first']) + last_el = get_child(timeline, ['imageLast', 'last']) + if first_el is None or last_el is None: + return + + first_text = first_el.text + last_text = last_el.text + if not first_text.isdigit() or not last_text.isdigit(): + return + + first = int(first_text) + last = int(last_text) + if first > last: + return + + width = int_or_none(xpath_text(timeline, './imageWidth', 'thumbnail width')) + height = int_or_none(xpath_text(timeline, './imageHeight', 'thumbnail height')) + + return [{ + 'url': self._proto_relative_url(pattern_el.text.replace('#', compat_str(i)), 'http:'), + 'width': width, + 'height': height, + } for i in range(first, last + 1)] def _real_extract(self, url): mobj = re.match(self._VALID_URL, url) @@ -44,39 +75,64 @@ class TNAFlixIE(InfoExtractor): webpage = self._download_webpage(url, display_id) + cfg_url = self._proto_relative_url(self._html_search_regex( + self._CONFIG_REGEX, webpage, 'flashvars.config'), 'http:') + + cfg_xml = self._download_xml( + cfg_url, display_id, 'Downloading metadata', + transform_source=fix_xml_ampersands) + + formats = [] + + def extract_video_url(vl): + return re.sub('speed=\d+', 'speed=', vl.text) + + video_link = cfg_xml.find('./videoLink') + if video_link is not None: + formats.append({ + 'url': extract_video_url(video_link), + 'ext': xpath_text(cfg_xml, './videoConfig/type', 'type', default='flv'), + }) + + for item in cfg_xml.findall('./quality/item'): + video_link = item.find('./videoLink') + if video_link is None: + continue + res = item.find('res') + format_id = None if res is None else res.text + height = int_or_none(self._search_regex( + r'^(\d+)[pP]', format_id, 'height', default=None)) + formats.append({ + 'url': self._proto_relative_url(extract_video_url(video_link), 'http:'), + 'format_id': format_id, + 'height': height, + }) + + self._sort_formats(formats) + + thumbnail = self._proto_relative_url( + xpath_text(cfg_xml, './startThumb', 'thumbnail'), 'http:') + thumbnails = self._extract_thumbnails(cfg_xml) + title = self._html_search_regex( self._TITLE_REGEX, webpage, 'title') if self._TITLE_REGEX else self._og_search_title(webpage) - description = self._html_search_regex( - self._DESCRIPTION_REGEX, webpage, 'description', fatal=False, default='') age_limit = self._rta_search(webpage) duration = parse_duration(self._html_search_meta( 'duration', webpage, 'duration', default=None)) - cfg_url = self._proto_relative_url(self._html_search_regex( - self._CONFIG_REGEX, webpage, 'flashvars.config'), 'http:') + def extract_field(pattern, name): + return self._html_search_regex(pattern, webpage, name, default=None) if pattern else None - cfg_xml = self._download_xml( - cfg_url, display_id, note='Downloading metadata', - transform_source=fix_xml_ampersands) + description = extract_field(self._DESCRIPTION_REGEX, 'description') + uploader = extract_field(self._UPLOADER_REGEX, 'uploader') + view_count = str_to_int(extract_field(self._VIEW_COUNT_REGEX, 'view count')) + comment_count = str_to_int(extract_field(self._COMMENT_COUNT_REGEX, 'comment count')) + average_rating = float_or_none(extract_field(self._AVERAGE_RATING_REGEX, 'average rating')) - thumbnail = self._proto_relative_url( - cfg_xml.find('./startThumb').text, 'http:') - - formats = [] - for item in cfg_xml.findall('./quality/item'): - video_url = re.sub('speed=\d+', 'speed=', item.find('videoLink').text) - format_id = item.find('res').text - fmt = { - 'url': self._proto_relative_url(video_url, 'http:'), - 'format_id': format_id, - } - m = re.search(r'^(\d+)', format_id) - if m: - fmt['height'] = int(m.group(1)) - formats.append(fmt) - self._sort_formats(formats) + categories_str = extract_field(self._CATEGORIES_REGEX, 'categories') + categories = categories_str.split(', ') if categories_str is not None else [] return { 'id': video_id, @@ -84,7 +140,130 @@ class TNAFlixIE(InfoExtractor): 'title': title, 'description': description, 'thumbnail': thumbnail, + 'thumbnails': thumbnails, 'duration': duration, 'age_limit': age_limit, + 'uploader': uploader, + 'view_count': view_count, + 'comment_count': comment_count, + 'average_rating': average_rating, + 'categories': categories, 'formats': formats, } + + +class TNAFlixIE(TNAFlixNetworkBaseIE): + _VALID_URL = r'https?://(?:www\.)?tnaflix\.com/[^/]+/(?P[^/]+)/video(?P\d+)' + + _TITLE_REGEX = r'(.+?) - TNAFlix Porn Videos' + _DESCRIPTION_REGEX = r'

([^<]+)

' + _UPLOADER_REGEX = r'(?s)]+class="infoTitle"[^>]*>Uploaded By:(.+?).+?)-(?P[0-9]+)\.html' + + _UPLOADER_REGEX = r']+class="infoTitle"[^>]*>Uploaded By:(.+?)' + + _TESTS = [{ + 'url': 'http://www.empflix.com/videos/Amateur-Finger-Fuck-33051.html', + 'md5': 'b1bc15b6412d33902d6e5952035fcabc', + 'info_dict': { + 'id': '33051', + 'display_id': 'Amateur-Finger-Fuck', + 'ext': 'mp4', + 'title': 'Amateur Finger Fuck', + 'description': 'Amateur solo finger fucking.', + 'thumbnail': 're:https?://.*\.jpg$', + 'duration': 83, + 'age_limit': 18, + 'uploader': 'cwbike', + 'categories': ['Amateur', 'Anal', 'Fisting', 'Home made', 'Solo'], + } + }, { + 'url': 'http://www.empflix.com/videos/[AROMA][ARMD-718]-Aoi-Yoshino-Sawa-25826.html', + 'only_matching': True, + }] + + +class MovieFapIE(TNAFlixNetworkBaseIE): + _VALID_URL = r'https?://(?:www\.)?moviefap\.com/videos/(?P[0-9a-f]+)/(?P[^/]+)\.html' + + _VIEW_COUNT_REGEX = r'
Views\s*([\d,.]+)' + _COMMENT_COUNT_REGEX = r']+id="comCount"[^>]*>([\d,.]+)' + _AVERAGE_RATING_REGEX = r'Current Rating\s*
\s*([\d.]+)' + _CATEGORIES_REGEX = r'(?s)]+id="vid_info"[^>]*>\s*]*>.+?
(.*?)
' + + _TESTS = [{ + # normal, multi-format video + 'url': 'http://www.moviefap.com/videos/be9867c9416c19f54a4a/experienced-milf-amazing-handjob.html', + 'md5': '26624b4e2523051b550067d547615906', + 'info_dict': { + 'id': 'be9867c9416c19f54a4a', + 'display_id': 'experienced-milf-amazing-handjob', + 'ext': 'mp4', + 'title': 'Experienced MILF Amazing Handjob', + 'description': 'Experienced MILF giving an Amazing Handjob', + 'thumbnail': 're:https?://.*\.jpg$', + 'age_limit': 18, + 'uploader': 'darvinfred06', + 'view_count': int, + 'comment_count': int, + 'average_rating': float, + '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', + 'display_id': 'jeune-couple-russe', + 'ext': 'flv', + 'title': 'Jeune Couple Russe', + 'description': 'Amateur', + 'thumbnail': 're:https?://.*\.jpg$', + 'age_limit': 18, + 'uploader': 'whiskeyjar', + 'view_count': int, + 'comment_count': int, + 'average_rating': float, + 'categories': ['Amateur', 'Teen'], + } + }]