Connect Your Plex Server To Your Google Drive

Introduction

This tutorial will help you connect your Google Drive to your Bytesized Plex server using Plexdrive. Using Plexdrive you can stream content directly from your Google Drive without having to download it to the server first.

Plexdrive setup and running requires certain level of knowledge.

Bytesized Hosting does not provide support or will help debugging issues caused by plexdrive. See this news item for more details on why that is the case.

Please note
  • Plexdrive only works with Google Drive

  • Plexdrive is read-only, use rClone for uploading files.

  • Never ever mount on your home folder (This includes ~ or $HOME or an absolute path to your home folder.) This will break your whole box.

  • We don't support direct connections of your apps to the mounts that you made because connecting your apps directly to the mount can make that app highly unstable. If your apps stop responding, you will have to troubleshoot the issues yourself.

Getting your API credentials for Google Drive

First, you need your own API credentials. Open your browser and visit https://console.developers.google.com

On Dashboard choose Google Drive API

Imgur

Click enable

Imgur

Click Create credentials and select OAuth client ID.

Imgur

Before you can proceed with creating the API, you are nagged to Configure consent screen, so click that.

Imgur

Type a description (Plex would do) and hit Save.

Imgur

Select Other under Application type and give your API an appropriate name, such as Plex. Then click Create.

Imgur

You will be given your own client ID and client secret which you will need later on so make sure that you don't close the window containing your Client ID and Client secret.

Imgur

Installing Plexdrive

Access your box via SSH by using your Terminal or via Kitty(if you're using Windows). First make sure that the apps directory exists, if the mentioned directory don't exist you will have to create it by typing:

mkdir ~/apps

To install the latest version (as of this writing) of Plexdrive type:

cd ~/apps && wget https://github.com/plexdrive/plexdrive/releases/download/5.2.1/plexdrive-linux-amd64 -O plexdrive

Change the permissions on the file you just downloaded:

chmod 755 ~/apps/plexdrive

You have now successfully installed your Plexdrive

Connecting your Google Drive on the server

First, let's create the mount directory, this is the folder your Google Drive content will show up in:

mkdir -p ~/mnt/plexdrive

To speed up the installation a bit, create a screen session so that we can proceed while Plexdrive is creating the cache. Type:

screen -S plexdrive

This will open a new session which we can place in the background later to continue setting things up. Type:

~/apps/plexdrive mount -c ~/.plexdrive -o allow_other -v 4 --refresh-interval=1m ~/mnt/plexdrive

You will be asked to provide your generated client ID. This is the Google client ID you created in previously. The codes are probably still sitting on your screen. Copy/paste it and press enter to continue.

Do the same with the generated client secret, If you had closed your browser after all, head back to https://console.developers.google.com, click Credentials, and click Edit behind the API you created. This will show you the OAuth information again.

You will now be asked to paste a link in your browser.

Imgur

Paste this link in your Browser. You are asked to authorize Google drive and will be given an authorization code. Copy/past that code into your Terminal/Kitty .

If all goes well, Plexdrive will start generating the cache. This will take a long time, but thanks to the separate screen we do not have to wait till it is completely finished. I do suggest waiting a few minutes until it mentions that it finished the initial scanning.

Once the cache creating process slows down to 1 or 2 items at the time, you can safely detach the screen . To detach from the screen press CTRL+A, then CTRL+D. You'll be returned to your standard SSH interface with a confirmation in brackets that says '[detached from xxxxx.plexdrive].'

Adding your Google Drive content to Plex

Restart your Plex, once restarted go to your Plex and add a new Library. Name it whatever you want. In my example i will name it Plexdrive and my folder for movies on Google Drive is called PlexdriveMovies.

Pick an option Add folders and in path there you need to type the next path:

/data/mnt/plexdrive/PlexdriveMovies

After you have set the path , press Save changes and then run the scan of the library and you're ready to go.

Optional

Create startup/shutdown scripts for Plexdrive

What's handy about these scripts is that in case a server that you're on reboots , your Plexdrive will be automatically started(mounted).

Startup script

First create/open a new file called plexdrive by typing:

nano ~/.startup/plexdrive

Once created/opened , in your plexdrive file copy/paste the code below:

#!/bin/bash

echo "Starting Plexdrive"

/sbin/start-stop-daemon -S -u $USER -d $HOME --exec /usr/bin/screen -- -dmS  plexdrive ~/apps/plexdrive mount -c ~/.plexdrive -o allow_other -v 4 --chunk-load-ahead=0 --refresh-interval=1m ~/mnt/plexdrive

Save the file by using the keys ctrl + o from your keyboard and then close the file by using ctrl + x.

Give the file executable permissions by typing:

chmod +x ~/.startup/plexdrive
Shutdown script

create/open a new file called plexdrive by typing:

nano ~/.shutdown/plexdrive

Once created/opened , in your plexdrive file copy/paste the code below:

#!/bin/bash
echo "Stoping Plexdrive"

fusermount -u ~/mnt/plexdrive

Save the file by using the keys ctrl + o from your keyboard and then close the file by using ctrl + x.

Give the file executable permissions by typing:

chmod +x ~/.shutdown/plexdrive
Using the commands

Once you have setup the startup/shutdown scripts you just need to type ~/.startup/plexdrive if you want to start Plexdrive , or~/.shutdown/plexdrive if you want to stop Plexdrive.

Tips & Tricks

If during the configuration you make any issues and Plexdrive is throwing "Transport endpoint is not connected" errors you can usually get rid of that by using fusermount -u ~/mnt/plexdrive and then trying to connect again.

You will have to restart Plex after the drive is mounted in order for Plex to be able to recognise the files.


Last Author Contributors Versions Last update
Alchemist None 28 Wed, 25 May 2022 10:15:00 +0200