You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.7 KiB

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