]>
jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/fc2.py
1 #! -*- coding: utf-8 -*-
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
17 class FC2IE(InfoExtractor
):
18 _VALID_URL
= r
'^http://video\.fc2\.com/(?:[^/]+/)*content/(?P<id>[^/]+)'
20 _NETRC_MACHINE
= 'fc2'
22 'url': 'http://video.fc2.com/en/content/20121103kUan1KHs',
23 'md5': 'a6ebe8ebe0396518689d963774a54eb7',
25 'id': '20121103kUan1KHs',
27 'title': 'Boxing again with Puff',
30 'url': 'http://video.fc2.com/en/content/20150125cEva0hDn/',
32 'id': '20150125cEva0hDn',
36 'username': 'ytdl@yt-dl.org',
38 'skip': 'requires actual password'
41 'url': 'http://video.fc2.com/en/a/content/20130926eZpARwsF',
42 'only_matching': True,
46 (username
, password
) = self
._get
_login
_info
()
47 if username
is None or password
is None:
58 # Convert to UTF-8 *before* urlencode because Python 2.x's urlencode
60 login_form
= dict((k
.encode('utf-8'), v
.encode('utf-8')) for k
, v
in login_form_strs
.items())
61 login_data
= compat_urllib_parse
.urlencode(login_form
).encode('utf-8')
62 request
= compat_urllib_request
.Request(
63 'https://secure.id.fc2.com/index.php?mode=login&switch_language=en', login_data
)
65 login_results
= self
._download
_webpage
(request
, None, note
='Logging in', errnote
='Unable to log in')
66 if 'mode=redirect&login=done' not in login_results
:
67 self
.report_warning('unable to log in: bad username or password')
71 login_redir
= compat_urllib_request
.Request('http://id.fc2.com/?mode=redirect&login=done')
72 self
._download
_webpage
(
73 login_redir
, None, note
='Login redirect', errnote
='Login redirect failed')
77 def _real_extract(self
, url
):
78 video_id
= self
._match
_id
(url
)
80 webpage
= self
._download
_webpage
(url
, video_id
)
81 self
._downloader
.cookiejar
.clear_session_cookies() # must clear
84 title
= self
._og
_search
_title
(webpage
)
85 thumbnail
= self
._og
_search
_thumbnail
(webpage
)
86 refer
= url
.replace('/content/', '/a/content/')
88 mimi
= hashlib
.md5((video_id
+ '_gGddgPfeaf_gzyr').encode('utf-8')).hexdigest()
91 "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&".
92 format(video_id
, mimi
, compat_urllib_request
.quote(refer
, safe
=b
'').replace('.', '%2E')))
94 info_webpage
= self
._download
_webpage
(
95 info_url
, video_id
, note
='Downloading info page')
96 info
= compat_urlparse
.parse_qs(info_webpage
)
98 if 'err_code' in info
:
99 # most of the time we can still download wideo even if err_code is 403 or 602
101 'Error code was: %s... but still trying' % info
['err_code'][0])
103 if 'filepath' not in info
:
104 raise ExtractorError('Cannot download file. Are you logged in?')
106 video_url
= info
['filepath'][0] + '?mid=' + info
['mid'][0]
107 title_info
= info
.get('title')
109 title
= title_info
[0]
116 'thumbnail': thumbnail
,