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