1c652813adb96b994c3ba517db994805e8ea8eb3
[youtube-dl] / youtube_dl / extractor / mofosex.py
1 from __future__ import unicode_literals
2
3 from ..utils import (
4     int_or_none,
5     str_to_int,
6     unified_strdate,
7 )
8 from .keezmovies import KeezMoviesIE
9
10
11 class MofosexIE(KeezMoviesIE):
12     _VALID_URL = r'https?://(?:www\.)?mofosex\.com/videos/(?P<id>\d+)/(?P<display_id>[^/?#&.]+)\.html'
13     _TESTS = [{
14         'url': 'http://www.mofosex.com/videos/318131/amateur-teen-playing-and-masturbating-318131.html',
15         'md5': '558fcdafbb63a87c019218d6e49daf8a',
16         'info_dict': {
17             'id': '318131',
18             'display_id': 'amateur-teen-playing-and-masturbating-318131',
19             'ext': 'mp4',
20             'title': 'amateur teen playing and masturbating',
21             'thumbnail': r're:^https?://.*\.jpg$',
22             'upload_date': '20121114',
23             'view_count': int,
24             'like_count': int,
25             'dislike_count': int,
26             'age_limit': 18,
27         }
28     }, {
29         # This video is no longer available
30         'url': 'http://www.mofosex.com/videos/5018/japanese-teen-music-video.html',
31         'only_matching': True,
32     }]
33
34     def _real_extract(self, url):
35         webpage, info = self._extract_info(url)
36
37         view_count = str_to_int(self._search_regex(
38             r'VIEWS:</span>\s*([\d,.]+)', webpage, 'view count', fatal=False))
39         like_count = int_or_none(self._search_regex(
40             r'id=["\']amountLikes["\'][^>]*>(\d+)', webpage,
41             'like count', fatal=False))
42         dislike_count = int_or_none(self._search_regex(
43             r'id=["\']amountDislikes["\'][^>]*>(\d+)', webpage,
44             'like count', fatal=False))
45         upload_date = unified_strdate(self._html_search_regex(
46             r'Added:</span>([^<]+)', webpage, 'upload date', fatal=False))
47
48         info.update({
49             'view_count': view_count,
50             'like_count': like_count,
51             'dislike_count': dislike_count,
52             'upload_date': upload_date,
53             'thumbnail': self._og_search_thumbnail(webpage),
54         })
55
56         return info