[youtube] Fix extraction.
[youtube-dl] / youtube_dl / extractor / mofosex.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7     int_or_none,
8     str_to_int,
9     unified_strdate,
10 )
11 from .keezmovies import KeezMoviesIE
12
13
14 class MofosexIE(KeezMoviesIE):
15     _VALID_URL = r'https?://(?:www\.)?mofosex\.com/videos/(?P<id>\d+)/(?P<display_id>[^/?#&.]+)\.html'
16     _TESTS = [{
17         'url': 'http://www.mofosex.com/videos/318131/amateur-teen-playing-and-masturbating-318131.html',
18         'md5': '558fcdafbb63a87c019218d6e49daf8a',
19         'info_dict': {
20             'id': '318131',
21             'display_id': 'amateur-teen-playing-and-masturbating-318131',
22             'ext': 'mp4',
23             'title': 'amateur teen playing and masturbating',
24             'thumbnail': r're:^https?://.*\.jpg$',
25             'upload_date': '20121114',
26             'view_count': int,
27             'like_count': int,
28             'dislike_count': int,
29             'age_limit': 18,
30         }
31     }, {
32         # This video is no longer available
33         'url': 'http://www.mofosex.com/videos/5018/japanese-teen-music-video.html',
34         'only_matching': True,
35     }]
36
37     def _real_extract(self, url):
38         webpage, info = self._extract_info(url)
39
40         view_count = str_to_int(self._search_regex(
41             r'VIEWS:</span>\s*([\d,.]+)', webpage, 'view count', fatal=False))
42         like_count = int_or_none(self._search_regex(
43             r'id=["\']amountLikes["\'][^>]*>(\d+)', webpage,
44             'like count', fatal=False))
45         dislike_count = int_or_none(self._search_regex(
46             r'id=["\']amountDislikes["\'][^>]*>(\d+)', webpage,
47             'like count', fatal=False))
48         upload_date = unified_strdate(self._html_search_regex(
49             r'Added:</span>([^<]+)', webpage, 'upload date', fatal=False))
50
51         info.update({
52             'view_count': view_count,
53             'like_count': like_count,
54             'dislike_count': dislike_count,
55             'upload_date': upload_date,
56             'thumbnail': self._og_search_thumbnail(webpage),
57         })
58
59         return info
60
61
62 class MofosexEmbedIE(InfoExtractor):
63     _VALID_URL = r'https?://(?:www\.)?mofosex\.com/embed/?\?.*?\bvideoid=(?P<id>\d+)'
64     _TESTS = [{
65         'url': 'https://www.mofosex.com/embed/?videoid=318131&referrer=KM',
66         'only_matching': True,
67     }]
68
69     @staticmethod
70     def _extract_urls(webpage):
71         return re.findall(
72             r'<iframe[^>]+\bsrc=["\']((?:https?:)?//(?:www\.)?mofosex\.com/embed/?\?.*?\bvideoid=\d+)',
73             webpage)
74
75     def _real_extract(self, url):
76         video_id = self._match_id(url)
77         return self.url_result(
78             'http://www.mofosex.com/videos/{0}/{0}.html'.format(video_id),
79             ie=MofosexIE.ie_key(), video_id=video_id)