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.

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