aboutsummaryrefslogtreecommitdiffhomepage
path: root/youtube_dl/extractor/njpwworld.py
blob: 3639d142ff461a541664a92ff19035799d5e91ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# coding: utf-8
from __future__ import unicode_literals

import re

from .common import InfoExtractor
from ..compat import compat_urlparse
from ..utils import (
    get_element_by_class,
    urlencode_postdata,
)


class NJPWWorldIE(InfoExtractor):
    _VALID_URL = r'https?://(front\.)?njpwworld\.com/p/(?P<id>[a-z0-9_]+)'
    IE_DESC = '新日本プロレスワールド'
    _NETRC_MACHINE = 'njpwworld'

    _TESTS = [{
        'url': 'http://njpwworld.com/p/s_series_00155_1_9/',
        'info_dict': {
            'id': 's_series_00155_1_9',
            'ext': 'mp4',
            'title': '闘強導夢2000 2000年1月4日 東京ドーム 第9試合 ランディ・サベージ VS リック・スタイナー',
            'tags': list,
        },
        'params': {
            'skip_download': True,  # AES-encrypted m3u8
        },
        'skip': 'Requires login',
    }, {
        'url': 'https://front.njpwworld.com/p/s_series_00563_16_bs',
        'info_dict': {
            'id': 's_series_00563_16_bs',
            'ext': 'mp4',
            'title': 'WORLD TAG LEAGUE 2020 & BEST OF THE SUPER Jr.27 2020年12月6日 福岡・福岡国際センター バックステージコメント(字幕あり)',
            'tags': ["福岡・福岡国際センター", "バックステージコメント", "2020", "20年代"],
        },
        'params': {
            'skip_download': True,
        },
    }]

    _LOGIN_URL = 'https://front.njpwworld.com/auth/login'

    def _real_initialize(self):
        self._login()

    def _login(self):
        username, password = self._get_login_info()
        # No authentication to be performed
        if not username:
            return True

        # Setup session (will set necessary cookies)
        self._request_webpage(
            'https://njpwworld.com/', None, note='Setting up session')

        webpage, urlh = self._download_webpage_handle(
            self._LOGIN_URL, None,
            note='Logging in', errnote='Unable to login',
            data=urlencode_postdata({'login_id': username, 'pw': password}),
            headers={'Referer': 'https://front.njpwworld.com/auth'})
        # /auth/login will return 302 for successful logins
        if urlh.geturl() == self._LOGIN_URL:
            self.report_warning('unable to login')
            return False

        return True

    def _real_extract(self, url):
        video_id = self._match_id(url)

        webpage = self._download_webpage(url, video_id)

        formats = []
        for kind, vid in re.findall(r'if\s+\(\s*imageQualityType\s*==\s*\'([^\']+)\'\s*\)\s*{\s*video_id\s*=\s*"(\d+)"', webpage):
            player_path = '/intent?id=%s&type=url' % vid
            player_url = compat_urlparse.urljoin(url, player_path)
            formats.append({
                'url': player_url,
                'format_id': kind,
                'ext': 'mp4',
                'protocol': 'm3u8',
                'quality': 2 if kind == 'high' else 1,
            })

        self._sort_formats(formats)

        tag_block = get_element_by_class('tag-block', webpage)
        tags = re.findall(
            r'<a[^>]+class="tag-[^"]+"[^>]*>([^<]+)</a>', tag_block
        ) if tag_block else None

        return {
            'id': video_id,
            'title': get_element_by_class('article-title', webpage) or self._og_search_title(webpage),
            'formats': formats,
            'tags': tags,
        }