xinpianchang.py 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. int_or_none,
  4. try_get,
  5. update_url_query,
  6. url_or_none,
  7. )
  8. class XinpianchangIE(InfoExtractor):
  9. _VALID_URL = r'https?://www\.xinpianchang\.com/(?P<id>[^/]+?)(?:\D|$)'
  10. IE_NAME = 'xinpianchang'
  11. IE_DESC = 'xinpianchang.com'
  12. _TESTS = [{
  13. 'url': 'https://www.xinpianchang.com/a11766551',
  14. 'info_dict': {
  15. 'id': 'a11766551',
  16. 'ext': 'mp4',
  17. 'title': '北京2022冬奥会闭幕式再见短片-冰墩墩下班了',
  18. 'description': 'md5:4a730c10639a82190fabe921c0fa4b87',
  19. 'duration': 151,
  20. 'thumbnail': r're:^https?://oss-xpc0\.xpccdn\.com.+/assets/',
  21. 'uploader': '正时文创',
  22. 'uploader_id': 10357277,
  23. 'categories': ['宣传片', '国家城市', '广告', '其他'],
  24. 'keywords': ['北京冬奥会', '冰墩墩', '再见', '告别', '冰墩墩哭了', '感动', '闭幕式', '熄火']
  25. },
  26. }, {
  27. 'url': 'https://www.xinpianchang.com/a11762904',
  28. 'info_dict': {
  29. 'id': 'a11762904',
  30. 'ext': 'mp4',
  31. 'title': '冬奥会决胜时刻《法国派出三只鸡?》',
  32. 'description': 'md5:55cb139ef8f48f0c877932d1f196df8b',
  33. 'duration': 136,
  34. 'thumbnail': r're:^https?://oss-xpc0\.xpccdn\.com.+/assets/',
  35. 'uploader': '精品动画',
  36. 'uploader_id': 10858927,
  37. 'categories': ['动画', '三维CG'],
  38. 'keywords': ['France Télévisions', '法国3台', '蠢萌', '冬奥会']
  39. },
  40. }, {
  41. 'url': 'https://www.xinpianchang.com/a11779743?from=IndexPick&part=%E7%BC%96%E8%BE%91%E7%B2%BE%E9%80%89&index=2',
  42. 'only_matching': True,
  43. }]
  44. def _real_extract(self, url):
  45. video_id = self._match_id(url)
  46. webpage = self._download_webpage(url, video_id=video_id)
  47. domain = self.find_value_with_regex(var='requireNewDomain', webpage=webpage)
  48. vid = self.find_value_with_regex(var='vid', webpage=webpage)
  49. app_key = self.find_value_with_regex(var='modeServerAppKey', webpage=webpage)
  50. api = update_url_query(f'{domain}/mod/api/v2/media/{vid}', {'appKey': app_key})
  51. data = self._download_json(api, video_id=video_id)['data']
  52. formats, subtitles = [], {}
  53. for k, v in data.get('resource').items():
  54. if k in ('dash', 'hls'):
  55. v_url = v.get('url')
  56. if not v_url:
  57. continue
  58. if k == 'dash':
  59. fmts, subs = self._extract_mpd_formats_and_subtitles(v_url, video_id=video_id)
  60. elif k == 'hls':
  61. fmts, subs = self._extract_m3u8_formats_and_subtitles(v_url, video_id=video_id)
  62. formats.extend(fmts)
  63. subtitles = self._merge_subtitles(subtitles, subs)
  64. elif k == 'progressive':
  65. formats.extend([{
  66. 'url': url_or_none(prog.get('url')),
  67. 'width': int_or_none(prog.get('width')),
  68. 'height': int_or_none(prog.get('height')),
  69. 'ext': 'mp4',
  70. } for prog in v if prog.get('url') or []])
  71. return {
  72. 'id': video_id,
  73. 'title': data.get('title'),
  74. 'description': data.get('description'),
  75. 'duration': int_or_none(data.get('duration')),
  76. 'categories': data.get('categories'),
  77. 'keywords': data.get('keywords'),
  78. 'thumbnail': data.get('cover'),
  79. 'uploader': try_get(data, lambda x: x['owner']['username']),
  80. 'uploader_id': try_get(data, lambda x: x['owner']['id']),
  81. 'formats': formats,
  82. 'subtitles': subtitles,
  83. }
  84. def find_value_with_regex(self, var, webpage):
  85. return self._search_regex(rf'var\s{var}\s=\s\"(?P<vid>[^\"]+)\"', webpage, name=var)