cctv.py 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. float_or_none,
  5. try_get,
  6. unified_timestamp,
  7. )
  8. class CCTVIE(InfoExtractor):
  9. IE_DESC = '央视网'
  10. _VALID_URL = r'https?://(?:(?:[^/]+)\.(?:cntv|cctv)\.(?:com|cn)|(?:www\.)?ncpa-classic\.com)/(?:[^/]+/)*?(?P<id>[^/?#&]+?)(?:/index)?(?:\.s?html|[?#&]|$)'
  11. _TESTS = [{
  12. # fo.addVariable("videoCenterId","id")
  13. 'url': 'http://sports.cntv.cn/2016/02/12/ARTIaBRxv4rTT1yWf1frW2wi160212.shtml',
  14. 'md5': 'd61ec00a493e09da810bf406a078f691',
  15. 'info_dict': {
  16. 'id': '5ecdbeab623f4973b40ff25f18b174e8',
  17. 'ext': 'mp4',
  18. 'title': '[NBA]二少联手砍下46分 雷霆主场击败鹈鹕(快讯)',
  19. 'description': 'md5:7e14a5328dc5eb3d1cd6afbbe0574e95',
  20. 'duration': 98,
  21. 'uploader': 'songjunjie',
  22. 'timestamp': 1455279956,
  23. 'upload_date': '20160212',
  24. },
  25. }, {
  26. # var guid = "id"
  27. 'url': 'http://tv.cctv.com/2016/02/05/VIDEUS7apq3lKrHG9Dncm03B160205.shtml',
  28. 'info_dict': {
  29. 'id': 'efc5d49e5b3b4ab2b34f3a502b73d3ae',
  30. 'ext': 'mp4',
  31. 'title': '[赛车]“车王”舒马赫恢复情况成谜(快讯)',
  32. 'description': '2月4日,蒙特泽莫罗透露了关于“车王”舒马赫恢复情况,但情况是否属实遭到了质疑。',
  33. 'duration': 37,
  34. 'uploader': 'shujun',
  35. 'timestamp': 1454677291,
  36. 'upload_date': '20160205',
  37. },
  38. 'params': {
  39. 'skip_download': True,
  40. },
  41. }, {
  42. # changePlayer('id')
  43. 'url': 'http://english.cntv.cn/special/four_comprehensives/index.shtml',
  44. 'info_dict': {
  45. 'id': '4bb9bb4db7a6471ba85fdeda5af0381e',
  46. 'ext': 'mp4',
  47. 'title': 'NHnews008 ANNUAL POLITICAL SEASON',
  48. 'description': 'Four Comprehensives',
  49. 'duration': 60,
  50. 'uploader': 'zhangyunlei',
  51. 'timestamp': 1425385521,
  52. 'upload_date': '20150303',
  53. },
  54. 'params': {
  55. 'skip_download': True,
  56. },
  57. }, {
  58. # loadvideo('id')
  59. 'url': 'http://cctv.cntv.cn/lm/tvseries_russian/yilugesanghua/index.shtml',
  60. 'info_dict': {
  61. 'id': 'b15f009ff45c43968b9af583fc2e04b2',
  62. 'ext': 'mp4',
  63. 'title': 'Путь,усыпанный космеями Серия 1',
  64. 'description': 'Путь, усыпанный космеями',
  65. 'duration': 2645,
  66. 'uploader': 'renxue',
  67. 'timestamp': 1477479241,
  68. 'upload_date': '20161026',
  69. },
  70. 'params': {
  71. 'skip_download': True,
  72. },
  73. }, {
  74. # var initMyAray = 'id'
  75. 'url': 'http://www.ncpa-classic.com/2013/05/22/VIDE1369219508996867.shtml',
  76. 'info_dict': {
  77. 'id': 'a194cfa7f18c426b823d876668325946',
  78. 'ext': 'mp4',
  79. 'title': '小泽征尔音乐塾 音乐梦想无国界',
  80. 'duration': 2173,
  81. 'timestamp': 1369248264,
  82. 'upload_date': '20130522',
  83. },
  84. 'params': {
  85. 'skip_download': True,
  86. },
  87. }, {
  88. # videoCenterId: "id"
  89. 'url': 'http://news.cctv.com/2024/02/21/ARTIcU5tKIOIF2myEGCATkLo240221.shtml',
  90. 'info_dict': {
  91. 'id': '5c846c0518444308ba32c4159df3b3e0',
  92. 'ext': 'mp4',
  93. 'title': '《平“语”近人——习近平喜欢的典故》第三季 第5集:风物长宜放眼量',
  94. 'uploader': 'yangjuan',
  95. 'timestamp': 1708554940,
  96. 'upload_date': '20240221',
  97. },
  98. 'params': {
  99. 'skip_download': True,
  100. },
  101. }, {
  102. # var ids = ["id"]
  103. 'url': 'http://www.ncpa-classic.com/clt/more/416/index.shtml',
  104. 'info_dict': {
  105. 'id': 'a8606119a4884588a79d81c02abecc16',
  106. 'ext': 'mp3',
  107. 'title': '来自维也纳的新年贺礼',
  108. 'description': 'md5:f13764ae8dd484e84dd4b39d5bcba2a7',
  109. 'duration': 1578,
  110. 'uploader': 'djy',
  111. 'timestamp': 1482942419,
  112. 'upload_date': '20161228',
  113. },
  114. 'params': {
  115. 'skip_download': True,
  116. },
  117. 'expected_warnings': ['Failed to download m3u8 information'],
  118. }, {
  119. 'url': 'http://ent.cntv.cn/2016/01/18/ARTIjprSSJH8DryTVr5Bx8Wb160118.shtml',
  120. 'only_matching': True,
  121. }, {
  122. 'url': 'http://tv.cntv.cn/video/C39296/e0210d949f113ddfb38d31f00a4e5c44',
  123. 'only_matching': True,
  124. }, {
  125. 'url': 'http://english.cntv.cn/2016/09/03/VIDEhnkB5y9AgHyIEVphCEz1160903.shtml',
  126. 'only_matching': True,
  127. }, {
  128. 'url': 'http://tv.cctv.com/2016/09/07/VIDE5C1FnlX5bUywlrjhxXOV160907.shtml',
  129. 'only_matching': True,
  130. }, {
  131. 'url': 'http://tv.cntv.cn/video/C39296/95cfac44cabd3ddc4a9438780a4e5c44',
  132. 'only_matching': True,
  133. }]
  134. def _real_extract(self, url):
  135. video_id = self._match_id(url)
  136. webpage = self._download_webpage(url, video_id)
  137. video_id = self._search_regex(
  138. [r'var\s+guid\s*=\s*["\']([\da-fA-F]+)',
  139. r'videoCenterId(?:["\']\s*,|:)\s*["\']([\da-fA-F]+)',
  140. r'changePlayer\s*\(\s*["\']([\da-fA-F]+)',
  141. r'load[Vv]ideo\s*\(\s*["\']([\da-fA-F]+)',
  142. r'var\s+initMyAray\s*=\s*["\']([\da-fA-F]+)',
  143. r'var\s+ids\s*=\s*\[["\']([\da-fA-F]+)'],
  144. webpage, 'video id')
  145. data = self._download_json(
  146. 'http://vdn.apps.cntv.cn/api/getHttpVideoInfo.do', video_id,
  147. query={
  148. 'pid': video_id,
  149. 'url': url,
  150. 'idl': 32,
  151. 'idlr': 32,
  152. 'modifyed': 'false',
  153. })
  154. title = data['title']
  155. formats = []
  156. video = data.get('video')
  157. if isinstance(video, dict):
  158. for quality, chapters_key in enumerate(('lowChapters', 'chapters')):
  159. video_url = try_get(
  160. video, lambda x: x[chapters_key][0]['url'], str)
  161. if video_url:
  162. formats.append({
  163. 'url': video_url,
  164. 'format_id': 'http',
  165. 'quality': quality,
  166. # Sample clip
  167. 'preference': -10,
  168. })
  169. hls_url = try_get(data, lambda x: x['hls_url'], str)
  170. if hls_url:
  171. hls_url = re.sub(r'maxbr=\d+&?', '', hls_url)
  172. formats.extend(self._extract_m3u8_formats(
  173. hls_url, video_id, 'mp4', entry_protocol='m3u8_native',
  174. m3u8_id='hls', fatal=False))
  175. uploader = data.get('editer_name')
  176. description = self._html_search_meta(
  177. 'description', webpage, default=None)
  178. timestamp = unified_timestamp(data.get('f_pgmtime'))
  179. duration = float_or_none(try_get(video, lambda x: x['totalLength']))
  180. return {
  181. 'id': video_id,
  182. 'title': title,
  183. 'description': description,
  184. 'uploader': uploader,
  185. 'timestamp': timestamp,
  186. 'duration': duration,
  187. 'formats': formats,
  188. }