1 #! -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
7 from .common import InfoExtractor
11 compat_urllib_request,
16 class FC2IE(InfoExtractor):
17 _VALID_URL = r'^http://video\.fc2\.com/((?P<lang>[^/]+)/)?(a/)?content/(?P<id>[^/]+)'
19 _NETRC_MACHINE = 'fc2'
21 'url': 'http://video.fc2.com/en/content/20121103kUan1KHs',
22 'md5': 'a6ebe8ebe0396518689d963774a54eb7',
24 'id': '20121103kUan1KHs',
26 'title': 'Boxing again with Puff',
30 #def _real_initialize(self):
34 (username, password) = self._get_login_info()
35 if (username is None) or (password is None):
36 self.to_screen('unable to log in: will be downloading in non authorized mode') # report_warning
47 # Convert to UTF-8 *before* urlencode because Python 2.x's urlencode
49 login_form = dict((k.encode('utf-8'), v.encode('utf-8')) for k, v in login_form_strs.items())
50 login_data = compat_urllib_parse.urlencode(login_form).encode('utf-8')
51 request = compat_urllib_request.Request(
52 'https://secure.id.fc2.com/index.php?mode=login&switch_language=en', login_data)
54 login_results = self._download_webpage(request, None, note='Logging in', errnote='Unable to log in')
55 if 'mode=redirect&login=done' not in login_results:
56 self.to_screen('unable to log in: bad username or password') # report_warning
60 login_redir = compat_urllib_request.Request('http://id.fc2.com/?mode=redirect&login=done')
61 redir_res = self._download_webpage(login_redir, None, note='Login redirect', errnote='Something is not right')
65 def _real_extract(self, url):
66 mobj = re.match(self._VALID_URL, url)
67 video_id = mobj.group('id')
69 webpage = self._download_webpage(url, video_id)
70 self._downloader.cookiejar.clear_session_cookies() # must clear
73 title = self._og_search_title(webpage)
74 thumbnail = self._og_search_thumbnail(webpage)
76 refer = (url if '/a/content/' in url else url.replace('/content/', '/a/content/'));
77 mimi = hashlib.md5((video_id + '_gGddgPfeaf_gzyr').encode('utf-8')).hexdigest()
80 "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&".
81 format(video_id, mimi, compat_urllib_request.quote(refer, safe='').replace('.','%2E')))
83 info_webpage = self._download_webpage(
84 info_url, video_id, note='Downloading info page')
85 info = compat_urlparse.parse_qs(info_webpage)
87 if 'err_code' in info:
88 #raise ExtractorError('Error code: %s' % info['err_code'][0])
89 # most of the time we can still download wideo even if err_code is 403 or 602
90 self.to_screen('Error code was: %s... but still trying' % info['err_code'][0]) # report_warning
92 if 'filepath' not in info:
93 raise ExtractorError('Cannot download file. Are you logged?')
95 video_url = info['filepath'][0] + '?mid=' + info['mid'][0]
96 title_info = info.get('title')
105 'thumbnail': thumbnail,