Merge branch 'varzesh3' of https://github.com/mtp1376/youtube-dl into mtp1376-varzesh3
[youtube-dl] / youtube_dl / extractor / eroprofile.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..compat import compat_urllib_parse
7 from ..utils import ExtractorError
8
9
10 class EroProfileIE(InfoExtractor):
11     _VALID_URL = r'https?://(?:www\.)?eroprofile\.com/m/videos/view/(?P<id>[^/]+)'
12     _LOGIN_URL = 'http://www.eroprofile.com/auth/auth.php?'
13     _NETRC_MACHINE = 'eroprofile'
14     _TESTS = [{
15         'url': 'http://www.eroprofile.com/m/videos/view/sexy-babe-softcore',
16         'md5': 'c26f351332edf23e1ea28ce9ec9de32f',
17         'info_dict': {
18             'id': '3733775',
19             'display_id': 'sexy-babe-softcore',
20             'ext': 'm4v',
21             'title': 'sexy babe softcore',
22             'thumbnail': 're:https?://.*\.jpg',
23             'age_limit': 18,
24         }
25     }, {
26         'url': 'http://www.eroprofile.com/m/videos/view/Try-It-On-Pee_cut_2-wmv-4shared-com-file-sharing-download-movie-file',
27         'md5': '1baa9602ede46ce904c431f5418d8916',
28         'info_dict': {
29             'id': '1133519',
30             'ext': 'm4v',
31             'title': 'Try It On Pee_cut_2.wmv - 4shared.com - file sharing - download movie file',
32             'thumbnail': 're:https?://.*\.jpg',
33             'age_limit': 18,
34         },
35         'skip': 'Requires login',
36     }]
37
38     def _login(self):
39         (username, password) = self._get_login_info()
40         if username is None:
41             return
42
43         query = compat_urllib_parse.urlencode({
44             'username': username,
45             'password': password,
46             'url': 'http://www.eroprofile.com/',
47         })
48         login_url = self._LOGIN_URL + query
49         login_page = self._download_webpage(login_url, None, False)
50
51         m = re.search(r'Your username or password was incorrect\.', login_page)
52         if m:
53             raise ExtractorError(
54                 'Wrong username and/or password.', expected=True)
55
56         self.report_login()
57         redirect_url = self._search_regex(
58             r'<script[^>]+?src="([^"]+)"', login_page, 'login redirect url')
59         self._download_webpage(redirect_url, None, False)
60
61     def _real_initialize(self):
62         self._login()
63
64     def _real_extract(self, url):
65         display_id = self._match_id(url)
66
67         webpage = self._download_webpage(url, display_id)
68
69         m = re.search(r'You must be logged in to view this video\.', webpage)
70         if m:
71             raise ExtractorError(
72                 'This video requires login. Please specify a username and password and try again.', expected=True)
73
74         video_id = self._search_regex(
75             [r"glbUpdViews\s*\('\d*','(\d+)'", r'p/report/video/(\d+)'],
76             webpage, 'video id', default=None)
77
78         video_url = self._search_regex(
79             r'<source src="([^"]+)', webpage, 'video url')
80         title = self._html_search_regex(
81             r'Title:</th><td>([^<]+)</td>', webpage, 'title')
82         thumbnail = self._search_regex(
83             r'onclick="showVideoPlayer\(\)"><img src="([^"]+)',
84             webpage, 'thumbnail', fatal=False)
85
86         return {
87             'id': video_id,
88             'display_id': display_id,
89             'url': video_url,
90             'title': title,
91             'thumbnail': thumbnail,
92             'age_limit': 18,
93         }