]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/fc2.py
81ceace53289709b93d7c647f6627197320381ef
[youtubedl] / youtube_dl / extractor / fc2.py
1 #! -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
3
4 import hashlib
5
6 from .common import InfoExtractor
7 from ..compat import (
8 compat_urllib_request,
9 compat_urlparse,
10 )
11 from ..utils import (
12 ExtractorError,
13 )
14
15
16 class FC2IE(InfoExtractor):
17 _VALID_URL = r'^http://video\.fc2\.com/(?:[^/]+/)?content/(?P<id>[^/]+)'
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):
30 video_id = self._match_id(url)
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
38 mimi = hashlib.md5((video_id + '_gGddgPfeaf_gzyr').encode('utf-8')).hexdigest()
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&".
42 format(video_id, mimi, compat_urllib_request.quote(refer, safe='').replace('.', '%2E')))
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]
52 title_info = info.get('title')
53 if title_info:
54 title = title_info[0]
55
56 return {
57 'id': video_id,
58 'title': title,
59 'url': video_url,
60 'ext': 'flv',
61 'thumbnail': thumbnail,
62 }