Scripts to facilitate the use of cloud storage providers (i.e. Google Drive) as storage for Plex media using rclone
The purpose of this project is to use Cloud Drives as a means of storage for Plex. These scripts can support any cloud drive services that are supported by rclone. The main use case of this project specifically targets using Google Drive unlimited accounts. Traditionally, using a Drive account with Plex runs into issues with exceeding Google's API call quota. This occurs during Plex scans of large media collections. To combat this, this project automates the uploading of media to a Drive account and automatically scans the individual directories where new media was placed. This means that only a small subset of the media library will be scanned as opposed to scanning the entire collection (requires automatic Plex scans to be switched off). The scripts also has the ability to upload media to multiple Google accounts for redundancy in a RAID 1-like manner. This can be useful if the Drive accounts have the potential to be banned or revoked (i.e. purchased on eBay, etc.).
These scripts are use at your own risk, meaning I am not responsible for any issues or faults that may arise. I have tested these scripts on my own systems and verfied their functionality; however, due diligence is required by the end user. I am in no way affiliated with Google, Plex Inc., or rclone. I am not responsible if a ban is place on the user's Drive account due to abuse or excessive API calls.
Clone Git repo in home directory
> ~$ git clone https://github.com/masonr/PLEXiDRIVE
Edit permissions to allow plex user full access
> ~$ sudo chmod -R 777 PLEXiDRIVE
Move rclone into a directory found in the PATH environment variable and edit permissions
> ~$ sudo mv rclone /usr/local/bin/
> ~$ sudo chown root:root /usr/local/bin/rclone
> ~$ sudo chmod 755 /usr/local/bin/rclone
Mount Google Drive(s) using rclone mount with options
> ~$ sudo mkdir /mnt/gdrive-main
> ~$ sudo rclone mount --allow-non-empty --allow-other gdrive-main:/ /mnt/gdrive-main &
Edit path as needed and use rclone remote names configured in Step 3
Alternatively, plexdrive should also be able to achieve mounting the remote drive without needing to change anything.
Encrypted rclone mounts can also be used, but be sure to point your Plex libraries to the decrypted mounts and use the encrypted rclone mount names in the plexidrive config file.
Determine the Plex media section numbers for the Movies and TV Show libraries
> ~/PLEXiDRIVE$ sudo su -c 'export LD_LIBRARY_PATH=/usr/lib/plexmediaserver; /usr/lib/plexmediaserver/Plex\ Media\ Scanner --list' plex
1: Movies
2: TV Shows
See command and example output above
Simply run the script below after configuring the Plex server and setting up the plexidrive.conf file
> ~/PLEXiDRIVE$ ./plexidrive.sh
> ~/PLEXiDRIVE$ sudo su -c './plex-scan.sh' plex
In order to automate the uploading of media and Plex scans, cron jobs can be used. Add a cron job to the root crontab for the Plex scan, and to the local user's account for the media uploads.
Example cron job to run PLEXiDRIVE every 4 hours:
0 */4 * * * /bin/bash /path/to/PLEXiDRIVE/plexidrive.sh && su -c '/bin/bash /path/to/PLEXiDRIVE/plex-scan.sh' plex
## GDrive Settings ##
num_of_gdrives=1
drive_names=('gdrive-main')
## Options ##
delete_after_upload=true # true/false
file_types="mkv|avi|mp4|m4v|mpg|wmv|flv"
rclone_config=""
## Plex Library Directories ##
plex_tvshow_path="/mnt/main/TV Shows" # no ending /
plex_movies_path="/mnt/main/Movies" # no ending /
plex_movies_section_num=1
plex_tvshow_section_num=2
## Local Media Directories ##
local_tvshow_path="/home/masonr/tv-shows/" # end with /
local_movies_path="/home/masonr/movies/" # end with /
## Enable/Disable Components ##
enable_show_uploads=true # true/false
enable_movie_uploads=true # true/false
## GDrive Settings ##
num_of_gdrives=2
drive_names=('gdrive-main' 'gdrive-backup')
## Options ##
delete_after_upload=true # true/false
file_types="mkv|avi|mp4|m4v|mpg|wmv|flv|mpeg"
rclone_config="/home/masonr/.config/rclone/rclone.conf"
## Plex Library Directories ##
plex_tvshow_path="/mnt/main/TV Shows" # no ending /
plex_movies_path="/mnt/backup/Movies" # no ending /
plex_movies_section_num=1
plex_tvshow_section_num=2
## Local Media Directories ##
local_tvshow_path="/home/masonr/tv-shows/" # end with /
local_movies_path="/home/masonr/movies/" # end with /
## Enable/Disable Components ##
enable_show_uploads=true # true/false
enable_movie_uploads=true # true/false