]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/kankan.py
debian/NEWS: Add link to my webpage to give more details.
[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 'file': '48863.flv',
17 'md5': '29aca1e47ae68fc28804aca89f29507e',
18 'info_dict': {
19 'title': 'Ready To Go',
20 },
21 'skip': 'Only available from China',
22 }
23
24 def _real_extract(self, url):
25 mobj = re.match(self._VALID_URL, url)
26 video_id = mobj.group('id')
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 }