Whatbox Logo
Login for certain variables to be updated with your slot's information

Wiki > Plex Autoscan

Plex Autoscan is no longer in development and may stop working at any time.

Plex Autoscan is a Python 2.7 script that assists in the importing of Sonarr, Radarr, and Lidarr downloads into Plex Media Server.

Advanced installation and configuration steps are required to use the script correctly.

Installation

virtualenv

Follow the instructions in the virtualenv article to install and activate a Python 2.7 virtual environment. If you have previously set up a Python 2.7 virtualenv, you may choose to re-use it or create a new one with a different name.

Plex Autoscan

Connect to your slot via SSH

  1. Create the directory for Plex Autoscan:

     mkdir -p ~/plex_autoscan
    
  2. Download Plex Autoscan from GitHub

     git clone --branch master https://github.com/l3uddz/plex_autoscan.git ~/plex_autoscan
    
  3. Activate virtualenv (if not activated)

     source ~/virtualenv2/bin/activate
    
  4. Install Python dependencies for Plex Autoscan

     cd ~/plex_autoscan; pip install -r requirements.txt; find . -name '*.pyc' -delete
    
  5. Generate a default config.json file

     python ~/plex_autoscan/scan.py sections
    
  6. Update the configuration files. Run all of the following commands. The sed commands listed here will make all of the required edits to the configuration files for you.

     source ~/.bash_profile
     
     sed -i -e 's|/var/lib/plexmediaserver/|/home/user/|g' -e 's|/usr/lib/plexmediaserver/|/home/user/Library/Plex/current/usr/lib/plexmediaserver/|g' -e 's|32400|'"$PLEX_PORT"'|g' -e 's|"USE_SUDO": true|"USE_SUDO": false|g'  -e 's|3467|26365|g' ~/plex_autoscan/config/config.json
     
     sed -i -e 's|/tmp/|/home/user/.tmp/|g' ~/plex_autoscan/scripts/plex_token.sh
    
  7. Obtain an X-Plex-Token. The script provided with Plex Autoscan will ask you to log in with your Plex account to obtain a token.

     bash ~/plex_autoscan/scripts/plex_token.sh
    

Copy the token given to you by the script, then replace EXAMPLETOKEN in the following command with that token.

    sed -i -e 's|"PLEX_TOKEN": "",|"PLEX_TOKEN": "EXAMPLETOKEN",|g' ~/plex_autoscan/config/config.json
  1. With your virtualenv activated, run Plex Autoscan's server.

     python ~/plex_autoscan/scan.py server
    

The program will output a URL. Replace 0.0.0.0:26365 with server.whatbox.ca:26365 and you can use that URL as your webhook URL in Sonarr/Radarr/Lidarr.

To leave Plex Autoscan running in the background, press Ctrl-C to exit Plex Autoscan (or disconnect/reconnect to SSH) and then run the following command

    screen -dmS autoscan ~/virtualenv2/bin/python ~/plex_autoscan/scan.py server

Usage

  • If you need to update Plex Autoscan, this command will update to the latest version

      cd ~/plex_autoscan; git pull
    

Automatically Restart

Below are steps to take to have Plex Autoscan automatically restart if it crashes, or if the server is rebooted.

  1. Make a file to be used for the script. touch ~/autoscan_restart.cron

  2. Edit the file and enter the text below. nano -w ~/autoscan_restart.cron

     #!/bin/bash
     if pgrep -fx "python /home/user/plex_autoscan/scan.py"
     then
         echo "Plex Autoscan is running."
     else 
         echo "Plex Autoscan is not running, starting Plex Autoscan"
         /home/user/virtualenv2/bin/python /home/user/plex_autoscan/scan.py
     fi
     exit
    
  3. Save the file with Ctrl+x and the "y" and Enter to accept overwriting.

  4. Make the script executable. chmod +x ~/autoscan_restart.cron

  5. Open your crontab. EDITOR=nano crontab -e

  6. Enter the following text

     @reboot /home/user/autoscan_restart.cron >/dev/null 2>&1
     */5 * * * * /home/user/autoscan_restart.cron >/dev/null 2>&1
    
  7. Save the crontab with Ctrl-S then exit nano with Ctrl-X