Skip to content

Instantly share code, notes, and snippets.

@brimur
Last active November 12, 2024 19:36
Show Gist options
  • Select an option

  • Save brimur/95277e75ca399d5d52b61e6aa192d1cd to your computer and use it in GitHub Desktop.

Select an option

Save brimur/95277e75ca399d5d52b61e6aa192d1cd to your computer and use it in GitHub Desktop.
Cache unwatched On Deck items in Plex using rclone
#######################################
# 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)
@frank1x
Copy link

frank1x commented Jan 28, 2022

Works perfect, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment