Plex_Autoscan Setup

If you are a fan of plex_autoscan please support the developers with donations: https://github.com/l3uddz/plex_autoscan#donate

To setup Plex_Autoscan on Ubuntu/Debian first login to SSH with your non-root sudo user and run the following command to install Python and PIP:

sudo apt update && sudo apt install python python-pip -y

Now we will install Plex_Autoscan.

cd /opt && sudo git clone https://github.com/l3uddz/plex_autoscan
cd /opt/plex_autoscan
sudo apt install python-dev gcc -y && sudo python -m pip install setuptools && sudo python -m pip install -r requirements.txt

Now we need to create a config.json file to this type the follow:

/opt/plex_autoscan/scan.py sections

Now we need to edit the setting in the config.json file to do this type:

sudo nano /opt/plex_autoscan/config/config.json

This is my config.json file you need to edit the bold text sections. To get your “PLEX_TOKEN” load up your Plex Server in the Plex Web App and browse to a library item. Click the 3 dots icon and go to Get Info now click the link in the bottom left corner of this window called View XML now in the URL for this XML page you should see a bit at the end that says X-Plex-Token= copy and paste the code after X-Plex-Token= into the config file. https://support.plex.tv/articles/204059436-finding-an-authentication-token-x-plex-token/

{
  "DOCKER_NAME": "plex", 
  "GOOGLE": {
    "ALLOWED": {
      "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"
      ], 
      "FILE_PATHS": [
        "PlexCloudServers/Media/",
        "PlexCloudServers [A][Part 2]/Media/"
      ], 
      "MIME_TYPES": true, 
      "MIME_TYPES_LIST": [
        "video"
      ]
    }, 
    "CLIENT_ID": "Enter your Client ID", 
    "CLIENT_SECRET": "Enter your Client Secret", 
    "ENABLED": true, 
    "POLL_INTERVAL": 120, 
    "SHOW_CACHE_LOGS": true, 
    "TEAMDRIVE": true, 
    "TEAMDRIVES": ["PlexCloudServers","PlexCloudServers [A][Part 2]"]
  }, 
  "PLEX_ANALYZE_DIRECTORY": true, 
  "PLEX_ANALYZE_TYPE": "basic", 
  "PLEX_CHECK_BEFORE_SCAN": false, 
  "PLEX_DATABASE_PATH": "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db", 
  "PLEX_EMPTY_TRASH": true, 
  "PLEX_EMPTY_TRASH_CONTROL_FILES": [
    "/mnt/plexcloudservers/mounted.bin"
  ], 
  "PLEX_EMPTY_TRASH_MAX_FILES": 100, 
  "PLEX_EMPTY_TRASH_ZERO_DELETED": false, 
  "PLEX_LD_LIBRARY_PATH": "/usr/lib/plexmediaserver", 
  "PLEX_LOCAL_URL": "http://localhost:32400", 
  "PLEX_SCANNER": "/usr/lib/plexmediaserver/Plex\\ Media\\ Scanner", 
  "PLEX_SECTION_PATH_MAPPINGS": {
    "1": [
      "/Movies/"
    ], 
    "2": [
      "/TV/"
    ]
  }, 
  "PLEX_SUPPORT_DIR": "/var/lib/plexmediaserver/Library/Application\\ Support", 
  "PLEX_TOKEN": "Enter your Plex Token", 
  "PLEX_USER": "plex", 
  "PLEX_WAIT_FOR_EXTERNAL_SCANNERS": true, 
  "RCLONE_RC_CACHE_EXPIRE": {
    "ENABLED": false, 
    "FILE_EXISTS_TO_REMOTE_MAPPINGS": {
      "Media/": [
        "/home/thompsons/plexdrive/Media/"
      ]
    }, 
    "RC_URL": "http://localhost:5572"
  }, 
  "RUN_COMMAND_AFTER_SCAN": "", 
  "RUN_COMMAND_BEFORE_SCAN": "", 
  "SERVER_ALLOW_MANUAL_SCAN": false, 
  "SERVER_FILE_CHECK_DELAY": 60, 
  "SERVER_FILE_EXIST_PATH_MAPPINGS": {
    "/home/thompsons/plexdrive/": [
      "/data/"
    ]
  }, 
  "SERVER_IGNORE_LIST": [
    "/.grab/", 
    ".DS_Store", 
    "Thumbs.db"
  ], 
  "SERVER_IP": "0.0.0.0", 
  "SERVER_MAX_FILE_CHECKS": 10, 
  "SERVER_PASS": "7904bbf306654e83a2a3c8e78fce695a", 
  "SERVER_PATH_MAPPINGS": {
    "/mnt/plexcloudservers/": [
      "/mnt/plexcloudservers/",
      "PlexCloudServers/Media/",
      "PlexCloudServers [A][Part 2]/Media/"
    ]
  }, 
  "SERVER_PORT": 3467, 
  "SERVER_SCAN_DELAY": 180, 
  "SERVER_SCAN_FOLDER_ON_FILE_EXISTS_EXHAUSTION": false, 
  "SERVER_SCAN_PRIORITIES": {
    "0": [
      "/Movies/"
    ], 
    "1": [
      "/TV/"
    ], 
    "2": [
      "/Music/"
    ]
  }, 
  "SERVER_USE_SQLITE": true, 
  "USE_DOCKER": false, 
  "USE_SUDO": false
}

Once you have made these edits press Ctrl+X and then press Y to save.

Now we need to authorize Plex_Autoscan with Google Drive. To do this type: (This will give you a link copy and paste it into you web browser and paste the code it gives you back into the terminal window.)

/opt/plex_autoscan/scan.py authorize

Now we need to change the owneship of the plex_autscan folder. Type:

sudo chown -R plex:plex /opt/plex_autoscan

To run Plex_Autoscan in the background and from startup we need to setup a systemd service. To do this type:

sudo nano /etc/systemd/system/plex_autoscan.service

Paste the following into the file and press Ctrl+X and then press Y to save and create the file. (You may need to change the user and group ID below to the same as your non-sudo root users you can find out your UID and GID by typing id into SSH.)

# /etc/systemd/system/plex_autoscan.service

[Unit]
Description=Plex Autoscan
After=network-online.target

[Service]
User=plex
Group=plex
Type=simple
WorkingDirectory=/opt/plex_autoscan/
ExecStart=/opt/plex_autoscan/scan.py server --loglevel=INFO
Restart=always
RestartSec=10

[Install]
WantedBy=default.target

Run the following line by line to enable and start the service:

sudo systemctl daemon-reload
sudo systemctl enable plex_autoscan.service
sudo systemctl start plex_autoscan.service

Now check that it is running by typing: (It should say active (running) in green if it is working)

systemctl status plex_autoscan.service

Note: Any changes to /opt/plex_autoscan/config/config.json including those when running the library update command will require you to restart the service by typing:

sudo systemctl restart plex_autoscan.service

If you having issues with ites not scanning in please type the following command: (This will give you a log which will help you troubleshoot the issue)

tail -f /opt/plex_autoscan/plex_autoscan.log

If you find plex_autoscan useful please support the developers by donating here: https://github.com/l3uddz/plex_autoscan#donate

Scroll to Top