""" Date: 18th/July/2026 Created by: Jap-Slappa Make Episodes Dict +PSG v1.0 Customised By: Jap-Slappa Completed: ???? /July/2026 """ import PySimpleGUI as sg import traceback import json import sys import time from pathlib import Path # Tell Python to look in your C-Drive helper folder # Use raw strings (r"...") to handle Windows backslashes properly sys.path.append(r"C:\My_Python_Helper_Modules") import Get_Date_and_Time__v1 as Get_Date_and_Time import Error_Handling # Get_Date_and_Time.Fav_Day_date_and_time_string() def basic_custom_error(): """Print Minimal Custom info about basic Python stack trace --- Code Example: >>> except: my_custom_error() --- NOTE: Module Name or Function name where the error occurred... | Are NOT required, as ARGs - Nor Provided at print-out! """ print() print(' ============= An exception occurred =============') print(' =================================================== ') traceback.print_exc(limit=1, file=sys.stdout) print(' =================================================== ') print() time.sleep(2.0) #? === End Of Function == Anime_Show_target_folder = r'\\192.168.4.212\web\00.My_Watclists_4_Kodi\z-Umbrella-Anime-STRMs\01.Anime-TV\Py NFO Updater\v4.0 - PSG Project Completed!\Chainsaw Man (2022)' def Func_03__get_Ep_Txt(file_path): try: # Example: Chainsaw Man - S01E01 - DOG & CHAINSAW.nfo pathlib_file_path = Path(file_path) file_path_name = str(pathlib_file_path.name) name_split_01 = file_path_name.split('-') # Unpack the split name-01 #? This Worked!! show_name, season_Ep, Ep_name = name_split_01 print() # print('=== Func_03__get_Ep_Txt() | Function ===') print('=== To Split ALL NFO File Names ========') print('name_split_01: ', name_split_01) # print('---') # print('show_name: ', show_name.strip()) print('season_Ep: ', season_Ep.strip()) # print('..Ep_name: ', Ep_name.strip()) print() return season_Ep.strip() except Exception as Error: basic_custom_error() print(f"(Error: {Error})") #? === End Of Function == show_Dict = {} def Func_02__process_season_folder(folder_path): """ Purpose: """ try: season_name = str(Path(folder_path).name).strip() # Create the 1st level of the Dict. Outer-Level show_Dict[season_name] = {} # Scan the target folder + find all NFO Files get_NFOs_list = list(Path(folder_path).iterdir()) print() print('=== Func_02__process_season_folder() | Function ===') print('=== To Find ALL NFO Files ================') for idx, path in enumerate(get_NFOs_list, start=1): idx_string = str(idx).zfill(2) # print(f"{idx_string} - NFO Path: ", path.name) if path.is_file() and path.suffix != '.nfo': continue if path.is_file() and path.suffix == '.nfo': # print() # print(' =================================================== ') print(f"{idx_string} - Found Path IS a NFO: ", path.name) # print(f"{idx_string} - Found Path IS a NFO: \n", path) # print(' =================================================== ') # print() season_Ep_txt = Func_03__get_Ep_Txt(path) # Adding a new key-value pair to existing Empty dictionary (Flat x0 Levels) # example... thisdict["color"] = "red" # Adding a new key-value pair to existing inner dictionary (Nested x1 Levels) # Example: person['employee1']['department'] = 'HR' show_Dict[season_name][season_Ep_txt] = str(path).strip() # return except Exception as Error: basic_custom_error() print(f"(Error: {Error})") #? === End Of Function == def Func_01__get_folders_loop_01(TV_Show_target_folder): try: # print() print('====== Func_01__get_folders_loop_01() | Function ======') print('====== Loop To - Find ALL Season Folders ==============') target_folder_txt = 'Season' found_season = '' # Scan the target folder + find all season folders get_folders_list = list(Path(TV_Show_target_folder).iterdir()) for idx, path in enumerate(get_folders_list, start=1): idx_string = str(idx).zfill(2) print(f"{idx_string} - Found Path: ", path.name) if path.is_dir() and target_folder_txt in path.name: print() print(' =================================================== ') print(f"{idx_string} - Found Path IS a Folder: ", path.name) print(f"{idx_string} - Found Path IS a Folder: \n", path) print(' =================================================== ') print() found_season = path Func_02__process_season_folder(found_season) return except Exception as Error: basic_custom_error() print(f"(Error: {Error})") #? === End Of Function == try: Func_01__get_folders_loop_01(Anime_Show_target_folder) # print(show_Dict) print(json.dumps(show_Dict, indent=4)) except Exception as Error: basic_custom_error() print(f"(Error: {Error})")