]>
Commit | Line | Data |
---|---|---|
6bb608d0 LNO |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | from .common import InfoExtractor | |
5 | from ..compat import compat_urlparse | |
6 | from ..utils import ( | |
7 | ExtractorError, | |
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/(?P<id>\w+)/?' | |
19 | _TESTS = [{ | |
20 | 'url': 'https://piapro.jp/t/NXYR', | |
21 | 'md5': 'a9d52f27d13bafab7ee34116a7dcfa77', | |
22 | 'info_dict': { | |
23 | 'id': 'NXYR', | |
24 | 'ext': 'mp3', | |
25 | 'uploader': 'wowaka', | |
26 | 'uploader_id': 'wowaka', | |
27 | 'title': '裏表ラバーズ', | |
28 | 'thumbnail': r're:^https?://.*\.jpg$', | |
29 | } | |
30 | }] | |
31 | ||
52efa4b3 | 32 | _login_status = False |
6bb608d0 | 33 | |
52efa4b3 | 34 | def _perform_login(self, username, password): |
6bb608d0 LNO |
35 | login_ok = True |
36 | login_form_strs = { | |
37 | '_username': username, | |
38 | '_password': password, | |
39 | '_remember_me': 'on', | |
40 | 'login': 'ログイン' | |
41 | } | |
42 | self._request_webpage('https://piapro.jp/login/', None) | |
43 | urlh = self._request_webpage( | |
44 | 'https://piapro.jp/login/exe', None, | |
45 | note='Logging in', errnote='Unable to log in', | |
46 | data=urlencode_postdata(login_form_strs)) | |
47 | if urlh is False: | |
48 | login_ok = False | |
49 | else: | |
50 | parts = compat_urlparse.urlparse(urlh.geturl()) | |
51 | if parts.path != '/': | |
52 | login_ok = False | |
53 | if not login_ok: | |
54 | self.report_warning( | |
55 | 'unable to log in: bad username or password') | |
52efa4b3 | 56 | self._login_status = login_ok |
6bb608d0 LNO |
57 | |
58 | def _real_extract(self, url): | |
59 | video_id = self._match_id(url) | |
60 | webpage = self._download_webpage(url, video_id) | |
61 | ||
62 | category_id = self._search_regex(r'categoryId=(.+)">', webpage, 'category ID') | |
63 | if category_id not in ('1', '2', '21', '22', '23', '24', '25'): | |
64 | raise ExtractorError('The URL does not contain audio.', expected=True) | |
65 | ||
66 | str_duration, str_filesize = self._search_regex( | |
67 | r'サイズ:</span>(.+?)/\(([0-9,]+?[KMG]?B))', webpage, 'duration and size', | |
68 | group=(1, 2), default=(None, None)) | |
69 | str_viewcount = self._search_regex(r'閲覧数:</span>([0-9,]+)\s+', webpage, 'view count', fatal=False) | |
70 | ||
71 | uploader_id, uploader = self._search_regex( | |
72 | r'<a\s+class="cd_user-name"\s+href="/(.*)">([^<]+)さん<', webpage, 'uploader', | |
73 | group=(1, 2), default=(None, None)) | |
74 | content_id = self._search_regex(r'contentId\:\'(.+)\'', webpage, 'content ID') | |
75 | create_date = self._search_regex(r'createDate\:\'(.+)\'', webpage, 'timestamp') | |
76 | ||
77 | player_webpage = self._download_webpage( | |
78 | f'https://piapro.jp/html5_player_popup/?id={content_id}&cdate={create_date}', | |
79 | video_id, note='Downloading player webpage') | |
80 | ||
81 | return { | |
82 | 'id': video_id, | |
83 | 'title': self._html_search_regex(r'<h1\s+class="cd_works-title">(.+?)</h1>', webpage, 'title', fatal=False), | |
84 | 'description': self._html_search_regex(r'<p\s+class="cd_dtl_cap">(.+?)</p>\s*<div', webpage, 'description', fatal=False), | |
85 | 'uploader': uploader, | |
86 | 'uploader_id': uploader_id, | |
87 | 'timestamp': unified_timestamp(create_date, False), | |
88 | 'duration': parse_duration(str_duration), | |
89 | 'view_count': str_to_int(str_viewcount), | |
90 | 'thumbnail': self._html_search_meta('twitter:image', webpage), | |
91 | ||
92 | 'filesize_approx': parse_filesize(str_filesize.replace(',', '')), | |
93 | 'url': self._search_regex(r'mp3:\s*\'(.*?)\'\}', player_webpage, 'url'), | |
94 | 'ext': 'mp3', | |
95 | 'vcodec': 'none', | |
96 | } |