Last active
November 12, 2024 19:36
-
-
Save brimur/95277e75ca399d5d52b61e6aa192d1cd to your computer and use it in GitHub Desktop.
Cache unwatched On Deck items in Plex using rclone
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
| ####################################### | |
| # This python script should be run | |
| # as a cron job every 6 hours to | |
| # cache On Deck episodes. | |
| ######################################## | |
| import os | |
| import psutil | |
| from subprocess import check_call | |
| from itertools import chain | |
| from plexapi.server import PlexServer | |
| from plexapi.video import Episode | |
| PLEX_URL = 'http://127.0.0.1:32400' | |
| PLEX_TOKEN = '' | |
| if __name__ == '__main__': | |
| plex = PlexServer(PLEX_URL, PLEX_TOKEN) | |
| files = [] | |
| for video in plex.library.onDeck(): | |
| if isinstance(video, Episode): | |
| for media in video.media: | |
| for part in media.parts: | |
| files.append(part.file) | |
| for count, fileToCache in enumerate(files): | |
| if len(files) > 0: | |
| print("Next ep is " + fileToCache) | |
| startCache = 1 | |
| for proc in psutil.process_iter(): | |
| if proc.name() in 'rclone': | |
| if proc.cmdline()[1] in 'md5sum': | |
| if proc.cmdline()[4] in fileToCache: | |
| print("File is already being cached: " + fileToCache) | |
| startCache = 0 | |
| if startCache == 1: | |
| print("Starting cache of " + fileToCache) | |
| bashCommand = "nohup rclone md5sum --checkers 8 '" + fileToCache + "' &" | |
| os.system(bashCommand) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works perfect, thanks.