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.

53 lines
1.8 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import float_or_none
  6. class CCTVIE(InfoExtractor):
  7. _VALID_URL = r'''(?x)https?://(?:.+?\.)?
  8. (?:
  9. cctv\.(?:com|cn)|
  10. cntv\.cn
  11. )/
  12. (?:
  13. video/[^/]+/(?P<id>[0-9a-f]{32})|
  14. \d{4}/\d{2}/\d{2}/(?P<display_id>VID[0-9A-Za-z]+)
  15. )'''
  16. _TESTS = [{
  17. 'url': 'http://english.cntv.cn/2016/09/03/VIDEhnkB5y9AgHyIEVphCEz1160903.shtml',
  18. 'md5': '819c7b49fc3927d529fb4cd555621823',
  19. 'info_dict': {
  20. 'id': '454368eb19ad44a1925bf1eb96140a61',
  21. 'ext': 'mp4',
  22. 'title': 'Portrait of Real Current Life 09/03/2016 Modern Inventors Part 1',
  23. }
  24. }, {
  25. 'url': 'http://tv.cctv.com/2016/09/07/VIDE5C1FnlX5bUywlrjhxXOV160907.shtml',
  26. 'only_matching': True,
  27. }, {
  28. 'url': 'http://tv.cntv.cn/video/C39296/95cfac44cabd3ddc4a9438780a4e5c44',
  29. 'only_matching': True
  30. }]
  31. def _real_extract(self, url):
  32. video_id, display_id = re.match(self._VALID_URL, url).groups()
  33. if not video_id:
  34. webpage = self._download_webpage(url, display_id)
  35. video_id = self._search_regex(
  36. r'(?:fo\.addVariable\("videoCenterId",\s*|guid\s*=\s*)"([0-9a-f]{32})',
  37. webpage, 'video_id')
  38. api_data = self._download_json(
  39. 'http://vdn.apps.cntv.cn/api/getHttpVideoInfo.do?pid=' + video_id, video_id)
  40. m3u8_url = re.sub(r'maxbr=\d+&?', '', api_data['hls_url'])
  41. return {
  42. 'id': video_id,
  43. 'title': api_data['title'],
  44. 'formats': self._extract_m3u8_formats(
  45. m3u8_url, video_id, 'mp4', 'm3u8_native', fatal=False),
  46. 'duration': float_or_none(api_data.get('video', {}).get('totalLength')),
  47. }