Compare commits

..

3 Commits

Author SHA1 Message Date
sepro
0910849587
Apply suggestions from code review 2023-12-05 18:08:09 +01:00
Mozi
295e8e45aa [ie/eplus] add back the Edge UA for DRM detection 2023-12-06 00:58:21 +08:00
Mozi
5b762e5c4e [ie/eplus] apply suggestions; JSON response; raise exceptions if needed
Co-authored-by: sepro <4618135+seproDev@users.noreply.github.com>
2023-12-06 00:51:15 +08:00

View File

@ -1,5 +1,4 @@
import json import json
import random
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import ( from ..utils import (
@ -7,7 +6,6 @@ from ..utils import (
try_call, try_call,
unified_timestamp, unified_timestamp,
urlencode_postdata, urlencode_postdata,
xpath_text,
) )
@ -15,10 +13,8 @@ class EplusIbIE(InfoExtractor):
_NETRC_MACHINE = 'eplus' _NETRC_MACHINE = 'eplus'
IE_NAME = 'eplus' IE_NAME = 'eplus'
IE_DESC = 'e+ (イープラス)' IE_DESC = 'e+ (イープラス)'
_VALID_URL = [ _VALID_URL = [r'https?://live\.eplus\.jp/ex/player\?ib=(?P<id>(?:\w|%2B|%2F){86}%3D%3D)',
r'https?://live\.eplus\.jp/ex/player\?ib=(?P<id>(?:\w|%2B|%2F){86}%3D%3D)', r'https?://live\.eplus\.jp/(?P<id>sample|\d+)']
r'https?://live\.eplus\.jp/(?P<id>sample|\d+)',
]
_TESTS = [{ _TESTS = [{
'url': 'https://live.eplus.jp/ex/player?ib=YEFxb3Vyc2Dombnjg7blkrLlrablnJLjgrnjgq%2Fjg7zjg6vjgqLjgqTjg4njg6vlkIzlpb3kvJpgTGllbGxhIQ%3D%3D', 'url': 'https://live.eplus.jp/ex/player?ib=YEFxb3Vyc2Dombnjg7blkrLlrablnJLjgrnjgq%2Fjg7zjg6vjgqLjgqTjg4njg6vlkIzlpb3kvJpgTGllbGxhIQ%3D%3D',
'info_dict': { 'info_dict': {
@ -79,34 +75,33 @@ class EplusIbIE(InfoExtractor):
}] }]
_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' _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'
_TEST_EVENT_URL = 'https://live.eplus.jp/2053935'
def _perform_login(self, id, password): def _perform_login(self, id, password):
fake_event_url = f'https://live.eplus.jp/{random.randrange(2000000, 10000000)}'
webpage, urlh = self._download_webpage_handle( webpage, urlh = self._download_webpage_handle(
fake_event_url, None, note='Getting auth status', errnote='Unable to get auth status') self._TEST_EVENT_URL, None, note='Getting auth status', errnote='Unable to get auth status')
if urlh.url.startswith(fake_event_url): if urlh.url.startswith(self._TEST_EVENT_URL):
# already logged in # already logged in
return return
cltft_token = self._hidden_inputs(webpage).get('Token.Default') cltft_token = self._hidden_inputs(webpage).get('Token.Default')
if not cltft_token: if not cltft_token:
self.report_warning('Unable to get X-CLTFT-Token') raise ExtractorError('Unable to get X-CLTFT-Token', expected=False)
return
self._set_cookie('live.eplus.jp', 'X-CLTFT-Token', f'Token.Default={cltft_token}') self._set_cookie('live.eplus.jp', 'X-CLTFT-Token', f'Token.Default={cltft_token}')
login_xml = self._download_xml( login_json = self._download_json(
'https://live.eplus.jp/member/api/v1/FTAuth/idpw', None, 'https://live.eplus.jp/member/api/v1/FTAuth/idpw', None,
note='Sending pre-login info', errnote='Unable to send pre-login info', headers={ note='Sending pre-login info', errnote='Unable to send pre-login info', headers={
'Content-Type': 'application/json; charset=UTF-8', 'Content-Type': 'application/json; charset=UTF-8',
'Referer': urlh.url, 'Referer': urlh.url,
'X-Cltft-Token': f'Token.Default={cltft_token}', 'X-Cltft-Token': f'Token.Default={cltft_token}',
'Accept': '*/*',
}, data=json.dumps({ }, data=json.dumps({
'loginId': id, 'loginId': id,
'loginPassword': password, 'loginPassword': password,
}).encode('utf-8')) }).encode())
flag = xpath_text(login_xml, './isSuccess', default=None) if not login_json.get('isSuccess'):
if flag != 'true': raise ExtractorError('Login failed: Invalid id or password', expected=True)
raise
self._request_webpage( self._request_webpage(
urlh.url, None, note='Logging in', errnote='Unable to log in', urlh.url, None, note='Logging in', errnote='Unable to log in',
@ -122,7 +117,8 @@ class EplusIbIE(InfoExtractor):
def _real_extract(self, url): def _real_extract(self, url):
video_id = self._match_id(url) video_id = self._match_id(url)
webpage, urlh = self._download_webpage_handle(url, video_id) webpage, urlh = self._download_webpage_handle(
url, video_id, headers={'User-Agent': self._USER_AGENT})
if urlh.url.startswith('https://live.eplus.jp/member/auth'): if urlh.url.startswith('https://live.eplus.jp/member/auth'):
self.raise_login_required() self.raise_login_required()