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.

92 lines
3.0 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. def _real_initialize(self):
  29. self._login()
  30. def _login(self):
  31. username, password = self._get_login_info()
  32. # No authentication to be performed
  33. if not username:
  34. return True
  35. webpage, urlh = self._download_webpage_handle(
  36. 'https://njpwworld.com/auth/login', None,
  37. note='Logging in', errnote='Unable to login',
  38. data=urlencode_postdata({'login_id': username, 'pw': password}),
  39. headers={'Referer': 'https://njpwworld.com/auth'})
  40. # /auth/login will return 302 for successful logins
  41. if urlh.geturl() == 'https://njpwworld.com/auth/login':
  42. self.report_warning('unable to login')
  43. return False
  44. return True
  45. def _real_extract(self, url):
  46. video_id = self._match_id(url)
  47. webpage = self._download_webpage(url, video_id)
  48. formats = []
  49. for mobj in re.finditer(r'<a[^>]+\bhref=(["\'])/player.+?[^>]*>', webpage):
  50. player = extract_attributes(mobj.group(0))
  51. player_path = player.get('href')
  52. if not player_path:
  53. continue
  54. kind = self._search_regex(
  55. r'(low|high)$', player.get('class') or '', 'kind',
  56. default='low')
  57. player_url = compat_urlparse.urljoin(url, player_path)
  58. player_page = self._download_webpage(
  59. player_url, video_id, note='Downloading player page')
  60. entries = self._parse_html5_media_entries(
  61. player_url, player_page, video_id, m3u8_id='hls-%s' % kind,
  62. m3u8_entry_protocol='m3u8_native')
  63. kind_formats = entries[0]['formats']
  64. for f in kind_formats:
  65. f['quality'] = 2 if kind == 'high' else 1
  66. formats.extend(kind_formats)
  67. self._sort_formats(formats)
  68. post_content = get_element_by_class('post-content', webpage)
  69. tags = re.findall(
  70. r'<li[^>]+class="tag-[^"]+"><a[^>]*>([^<]+)</a></li>', post_content
  71. ) if post_content else None
  72. return {
  73. 'id': video_id,
  74. 'title': self._og_search_title(webpage),
  75. 'formats': formats,
  76. 'tags': tags,
  77. }