njpwworld.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import re
  2. from .common import InfoExtractor
  3. from ..compat import compat_urlparse
  4. from ..utils import (
  5. get_element_by_class,
  6. urlencode_postdata,
  7. )
  8. class NJPWWorldIE(InfoExtractor):
  9. _VALID_URL = r'https?://(front\.)?njpwworld\.com/p/(?P<id>[a-z0-9_]+)'
  10. IE_DESC = '新日本プロレスワールド'
  11. _NETRC_MACHINE = 'njpwworld'
  12. _TESTS = [{
  13. 'url': 'http://njpwworld.com/p/s_series_00155_1_9/',
  14. 'info_dict': {
  15. 'id': 's_series_00155_1_9',
  16. 'ext': 'mp4',
  17. 'title': '闘強導夢2000 2000年1月4日 東京ドーム 第9試合 ランディ・サベージ VS リック・スタイナー',
  18. 'tags': list,
  19. },
  20. 'params': {
  21. 'skip_download': True, # AES-encrypted m3u8
  22. },
  23. 'skip': 'Requires login',
  24. }, {
  25. 'url': 'https://front.njpwworld.com/p/s_series_00563_16_bs',
  26. 'info_dict': {
  27. 'id': 's_series_00563_16_bs',
  28. 'ext': 'mp4',
  29. 'title': 'WORLD TAG LEAGUE 2020 & BEST OF THE SUPER Jr.27 2020年12月6日 福岡・福岡国際センター バックステージコメント(字幕あり)',
  30. 'tags': ["福岡・福岡国際センター", "バックステージコメント", "2020", "20年代"],
  31. },
  32. 'params': {
  33. 'skip_download': True,
  34. },
  35. }]
  36. _LOGIN_URL = 'https://front.njpwworld.com/auth/login'
  37. def _perform_login(self, username, password):
  38. # Setup session (will set necessary cookies)
  39. self._request_webpage(
  40. 'https://njpwworld.com/', None, note='Setting up session')
  41. webpage, urlh = self._download_webpage_handle(
  42. self._LOGIN_URL, None,
  43. note='Logging in', errnote='Unable to login',
  44. data=urlencode_postdata({'login_id': username, 'pw': password}),
  45. headers={'Referer': 'https://front.njpwworld.com/auth'})
  46. # /auth/login will return 302 for successful logins
  47. if urlh.geturl() == self._LOGIN_URL:
  48. self.report_warning('unable to login')
  49. return False
  50. return True
  51. def _real_extract(self, url):
  52. video_id = self._match_id(url)
  53. webpage = self._download_webpage(url, video_id)
  54. formats = []
  55. for kind, vid in re.findall(r'if\s+\(\s*imageQualityType\s*==\s*\'([^\']+)\'\s*\)\s*{\s*video_id\s*=\s*"(\d+)"', webpage):
  56. player_path = '/intent?id=%s&type=url' % vid
  57. player_url = compat_urlparse.urljoin(url, player_path)
  58. formats += self._extract_m3u8_formats(
  59. player_url, video_id, 'mp4', 'm3u8_native', m3u8_id=kind, fatal=False, quality=int(kind == 'high'))
  60. tag_block = get_element_by_class('tag-block', webpage)
  61. tags = re.findall(
  62. r'<a[^>]+class="tag-[^"]+"[^>]*>([^<]+)</a>', tag_block
  63. ) if tag_block else None
  64. return {
  65. 'id': video_id,
  66. 'title': get_element_by_class('article-title', webpage) or self._og_search_title(webpage),
  67. 'formats': formats,
  68. 'tags': tags,
  69. }