[Motherless] Add new extractor
[youtube-dl] / youtube_dl / extractor / motherless.py
1 from __future__ import unicode_literals
2
3 import datetime
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import str_to_int
8
9
10 class MotherlessIE(InfoExtractor):
11     """Information Extractor for Motherless"""
12     _VALID_URL = r'http://(?:www\.)?motherless\.com/(?P<id>[A-Z0-9]+)'
13     _TESTS = [
14         {
15             'url': 'http://motherless.com/AC3FFE1',
16             'md5': '5527fef81d2e529215dad3c2d744a7d9',
17             'info_dict': {
18                 'id': 'AC3FFE1',
19                 'ext': 'flv',
20                 'title': 'Fucked in the ass while playing PS3',
21                 'categories': ['Gaming', 'anal', 'reluctant', 'rough', 'Wife'],
22                 'upload_date': '20100913',
23                 'uploader_id': 'famouslyfuckedup',
24                 'thumbnail': 'http://thumbs.motherlessmedia.com/thumbs/AC3FFE1.jpg',
25                 'age_limit': 18,
26             }
27         },
28         {
29             'url': 'http://motherless.com/532291B',
30             'md5': 'bc59a6b47d1f958e61fbd38a4d31b131',
31             'info_dict': {
32                 'id': '532291B',
33                 'ext': 'mp4',
34                 'title': 'Amazing girl playing the omegle game, PERFECT!',
35                 'categories': ['Amateur', 'webcam', 'omegle', 'pink', 'young', 'masturbate', 'teen', 'game', 'hairy'],
36                 'upload_date': '20140622',
37                 'uploader_id': 'Sulivana7x',
38                 'thumbnail': 'http://thumbs.motherlessmedia.com/thumbs/532291B.jpg',
39                 'age_limit': 18,
40             }
41         }
42     ]
43
44     def _real_extract(self,url):
45         mobj = re.match(self._VALID_URL, url)
46         video_id = mobj.group('id')
47
48         webpage = self._download_webpage(url, video_id)
49
50         title = self._html_search_regex(r'<title>(?P<title>.+?) - MOTHERLESS.COM</title>', webpage, 'title')
51         video_url = self._search_regex(r"__fileurl = '(?P<video_url>[^']+)'", webpage, 'video_url')
52         thumbnail = self._og_search_thumbnail(webpage)
53         age_limit = self._rta_search(webpage)  # Hint: it's 18 ;)
54         view_count = str_to_int(self._html_search_regex(r'<strong>Views</strong>(.+?)</h2>', webpage,
55                                                         'view_count', flags=re.DOTALL))
56
57         like_count = str_to_int(self._html_search_regex(r'<strong>Favorited</strong>(.+?)</h2>', webpage,
58                                                         'like_count', flags=re.DOTALL))
59         comment_count = webpage.count('class="media-comment-contents"')
60         uploader_id = self._html_search_regex(r'<div class="thumb-member-username">.*?<a [^>]*>(.+?)</a>',
61                                               webpage, 'uploader_id', flags=re.DOTALL)
62
63         categories = self._html_search_meta('keywords', webpage)
64         if categories is not None:
65             categories = [cat.strip() for cat in categories.split(',')]
66
67         upload_date = self._html_search_regex(r'<strong>Uploaded</strong>(.+?)</h2>', webpage,
68                                               'upload_date', flags=re.DOTALL)
69         mobj = re.search(r'(\d+) days? ago', upload_date, re.I)
70         if mobj is not None:
71             upload_date = datetime.datetime.now() - datetime.timedelta(days=int(mobj.group(1)))
72         else:
73             mobj = re.search(r'(\w+) (\d+)\w* (\d+)', upload_date, re.I)
74             if mobj is not None:
75                 upload_date = datetime.datetime.strptime('%s %s %s' % mobj.groups(), '%b %d %Y').date()
76             else:
77                 upload_date = None
78         if upload_date is not None:
79             upload_date = upload_date.strftime('%Y%m%d')
80
81         return {
82             'id': video_id,
83             'title': title,
84             'upload_date': upload_date,
85             'uploader_id': uploader_id,
86             'thumbnail': thumbnail,
87             'categories': categories,
88             'view_count': view_count,
89             'like_count': like_count,
90             'comment_count': comment_count,
91             'age_limit': age_limit,
92             'url': video_url,
93         }