-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
178 lines (151 loc) · 6.84 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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/python
import os
import sys
from colour import Color
import configparser
#rootdir = 'D:/FL STUDIO!/!SAMPLES/!SWAIN -PARANOID'
config_folder = ''
config_folder_color1 = ''
config_folder_color2 = ''
config_file_color1 = ''
config_file_color2 = ''
config_ignore_subs = ''
def main():
loadsettings('settings.txt')
os.system('color 4')
print("Make sure the settings below are correct before continuing.")
print("Folder: "+config_folder)
print("Ignore subfolders: " + config_ignore_subs)
input("Press enter if these settings are correct.")
os.system('color a')
# remove nfo files first
if config_ignore_subs == 'false':
for subdir, dirs, files in os.walk(config_folder):
for file in files:
# print(os.path.splitext(file)[1])
if os.path.splitext(file)[1] == ".nfo":
os.remove(subdir + os.sep + file)
if config_ignore_subs == 'true':
for file in os.listdir(config_folder):
if os.path.splitext(file)[1] == ".nfo":
os.remove(config_folder + os.sep + file)
# dict1 is wavs
dirlist = []
dict1 = {}
#if ignore sub folders is true, we will not use os.walk
if config_ignore_subs == 'false':
for subdir, dirs, files in os.walk(config_folder):
if subdir not in dirlist:
dirlist.append(subdir)
for file in files:
count = dict1.get(subdir, 0)
count = count + 1
dict1[subdir] = count
if subdir not in dirlist:
dirlist.append(subdir)
if config_ignore_subs == 'true':
for file in os.listdir(config_folder):
subdir = config_folder+os.sep+file
if subdir not in dirlist:
dirlist.append(subdir)
#make root folder colored
originalpath = os.getcwd()
os.chdir(config_folder)
os.chdir('../')
with open(os.path.basename(config_folder) + ".nfo", 'w') as f:
color1 = Color(config_folder_color1)
sys.stdout.write("\rcurrent file: "+os.path.basename(config_folder)+"...................................")
finalcolor = str(color1.hex_l)[1:]
finalcolorfinal = finalcolor[4]+finalcolor[5]+finalcolor[2]+finalcolor[3]+finalcolor[0]+finalcolor[1]
f.write('Color=$' + finalcolorfinal + '\n')
f.write('IconIndex=21\n')
f.write('HeightOfs=0\n')
f.write('SortGroup=1\n')
f.write('---------\n')
f.write("colorized by zigafide's colorizer\n")
f.write('follow @zigafidethegod on Instagram')
os.chdir(originalpath)
#dirlist.append(config_folder)
folderindex = {}
foldersize = {}
#add all folders to dict
for folder in dirlist:
folderindex[os.path.dirname(folder)] = 0
foldersize[os.path.dirname(folder)] = 0
for folder in dirlist:
foldersize[os.path.dirname(folder)] = foldersize[os.path.dirname(folder)] + 1
for folder in dirlist:
foldername = os.path.basename(folder)
# print(dict1[key])
if os.path.isfile(folder):
foldername = os.path.splitext(foldername)[0]
with open(os.path.dirname(folder) + os.sep + foldername + ".nfo", 'w') as f:
color1 = Color(config_folder_color1)
color2 = Color(config_folder_color2)
colors = list(color1.range_to(color2, foldersize[os.path.dirname(folder)]))
sys.stdout.write("\rcurrent file: "+foldername+"...................................")
finalcolor = str(colors[folderindex[os.path.dirname(folder)]].hex_l)[1:]
finalcolorfinal = finalcolor[4]+finalcolor[5]+finalcolor[2]+finalcolor[3]+finalcolor[0]+finalcolor[1]
f.write('Color=$' + finalcolorfinal + '\n')
f.write('IconIndex=21\n')
f.write('HeightOfs=0\n')
f.write('SortGroup=1\n')
f.write('---------\n')
f.write("colorized by zigafide's colorizer\n")
f.write('follow @zigafidethegod on Instagram')
folderindex[os.path.dirname(folder)] = folderindex[os.path.dirname(folder)] + 1
for key in dict1.keys():
for subdir, dirs, files in os.walk(key):
index = 0
howmanyfiles = dict1[key]
for file in files:
# print(file)
# print(dict1[key])
if not os.path.splitext(file)[1] == '.nfo':
if os.path.isfile(key + os.sep + file):
with open(key + os.sep + os.path.splitext(file)[0] + ".nfo", 'w') as f:
# convert hex to decimal
color1 = Color(config_file_color1)
color2 = Color(config_file_color2)
colors = list(color1.range_to(color2, howmanyfiles))
extension = os.path.splitext(file)[1]
iconindex = iconfromext(extension)
sys.stdout.write("\rcurrent file: " + file+"...................................")
finalcolor = str(colors[index].hex_l)[1:]
finalcolorfinal = finalcolor[4]+finalcolor[5]+finalcolor[2]+finalcolor[3]+finalcolor[0]+finalcolor[1]
f.write('Color=$' + finalcolorfinal + '\n')
f.write('IconIndex=' + str(iconindex) + '\n')
f.write('HeightOfs=0\n')
f.write('SortGroup=1\n')
f.write('---------\n')
f.write("colorized by zigafide's colorizer\n")
f.write('follow @zigafidethegod on Instagram')
index = index + 1
#function for deciding which icon to use
def iconfromext(ext):
match ext:
case '.wav':
return 33
case '.mid':
return 9
case _:
return 33
def loadsettings(filename):
config = configparser.ConfigParser()
config.read("settings.txt")
global config_folder
global config_folder_color1
global config_folder_color2
global config_file_color1
global config_file_color2
global config_ignore_subs
config_folder = config.get("config", "drumkit_folder")
config_folder_color1 = config.get("config", "folders_color1")
config_folder_color2 = config.get("config", "folders_color2")
config_file_color1 = config.get("config", "files_color1")
config_file_color2 = config.get("config", "files_color2")
config_ignore_subs = config.get("config", "ignore_sub_folders")
main()
print("\nDone!")
print("Script by zigafide")
input(".")