-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto.py
149 lines (101 loc) · 4.82 KB
/
auto.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
import os
from tkinter import messagebox
class Automatic:
def __init__(self):
self.letters = ("C", "D", "E", "F") # Units where the program will try to find osu!/songs
self.skipFiles = (".rar",".zip",".7z")
self.templates = (
":/Users/" + os.getlogin() + "/AppData/Local/osu!/Songs",
":/Program Files/osu!/Songs",
":/Program Files (x86)/osu!/Songs"
)
self.currentTry = ""
self.manualDir = ()
self.posDirs = []
# ---------------------------
self.bmFiltered = []
self.filtered_video_list = []
self.currentID = ""
self.listaNum = ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9")
self.door = True
def construct_dirs(self): # Method only called when class instanced
"""Constructs all possible directories with the given parameters in
self.templates and self.letters"""
for letter in self.letters:
for dir in self.templates:
self.posDirs.append(letter + dir)
def choose_dir(self, check_val, entry_dir):
"""Checks which dir from self.posDirs is the correct one"""
if check_val == 1: # If checkbox enabled
for i in self.posDirs: # Looking for the Songs directory
self.currentTry = i
if os.path.isdir(self.currentTry): # If dir exists the enter
os.chdir(self.currentTry)
print("Directory", self.currentTry, "successully found!")
break
else:
# print("Directory not found at", self.currentTry)
self.currentTry = ""
if self.currentTry == "":
messagebox.showerror('Error', "Default folder couldn't be found," +
"\n use the custom directory option."
)
return "error"
# This will be executed in case the automatic detection didn't work.
elif check_val == 0 or entry_dir == "": # If checkbox not enabled or entry empty
self.currentTry = entry_dir
if os.path.isdir(self.currentTry):
os.chdir(self.currentTry)
print("Directory", self.currentTry, "successully found!")
else:
messagebox.showerror("Error", "The selected directory does not exist.")
print("Directory not found at", self.currentTry)
self.currentTry = ""
return "error"
else:
return None
def check_dirs(self):
"""Detects which folders in Songs are beatmap folders and which not"""
for bm in os.listdir(): # Looking for just beatmap folders
self.door = True
if bm.count(" ") == 0: # Skip files/folders in "Songs" without spaces
continue
if bm[-4:] in self.skipFiles: # Skip compressed files
continue
else: # Detects if the folder is a beatmap one using the ID
self.currentID = bm[0:bm.find(" ")]
# print(type(self.currentID))
for char in self.currentID:
if char in self.listaNum:
continue
else:
self.door = False
break
if self.door:
self.bmFiltered.append(self.currentTry + "/" + bm)
def filter_videos(self):
"""Creates a new list that contains the video folders"""
for directory in self.bmFiltered: # Looking for videos
os.chdir(directory)
for file in os.listdir():
# FILTERS
if ".mp4" in file[-4:]:
self.filtered_video_list.append(directory + "/" + file)
elif ".avi" in file[-4:]:
self.filtered_video_list.append(directory + "/" + file)
elif ".flv" in file[-4:]:
self.filtered_video_list.append(directory + "/" + file)
elif ".wmv" in file[-4:]:
self.filtered_video_list.append(directory + "/" + file)
def reset(self): # Called from main class.
"""Resets some vars of the class"""
self.currentTry = ""
self.manualDir = ()
# ---------------------------
self.bmFiltered.clear()
self.filtered_video_list.clear()
self.currentID = ""
self.door = True
if __name__ != "__main__":
auto_obj = Automatic()
auto_obj.construct_dirs() # This method is called here because It will just be exec once.