]>
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 ( |
8e71456a PH |
8 | compat_urllib_request, |
9 | compat_urlparse, | |
10 | ) | |
1cc79574 PH |
11 | from ..utils import ( |
12 | ExtractorError, | |
13 | ) | |
8e71456a PH |
14 | |
15 | ||
16 | class FC2IE(InfoExtractor): | |
1cc79574 | 17 | _VALID_URL = r'^http://video\.fc2\.com/(?:[^/]+/)?content/(?P<id>[^/]+)' |
8e71456a PH |
18 | IE_NAME = 'fc2' |
19 | _TEST = { | |
20 | 'url': 'http://video.fc2.com/en/content/20121103kUan1KHs', | |
21 | 'md5': 'a6ebe8ebe0396518689d963774a54eb7', | |
22 | 'info_dict': { | |
23 | 'id': '20121103kUan1KHs', | |
24 | 'ext': 'flv', | |
25 | 'title': 'Boxing again with Puff', | |
26 | }, | |
27 | } | |
28 | ||
29 | def _real_extract(self, url): | |
1cc79574 | 30 | video_id = self._match_id(url) |
8e71456a PH |
31 | webpage = self._download_webpage(url, video_id) |
32 | self._downloader.cookiejar.clear_session_cookies() # must clear | |
33 | ||
34 | title = self._og_search_title(webpage) | |
35 | thumbnail = self._og_search_thumbnail(webpage) | |
36 | refer = url.replace('/content/', '/a/content/') | |
37 | ||
386ba39c | 38 | mimi = hashlib.md5((video_id + '_gGddgPfeaf_gzyr').encode('utf-8')).hexdigest() |
8e71456a PH |
39 | |
40 | info_url = ( | |
41 | "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&". | |
5f6a1245 | 42 | format(video_id, mimi, compat_urllib_request.quote(refer, safe='').replace('.', '%2E'))) |
8e71456a PH |
43 | |
44 | info_webpage = self._download_webpage( | |
45 | info_url, video_id, note='Downloading info page') | |
46 | info = compat_urlparse.parse_qs(info_webpage) | |
47 | ||
48 | if 'err_code' in info: | |
49 | raise ExtractorError('Error code: %s' % info['err_code'][0]) | |
50 | ||
51 | video_url = info['filepath'][0] + '?mid=' + info['mid'][0] | |
23ae281b PH |
52 | title_info = info.get('title') |
53 | if title_info: | |
54 | title = title_info[0] | |
8e71456a PH |
55 | |
56 | return { | |
57 | 'id': video_id, | |
23ae281b | 58 | 'title': title, |
8e71456a PH |
59 | 'url': video_url, |
60 | 'ext': 'flv', | |
61 | 'thumbnail': thumbnail, | |
62 | } |