Acd and GDRIVE working together

Now I have one ACD and one GDRIVE sync, so…

Is there anyway to mount both and scan media with Kodi on the ACD mount and when you play some file it load from Gdrive?

Both are totally sync

Would be awesome if something like this exists. For Plex user to.
Let plex do the scanning on ACD and playing from gdrive.

But I don’t think so…

I do something similar with Kodi to scan local directories and then mount them by NFS for playback.

Run Kodi on a central server then you can do a path substitution using advancedsettings.xml with a central SQL database. (I use a headless docker container: https://hub.docker.com/r/celedhrim/kodi-server/ )

For example, define your source as “/Google/Movies” on the server and all clients and then do a path substitution only on the server that replaces “Google” with “ACD.” The server will then scan “/ACD/Movies” locally, but it will store values in the SQL database as “/Google/Movies.” When the clients read the database, they will then look for files in /Google/Movies.

I do something like that with Plex using scripts and cron jobs.

Disable all automatic library updates on Plex and create a script that runs the Plex Library Scanner manually. At the top of this script, switch the fuse mount point from Google to ACD, then initiate the scan, and then switch the mount point back. The result is that Plex uses Google for scanning and ACD for playback.

It is not perfect; if a user connects and starts to play a file when the script runs, they will stream from ACD while Plex is scanning.

@chezmojo do you mind sharing your scripts?

Just make sure you alway upload your files to ACD first then sync to GDRIVE, since modification date changes are not supported by ACD, but they work for GDRIVE.

I am very interested in the script, as well

For example, attach ‘sonarr_scanner.sh’ to Sonarr as a download notification. Inside ‘sonarr_scanner.sh’:

#!/bin/bash

TARGET="/Plex"
ACD="ACD:"
GOOGLE="Google:"
RCLONE="rclone mount --read-only --allow-other"

fusermount -u $TARGET
($RCLONE $ACD $TARGET &)&
sudo -u plex -E -H LD_LIBRARY_PATH=/usr/lib/plexmediaserver /usr/lib/plexmediaserver/Plex\ Media\ Scanner -s -r -c 1 -d $sonarr_series_path
fusermount -u $TARGET
($RCLONE $GOOGLE $TARGET &)&

Replace -c 1 with the library ID of your TV Library in Plex (you can get it by hovering over your library in the web interface.)

Make sure you update sudoers:

visudo -f /etc/sudoers.d/plex

Add this line:

your_user_name ALL=(plex) NOPASSWD:SETENV: /usr/lib/plexmediaserver/Plex\ Media\ Scanner

Where your_user_name is the account from which you execute the script.

You can also add a check after fusermount to make sure you do not try to scan an empty directory after a failed unmount:

 fusermount -u $TARGET
 if [ $? != 0 ]; then echo "Failed to unmount, not scanning."; exit 1; fi

… and/or check that the path to be scanned exists at the top of the script:

#!/bin/bash
if [ ! -d "$sonarr_series_path" ]; then echo "Target dir not found, skipping scan."; exit 1; fi

(Sorry for all the edits… typing from memory while procrastinating at work.)

1 Like

Thanks for this!

I hope ACD someday fix this

I suggest you change it to usermount -uz $TARGET so it will unmount even when drive is busy.

Use that or if [ $? != 0 ]; then echo "Failed to unmount, not scanning."; exit 1; fi if you prefer to have the script exit instead of forcing a dismount while a file is open… it depends on your usage case.

You can also add a check to see that the mount has switched:

($RCLONE $ACD $TARGET &)&
df | grep -q "$ACD"
if [ $? != 0 ]; then echo "Failed to switch mounts, not scanning."; exit 1; fi

How you put the script together depends on how you use it. In this case since Plex is only going to scan the folder given by Sonarr you are not likely to get banned if the mount does not switch (unless you are downloading a whole show.)

If you use it outside of Sonarr, for example, sudo -u plex -E -H LD_LIBRARY_PATH=/usr/lib/plexmediaserver /usr/lib/plexmediaserver/Plex\ Media\ Scanner -s -r -c 1 -d "$1" then you should add something like this to the top of the script to avoid running it while a scan is already going:

if pidof -o %PPID -x "$(basename $0)"; then echo "Already scanning..."; exit 1; fi

Or you can use a while statement instead if to queue scans, for example, if you use multiple downloaders:

while pidof -o %PPID -x "$(basename $0)"; do echo "Already scanning..."; sleep 1; done
1 Like

Here is everything combined:

#!/bin/bash

# Don't forget to add this line to sudoers:
# your_user_name ALL=(plex) NOPASSWD:SETENV: /usr/lib/plexmediaserver/Plex\ Media\ Scanner


# Change these to suit your needs
TARGET="/Plex"
ACD="ACD:"
GOOGLE="Google:"
PLEXLIBRARY=1 #Get this by hovering over library in the web interface
TIMEOUT=600 # In seconds
# Change $sonarr_series_path to $1 to call as script <dir to scan>
SCANDIR=$sonarr_series_path


RCLONE="rclone mount --read-only --allow-other"
if [ ! -d "$SCANDIR" ]
then
    echo "Target dir not found, skipping scan."
    exit 1
fi

i=0
while pidof -o %PPID -x "$(basename $0)"
do
    echo "Already scanning..."
    sleep 1
    i=$((i+1))
    if [ $i -gt $TIMEOUT ]
    then
        echo "Timed out waiting for other scanners to finish."
        exit 1
    fi
done

fusermount -qu $TARGET
($RCLONE $ACD $TARGET &)&

df | grep -q "$ACD"
if [ $? != 0 ]
then
    echo "Failed to switch mounts, not scanning."
    exit 1
fi

sudo -u plex -E -H LD_LIBRARY_PATH=/usr/lib/plexmediaserver /usr/lib/plexmediaserver/Plex\ Media\ Scanner -s -r -c $PLEXLIBRARY -d "$SCANDIR"

fusermount -qu $TARGET
($RCLONE $GOOGLE $TARGET &)&
2 Likes

I haven’t tried this but I think this is the direction I’m going to try. Other than overhead, is there a reason not to have both ACD and GDrive mounted at the same time? Something like:

/mnt/acd-encrypt/ /mnt/gd-encrypt/
and then symlink between the two depending on what you need. So when scanning set up /mnt/plex-media/ -> /mnt/acd-encrypt
and then when just playing movies back point the link to the GDrive mount. To switch, you just need to change the symlink rather than having to unmount/remount. Plex points to the symlink and you just swap the link.

Yep, that’ll work… I usually use UnionFS so that I can upload / delete / whatever, but I suppose a symlink would work just as well.

rather than a symlink, you could use a bind mount. Depends on what you need and if a symlink will cause you issues or not.

sudo mount --bind $MEDIA /mnt/plex-media/

You can also layer them and on failure simply remove the upper one and the lower appears.

sudo mount --bind $MEDIA1 /mnt/plex-media/
sudo mount --bind $MEDIA2 /mnt/plex-media/

anyone tested this can confirm? cron once every few hours?

I just remade the script that scans only new/modified folders ( based on new/modified files inside ) since someone reported that folder modify dates where not changing for them when they overwritten a file inside.

imo if you have acd & gdrive completly synced the best practice would be to point Sonarr/Radarr to ACD mount and Plex to Gdrive mount ( you can have 2 unionfs mounts )

If have both acd and gdrive in sync, could it be as simple as mounting both drives and then use the gdrive mount for plex and then use Ajki’s script to scan the acd mount ?

This way the scans would run against acd not gdrive, and so should hopefully avoid the gdrive ban

Edit: in answer to my own question, nope that didn’t work.

@Ajki,

please forgive me if I am wrong, but I think there might be a little error/typo in the TV scanner section of the plex-scan-new.sh script.

This line:

$LD_LIBRARY_PATH/usr/lib/plexmediaserver/Plex\ Media\ Scanner --scan --refresh --section “$TVSECTION” --directory “$FOLDER” | tee -a “$LOGFILE”

I think it should be:

$LD_LIBRARY_PATH/Plex\ Media\ Scanner --scan --refresh --section “$TVSECTION” --directory “$FOLDER” | tee -a “$LOGFILE”

as $LD_LIBRARY_PATH has /usr/lib/plexmediaserver as its value

1 Like

Yes it was a typo, thanks i fixed it.

1 Like