-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.py
67 lines (64 loc) · 2.04 KB
/
main.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
import time
from lib.pixiv import PixivAPI
from lib.config import Config
from lib import utils, cmd
def download_users(api, config, option, **kwargs):
start_time = time.time()
print("logging in to Pixiv...")
api.login(config.username, config.password)
if option == "artwork":
result = api.save_users_artworks(config.users, config.save_dir)
elif option == "bookmark":
result = api.save_users_bookmarks(config.bookmarks, config.save_dir)
elif option == "ranking":
result = api.save_rankings(**kwargs)
duration = time.time() - start_time
size_mb = result["size"] / 1048576
print("\nSUMMARY")
print("---------------------------------")
print(f"time elapsed:\t{duration:.4f} seconds")
print(f"total size:\t{size_mb:.4f} MB")
print(f"total artworks:\t{result['count']} artworks")
print(f"download speed:\t{(size_mb / duration):.4f} MB/s")
def main():
api = PixivAPI()
args = cmd.main_parser()
config = Config(args.f)
if args.l:
config.print()
if args.u:
config.username = args.u
if args.p:
config.password = args.p
if args.s:
config.save_dir = args.s
if args.t:
api.threads = args.t
if args.option == "artwork":
if args.a:
config.add_users(args.a)
if args.d:
config.delete_users(args.d)
if args.c:
config.clear_users(args.c)
download_users(api, config, args.option)
elif args.option == "bookmark":
if args.a:
config.add_bookmarks(args.a)
if args.d:
config.delete_bookmarks(args.d)
if args.c:
config.clear_bookmarks(args.c)
download_users(api, config, args.option)
elif args.option == "ranking":
params = {
"mode": args.m,
"content": args.c,
"date": args.d,
"limit": args.n,
"dir_path": config.save_dir
}
download_users(api, config, args.option, **params)
config.update()
if __name__ == '__main__':
main()