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

pialive.py (5522B)


  1. from .common import InfoExtractor
  2. from ..utils import (
  3. ExtractorError,
  4. clean_html,
  5. extract_attributes,
  6. get_element_by_class,
  7. get_element_html_by_class,
  8. multipart_encode,
  9. str_or_none,
  10. unified_timestamp,
  11. url_or_none,
  12. )
  13. from ..utils.traversal import traverse_obj
  14. class PiaLiveIE(InfoExtractor):
  15. _VALID_URL = r'https?://player\.pia-live\.jp/stream/(?P<id>[\w-]+)'
  16. _PLAYER_ROOT_URL = 'https://player.pia-live.jp/'
  17. _PIA_LIVE_API_URL = 'https://api.pia-live.jp'
  18. _API_KEY = 'kfds)FKFps-dms9e'
  19. _TESTS = [{
  20. 'url': 'https://player.pia-live.jp/stream/4JagFBEIM14s_hK9aXHKf3k3F3bY5eoHFQxu68TC6krUDqGOwN4d61dCWQYOd6CTxl4hjya9dsfEZGsM4uGOUdax60lEI4twsXGXf7crmz8Gk__GhupTrWxA7RFRVt76',
  21. 'info_dict': {
  22. 'id': '88f3109a-f503-4d0f-a9f7-9f39ac745d84',
  23. 'display_id': '2431867_001',
  24. 'title': 'こながめでたい日2024の視聴ページ | PIA LIVE STREAM(ぴあライブストリーム)',
  25. 'live_status': 'was_live',
  26. 'comment_count': int,
  27. },
  28. 'params': {
  29. 'getcomments': True,
  30. 'skip_download': True,
  31. 'ignore_no_formats_error': True,
  32. },
  33. 'skip': 'The video is no longer available',
  34. }, {
  35. 'url': 'https://player.pia-live.jp/stream/4JagFBEIM14s_hK9aXHKf3k3F3bY5eoHFQxu68TC6krJdu0GVBVbVy01IwpJ6J3qBEm3d9TCTt1d0eWpsZGj7DrOjVOmS7GAWGwyscMgiThopJvzgWC4H5b-7XQjAfRZ',
  36. 'info_dict': {
  37. 'id': '9ce8b8ba-f6d1-4d1f-83a0-18c3148ded93',
  38. 'display_id': '2431867_002',
  39. 'title': 'こながめでたい日2024の視聴ページ | PIA LIVE STREAM(ぴあライブストリーム)',
  40. 'live_status': 'was_live',
  41. 'comment_count': int,
  42. },
  43. 'params': {
  44. 'getcomments': True,
  45. 'skip_download': True,
  46. 'ignore_no_formats_error': True,
  47. },
  48. 'skip': 'The video is no longer available',
  49. }]
  50. def _extract_var(self, variable, html):
  51. return self._search_regex(
  52. rf'(?:var|const|let)\s+{variable}\s*=\s*(["\'])(?P<value>(?:(?!\1).)+)\1',
  53. html, f'variable {variable}', group='value')
  54. def _real_extract(self, url):
  55. video_key = self._match_id(url)
  56. webpage = self._download_webpage(url, video_key)
  57. program_code = self._extract_var('programCode', webpage)
  58. article_code = self._extract_var('articleCode', webpage)
  59. title = self._html_extract_title(webpage)
  60. if get_element_html_by_class('play-end', webpage):
  61. raise ExtractorError('The video is no longer available', expected=True, video_id=program_code)
  62. if start_info := clean_html(get_element_by_class('play-waiting__date', webpage)):
  63. date, time = self._search_regex(
  64. r'(?P<date>\d{4}/\d{1,2}/\d{1,2})\([月火水木金土日]\)(?P<time>\d{2}:\d{2})',
  65. start_info, 'start_info', fatal=False, group=('date', 'time'))
  66. if date and time:
  67. release_timestamp_str = f'{date} {time} +09:00'
  68. release_timestamp = unified_timestamp(release_timestamp_str)
  69. self.raise_no_formats(f'The video will be available after {release_timestamp_str}', expected=True)
  70. return {
  71. 'id': program_code,
  72. 'title': title,
  73. 'live_status': 'is_upcoming',
  74. 'release_timestamp': release_timestamp,
  75. }
  76. payload, content_type = multipart_encode({
  77. 'play_url': video_key,
  78. 'api_key': self._API_KEY,
  79. })
  80. api_data_and_headers = {
  81. 'data': payload,
  82. 'headers': {'Content-Type': content_type, 'Referer': self._PLAYER_ROOT_URL},
  83. }
  84. player_tag_list = self._download_json(
  85. f'{self._PIA_LIVE_API_URL}/perf/player-tag-list/{program_code}', program_code,
  86. 'Fetching player tag list', 'Unable to fetch player tag list', **api_data_and_headers)
  87. return self.url_result(
  88. extract_attributes(player_tag_list['data']['movie_one_tag'])['src'],
  89. url_transparent=True, title=title, display_id=program_code,
  90. __post_extractor=self.extract_comments(program_code, article_code, api_data_and_headers))
  91. def _get_comments(self, program_code, article_code, api_data_and_headers):
  92. chat_room_url = traverse_obj(self._download_json(
  93. f'{self._PIA_LIVE_API_URL}/perf/chat-tag-list/{program_code}/{article_code}', program_code,
  94. 'Fetching chat info', 'Unable to fetch chat info', fatal=False, **api_data_and_headers),
  95. ('data', 'chat_one_tag', {extract_attributes}, 'src', {url_or_none}))
  96. if not chat_room_url:
  97. return
  98. comment_page = self._download_webpage(
  99. chat_room_url, program_code, 'Fetching comment page', 'Unable to fetch comment page',
  100. fatal=False, headers={'Referer': self._PLAYER_ROOT_URL})
  101. if not comment_page:
  102. return
  103. yield from traverse_obj(self._search_json(
  104. r'var\s+_history\s*=', comment_page, 'comment list',
  105. program_code, contains_pattern=r'\[(?s:.+)\]', fatal=False), (..., {
  106. 'timestamp': (0, {int}),
  107. 'author_is_uploader': (1, {lambda x: x == 2}),
  108. 'author': (2, {str}),
  109. 'text': (3, {str}),
  110. 'id': (4, {str_or_none}),
  111. }))