]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/njpwworld.py
[extractor] Add `_perform_login` function (#2943)
[yt-dlp.git] / yt_dlp / extractor / njpwworld.py
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):
15 _VALID_URL = r'https?://(front\.)?njpwworld\.com/p/(?P<id>[a-z0-9_]+)'
16 IE_DESC = '新日本プロレスワールド'
17 _NETRC_MACHINE = 'njpwworld'
18
19 _TESTS = [{
20 'url': 'http://njpwworld.com/p/s_series_00155_1_9/',
21 'info_dict': {
22 'id': 's_series_00155_1_9',
23 'ext': 'mp4',
24 'title': '闘強導夢2000 2000年1月4日 東京ドーム 第9試合 ランディ・サベージ VS リック・スタイナー',
25 'tags': list,
26 },
27 'params': {
28 'skip_download': True, # AES-encrypted m3u8
29 },
30 'skip': 'Requires login',
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 }]
43
44 _LOGIN_URL = 'https://front.njpwworld.com/auth/login'
45
46 def _perform_login(self, username, password):
47 # Setup session (will set necessary cookies)
48 self._request_webpage(
49 'https://njpwworld.com/', None, note='Setting up session')
50
51 webpage, urlh = self._download_webpage_handle(
52 self._LOGIN_URL, None,
53 note='Logging in', errnote='Unable to login',
54 data=urlencode_postdata({'login_id': username, 'pw': password}),
55 headers={'Referer': 'https://front.njpwworld.com/auth'})
56 # /auth/login will return 302 for successful logins
57 if urlh.geturl() == self._LOGIN_URL:
58 self.report_warning('unable to login')
59 return False
60
61 return True
62
63 def _real_extract(self, url):
64 video_id = self._match_id(url)
65
66 webpage = self._download_webpage(url, video_id)
67
68 formats = []
69 for kind, vid in re.findall(r'if\s+\(\s*imageQualityType\s*==\s*\'([^\']+)\'\s*\)\s*{\s*video_id\s*=\s*"(\d+)"', webpage):
70 player_path = '/intent?id=%s&type=url' % vid
71 player_url = compat_urlparse.urljoin(url, player_path)
72 formats += self._extract_m3u8_formats(
73 player_url, video_id, 'mp4', 'm3u8_native', m3u8_id=kind, fatal=False, quality=int(kind == 'high'))
74
75 self._sort_formats(formats)
76
77 tag_block = get_element_by_class('tag-block', webpage)
78 tags = re.findall(
79 r'<a[^>]+class="tag-[^"]+"[^>]*>([^<]+)</a>', tag_block
80 ) if tag_block else None
81
82 return {
83 'id': video_id,
84 'title': get_element_by_class('article-title', webpage) or self._og_search_title(webpage),
85 'formats': formats,
86 'tags': tags,
87 }