-
-
Save frank1x/9a8f6066b17db645c13641d180b4ee03 to your computer and use it in GitHub Desktop.
Cache unwatched On Deck items in Plex using rclone
This file contains 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