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