logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

xinpianchang.py (3856B)


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