]>
Commit | Line | Data |
---|---|---|
8e71456a PH |
1 | #! -*- coding: utf-8 -*- |
2 | from __future__ import unicode_literals | |
3 | ||
8e71456a PH |
4 | import hashlib |
5 | ||
6 | from .common import InfoExtractor | |
1cc79574 | 7 | from ..compat import ( |
4231235c | 8 | compat_urllib_parse, |
8e71456a PH |
9 | compat_urllib_request, |
10 | compat_urlparse, | |
11 | ) | |
1cc79574 | 12 | from ..utils import ( |
cf83f532 | 13 | encode_dict, |
1cc79574 | 14 | ExtractorError, |
5c2266df | 15 | sanitized_Request, |
1cc79574 | 16 | ) |
8e71456a PH |
17 | |
18 | ||
19 | class FC2IE(InfoExtractor): | |
93462856 | 20 | _VALID_URL = r'^http://video\.fc2\.com/(?:[^/]+/)*content/(?P<id>[^/]+)' |
8e71456a | 21 | IE_NAME = 'fc2' |
4231235c | 22 | _NETRC_MACHINE = 'fc2' |
8940b860 | 23 | _TESTS = [{ |
8e71456a PH |
24 | 'url': 'http://video.fc2.com/en/content/20121103kUan1KHs', |
25 | 'md5': 'a6ebe8ebe0396518689d963774a54eb7', | |
26 | 'info_dict': { | |
27 | 'id': '20121103kUan1KHs', | |
28 | 'ext': 'flv', | |
29 | 'title': 'Boxing again with Puff', | |
30 | }, | |
8940b860 PH |
31 | }, { |
32 | 'url': 'http://video.fc2.com/en/content/20150125cEva0hDn/', | |
33 | 'info_dict': { | |
34 | 'id': '20150125cEva0hDn', | |
35 | 'ext': 'mp4', | |
36 | }, | |
37 | 'params': { | |
38 | 'username': 'ytdl@yt-dl.org', | |
39 | 'password': '(snip)', | |
38d05d17 YCH |
40 | }, |
41 | 'skip': 'requires actual password', | |
52dfb7ff S |
42 | }, { |
43 | 'url': 'http://video.fc2.com/en/a/content/20130926eZpARwsF', | |
44 | 'only_matching': True, | |
8940b860 | 45 | }] |
4231235c | 46 | |
47 | def _login(self): | |
48 | (username, password) = self._get_login_info() | |
8940b860 PH |
49 | if username is None or password is None: |
50 | return False | |
4231235c | 51 | |
52 | # Log in | |
53 | login_form_strs = { | |
8940b860 | 54 | 'email': username, |
4231235c | 55 | 'password': password, |
8940b860 PH |
56 | 'done': 'video', |
57 | 'Submit': ' Login ', | |
4231235c | 58 | } |
59 | ||
cf83f532 | 60 | login_data = compat_urllib_parse.urlencode(encode_dict(login_form_strs)).encode('utf-8') |
5c2266df | 61 | request = sanitized_Request( |
4231235c | 62 | 'https://secure.id.fc2.com/index.php?mode=login&switch_language=en', login_data) |
63 | ||
64 | login_results = self._download_webpage(request, None, note='Logging in', errnote='Unable to log in') | |
65 | if 'mode=redirect&login=done' not in login_results: | |
8940b860 | 66 | self.report_warning('unable to log in: bad username or password') |
4231235c | 67 | return False |
8940b860 | 68 | |
4231235c | 69 | # this is also needed |
5c2266df | 70 | login_redir = sanitized_Request('http://id.fc2.com/?mode=redirect&login=done') |
8940b860 PH |
71 | self._download_webpage( |
72 | login_redir, None, note='Login redirect', errnote='Login redirect failed') | |
4231235c | 73 | |
74 | return True | |
8e71456a PH |
75 | |
76 | def _real_extract(self, url): | |
1cc79574 | 77 | video_id = self._match_id(url) |
8940b860 | 78 | self._login() |
8e71456a PH |
79 | webpage = self._download_webpage(url, video_id) |
80 | self._downloader.cookiejar.clear_session_cookies() # must clear | |
4231235c | 81 | self._login() |
8e71456a PH |
82 | |
83 | title = self._og_search_title(webpage) | |
84 | thumbnail = self._og_search_thumbnail(webpage) | |
39955b04 | 85 | refer = url.replace('/content/', '/a/content/') if '/a/content/' not in url else url |
8e71456a | 86 | |
386ba39c | 87 | mimi = hashlib.md5((video_id + '_gGddgPfeaf_gzyr').encode('utf-8')).hexdigest() |
8e71456a PH |
88 | |
89 | info_url = ( | |
90 | "http://video.fc2.com/ginfo.php?mimi={1:s}&href={2:s}&v={0:s}&fversion=WIN%2011%2C6%2C602%2C180&from=2&otag=0&upid={0:s}&tk=null&". | |
c5864a8c | 91 | format(video_id, mimi, compat_urllib_request.quote(refer, safe=b'').replace('.', '%2E'))) |
8e71456a PH |
92 | |
93 | info_webpage = self._download_webpage( | |
94 | info_url, video_id, note='Downloading info page') | |
95 | info = compat_urlparse.parse_qs(info_webpage) | |
96 | ||
97 | if 'err_code' in info: | |
4231235c | 98 | # most of the time we can still download wideo even if err_code is 403 or 602 |
8940b860 PH |
99 | self.report_warning( |
100 | 'Error code was: %s... but still trying' % info['err_code'][0]) | |
40b1cbaf | 101 | |
4231235c | 102 | if 'filepath' not in info: |
8940b860 | 103 | raise ExtractorError('Cannot download file. Are you logged in?') |
8e71456a PH |
104 | |
105 | video_url = info['filepath'][0] + '?mid=' + info['mid'][0] | |
23ae281b PH |
106 | title_info = info.get('title') |
107 | if title_info: | |
108 | title = title_info[0] | |
8e71456a PH |
109 | |
110 | return { | |
111 | 'id': video_id, | |
23ae281b | 112 | 'title': title, |
8e71456a PH |
113 | 'url': video_url, |
114 | 'ext': 'flv', | |
115 | 'thumbnail': thumbnail, | |
116 | } |