Code Monkey home page Code Monkey logo

plexcache's Introduction

TLDR: Move the media currently On Deck/Watchlist on Plex from the array to the cache.

This Python script reduces energy consumption by minimizing the need to spin up the array/disk(s) when watching recurrent media like TV series. It achieves this by moving the media from the OnDeck library of the main user, all other users, and the main user's watchlist. For TV shows/anime, it also fetches the next specified number of episodes.

The project contains two scripts: a setup script and a main script. The setup script prompts the user to specify the folders where the media is stored and fetches the mapped Plex media paths and will create the settings file, which can also be created/edited manually. The script was initially developed for Unraid but is compatible with other systems.

The script can:

  • Fetch a specified number of episodes from the "onDeck" for the main user and other specified users, as well as the main user's watchlist.
  • Skip fetching onDeck media for specified users.
  • Search only the specified libraries.
  • Check for free space before moving any file.
  • Move watched media present on the cache drive back to the array.
  • Move relative subtitles along with the media moved to or from the cache.
  • Filter media older than a specified number of days.
  • Run in debug mode for testing.
  • Exit the script if any active session or skip the currently playing media.
  • Find your missing unicorn.

Disclaimer:

Before you dive in, here's a reality check: this script comes without any warranties, guarantees, or magic powers.

By using this script, you accept that you're responsible for any consequences that may result. The author will not be held liable for data loss, corruption, or any other problems you may encounter. So, it's on you to make sure you have backups and test this script thoroughly before you unleash its awesome power.

Now, go ahead and take script for a spin.

How to run the setup script:

The instructions below are applicable to the main operating systems:

  1. Check Python Installation:
  • First, you need to check whether Python is installed on your system. On Windows, open the Command Prompt or PowerShell, and on macOS or Linux, open the Terminal. Type "python --version" and hit enter. If you see a version number, then Python is already installed (skip step 2), otherwise, you need to download and install Python.
  1. Install Python:
  • If Python is not installed, then go to the official Python website1 and download the latest version for your operating system. Follow the instructions in the installer to complete the installation.
  1. Install the "plexapi" and "requests" modules:
  • Open the Command Prompt or Terminal and type "pip install plexapi requests" and hit enter. This will download and install the "plexapi" and "requests" modules.
  1. Run the Python Script:
  • Once you have installed Python and the required modules, you can run the Python script. Navigate to the directory where the script is located, and open the Command Prompt or Terminal. Type "python setup.py" and hit enter. This will execute the Python script. Note: In some cases, you may need to use "python3" instead of "python" if you have both Python 2 and 3 installed on your system.

How to run the main script:

Be sure you have the settings file configured accordingly before running the script.

Note that the "settings.json" file is assumed to be located in the same directory, but this can be changed by editing the "settings_filename" variable in the script.

  1. For users of Unraid, the following instructions can be followed to execute the script:

    • A) Install Python directly on Unraid (using NerdTools2 plugin) and manually install the required dependencies (plexapi). Then, run the script using cron or the User Scripts plugin3. However, this method is not officially recommended, but I have personally noticed some random authentication errors in chronos.

    • B) Execute it on Chronos4 (docker container), which can be installed from the Unraid app store:
      - Allocate an additional path to the default ones and direct it to "/mnt" in both the host and the container. Also, set the container network type: to Host. - Create a new script, configure how to trigger it (preferably using cron), and paste the contents of the plexoncache.py script in the Python script box, change the path of the settings_filename variable accordingly before proceeding. - Install the required modules by typing "plexapi" in the Pip requirements box and pressing "Install pip requirements." - Save the script and execute it.

  2. For every other user, use the instruction of the setup script, the only difference is the "plexapi" module is the only one required.

Thank you:

To brimur5, your script is what helped and inspired me in the first place, and thank you to every single one which contributed and even just commented about the project. ❤️

Footnotes

  1. Python Download

  2. Nerd Tools Plugin official topic on the unraid forum

  3. User Scripts Plugin official topic on the unraid forum

  4. Chronos on Github

  5. brimur/preCachePlexOnDeckEpiosodes.py

plexcache's People

Contributors

bexem avatar extrobe avatar trevski13 avatar dsaunier-sunlight avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.