feat: implement age limit

This commit is contained in:
Yannik Schmidt
2025-04-13 00:52:51 +02:00
parent 4e9b85ee6d
commit 8e5bfd9ae3
4 changed files with 18 additions and 5 deletions

View File

@@ -338,6 +338,8 @@ if __name__ == "__main__":
password = config_loaded.get("Password:")
install_dir = config_loaded["Install dir:"]
backend_type = config_loaded["Select option:"]
hide_above_age = config_loaded.get("hide_above_age") or 100
# fix abs path if not set #
if os.path.abspath(install_dir):
@@ -365,7 +367,8 @@ if __name__ == "__main__":
# add db backend #
if backend_type == "HTTP/HTTPS":
db = data_backend.HTTP(None, None, install_dir, remote_root_dir="./", server=server, progress_bar_wrapper=pgw, tkinter_root=app)
db = data_backend.HTTP(None, None, install_dir, remote_root_dir="./", server=server, progress_bar_wrapper=pgw,
tkinter_root=app, hide_above_age=hide_above_age)
elif backend_type == "FTP/FTPS":
db = data_backend.FTP(user, password, install_dir, server=server,
remote_root_dir=remote_root_dir, progress_bar_wrapper=pgw, tkinter_root=app)

View File

@@ -16,7 +16,7 @@ class DataBackend:
os.makedirs(cache_dir, exist_ok=True)
def __init__(self, user, password, install_dir, server=None, remote_root_dir=None,
progress_bar_wrapper=None, tkinter_root=None):
progress_bar_wrapper=None, tkinter_root=None, hide_above_age=100):
self.user = user
self.password = password
@@ -26,6 +26,7 @@ class DataBackend:
self.progress_bar_wrapper = progress_bar_wrapper
self.root = tkinter_root
self.cache_dir = "./cache/"
self.hide_above_age = hide_above_age
def get(self, path, return_content=False):
'''Return the contents of this path'''
@@ -163,7 +164,7 @@ class HTTP(DataBackend):
# f.write(r.text)
# this is with streaming
chunk_size = 1024 * 1024 * 50 # 50MB
chunk_size = 1024 * 1024 * 5 # 5MB
r = requests.get(self._get_url(), params={"path": path, "as_string": True}, stream=True)
r.raise_for_status()
@@ -264,4 +265,12 @@ class HTTP(DataBackend):
print("Software List:", software_list)
print("Invalid:", list(filter(lambda x: x.invalid, software_list)))
print("Valid:", list(filter(lambda x: not x.invalid, software_list)))
return list(filter(lambda x: not x.invalid, software_list))
# filter valid #
results_valid = list(filter(lambda x: not x.invalid, software_list))
# filer age #
print("Age limit set to", self.hide_above_age, "games have", [x.age_limit for x in software_list])
results_with_age = list(filter(lambda x: x.age_limit <= self.hide_above_age, results_valid))
return results_with_age

View File

@@ -107,7 +107,7 @@ class ProgressBarApp:
same_size_count += 1
else:
same_size_count = 0
if same_size_count > 5:
if same_size_count > 100:
self.root.after(0, delete_button.config, {"state": tk.NORMAL, "text": "Failed - Delete file manually!"})
self.progress_bars.append((progress, frame, path, delete_button))
self.update_delete_all_button()

View File

@@ -59,6 +59,7 @@ class Software:
self.run_exe = meta.get("run_exe")
self.installer = meta.get("installer")
self.installer_no_admin = meta.get("installer_no_admin")
self.age_limit = meta.get("age_limit") or 20
self.pictures = [ self.backend.get(pp, self.cache_dir) for pp in
self.backend.list(os.path.join(self.directory, "pictures"), fullpaths=True) ]