logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

njpwworld.py (3444B)


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