-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathtest.py
More file actions
147 lines (124 loc) · 3.82 KB
/
test.py
File metadata and controls
147 lines (124 loc) · 3.82 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import asyncio
import json
import logging
import httpx
from pikpakapi import PikPakApi
async def log_token(client, extra_data):
logging.info(f"Token: {client.encoded_token}, Extra Data: {extra_data}")
async def test():
client = PikPakApi(
username="your_username",
password="your_password",
httpx_client_args={
"proxy": "http://127.0.0.1:1081",
"transport": httpx.AsyncHTTPTransport(retries=3),
},
token_refresh_callback=log_token,
token_refresh_callback_kwargs={"extra_data": "test"},
)
await client.login()
await client.refresh_access_token()
tasks = await client.offline_list()
print(json.dumps(tasks, indent=4))
print("=" * 30, end="\n\n")
if tasks.get("tasks"):
await client.delete_tasks(task_ids=[tasks["tasks"][0]["id"]])
print(json.dumps(client.get_user_info(), indent=4))
print("=" * 30, end="\n\n")
print(
json.dumps(
await client.offline_download(
"magnet:?xt=urn:btih:42b46b971332e776e8b290ed34632d5c81a1c47c"
),
indent=4,
)
)
print("=" * 30, end="\n\n")
print(json.dumps(await client.offline_list(), indent=4))
print("=" * 30, end="\n\n")
print(
json.dumps(
await client.offline_file_info("VN5omQUMRn5NlHL8lMt91q5Io1"), indent=4
)
)
print("=" * 30, end="\n\n")
print(
json.dumps(
await client.file_rename(
"VNayNjZtsdmka4YrwZWVj-r4o1",
"[Nekomoe kissaten][Deaimon][11][1080p][CHS]_01.mp4",
),
indent=4,
)
)
print("=" * 30, end="\n\n")
print(
json.dumps(
await client.file_batch_star(ids=["VN6qSS-FBcaI6l7YltWsjUU1o1"]), indent=4
)
)
print("=" * 30, end="\n\n")
print(
json.dumps(
await client.file_batch_unstar(ids=["VN6qSS-FBcaI6l7YltWsjUU1o1"]), indent=4
)
)
print("=" * 30, end="\n\n")
print(json.dumps(await client.file_star_list(), indent=4))
print("=" * 30, end="\n\n")
print(
json.dumps(
await client.file_batch_share(
ids=["VN6qSS-FBcaI6l7YltWsjUU1o1"], need_password=True
)
)
)
print("=" * 30, end="\n\n")
print(json.dumps(await client.get_quota_info(), indent=4))
print("=" * 30, end="\n\n")
print(
json.dumps(
await client.get_share_info(
"https://mypikpak.com/s/VO8BcRb-0fibD0Ncymp8nxSMo1"
),
indent=4,
)
)
test_restore = await client.get_share_info(
"https://mypikpak.com/s/VO8BcRb-0fibD0Ncymp8nxSMo1/VO8Ba45l-FRcCf559uZjwjFjo1"
)
await client.restore(
share_id="VO8BcRb-0fibD0Ncymp8nxSMo1",
pass_code_token=test_restore.get("pass_code_token"),
file_ids=[
"VO8BcNTLpxHtBHDFH0d5cGRzo1",
],
)
async def test_save():
client = PikPakApi(
username="your_username",
password="your_password",
)
await client.login()
await client.refresh_access_token()
with open("pikpak.json", "w") as f:
f.write(json.dumps(client.to_dict(), indent=4))
with open("pikpak.json", "r") as f:
data = json.load(f)
client = PikPakApi.from_dict(data)
await client.refresh_access_token()
print(json.dumps(client.get_user_info(), indent=4))
print(
json.dumps(
await client.get_share_info(
"https://mypikpak.com/s/VO8BcRb-0fibD0Ncymp8nxSMo1"
),
indent=4,
)
)
if __name__ == "__main__":
logging.basicConfig(
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
)
asyncio.run(test())
asyncio.run(test_save())