eplus.py 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. import json
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. ExtractorError,
  5. try_call,
  6. unified_timestamp,
  7. urlencode_postdata,
  8. )
  9. class EplusIbIE(InfoExtractor):
  10. _NETRC_MACHINE = 'eplus'
  11. IE_NAME = 'eplus'
  12. IE_DESC = 'e+ (イープラス)'
  13. _VALID_URL = [r'https?://live\.eplus\.jp/ex/player\?ib=(?P<id>(?:\w|%2B|%2F){86}%3D%3D)',
  14. r'https?://live\.eplus\.jp/(?P<id>sample|\d+)']
  15. _TESTS = [{
  16. 'url': 'https://live.eplus.jp/ex/player?ib=41K6Wzbr3PlcMD%2FOKHFlC%2FcZCe2Eaw7FK%2BpJS1ooUHki8d0vGSy2mYqxillQBe1dSnOxU%2B8%2FzXKls4XPBSb3vw%3D%3D',
  17. 'info_dict': {
  18. 'id': '335699-0001-006',
  19. 'title': '少女☆歌劇 レヴュースタァライト -The LIVE 青嵐- BLUE GLITTER <定点映像配信>【Streaming+(配信)】',
  20. 'live_status': 'was_live',
  21. 'release_date': '20201221',
  22. 'release_timestamp': 1608544800,
  23. },
  24. 'params': {
  25. 'skip_download': True,
  26. 'ignore_no_formats_error': True,
  27. },
  28. 'expected_warnings': [
  29. 'This event may not be accessible',
  30. 'No video formats found',
  31. 'Requested format is not available',
  32. ],
  33. }, {
  34. 'url': 'https://live.eplus.jp/ex/player?ib=6QSsQdyRAwOFZrEHWlhRm7vocgV%2FO0YzBZ%2BaBEBg1XR%2FmbLn0R%2F048dUoAY038%2F%2F92MJ73BsoAtvUpbV6RLtDQ%3D%3D&show_id=2371511',
  35. 'info_dict': {
  36. 'id': '348021-0054-001',
  37. 'title': 'ラブライブ!スーパースター!! Liella! First LoveLive! Tour ~Starlines~【東京/DAY.1】',
  38. 'live_status': 'was_live',
  39. 'release_date': '20220115',
  40. 'release_timestamp': 1642233600,
  41. 'description': str,
  42. },
  43. 'params': {
  44. 'skip_download': True,
  45. 'ignore_no_formats_error': True,
  46. },
  47. 'expected_warnings': [
  48. 'Could not find the playlist URL. This event may not be accessible',
  49. 'No video formats found!',
  50. 'Requested format is not available',
  51. ],
  52. }, {
  53. 'url': 'https://live.eplus.jp/sample',
  54. 'info_dict': {
  55. 'id': 'stream1ng20210719-test-005',
  56. 'title': 'Online streaming test for DRM',
  57. 'live_status': 'was_live',
  58. 'release_date': '20210719',
  59. 'release_timestamp': 1626703200,
  60. },
  61. 'params': {
  62. 'skip_download': True,
  63. 'ignore_no_formats_error': True,
  64. },
  65. 'expected_warnings': [
  66. 'Could not find the playlist URL. This event may not be accessible',
  67. 'No video formats found!',
  68. 'Requested format is not available',
  69. 'This video is DRM protected',
  70. ],
  71. }, {
  72. 'url': 'https://live.eplus.jp/2053935',
  73. 'info_dict': {
  74. 'id': '331320-0001-001',
  75. 'title': '丘みどり2020配信LIVE Vol.2 ~秋麗~ 【Streaming+(配信チケット)】',
  76. 'live_status': 'was_live',
  77. 'release_date': '20200920',
  78. 'release_timestamp': 1600596000,
  79. },
  80. 'params': {
  81. 'skip_download': True,
  82. 'ignore_no_formats_error': True,
  83. },
  84. 'expected_warnings': [
  85. 'Could not find the playlist URL. This event may not be accessible',
  86. 'No video formats found!',
  87. 'Requested format is not available',
  88. ],
  89. }]
  90. _USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0'
  91. def _login(self, username, password, urlh):
  92. if not self._get_cookies('https://live.eplus.jp/').get('ci_session'):
  93. raise ExtractorError('Unable to get ci_session cookie')
  94. cltft_token = urlh.headers.get('X-CLTFT-Token')
  95. if not cltft_token:
  96. raise ExtractorError('Unable to get X-CLTFT-Token')
  97. self._set_cookie('live.eplus.jp', 'X-CLTFT-Token', cltft_token)
  98. login_json = self._download_json(
  99. 'https://live.eplus.jp/member/api/v1/FTAuth/idpw', None,
  100. note='Sending pre-login info', errnote='Unable to send pre-login info', headers={
  101. 'Content-Type': 'application/json; charset=UTF-8',
  102. 'Referer': urlh.url,
  103. 'X-Cltft-Token': cltft_token,
  104. 'Accept': '*/*',
  105. }, data=json.dumps({
  106. 'loginId': username,
  107. 'loginPassword': password,
  108. }).encode())
  109. if not login_json.get('isSuccess'):
  110. raise ExtractorError('Login failed: Invalid id or password', expected=True)
  111. self._request_webpage(
  112. urlh.url, None, note='Logging in', errnote='Unable to log in',
  113. data=urlencode_postdata({
  114. 'loginId': username,
  115. 'loginPassword': password,
  116. 'Token.Default': cltft_token,
  117. 'op': 'nextPage',
  118. }), headers={'Referer': urlh.url})
  119. def _real_extract(self, url):
  120. video_id = self._match_id(url)
  121. webpage, urlh = self._download_webpage_handle(
  122. url, video_id, headers={'User-Agent': self._USER_AGENT})
  123. if urlh.url.startswith('https://live.eplus.jp/member/auth'):
  124. username, password = self._get_login_info()
  125. if not username:
  126. self.raise_login_required()
  127. self._login(username, password, urlh)
  128. webpage = self._download_webpage(
  129. url, video_id, headers={'User-Agent': self._USER_AGENT})
  130. data_json = self._search_json(r'<script>\s*var app\s*=', webpage, 'data json', video_id)
  131. if data_json.get('drm_mode') == 'ON':
  132. self.report_drm(video_id)
  133. if data_json.get('is_pass_ticket') == 'YES':
  134. raise ExtractorError(
  135. 'This URL is for a pass ticket instead of a player page', expected=True)
  136. delivery_status = data_json.get('delivery_status')
  137. archive_mode = data_json.get('archive_mode')
  138. release_timestamp = try_call(lambda: unified_timestamp(data_json['event_datetime']) - 32400)
  139. release_timestamp_str = data_json.get('event_datetime_text') # JST
  140. self.write_debug(f'delivery_status = {delivery_status}, archive_mode = {archive_mode}')
  141. if delivery_status == 'PREPARING':
  142. live_status = 'is_upcoming'
  143. elif delivery_status == 'STARTED':
  144. live_status = 'is_live'
  145. elif delivery_status == 'STOPPED':
  146. if archive_mode != 'ON':
  147. raise ExtractorError(
  148. 'This event has ended and there is no archive for this event', expected=True)
  149. live_status = 'post_live'
  150. elif delivery_status == 'WAIT_CONFIRM_ARCHIVED':
  151. live_status = 'post_live'
  152. elif delivery_status == 'CONFIRMED_ARCHIVE':
  153. live_status = 'was_live'
  154. else:
  155. self.report_warning(f'Unknown delivery_status {delivery_status}, treat it as a live')
  156. live_status = 'is_live'
  157. formats = []
  158. m3u8_playlist_urls = self._search_json(
  159. r'var\s+listChannels\s*=', webpage, 'hls URLs', video_id, contains_pattern=r'\[.+\]', default=[])
  160. if not m3u8_playlist_urls:
  161. if live_status == 'is_upcoming':
  162. self.raise_no_formats(
  163. f'Could not find the playlist URL. This live event will begin at {release_timestamp_str} JST', expected=True)
  164. else:
  165. self.raise_no_formats(
  166. 'Could not find the playlist URL. This event may not be accessible', expected=True)
  167. elif live_status == 'is_upcoming':
  168. self.raise_no_formats(f'This live event will begin at {release_timestamp_str} JST', expected=True)
  169. elif live_status == 'post_live':
  170. self.raise_no_formats('This event has ended, and the archive will be available shortly', expected=True)
  171. else:
  172. for m3u8_playlist_url in m3u8_playlist_urls:
  173. formats.extend(self._extract_m3u8_formats(m3u8_playlist_url, video_id))
  174. # FIXME: HTTP request headers need to be updated to continue download
  175. warning = 'Due to technical limitations, the download will be interrupted after one hour'
  176. if live_status == 'is_live':
  177. self.report_warning(warning)
  178. elif live_status == 'was_live':
  179. self.report_warning(f'{warning}. You can restart to continue the download')
  180. return {
  181. 'id': data_json['app_id'],
  182. 'title': data_json.get('app_name'),
  183. 'formats': formats,
  184. 'live_status': live_status,
  185. 'description': data_json.get('content'),
  186. 'release_timestamp': release_timestamp,
  187. }