]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/njpwworld.py
f5e3f6815e6e9fee65a386b8ba93b9e6ba0e4d83
[youtubedl] / youtube_dl / 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?://njpwworld\.com/p/(?P<id>[a-z0-9_]+)'
16 IE_DESC = '新日本プロレスワールド'
17 _NETRC_MACHINE = 'njpwworld'
18
19 _TEST = {
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': '第9試合 ランディ・サベージ vs リック・スタイナー',
25 'tags': list,
26 },
27 'params': {
28 'skip_download': True, # AES-encrypted m3u8
29 },
30 'skip': 'Requires login',
31 }
32
33 def _real_initialize(self):
34 self._login()
35
36 def _login(self):
37 username, password = self._get_login_info()
38 # No authentication to be performed
39 if not username:
40 return True
41
42 webpage, urlh = self._download_webpage_handle(
43 'https://njpwworld.com/auth/login', None,
44 note='Logging in', errnote='Unable to login',
45 data=urlencode_postdata({'login_id': username, 'pw': password}))
46 # /auth/login will return 302 for successful logins
47 if urlh.geturl() == 'https://njpwworld.com/auth/login':
48 self.report_warning('unable to login')
49 return False
50
51 return True
52
53 def _real_extract(self, url):
54 video_id = self._match_id(url)
55
56 webpage = self._download_webpage(url, video_id)
57
58 formats = []
59 for player_url, kind in re.findall(r'<a[^>]+href="(/player[^"]+)".+?<img[^>]+src="[^"]+qf_btn_([^".]+)', webpage):
60 player_url = compat_urlparse.urljoin(url, player_url)
61
62 player_page = self._download_webpage(
63 player_url, video_id, note='Downloading player page')
64
65 entries = self._parse_html5_media_entries(
66 player_url, player_page, video_id, m3u8_id='hls-%s' % kind,
67 m3u8_entry_protocol='m3u8_native',
68 preference=2 if 'hq' in kind else 1)
69 formats.extend(entries[0]['formats'])
70
71 self._sort_formats(formats)
72
73 post_content = get_element_by_class('post-content', webpage)
74 tags = re.findall(
75 r'<li[^>]+class="tag-[^"]+"><a[^>]*>([^<]+)</a></li>', post_content
76 ) if post_content else None
77
78 return {
79 'id': video_id,
80 'title': self._og_search_title(webpage),
81 'formats': formats,
82 'tags': tags,
83 }