aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/extractor/kankan.py
blob: 445d465017f513b55839ed9323c95212e6de7fb7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import re

from .common import InfoExtractor
from ..utils import determine_ext


class KankanIE(InfoExtractor):
    _VALID_URL = r'https?://(?:.*?\.)?kankan\.com/.+?/(?P<id>\d+)\.shtml'
    
    _TEST = {
        u'url': u'http://yinyue.kankan.com/vod/48/48863.shtml',
        u'file': u'48863.flv',
        u'md5': u'29aca1e47ae68fc28804aca89f29507e',
        u'info_dict': {
            u'title': u'Ready To Go',
        },
    }

    def _real_extract(self, url):
        mobj = re.match(self._VALID_URL, url)
        video_id = mobj.group('id')
        webpage = self._download_webpage(url, video_id)

        title = self._search_regex(r'(?:G_TITLE=|G_MOVIE_TITLE = )[\'"](.+?)[\'"]', webpage, u'video title')
        surls = re.search(r'surls:\[\'.+?\'\]|lurl:\'.+?\.flv\'', webpage).group(0)
        gcids = re.findall(r"http://.+?/.+?/(.+?)/", surls)
        gcid = gcids[-1]

        video_info_page = self._download_webpage('http://p2s.cl.kankan.com/getCdnresource_flv?gcid=%s' % gcid,
                                                 video_id, u'Downloading video url info')
        ip = self._search_regex(r'ip:"(.+?)"', video_info_page, u'video url ip')
        path = self._search_regex(r'path:"(.+?)"', video_info_page, u'video url path')
        video_url = 'http://%s%s' % (ip, path)

        return {'id': video_id,
                'title': title,
                'url': video_url,
                'ext': determine_ext(video_url),
                }