-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanicon.py
92 lines (82 loc) · 2.83 KB
/
manicon.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
import os
from time import sleep
import cfscrape
import regex
import requests
from PIL import Image, ImageOps
def createicon(folder: str, name: str, pic: str):
img = Image.open(pic)
img = ImageOps.expand(img, (69, 0, 69, 0), fill=0)
img = ImageOps.fit(img, (300, 300)).convert("RGBA")
datas = img.getdata()
newData = []
for item in datas:
if item[0] == 0 and item[1] == 0 and item[2] == 0:
newData.append((0, 0, 0, 0))
else:
newData.append(item)
img.putdata(newData)
img.save(folder + "\\" + name + ".ico")
img.close()
return folder + "\\" + name + ".ico"
def process(folder: str):
name = regex.sub(r" \[anidb-\d+]", "", folder)
query = """
query ($name: String) {
Media (search: $name, type: ANIME) {
id
title {
romaji
}
bannerImage
coverImage {
extraLarge
}
}
}
"""
variables = {
"name": name
}
url = 'https://graphql.anilist.co'
response = requests.post(url, json={'query': query, 'variables': variables}).json()["data"]["Media"]
id = response["id"]
banner = response["bannerImage"]
cover = response["coverImage"]["extraLarge"]
if not os.path.exists(folder + "\\Cover"):
os.mkdir(folder + "\\Cover")
scraper = cfscrape.create_scraper()
if not os.path.exists(folder + "\\Cover\\" + str(id) + "b.png"):
if banner:
bannerimg = scraper.get(banner)
with open(folder + "\\Cover\\" + str(id) + "b.png", 'wb') as f:
bannerimg.decode_content = True
f.write(bannerimg.content)
if not os.path.exists(folder + "\\Cover\\" + str(id) + "c.png"):
coverimg = scraper.get(cover)
with open(folder + "\\Cover\\" + str(id) + "c.png", 'wb') as f:
coverimg.decode_content = True
f.write(coverimg.content)
if os.path.exists(folder + "\\" + name + ".ico") or os.path.exists(folder + "\\desktop.ini"):
print(name + " Already done")
return
try:
icon = createicon(folder, name, folder + "\\Cover\\" + str(id) + "c.png")
except:
print("Ran into an error. Blame the Dev :(")
return
f = open(folder + "\\desktop.ini", "w+", encoding="ANSI")
f.write("[.ShellClassInfo]\nConfirmFileOp=0\n")
f.write(f"IconResource={name}.ico,0")
f.write(f"\nIconFile={name}.ico\nIconIndex=0")
f.close()
os.system('attrib +r \"{}\\{}\"'.format(os.getcwd(),folder))
os.system('attrib +h \"{}\\desktop.ini\"'.format(folder))
os.system('attrib +h \"{}\"'.format(icon))
folders = next(os.walk('.'))[1]
count = 0
for folder in folders:
if (count == 89):
sleep(60)
process(folder)
count += 1