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