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.

83 lines
2.6 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. get_element_by_class,
  8. urlencode_postdata,
  9. )
  10. class NJPWWorldIE(InfoExtractor):
  11. _VALID_URL = r'https?://njpwworld\.com/p/(?P<id>[a-z0-9_]+)'
  12. IE_DESC = '新日本プロレスワールド'
  13. _NETRC_MACHINE = 'njpwworld'
  14. _TEST = {
  15. 'url': 'http://njpwworld.com/p/s_series_00155_1_9/',
  16. 'info_dict': {
  17. 'id': 's_series_00155_1_9',
  18. 'ext': 'mp4',
  19. 'title': '第9試合 ランディ・サベージ vs リック・スタイナー',
  20. 'tags': list,
  21. },
  22. 'params': {
  23. 'skip_download': True, # AES-encrypted m3u8
  24. },
  25. 'skip': 'Requires login',
  26. }
  27. def _real_initialize(self):
  28. self._login()
  29. def _login(self):
  30. username, password = self._get_login_info()
  31. # No authentication to be performed
  32. if not username:
  33. return True
  34. webpage, urlh = self._download_webpage_handle(
  35. 'https://njpwworld.com/auth/login', None,
  36. note='Logging in', errnote='Unable to login',
  37. data=urlencode_postdata({'login_id': username, 'pw': password}))
  38. # /auth/login will return 302 for successful logins
  39. if urlh.geturl() == 'https://njpwworld.com/auth/login':
  40. self.report_warning('unable to login')
  41. return False
  42. return True
  43. def _real_extract(self, url):
  44. video_id = self._match_id(url)
  45. webpage = self._download_webpage(url, video_id)
  46. formats = []
  47. for player_url, kind in re.findall(r'<a[^>]+href="(/player[^"]+)".+?<img[^>]+src="[^"]+qf_btn_([^".]+)', webpage):
  48. player_url = compat_urlparse.urljoin(url, player_url)
  49. player_page = self._download_webpage(
  50. player_url, video_id, note='Downloading player page')
  51. entries = self._parse_html5_media_entries(
  52. player_url, player_page, video_id, m3u8_id='hls-%s' % kind,
  53. m3u8_entry_protocol='m3u8_native',
  54. preference=2 if 'hq' in kind else 1)
  55. formats.extend(entries[0]['formats'])
  56. self._sort_formats(formats)
  57. post_content = get_element_by_class('post-content', webpage)
  58. tags = re.findall(
  59. r'<li[^>]+class="tag-[^"]+"><a[^>]*>([^<]+)</a></li>', post_content
  60. ) if post_content else None
  61. return {
  62. 'id': video_id,
  63. 'title': self._og_search_title(webpage),
  64. 'formats': formats,
  65. 'tags': tags,
  66. }