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

Wiki > Plex Autoscan

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

Plex Autoscan uses Python 2.

Installation

virtualenv

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

Plex Autoscan

  1. Create the directory for Plex Autoscan:

     mkdir -p ~/plex_autoscan
    
  2. Download SABnzbd 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 defailt config.json file python scan.py sections

  6. Configure Settings nano -w ~/plex_autoscan/config/config.json

             {
     "DOCKER_NAME": "plex",
     "GOOGLE": {
         "ENABLED": false,
         "CLIENT_ID": "",
         "CLIENT_SECRET": "",
         "ALLOWED": {
         "FILE_PATHS": [],
         "FILE_EXTENSIONS": true,
         "FILE_EXTENSIONS_LIST": [
             "webm","mkv","flv","vob","ogv","ogg","drc","gif",
             "gifv","mng","avi","mov","qt","wmv","yuv","rm",
             "rmvb","asf","amv","mp4","m4p","m4v","mpg","mp2",
             "mpeg","mpe","mpv","m2v","m4v","svi","3gp","3g2",
             "mxf","roq","nsv","f4v","f4p","f4a","f4b","mp3",
             "flac","ts"
         ],
         "MIME_TYPES": true,
           "MIME_TYPES_LIST": [
             "video"
         ]
         },
         "TEAMDRIVE": false,
         "TEAMDRIVES": [],
         "POLL_INTERVAL": 60,
     `"SHOW_CACHE_LOGS": false
     },
     "PLEX_ANALYZE_DIRECTORY": true,
     "PLEX_ANALYZE_TYPE": "basic",
     "PLEX_FIX_MISMATCHED": false,
     "PLEX_FIX_MISMATCHED_LANG": "en",
     "PLEX_DATABASE_PATH": "/home/user/Library/Application Support/Plug-in Support/Databases/com.plexapp.plugins.library.db",
     "PLEX_EMPTY_TRASH": false,
     "PLEX_EMPTY_TRASH_CONTROL_FILES": [
         "/home/user/merge/mountexists"
     ],
     "PLEX_EMPTY_TRASH_MAX_FILES": 100,
     "PLEX_EMPTY_TRASH_ZERO_DELETED": false,
     "PLEX_LD_LIBRARY_PATH": "/home/user/Library/Plex/current/usr/lib/plexmediaserver/lib",
     "PLEX_SCANNER": "/home/user/Library/Plex/current/usr/lib/plexmediaserver/Plex Media Scanner",
     "PLEX_SUPPORT_DIR": "/home/user/Library/Application Support",
     "PLEX_USER": "plex",
     "PLEX_TOKEN": "ENTER YOUR PLEX SERVER TOKEN HERE",
     "PLEX_LOCAL_URL": "http://localhost:22879",
     "PLEX_CHECK_BEFORE_SCAN": false,
     "PLEX_WAIT_FOR_EXTERNAL_SCANNERS": true,
         "RCLONE": {
         "BINARY": "",
         "CONFIG": "",
         "CRYPT_MAPPINGS": {
         },
         "RC_CACHE_REFRESH": {
         "ENABLED": false,  
         "FILE_EXISTS_TO_REMOTE_MAPPINGS": {
             "Media/": [
                 "/home/user/merge/"
             ]      
         },
         "RC_URL": "http://localhost:5572"
         }
     },
       "RUN_COMMAND_BEFORE_SCAN": "",
     "RUN_COMMAND_AFTER_SCAN": "",
     "SERVER_ALLOW_MANUAL_SCAN": false,
     "SERVER_FILE_EXIST_PATH_MAPPINGS": {
         "/mnt/unionfs/media/": [
             "/data/"
         ]
     },
     "SERVER_IGNORE_LIST": [
         "/.grab/",
         ".DS_Store",
         "Thumbs.db"
     ],
     "SERVER_IP": "0.0.0.0",
     "SERVER_MAX_FILE_CHECKS": 10,
     "SERVER_FILE_CHECK_DELAY": 60,
     "SERVER_PASS": "9c4b81fe234e4d6eb9011cefe514d915",
     "SERVER_PATH_MAPPINGS": {
         "/mnt/unionfs/": [
             "/home/seed/media/fused/"
         ]
     },
     "SERVER_PORT": 3468,
     "SERVER_SCAN_DELAY": 180,
     "SERVER_SCAN_FOLDER_ON_FILE_EXISTS_EXHAUSTION": false,
     "SERVER_SCAN_PRIORITIES": {
         "1": [
         "/Movies/"
         ],
         "2": [
         "/TV/"
         ]
     },
     "SERVER_USE_SQLITE": true,
     "USE_DOCKER": false,
     "USE_SUDO": false
     }
    
  7. With your virtualenv activated, run Plex Autoscan.

     python ~/plex_autoscan/scan.py
    
  8. Open your browser and go to http://server.whatbox.ca:31250 and complete the setup wizard.

Usage

  • Open your browser and navigate to http://server.whatbox.ca:31250 to access the WebUI

  • 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 your Plex Autoscan instance automatically restart if it crashes, or if the server is rebooted.

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

  2. Edit the file and enter the text below. nano -w ~/plexauto_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/virtualenv3/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 ~/plexauto_restart.cron

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

  6. Enter the following text

     @reboot /home/user/plexauto_restart.cron >/dev/null 2>&1
     */5 * * * * /home/user/plexauto_restart.cron >/dev/null 2>&1
    
  7. Save the crontab with Ctrl+x and the "y" and Enter to accept overwriting.