1 from __future__ import unicode_literals
5 from .common import InfoExtractor
10 from ..compat import compat_str
13 class MovieFapIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:www\.)?moviefap\.com/videos/(?P<id>[0-9a-f]+)/(?P<name>[a-z-_]+)'
16 # normal, multi-format video
17 'url': 'http://www.moviefap.com/videos/be9867c9416c19f54a4a/experienced-milf-amazing-handjob.html',
18 'md5': '26624b4e2523051b550067d547615906',
20 'id': 'be9867c9416c19f54a4a',
22 'title': 'Experienced MILF Amazing Handjob',
23 'description': 'Experienced MILF giving an Amazing Handjob',
24 'thumbnail': 'http://img.moviefap.com/a16:9w990r/thumbs/be/322032-20l.jpg',
25 'uploader_id': 'darvinfred06',
26 'display_id': 'experienced-milf-amazing-handjob',
27 'categories': ['Amateur', 'Masturbation', 'Mature', 'Flashing']
30 # quirky single-format case where the extension is given as fid, but the video is really an flv
31 'url': 'http://www.moviefap.com/videos/e5da0d3edce5404418f5/jeune-couple-russe.html',
32 'md5': 'fa56683e291fc80635907168a743c9ad',
34 'id': 'e5da0d3edce5404418f5',
36 'title': 'Jeune Couple Russe',
37 'description': 'Amateur',
38 'thumbnail': 'http://pic.moviefap.com/thumbs/e5/949-18l.jpg',
39 'uploader_id': 'whiskeyjar',
40 'display_id': 'jeune-couple-russe',
41 'categories': ['Amateur', 'Teen']
46 def __get_thumbnail_data(xml):
49 Constructs a list of video thumbnails from timeline preview images.
50 :param xml: the information XML document to parse
53 timeline = xml.find('timeline')
55 # not all videos have the data - ah well
58 # get the required information from the XML
59 width = str_to_int(timeline.find('imageWidth').text)
60 height = str_to_int(timeline.find('imageHeight').text)
61 first = str_to_int(timeline.find('imageFirst').text)
62 last = str_to_int(timeline.find('imageLast').text)
63 pattern = timeline.find('imagePattern').text
65 # generate the list of thumbnail information dicts
67 for i in range(first, last + 1):
69 'url': pattern.replace('#', compat_str(i)),
75 def _real_extract(self, url):
77 video_id = self._match_id(url)
78 webpage = self._download_webpage(url, video_id)
80 # find and retrieve the XML document detailing video download URLs
81 info_url = self._html_search_regex(r'flashvars\.config = escape\("(.+?)"', webpage, 'player parameters')
82 xml = self._download_xml(info_url, video_id)
86 'title': self._html_search_regex(r'<div id="view_title"><h1>(.*?)</h1>', webpage, 'title'),
87 'display_id': re.compile(self._VALID_URL).match(url).group('name'),
88 'thumbnails': self.__get_thumbnail_data(xml),
89 'thumbnail': xpath_text(xml, 'startThumb', 'thumbnail'),
90 'description': self._html_search_regex(r'name="description" value="(.*?)"', webpage, 'description', fatal=False),
91 'uploader_id': self._html_search_regex(r'name="username" value="(.*?)"', webpage, 'uploader_id', fatal=False),
92 'view_count': str_to_int(self._html_search_regex(r'<br>Views <strong>([0-9]+)</strong>', webpage, 'view_count, fatal=False')),
93 'average_rating': float(self._html_search_regex(r'Current Rating<br> <strong>(.*?)</strong>', webpage, 'average_rating', fatal=False)),
94 'comment_count': str_to_int(self._html_search_regex(r'<span id="comCount">([0-9]+)</span>', webpage, 'comment_count', fatal=False)),
96 'webpage_url': self._html_search_regex(r'name="link" value="(.*?)"', webpage, 'webpage_url', fatal=False),
97 'categories': self._html_search_regex(r'</div>\s*(.*?)\s*<br>', webpage, 'categories', fatal=False).split(', ')
100 # find and add the format
101 if xml.find('videoConfig') is not None:
102 info['ext'] = xml.find('videoConfig').find('type').text
104 info['ext'] = 'flv' # guess...
106 # work out the video URL(s)
107 if xml.find('videoLink') is not None:
108 # single format available
109 info['url'] = xpath_text(xml, 'videoLink', 'url', True)
111 # multiple formats available
114 for item in xml.find('quality').findall('item'):
115 resolution = xpath_text(item, 'res', 'resolution', True) # 480p etc.
116 info['formats'].append({
117 'url': xpath_text(item, 'videoLink', 'url', True),
118 'resolution': resolution,
119 'height': int(re.findall(r'\d+', resolution)[0])
122 self._sort_formats(info['formats'])