]> gitweb @ CieloNegro.org - youtube-dl.git/blob - youtube_dl/extractor/moviefap.py
[moviefap] Remove redundant comments
[youtube-dl.git] / youtube_dl / extractor / moviefap.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import str_to_int
7
8
9 class MovieFapIE(InfoExtractor):
10     _VALID_URL = r'https?://(?:www\.)?moviefap\.com/videos/(?P<id>[0-9a-f]+)/(?P<name>[a-z-_]+)'
11     _TESTS = [{
12         # normal, multi-format video
13         'url': 'http://www.moviefap.com/videos/be9867c9416c19f54a4a/experienced-milf-amazing-handjob.html',
14         'md5': '26624b4e2523051b550067d547615906',
15         'info_dict': {
16             'id': 'be9867c9416c19f54a4a',
17             'ext': 'mp4',
18             'title': 'Experienced MILF Amazing Handjob',
19             'description': 'Experienced MILF giving an Amazing Handjob',
20             'thumbnail': 'http://img.moviefap.com/a16:9w990r/thumbs/be/322032-20l.jpg',
21             'uploader_id': 'darvinfred06',
22             'display_id': 'experienced-milf-amazing-handjob',
23             'categories': ['Amateur', 'Masturbation', 'Mature', 'Flashing']
24         }
25     }, {
26         # quirky single-format case where the extension is given as fid, but the video is really an flv
27         'url': 'http://www.moviefap.com/videos/e5da0d3edce5404418f5/jeune-couple-russe.html',
28         'md5': 'fa56683e291fc80635907168a743c9ad',
29         'info_dict': {
30             'id': 'e5da0d3edce5404418f5',
31             'ext': 'flv',
32             'title': 'Jeune Couple Russe',
33             'description': 'Amateur',
34             'thumbnail': 'http://pic.moviefap.com/thumbs/e5/949-18l.jpg',
35             'uploader_id': 'whiskeyjar',
36             'display_id': 'jeune-couple-russe',
37             'categories': ['Amateur', 'Teen']
38         }
39     }]
40
41     @staticmethod
42     def __get_thumbnail_data(xml):
43
44         """
45         Constructs a list of video thumbnails from timeline preview images.
46         :param xml: the information XML document to parse
47         """
48
49         timeline = xml.find('timeline')
50         if timeline is None:
51             # not all videos have the data - ah well
52             return []
53
54         # get the required information from the XML
55         width = str_to_int(timeline.find('imageWidth').text)
56         height = str_to_int(timeline.find('imageHeight').text)
57         first = str_to_int(timeline.find('imageFirst').text)
58         last = str_to_int(timeline.find('imageLast').text)
59         pattern = timeline.find('imagePattern').text
60
61         # generate the list of thumbnail information dicts
62         thumbnails = []
63         for i in range(first, last + 1):
64             thumbnails.append({
65                 'url': pattern.replace('#', str(i)),
66                 'width': width,
67                 'height': height
68             })
69         return thumbnails
70
71     def _real_extract(self, url):
72
73         video_id = self._match_id(url)
74         webpage = self._download_webpage(url, video_id)
75
76         # find and retrieve the XML document detailing video download URLs
77         info_url = self._html_search_regex(r'flashvars\.config = escape\("(.+?)"', webpage, 'player parameters')
78         xml = self._download_xml(info_url, video_id)
79
80         info = {
81             'id': video_id,
82             'title': self._html_search_regex(r'<div id="view_title"><h1>(.*?)</h1>', webpage, 'title'),
83             'display_id': re.compile(self._VALID_URL).match(url).group('name'),
84             'thumbnails': self.__get_thumbnail_data(xml),
85             'thumbnail': xml.find('startThumb').text,
86             'description': self._html_search_regex(r'name="description" value="(.*?)"', webpage, 'description', fatal=False),
87             'uploader_id': self._html_search_regex(r'name="username" value="(.*?)"', webpage, 'uploader_id', fatal=False),
88             'view_count': str_to_int(self._html_search_regex(r'<br>Views <strong>([0-9]+)</strong>', webpage, 'view_count, fatal=False')),
89             'average_rating': float(self._html_search_regex(r'Current Rating<br> <strong>(.*?)</strong>', webpage, 'average_rating', fatal=False)),
90             'comment_count': str_to_int(self._html_search_regex(r'<span id="comCount">([0-9]+)</span>', webpage, 'comment_count', fatal=False)),
91             'age_limit': 18,
92             'webpage_url': self._html_search_regex(r'name="link" value="(.*?)"', webpage, 'webpage_url', fatal=False),
93             'categories': self._html_search_regex(r'</div>\s*(.*?)\s*<br>', webpage, 'categories', fatal=False).split(', ')
94         }
95
96         # find and add the format
97         if xml.find('videoConfig') is not None:
98             info['ext'] = xml.find('videoConfig').find('type').text
99         else:
100             info['ext'] = 'flv'  # guess...
101
102         # work out the video URL(s)
103         if xml.find('videoLink') is not None:
104             # single format available
105             info['url'] = xml.find('videoLink').text
106         else:
107             # multiple formats available
108             info['formats'] = []
109
110             # N.B. formats are already in ascending order of quality
111             for item in xml.find('quality').findall('item'):
112                 info['formats'].append({
113                     'url': item.find('videoLink').text,
114                     'resolution': item.find('res').text  # 480p etc.
115                 })
116
117         return info