]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/kankan.py
[xhamster] use determine_ext
[youtube-dl] / youtube_dl / extractor / kankan.py
1 import re
2
3 from .common import InfoExtractor
4 from ..utils import determine_ext
5
6
7 class KankanIE(InfoExtractor):
8     _VALID_URL = r'https?://(?:.*?\.)?kankan\.com/.+?/(?P<id>\d+)\.shtml'
9     
10     _TEST = {
11         u'url': u'http://yinyue.kankan.com/vod/48/48863.shtml',
12         u'file': u'48863.flv',
13         u'md5': u'29aca1e47ae68fc28804aca89f29507e',
14         u'info_dict': {
15             u'title': u'Ready To Go',
16         },
17     }
18
19     def _real_extract(self, url):
20         mobj = re.match(self._VALID_URL, url)
21         video_id = mobj.group('id')
22         webpage = self._download_webpage(url, video_id)
23
24         title = self._search_regex(r'G_TITLE=[\'"](.+?)[\'"]', webpage, u'video title')
25         gcid = self._search_regex(r'lurl:[\'"]http://.+?/.+?/(.+?)/', webpage, u'gcid')
26
27         video_info_page = self._download_webpage('http://p2s.cl.kankan.com/getCdnresource_flv?gcid=%s' % gcid,
28                                                  video_id, u'Downloading video url info')
29         ip = self._search_regex(r'ip:"(.+?)"', video_info_page, u'video url ip')
30         path = self._search_regex(r'path:"(.+?)"', video_info_page, u'video url path')
31         video_url = 'http://%s%s' % (ip, path)
32
33         return {'id': video_id,
34                 'title': title,
35                 'url': video_url,
36                 'ext': determine_ext(video_url),
37                 }