Last active
October 23, 2024 16:41
-
-
Save kpatdev/c23767fb8a196838d946a69aa8bc3b1b to your computer and use it in GitHub Desktop.
Revisions
-
kpatdev revised this gist
Oct 23, 2024 . 1 changed file with 18 additions and 10 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,6 @@ import os from plexapi.server import PlexServer # Replace with your actual Plex server details PLEX_URL = 'http://<plex_server_ip>:32400' PLEX_TOKEN = '<plex_x_token>' @@ -14,15 +11,26 @@ def check_folders(): """Checks if the specified folders are mounted.""" for folder in FOLDERS: folder_path = os.path.join(MOUNT_PATH, folder) try: mounted = os.listdir(folder_path) if not mounted: print(f"Folder not mounted: {folder_path}") os.system(f"sudo umount {folder_path}") os.system(f"sudo mount {folder_path}") for _ in range(2): if os.path.exists(folder_path): break os.system(f"sudo umount {folder_path}") os.system(f"sudo mount {folder_path}") else: return False except: print(f"Unmounting and remounting (stale file): {folder_path}") os.system(f"sudo umount {folder_path}") os.system(f"sudo mount {folder_path}") for _ in range(2): if os.path.exists(folder_path): break else: return False return True -
kpatdev created this gist
Oct 21, 2024 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ import os from plexapi.server import PlexServer # Assumes all folders are inside /mnt/nfs # Tries to mount/remount broken mounts for systems that allow it # Replace with your actual Plex server details PLEX_URL = 'http://<plex_server_ip>:32400' PLEX_TOKEN = '<plex_x_token>' MOUNT_PATH = '/mnt/nfs' FOLDERS = ['movies', 'tvshows', 'homevideos', 'youtube'] def check_folders(): """Checks if the specified folders are mounted.""" for folder in FOLDERS: folder_path = os.path.join(MOUNT_PATH, folder) if not os.listdir(folder_path): print(f"Folder not mounted: {folder_path}") os.system(f"sudo umount {folder_path}") os.system("sudo mount -av") for _ in range(2): if os.path.exists(folder_path): break os.system(f"sudo umount {folder_path}") os.system("sudo mount -av") else: return False return True def empty_trash(plex): """Empties the trash for all libraries.""" for section in plex.library.sections(): try: section.emptyTrash() print(f"Emptied trash for library: {section.title}") except Exception as e: print(f"Failed to empty trash for {section.title}: {e}") if __name__ == "__main__": if check_folders(): try: plex = PlexServer(PLEX_URL, PLEX_TOKEN) empty_trash(plex) except Exception as e: print(f"Error connecting to Plex server: {e}") else: print("Plex media directory not mounted. Skipping trash cleanup.")