You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
3.2 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_urlparse
  6. from ..utils import (
  7. extract_attributes,
  8. get_element_by_class,
  9. urlencode_postdata,
  10. )
  11. class NJPWWorldIE(InfoExtractor):
  12. _VALID_URL = r'https?://njpwworld\.com/p/(?P<id>[a-z0-9_]+)'
  13. IE_DESC = '新日本プロレスワールド'
  14. _NETRC_MACHINE = 'njpwworld'
  15. _TEST = {
  16. 'url': 'http://njpwworld.com/p/s_series_00155_1_9/',
  17. 'info_dict': {
  18. 'id': 's_series_00155_1_9',
  19. 'ext': 'mp4',
  20. 'title': '第9試合 ランディ・サベージ vs リック・スタイナー',
  21. 'tags': list,
  22. },
  23. 'params': {
  24. 'skip_download': True, # AES-encrypted m3u8
  25. },
  26. 'skip': 'Requires login',
  27. }
  28. _LOGIN_URL = 'https://front.njpwworld.com/auth/login'
  29. def _real_initialize(self):
  30. self._login()
  31. def _login(self):
  32. username, password = self._get_login_info()
  33. # No authentication to be performed
  34. if not username:
  35. return True
  36. # Setup session (will set necessary cookies)
  37. self._request_webpage(
  38. 'https://njpwworld.com/', None, note='Setting up session')
  39. webpage, urlh = self._download_webpage_handle(
  40. self._LOGIN_URL, None,
  41. note='Logging in', errnote='Unable to login',
  42. data=urlencode_postdata({'login_id': username, 'pw': password}),
  43. headers={'Referer': 'https://front.njpwworld.com/auth'})
  44. # /auth/login will return 302 for successful logins
  45. if urlh.geturl() == self._LOGIN_URL:
  46. self.report_warning('unable to login')
  47. return False
  48. return True
  49. def _real_extract(self, url):
  50. video_id = self._match_id(url)
  51. webpage = self._download_webpage(url, video_id)
  52. formats = []
  53. for mobj in re.finditer(r'<a[^>]+\bhref=(["\'])/player.+?[^>]*>', webpage):
  54. player = extract_attributes(mobj.group(0))
  55. player_path = player.get('href')
  56. if not player_path:
  57. continue
  58. kind = self._search_regex(
  59. r'(low|high)$', player.get('class') or '', 'kind',
  60. default='low')
  61. player_url = compat_urlparse.urljoin(url, player_path)
  62. player_page = self._download_webpage(
  63. player_url, video_id, note='Downloading player page')
  64. entries = self._parse_html5_media_entries(
  65. player_url, player_page, video_id, m3u8_id='hls-%s' % kind,
  66. m3u8_entry_protocol='m3u8_native')
  67. kind_formats = entries[0]['formats']
  68. for f in kind_formats:
  69. f['quality'] = 2 if kind == 'high' else 1
  70. formats.extend(kind_formats)
  71. self._sort_formats(formats)
  72. post_content = get_element_by_class('post-content', webpage)
  73. tags = re.findall(
  74. r'<li[^>]+class="tag-[^"]+"><a[^>]*>([^<]+)</a></li>', post_content
  75. ) if post_content else None
  76. return {
  77. 'id': video_id,
  78. 'title': self._og_search_title(webpage),
  79. 'formats': formats,
  80. 'tags': tags,
  81. }