2015-06-27 12:11:23 +08:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
|
|
|
from .common import InfoExtractor
|
2015-06-28 03:52:12 +08:00
|
|
|
from ..utils import (
|
|
|
|
xpath_text,
|
|
|
|
str_to_int
|
|
|
|
)
|
2015-06-27 12:11:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
class MovieFapIE(InfoExtractor):
|
|
|
|
_VALID_URL = r'https?://(?:www\.)?moviefap\.com/videos/(?P<id>[0-9a-f]+)/(?P<name>[a-z-_]+)'
|
|
|
|
_TESTS = [{
|
2015-06-28 03:14:15 +08:00
|
|
|
# normal, multi-format video
|
2015-06-28 03:01:27 +08:00
|
|
|
'url': 'http://www.moviefap.com/videos/be9867c9416c19f54a4a/experienced-milf-amazing-handjob.html',
|
|
|
|
'md5': '26624b4e2523051b550067d547615906',
|
2015-06-27 12:11:23 +08:00
|
|
|
'info_dict': {
|
2015-06-28 03:01:27 +08:00
|
|
|
'id': 'be9867c9416c19f54a4a',
|
2015-06-27 12:11:23 +08:00
|
|
|
'ext': 'mp4',
|
2015-06-28 03:01:27 +08:00
|
|
|
'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',
|
2015-06-28 03:06:44 +08:00
|
|
|
'display_id': 'experienced-milf-amazing-handjob',
|
|
|
|
'categories': ['Amateur', 'Masturbation', 'Mature', 'Flashing']
|
2015-06-27 12:11:23 +08:00
|
|
|
}
|
2015-06-28 03:14:15 +08:00
|
|
|
}, {
|
|
|
|
# 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']
|
|
|
|
}
|
2015-06-27 12:11:23 +08:00
|
|
|
}]
|
|
|
|
|
|
|
|
@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
|
2015-06-27 12:22:35 +08:00
|
|
|
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)
|
2015-06-27 12:11:23 +08:00
|
|
|
pattern = timeline.find('imagePattern').text
|
|
|
|
|
|
|
|
# generate the list of thumbnail information dicts
|
|
|
|
thumbnails = []
|
2015-06-27 12:22:35 +08:00
|
|
|
for i in range(first, last + 1):
|
2015-06-27 12:11:23 +08:00
|
|
|
thumbnails.append({
|
|
|
|
'url': pattern.replace('#', str(i)),
|
2015-06-27 12:22:35 +08:00
|
|
|
'width': width,
|
|
|
|
'height': height
|
2015-06-27 12:11:23 +08:00
|
|
|
})
|
|
|
|
return thumbnails
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
|
|
|
|
|
|
|
video_id = self._match_id(url)
|
|
|
|
webpage = self._download_webpage(url, video_id)
|
|
|
|
|
2015-06-28 03:51:11 +08:00
|
|
|
# find and retrieve the XML document detailing video download URLs
|
2015-06-27 12:11:23 +08:00
|
|
|
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'<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),
|
2015-06-28 03:52:12 +08:00
|
|
|
'thumbnail': xpath_text(xml, 'startThumb', 'thumbnail'),
|
2015-06-28 03:36:46 +08:00
|
|
|
'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)),
|
2015-06-27 12:11:23 +08:00
|
|
|
'age_limit': 18,
|
2015-06-28 03:36:46 +08:00
|
|
|
'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(', ')
|
2015-06-27 12:11:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
# 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
|
2015-06-28 03:52:12 +08:00
|
|
|
info['url'] = xpath_text(xml, 'videoLink', 'url', True)
|
2015-06-27 12:11:23 +08:00
|
|
|
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({
|
2015-06-28 03:52:12 +08:00
|
|
|
'url': xpath_text(item, 'videoLink', 'url', True),
|
|
|
|
'resolution': xpath_text(item, 'res', 'resolution', True) # 480p etc.
|
2015-06-27 12:11:23 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
return info
|