Created
February 21, 2024 17:48
-
-
Save sirkingjamz/5a7f322125c8abadc6f83edfed03af97 to your computer and use it in GitHub Desktop.
Server Automated Maintenance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tkinter as tk | |
from tkinter import filedialog, messagebox, ttk | |
import os | |
root = tk.Tk() | |
root.title("File Organizer") | |
def select_monitoring_folder(): | |
folder = filedialog.askdirectory() | |
if folder: | |
listbox_monitored_folders.insert(tk.END, folder) | |
def clear_selected_folders(): | |
listbox_monitored_folders.delete(0, tk.END) | |
left_frame = tk.Frame(root) | |
left_frame.pack(side=tk.LEFT, padx=10, pady=10) | |
btn_select_folder = tk.Button(left_frame, text="Select Folder", command=select_monitoring_folder) | |
btn_select_folder.pack() | |
btn_clear_folders = tk.Button(left_frame, text="Clear Selection", command=clear_selected_folders) | |
btn_clear_folders.pack() | |
right_frame = tk.Frame(root) | |
right_frame.pack(side=tk.RIGHT, padx=10, pady=10) | |
listbox_monitored_folders = tk.Listbox(right_frame) | |
listbox_monitored_folders.pack() | |
btn_clear_list = tk.Button(right_frame, text="Clear Selection", command=clear_selected_folders) | |
btn_clear_list.pack() | |
bottom_left_frame = tk.Frame(root) | |
bottom_left_frame.pack(side=tk.LEFT, padx=10, pady=10) | |
chk_spam = tk.Checkbutton(bottom_left_frame, text="Spam") | |
chk_spam.pack() | |
chk_uploader_tags = tk.Checkbutton(bottom_left_frame, text="Uploader Tags") | |
chk_uploader_tags.pack() | |
chk_filler = tk.Checkbutton(bottom_left_frame, text="Filler") | |
chk_filler.pack() | |
btn_clear_options = tk.Button(bottom_left_frame, text="Clear Selection") | |
btn_clear_options.pack() | |
bottom_right_frame = tk.Frame(root) | |
bottom_right_frame.pack(side=tk.RIGHT, padx=10, pady=10) | |
def spam_callback(): | |
if var_spam.get(): | |
lbl_spam_status.config(text="Deleting Spam", fg="green") | |
else: | |
lbl_spam_status.config(text="", fg="black") | |
var_spam = tk.IntVar() | |
chk_spam = tk.Checkbutton(bottom_left_frame, text="Spam", variable=var_spam, command=spam_callback) | |
chk_spam.pack() | |
lbl_spam_status = tk.Label(bottom_right_frame, text="", fg="black") | |
lbl_spam_status.pack() | |
def uploader_tags_callback(): | |
if var_uploader_tags.get(): | |
entry_uploader_tags.config(state=tk.NORMAL) | |
chk_any.config(state=tk.NORMAL) | |
else: | |
entry_uploader_tags.config(state=tk.DISABLED) | |
chk_any.config(state=tk.DISABLED) | |
def any_callback(): | |
if var_any.get(): | |
entry_uploader_tags.config(state=tk.DISABLED) | |
else: | |
entry_uploader_tags.config(state=tk.NORMAL) | |
var_uploader_tags = tk.IntVar() | |
chk_uploader_tags = tk.Checkbutton(bottom_left_frame, text="Uploader Tags", variable=var_uploader_tags, command=uploader_tags_callback) | |
chk_uploader_tags.pack() | |
entry_uploader_tags = tk.Entry(bottom_right_frame, state=tk.DISABLED) | |
entry_uploader_tags.pack() | |
var_any = tk.IntVar() | |
chk_any = tk.Checkbutton(bottom_right_frame, text="Any", variable=var_any, state=tk.DISABLED, command=any_callback) | |
chk_any.pack() | |
def filler_callback(): | |
state = tk.NORMAL if var_filler.get() else tk.DISABLED | |
for chk in filler_checkboxes: | |
chk.config(state=state) | |
var_filler = tk.IntVar() | |
chk_filler = tk.Checkbutton(bottom_left_frame, text="Filler", variable=var_filler, command=filler_callback) | |
chk_filler.pack() | |
filler_options = ["JPG", "TXT", "HTM", "ANY"] | |
filler_checkboxes = [] | |
for opt in filler_options: | |
var = tk.IntVar() | |
chk = tk.Checkbutton(bottom_right_frame, text=opt, variable=var, state=tk.DISABLED) | |
chk.pack() | |
filler_checkboxes.append(chk) | |
def clear_all_selections(): | |
listbox_monitored_folders.delete(0, tk.END) | |
var_spam.set(0) | |
var_uploader_tags.set(0) | |
var_filler.set(0) | |
var_any.set(0) | |
entry_uploader_tags.delete(0, tk.END) | |
lbl_spam_status.config(text="") | |
for chk in filler_checkboxes: | |
chk.config(state=tk.DISABLED) | |
# Add this button to both left and right frames | |
btn_clear_all = tk.Button(left_frame, text="Clear All Selections", command=clear_all_selections) | |
btn_clear_all.pack() | |
# **Missing Episodes Functionality** | |
def find_missing_episodes(folders): | |
shows = {} | |
for folder in folders: | |
for root, _, files in os.walk(folder): | |
for file in files: | |
if file.endswith(('.mp4', '.mkv', '.avi')): | |
title, season, episode = extract_info_from_filename(file) | |
season = normalize_season(season) | |
if title not in shows: | |
shows[title] = 0 | |
shows[title] = max(shows[title], int(episode)) | |
results = [] | |
with open("missing_episodes.csv", "w", newline='') as csvfile: | |
writer = csv.writer(csvfile) | |
writer.writerow(["Show Name", "Season", "Episodes Found", "Status", "Season Length", "Directory"]) | |
for title, max_episode in shows.items(): | |
season = determine_season(title, max_episode) | |
status = "Missing" if max_episode < 28 else "Potentially Valid" | |
length = "N" if max_episode <= 13 else "L" if max_episode < 30 else "S" | |
directory = next((root for root, _, files in os.walk(folders) | |
for file in files if title in file), "Not Found") | |
results.append([title, season, max_episode, status, length, directory]) | |
writer.writerow([title, season, max_episode, status, length, directory]) | |
return results | |
def extract_info_from_filename(filename): | |
pattern = r"(.*) S(\d+|[sS]\d+) E?(\d+)" | |
match = re.match(pattern, filename) | |
if match: | |
return match.group(1), match.group(2), match.group(3) | |
else: | |
return filename, "0", "0" | |
def normalize_season(season): | |
season = season.lower().replace('s', '') | |
return season | |
def determine_season(title, max_episode): | |
if max_episode <= 13: | |
return "1" | |
else: | |
return "Unknown" | |
def analyze_missing_episodes(): | |
folders = listbox_monitored_folders.get(0, tk.END) | |
find_missing_episodes(folders) | |
messagebox.showinfo("Analysis Complete", "Missing episodes report saved as 'missing_episodes.csv'") | |
# **New Tab Setup** | |
notebook = ttk.Notebook(root) # Create a notebook for tabs | |
notebook.pack(expand=True, fill="both") | |
missing_episodes_tab = ttk.Frame(notebook) | |
notebook.add(missing_episodes_tab, text="Missing Episodes") | |
# Widgets within the tab | |
btn_analyze = tk.Button(missing_episodes_tab, text="Analyze", command=analyze_missing_episodes) | |
btn_analyze.pack() | |
output_text = tk.Text(missing_episodes_tab) | |
output_text.pack(expand=True, fill="both") | |
root.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment