]> gitweb @ CieloNegro.org - youtube-dl.git/blob - youtube_dl/extractor/moviefap.py
1985c53c00682524b07e9bdcb0fec515e9be81dc
[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         # find the video ID
74         video_id = self._match_id(url)
75
76         # retrieve the page HTML
77         webpage = self._download_webpage(url, video_id)
78
79         # find the URL of the XML document detailing video download URLs
80         info_url = self._html_search_regex(r'flashvars\.config = escape\("(.+?)"', webpage, 'player parameters')
81
82         # download that XML
83         xml = self._download_xml(info_url, video_id)
84
85         # create dictionary of properties we know so far, or can find easily
86         info = {
87             'id': video_id,
88             'title': self._html_search_regex(r'<div id="view_title"><h1>(.*?)</h1>', webpage, 'title'),
89             'display_id': re.compile(self._VALID_URL).match(url).group('name'),
90             'thumbnails': self.__get_thumbnail_data(xml),
91             'thumbnail': xml.find('startThumb').text,
92             'description': self._html_search_regex(r'name="description" value="(.*?)"', webpage, 'description'),
93             'uploader_id': self._html_search_regex(r'name="username" value="(.*?)"', webpage, 'uploader_id'),
94             'view_count': str_to_int(self._html_search_regex(r'<br>Views <strong>([0-9]+)</strong>', webpage, 'view_count')),
95             'average_rating': float(self._html_search_regex(r'Current Rating<br> <strong>(.*?)</strong>', webpage, 'average_rating')),
96             'comment_count': str_to_int(self._html_search_regex(r'<span id="comCount">([0-9]+)</span>', webpage, 'comment_count')),
97             'age_limit': 18,
98             'webpage_url': self._html_search_regex(r'name="link" value="(.*?)"', webpage, 'webpage_url'),
99             'categories': self._html_search_regex(r'</div>\s*(.*?)\s*<br>', webpage, 'categories').split(', ')
100         }
101
102         # find and add the format
103         if xml.find('videoConfig') is not None:
104             info['ext'] = xml.find('videoConfig').find('type').text
105         else:
106             info['ext'] = 'flv'  # guess...
107
108         # work out the video URL(s)
109         if xml.find('videoLink') is not None:
110             # single format available
111             info['url'] = xml.find('videoLink').text
112         else:
113             # multiple formats available
114             info['formats'] = []
115
116             # N.B. formats are already in ascending order of quality
117             for item in xml.find('quality').findall('item'):
118                 info['formats'].append({
119                     'url': item.find('videoLink').text,
120                     'resolution': item.find('res').text  # 480p etc.
121                 })
122
123         return info