]>
Commit | Line | Data |
---|---|---|
1 | import urllib.parse | |
2 | ||
3 | from .common import InfoExtractor | |
4 | from ..utils import ( | |
5 | ExtractorError, | |
6 | clean_html, | |
7 | get_element_by_class, | |
8 | parse_duration, | |
9 | parse_filesize, | |
10 | str_to_int, | |
11 | unified_timestamp, | |
12 | urlencode_postdata, | |
13 | ) | |
14 | ||
15 | ||
16 | class PiaproIE(InfoExtractor): | |
17 | _NETRC_MACHINE = 'piapro' | |
18 | _VALID_URL = r'https?://piapro\.jp/(?:t|content)/(?P<id>[\w-]+)/?' | |
19 | _TESTS = [{ | |
20 | 'url': 'https://piapro.jp/t/NXYR', | |
21 | 'md5': 'f7c0f760913fb1d44a1c45a4af793909', | |
22 | 'info_dict': { | |
23 | 'id': 'NXYR', | |
24 | 'ext': 'mp3', | |
25 | 'uploader': 'wowaka', | |
26 | 'uploader_id': 'wowaka', | |
27 | 'title': '裏表ラバーズ', | |
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, | |
34 | }, | |
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': 'シアン・キノ', | |
45 | 'duration': 229.0, | |
46 | 'timestamp': 1644030039, | |
47 | 'upload_date': '20220205', | |
48 | 'view_count': int, | |
49 | 'thumbnail': r're:^https?://.*\.(?:png|jpg)$', | |
50 | 'uploader_id': 'cyankino', | |
51 | }, | |
52 | }, { | |
53 | 'url': 'https://piapro.jp/content/hcw0z3a169wtemz6', | |
54 | 'only_matching': True, | |
55 | }, { | |
56 | 'url': 'https://piapro.jp/t/-SO-', | |
57 | 'only_matching': True, | |
58 | }] | |
59 | ||
60 | _login_status = False | |
61 | ||
62 | def _perform_login(self, username, password): | |
63 | login_ok = True | |
64 | login_form_strs = { | |
65 | '_username': username, | |
66 | '_password': password, | |
67 | '_remember_me': 'on', | |
68 | 'login': 'ログイン', | |
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: | |
78 | parts = urllib.parse.urlparse(urlh.url) | |
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') | |
84 | self._login_status = login_ok | |
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 | ||
94 | def extract_info(name, description): | |
95 | return self._search_regex(rf'{name}[::]\s*([\d\s,:/]+)\s*</p>', webpage, description, default=None) | |
96 | ||
97 | return { | |
98 | 'id': video_id, | |
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')), | |
107 | 'thumbnail': self._html_search_meta('twitter:image', webpage), | |
108 | 'filesize_approx': parse_filesize((extract_info('サイズ', 'size') or '').replace(',', '')), | |
109 | 'url': self._search_regex(r'\"url\":\s*\"(.*?)\"', webpage, 'url'), | |
110 | 'ext': 'mp3', | |
111 | 'vcodec': 'none', | |
112 | } |