-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpiapro.py
113 lines (82 loc) · 2.52 KB
/
piapro.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import requests
import re
import sys
import time
def login():
data = {
'_username': username,
'_password': password,
'_remember_me': 'on',
'login': 'ログイン'
}
r1 = s.get('https://piapro.jp/')
r = s.post('https://piapro.jp/login/exe', data = data, allow_redirects=False)
return s.cookies
def get_info(url):
r = requests.get(url)
contentId = re.findall('contentId:\'(.+?)\',', r.text)[0]
createDate = re.findall('createDate:\'(.+?)\',', r.text)[0]
return contentId, createDate
def get_mp3(url):
contentId, createDate = get_info(url)
htmlURL = f'https://piapro.jp/html5_player_popup/?id={contentId}&cdate={createDate}&p=0'
r = requests.get(htmlURL)
title = re.findall("title: '(.+?)'", r.text)
artist = re.findall("artist: '(.+?)'", r.text)
mp3 = re.findall("mp3: '(.+?)'", r.text)
print(title, artist, mp3)
def get_img(url):
cookies = login()
r = s.get(url, cookies = cookies)
html = r.text
try:
contentId = re.findall('contentId: \'(.+?)\'', html)[0]
createDate = re.findall('createDate]" required="required" value="(.+?)"', html)[0]
license = re.findall('license]" required="required" value="(.+?)"', html)[0]
folderId = re.findall('defaultFolderId:(.+?),', html)[0]
token = re.findall('_token]" value="(.+?)"', html)[0]
except:
print('作品禁止下载!')
sys.exit(0)
data = {
'DownloadWithBookmark[contentId]': contentId,
'DownloadWithBookmark[createDate]': createDate,
'DownloadWithBookmark[license]': license,
'DownloadWithBookmark[folderId]': folderId,
'DownloadWithBookmark[_token]': token,
}
r1 = s.post('https://piapro.jp/download/content_with_bookmark/', data, stream=True)
Type = r1.headers['Content-Type']
file_size = r1.headers['Content-Length']
if Type == 'image/jpeg':
suffix = '.jpg'
elif Type == 'image/png':
suffix = '.png'
elif Type == 'image/gif':
suffix = '.gif'
filename = f"{url.split('/')[-1]}_{createDate}{suffix}"
with open(filename, 'wb') as f2:
f2.write(r1.content)
f2.close()
print(f'下载完成:{filename}')
def main(url):
r = requests.get(url)
category = re.findall('view:\'(.+?)\'', r.text)[0]
if category == 'audio':
get_mp3(url)
sys.exit(0)
elif category == 'image':
if username and password:
get_img(url)
else:
print('下载图片需要登录,请填写帐号密码再进行操作。')
sys.exit(0)
if __name__ == '__main__':
s = requests.session()
username = '' # 帐号
password = '' # 密码
url = sys.argv[1]
start = time.time()
main(url)
end = time.time()
print('用时:{}秒'.format(int(end - start)))