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