]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/piapro.py
[ie/youtube] Suppress "Unavailable videos are hidden" warning (#10159)
[yt-dlp.git] / yt_dlp / extractor / piapro.py
CommitLineData
add96eb9 1import urllib.parse
2
6bb608d0 3from .common import InfoExtractor
6bb608d0
LNO
4from ..utils import (
5 ExtractorError,
3ba8de62
FG
6 clean_html,
7 get_element_by_class,
6bb608d0
LNO
8 parse_duration,
9 parse_filesize,
10 str_to_int,
11 unified_timestamp,
12 urlencode_postdata,
13)
14
15
16class PiaproIE(InfoExtractor):
17 _NETRC_MACHINE = 'piapro'
8e6e3651 18 _VALID_URL = r'https?://piapro\.jp/(?:t|content)/(?P<id>[\w-]+)/?'
6bb608d0
LNO
19 _TESTS = [{
20 'url': 'https://piapro.jp/t/NXYR',
1bcb9fe8 21 'md5': 'f7c0f760913fb1d44a1c45a4af793909',
6bb608d0
LNO
22 'info_dict': {
23 'id': 'NXYR',
24 'ext': 'mp3',
25 'uploader': 'wowaka',
26 'uploader_id': 'wowaka',
27 'title': '裏表ラバーズ',
1bcb9fe8
FG
28 'description': 'http://www.nicovideo.jp/watch/sm8082467',
29 'duration': 189.0,
30 'timestamp': 1251785475,
31 'thumbnail': r're:^https?://.*\.(?:png|jpg)$',
32 'upload_date': '20090901',
33 'view_count': int,
add96eb9 34 },
b52e788e
L
35 }, {
36 'note': 'There are break lines in description, mandating (?s) flag',
37 'url': 'https://piapro.jp/t/9cSd',
38 'md5': '952bb6d1e8de95050206408a87790676',
39 'info_dict': {
40 'id': '9cSd',
41 'ext': 'mp3',
42 'title': '青に溶けた風船 / 初音ミク',
43 'description': 'md5:d395a9bd151447631a5a1460bc7f9132',
44 'uploader': 'シアン・キノ',
1bcb9fe8
FG
45 'duration': 229.0,
46 'timestamp': 1644030039,
47 'upload_date': '20220205',
48 'view_count': int,
49 'thumbnail': r're:^https?://.*\.(?:png|jpg)$',
b52e788e 50 'uploader_id': 'cyankino',
add96eb9 51 },
1bcb9fe8
FG
52 }, {
53 'url': 'https://piapro.jp/content/hcw0z3a169wtemz6',
add96eb9 54 'only_matching': True,
8e6e3651
FG
55 }, {
56 'url': 'https://piapro.jp/t/-SO-',
add96eb9 57 'only_matching': True,
6bb608d0
LNO
58 }]
59
52efa4b3 60 _login_status = False
6bb608d0 61
52efa4b3 62 def _perform_login(self, username, password):
6bb608d0
LNO
63 login_ok = True
64 login_form_strs = {
65 '_username': username,
66 '_password': password,
67 '_remember_me': 'on',
add96eb9 68 'login': 'ログイン',
6bb608d0
LNO
69 }
70 self._request_webpage('https://piapro.jp/login/', None)
71 urlh = self._request_webpage(
72 'https://piapro.jp/login/exe', None,
73 note='Logging in', errnote='Unable to log in',
74 data=urlencode_postdata(login_form_strs))
75 if urlh is False:
76 login_ok = False
77 else:
add96eb9 78 parts = urllib.parse.urlparse(urlh.url)
6bb608d0
LNO
79 if parts.path != '/':
80 login_ok = False
81 if not login_ok:
82 self.report_warning(
83 'unable to log in: bad username or password')
52efa4b3 84 self._login_status = login_ok
6bb608d0
LNO
85
86 def _real_extract(self, url):
87 video_id = self._match_id(url)
88 webpage = self._download_webpage(url, video_id)
89
90 category_id = self._search_regex(r'categoryId=(.+)">', webpage, 'category ID')
91 if category_id not in ('1', '2', '21', '22', '23', '24', '25'):
92 raise ExtractorError('The URL does not contain audio.', expected=True)
93
3ba8de62
FG
94 def extract_info(name, description):
95 return self._search_regex(rf'{name}[::]\s*([\d\s,:/]+)\s*</p>', webpage, description, default=None)
6bb608d0
LNO
96
97 return {
98 'id': video_id,
3ba8de62
FG
99 'title': clean_html(get_element_by_class('contents_title', webpage)),
100 'description': clean_html(get_element_by_class('contents_description', webpage)),
101 'uploader': clean_html(get_element_by_class('contents_creator_txt', webpage)),
102 'uploader_id': self._search_regex(
103 r'<a\s+href="/([^"]+)"', get_element_by_class('contents_creator', webpage), 'uploader id', default=None),
104 'timestamp': unified_timestamp(extract_info('投稿日', 'timestamp'), False),
105 'duration': parse_duration(extract_info('長さ', 'duration')),
106 'view_count': str_to_int(extract_info('閲覧数', 'view count')),
6bb608d0 107 'thumbnail': self._html_search_meta('twitter:image', webpage),
3ba8de62
FG
108 'filesize_approx': parse_filesize((extract_info('サイズ', 'size') or '').replace(',', '')),
109 'url': self._search_regex(r'\"url\":\s*\"(.*?)\"', webpage, 'url'),
6bb608d0
LNO
110 'ext': 'mp3',
111 'vcodec': 'none',
112 }