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