]>
Commit | Line | Data |
---|---|---|
1 | from .common import InfoExtractor | |
2 | from ..compat import compat_urlparse | |
3 | from ..utils import ( | |
4 | ExtractorError, | |
5 | parse_duration, | |
6 | parse_filesize, | |
7 | str_to_int, | |
8 | unified_timestamp, | |
9 | urlencode_postdata, | |
10 | ) | |
11 | ||
12 | ||
13 | class PiaproIE(InfoExtractor): | |
14 | _NETRC_MACHINE = 'piapro' | |
15 | _VALID_URL = r'https?://piapro\.jp/(?:t|content)/(?P<id>[\w-]+)/?' | |
16 | _TESTS = [{ | |
17 | 'url': 'https://piapro.jp/t/NXYR', | |
18 | 'md5': 'f7c0f760913fb1d44a1c45a4af793909', | |
19 | 'info_dict': { | |
20 | 'id': 'NXYR', | |
21 | 'ext': 'mp3', | |
22 | 'uploader': 'wowaka', | |
23 | 'uploader_id': 'wowaka', | |
24 | 'title': '裏表ラバーズ', | |
25 | 'description': 'http://www.nicovideo.jp/watch/sm8082467', | |
26 | 'duration': 189.0, | |
27 | 'timestamp': 1251785475, | |
28 | 'thumbnail': r're:^https?://.*\.(?:png|jpg)$', | |
29 | 'upload_date': '20090901', | |
30 | 'view_count': int, | |
31 | } | |
32 | }, { | |
33 | 'note': 'There are break lines in description, mandating (?s) flag', | |
34 | 'url': 'https://piapro.jp/t/9cSd', | |
35 | 'md5': '952bb6d1e8de95050206408a87790676', | |
36 | 'info_dict': { | |
37 | 'id': '9cSd', | |
38 | 'ext': 'mp3', | |
39 | 'title': '青に溶けた風船 / 初音ミク', | |
40 | 'description': 'md5:d395a9bd151447631a5a1460bc7f9132', | |
41 | 'uploader': 'シアン・キノ', | |
42 | 'duration': 229.0, | |
43 | 'timestamp': 1644030039, | |
44 | 'upload_date': '20220205', | |
45 | 'view_count': int, | |
46 | 'thumbnail': r're:^https?://.*\.(?:png|jpg)$', | |
47 | 'uploader_id': 'cyankino', | |
48 | } | |
49 | }, { | |
50 | 'url': 'https://piapro.jp/content/hcw0z3a169wtemz6', | |
51 | 'only_matching': True | |
52 | }, { | |
53 | 'url': 'https://piapro.jp/t/-SO-', | |
54 | 'only_matching': True | |
55 | }] | |
56 | ||
57 | _login_status = False | |
58 | ||
59 | def _perform_login(self, username, password): | |
60 | login_ok = True | |
61 | login_form_strs = { | |
62 | '_username': username, | |
63 | '_password': password, | |
64 | '_remember_me': 'on', | |
65 | 'login': 'ログイン' | |
66 | } | |
67 | self._request_webpage('https://piapro.jp/login/', None) | |
68 | urlh = self._request_webpage( | |
69 | 'https://piapro.jp/login/exe', None, | |
70 | note='Logging in', errnote='Unable to log in', | |
71 | data=urlencode_postdata(login_form_strs)) | |
72 | if urlh is False: | |
73 | login_ok = False | |
74 | else: | |
75 | parts = compat_urlparse.urlparse(urlh.url) | |
76 | if parts.path != '/': | |
77 | login_ok = False | |
78 | if not login_ok: | |
79 | self.report_warning( | |
80 | 'unable to log in: bad username or password') | |
81 | self._login_status = login_ok | |
82 | ||
83 | def _real_extract(self, url): | |
84 | video_id = self._match_id(url) | |
85 | webpage = self._download_webpage(url, video_id) | |
86 | ||
87 | category_id = self._search_regex(r'categoryId=(.+)">', webpage, 'category ID') | |
88 | if category_id not in ('1', '2', '21', '22', '23', '24', '25'): | |
89 | raise ExtractorError('The URL does not contain audio.', expected=True) | |
90 | ||
91 | str_duration, str_filesize = self._search_regex( | |
92 | r'サイズ:</span>(.+?)/\(([0-9,]+?[KMG]?B))', webpage, 'duration and size', | |
93 | group=(1, 2), default=(None, None)) | |
94 | str_viewcount = self._search_regex(r'閲覧数:</span>([0-9,]+)\s+', webpage, 'view count', fatal=False) | |
95 | ||
96 | uploader_id, uploader = self._search_regex( | |
97 | r'<a\s+class="cd_user-name"\s+href="/(.*)">([^<]+)さん<', webpage, 'uploader', | |
98 | group=(1, 2), default=(None, None)) | |
99 | content_id = self._search_regex(r'contentId\:\'(.+)\'', webpage, 'content ID') | |
100 | create_date = self._search_regex(r'createDate\:\'(.+)\'', webpage, 'timestamp') | |
101 | ||
102 | player_webpage = self._download_webpage( | |
103 | f'https://piapro.jp/html5_player_popup/?id={content_id}&cdate={create_date}', | |
104 | video_id, note='Downloading player webpage') | |
105 | ||
106 | return { | |
107 | 'id': video_id, | |
108 | 'title': self._html_search_regex(r'<h1\s+class="cd_works-title">(.+?)</h1>', webpage, 'title', fatal=False), | |
109 | 'description': self._html_search_regex(r'(?s)<p\s+class="cd_dtl_cap">(.+?)</p>\s*<div', webpage, 'description', fatal=False), | |
110 | 'uploader': uploader, | |
111 | 'uploader_id': uploader_id, | |
112 | 'timestamp': unified_timestamp(create_date, False), | |
113 | 'duration': parse_duration(str_duration), | |
114 | 'view_count': str_to_int(str_viewcount), | |
115 | 'thumbnail': self._html_search_meta('twitter:image', webpage), | |
116 | ||
117 | 'filesize_approx': parse_filesize(str_filesize.replace(',', '')), | |
118 | 'url': self._search_regex(r'mp3:\s*\'(.*?)\'\}', player_webpage, 'url'), | |
119 | 'ext': 'mp3', | |
120 | 'vcodec': 'none', | |
121 | } |