]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/kankan.py
Update changelog.
[youtubedl] / youtube_dl / extractor / kankan.py
1 import re
2 import hashlib
3
4 from .common import InfoExtractor
5 from ..utils import determine_ext
6
7 _md5 = lambda s: hashlib.md5(s.encode('utf-8')).hexdigest()
8
9 class KankanIE(InfoExtractor):
10 _VALID_URL = r'https?://(?:.*?\.)?kankan\.com/.+?/(?P<id>\d+)\.shtml'
11
12 _TEST = {
13 u'url': u'http://yinyue.kankan.com/vod/48/48863.shtml',
14 u'file': u'48863.flv',
15 u'md5': u'29aca1e47ae68fc28804aca89f29507e',
16 u'info_dict': {
17 u'title': u'Ready To Go',
18 },
19 }
20
21 def _real_extract(self, url):
22 mobj = re.match(self._VALID_URL, url)
23 video_id = mobj.group('id')
24 webpage = self._download_webpage(url, video_id)
25
26 title = self._search_regex(r'(?:G_TITLE=|G_MOVIE_TITLE = )[\'"](.+?)[\'"]', webpage, u'video title')
27 surls = re.search(r'surls:\[\'.+?\'\]|lurl:\'.+?\.flv\'', webpage).group(0)
28 gcids = re.findall(r"http://.+?/.+?/(.+?)/", surls)
29 gcid = gcids[-1]
30
31 video_info_page = self._download_webpage('http://p2s.cl.kankan.com/getCdnresource_flv?gcid=%s' % gcid,
32 video_id, u'Downloading video url info')
33 ip = self._search_regex(r'ip:"(.+?)"', video_info_page, u'video url ip')
34 path = self._search_regex(r'path:"(.+?)"', video_info_page, u'video url path')
35 param1 = self._search_regex(r'param1:(\d+)', video_info_page, u'param1')
36 param2 = self._search_regex(r'param2:(\d+)', video_info_page, u'param2')
37 key = _md5('xl_mp43651' + param1 + param2)
38 video_url = 'http://%s%s?key=%s&key1=%s' % (ip, path, key, param2)
39
40 return {'id': video_id,
41 'title': title,
42 'url': video_url,
43 'ext': determine_ext(video_url),
44 }