]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/fc2.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
19 class FC2IE(InfoExtractor
):
20 _VALID_URL
= r
'^(?:https?://video\.fc2\.com/(?:[^/]+/)*content/|fc2:)(?P<id>[^/]+)'
22 _NETRC_MACHINE
= 'fc2'
24 'url': 'http://video.fc2.com/en/content/20121103kUan1KHs',
25 'md5': 'a6ebe8ebe0396518689d963774a54eb7',
27 'id': '20121103kUan1KHs',
29 'title': 'Boxing again with Puff',
32 'url': 'http://video.fc2.com/en/content/20150125cEva0hDn/',
34 'id': '20150125cEva0hDn',
38 'username': 'ytdl@yt-dl.org',
41 'skip': 'requires actual password',
43 'url': 'http://video.fc2.com/en/a/content/20130926eZpARwsF',
44 'only_matching': True,
48 username
, password
= self
._get
_login
_info
()
49 if username
is None or password
is None:
60 login_data
= urlencode_postdata(login_form_strs
)
61 request
= sanitized_Request(
62 'https://secure.id.fc2.com/index.php?mode=login&switch_language=en', login_data
)
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
:
66 self
.report_warning('unable to log in: bad username or password')
70 login_redir
= sanitized_Request('http://id.fc2.com/?mode=redirect&login=done')
71 self
._download
_webpage
(
72 login_redir
, None, note
='Login redirect', errnote
='Login redirect failed')
76 def _real_extract(self
, url
):
77 video_id
= self
._match
_id
(url
)
80 if not url
.startswith('fc2:'):
81 webpage
= self
._download
_webpage
(url
, video_id
)
82 self
._downloader
.cookiejar
.clear_session_cookies() # must clear
85 title
= 'FC2 video %s' % video_id
87 if webpage
is not None:
88 title
= self
._og
_search
_title
(webpage
)
89 thumbnail
= self
._og
_search
_thumbnail
(webpage
)
90 refer
= url
.replace('/content/', '/a/content/') if '/a/content/' not in url
else url
92 mimi
= hashlib
.md5((video_id
+ '_gGddgPfeaf_gzyr').encode('utf-8')).hexdigest()
95 '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&'.
96 format(video_id
, mimi
, compat_urllib_request
.quote(refer
, safe
=b
'').replace('.', '%2E')))
98 info_webpage
= self
._download
_webpage
(
99 info_url
, video_id
, note
='Downloading info page')
100 info
= compat_urlparse
.parse_qs(info_webpage
)
102 if 'err_code' in info
:
103 # most of the time we can still download wideo even if err_code is 403 or 602
105 'Error code was: %s... but still trying' % info
['err_code'][0])
107 if 'filepath' not in info
:
108 raise ExtractorError('Cannot download file. Are you logged in?')
110 video_url
= info
['filepath'][0] + '?mid=' + info
['mid'][0]
111 title_info
= info
.get('title')
113 title
= title_info
[0]
120 'thumbnail': thumbnail
,
124 class FC2EmbedIE(InfoExtractor
):
125 _VALID_URL
= r
'https?://video\.fc2\.com/flv2\.swf\?(?P<query>.+)'
126 IE_NAME
= 'fc2:embed'
129 'url': 'http://video.fc2.com/flv2.swf?t=201404182936758512407645&i=20130316kwishtfitaknmcgd76kjd864hso93htfjcnaogz629mcgfs6rbfk0hsycma7shkf85937cbchfygd74&i=201403223kCqB3Ez&d=2625&sj=11&lang=ja&rel=1&from=11&cmt=1&tk=TlRBM09EQTNNekU9&tl=プリズン・ブレイク%20S1-01%20マイケル%20【吹替】',
130 'md5': 'b8aae5334cb691bdb1193a88a6ab5d5a',
132 'id': '201403223kCqB3Ez',
134 'title': 'プリズン・ブレイク S1-01 マイケル 【吹替】',
135 'thumbnail': r
're:^https?://.*\.jpg$',
139 def _real_extract(self
, url
):
140 mobj
= self
._match
_valid
_url
(url
)
141 query
= compat_parse_qs(mobj
.group('query'))
143 video_id
= query
['i'][-1]
144 title
= query
.get('tl', ['FC2 video %s' % video_id
])[0]
146 sj
= query
.get('sj', [None])[0]
149 # See thumbnailImagePath() in ServerConst.as of flv2.swf
150 thumbnail
= 'http://video%s-thumbnail.fc2.com/up/pic/%s.jpg' % (
151 sj
, '/'.join((video_id
[:6], video_id
[6:8], video_id
[-2], video_id
[-1], video_id
)))
154 '_type': 'url_transparent',
155 'ie_key': FC2IE
.ie_key(),
156 'url': 'fc2:%s' % video_id
,
158 'thumbnail': thumbnail
,