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