Wiki > Plex Autoscan
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
-
Create the directory for Plex Autoscan:
mkdir -p ~/plex_autoscan
-
Download Plex Autoscan from GitHub
git clone --branch master https://github.com/l3uddz/plex_autoscan.git ~/plex_autoscan
-
Activate virtualenv (if not activated)
source ~/virtualenv2/bin/activate
-
Install Python dependencies for Plex Autoscan
cd ~/plex_autoscan; pip install -r requirements.txt; find . -name '*.pyc' -delete
-
Generate a default
config.json
filepython ~/plex_autoscan/scan.py sections
-
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|19621|g' ~/plex_autoscan/config/config.json sed -i -e 's|/tmp/|/home/user/.tmp/|g' ~/plex_autoscan/scripts/plex_token.sh
-
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
-
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:19621
with server.whatbox.ca:19621
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.
-
Make a file to be used for the script.
touch ~/autoscan_restart.cron
-
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
-
Save the file with Ctrl+x and the "y" and Enter to accept overwriting.
-
Make the script executable.
chmod +x ~/autoscan_restart.cron
-
Open your crontab.
EDITOR=nano crontab -e
-
Enter the following text
@reboot /home/user/autoscan_restart.cron >/dev/null 2>&1 */5 * * * * /home/user/autoscan_restart.cron >/dev/null 2>&1
-
Save the crontab with
Ctrl-S
then exit nano withCtrl-X