Skip to content
This repository was archived by the owner on Feb 11, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions plexidrive.conf
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
## Drive Settings ##
num_of_gdrives=1
drive_names=('')
drive_tvshow_path="Series" # path inside gdrive's - no ending /
drive_movies_path="Movies" # path inside gdrive's - no ending /

## Options ##
delete_after_upload=true # true/false
file_types="mkv|avi|mp4|m4v|mpg|wmv|flv"
min_age="0" # minimal age before moving to Drive
bw_limit="10M" #bandwidth limit (example: 10M)
rclone_config=""

## Plex Library Directories ##
Expand Down
6 changes: 3 additions & 3 deletions upload-movies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fi

# Loop through to see if any files are done downloading
IFS=$'\n';
for f in $(find "$local_movies_path" -regextype posix-egrep -regex ".*\.($file_types)$"); do
for f in $(find "$local_movies_path" -mmin +"$min_age" -regextype posix-egrep -regex ".*\.($file_types)$"); do

# Set up variables and folder
path=${f%/*}
Expand All @@ -41,9 +41,9 @@ for f in $(find "$local_movies_path" -regextype posix-egrep -regex ".*\.($file_t
echo "Starting upload to ${drive_names[i]}..."
if [ -z "$rclone_config" ]
then
rclone copy "$f" "${drive_names[i]}":/Movies/"$folder"/ &
rclone copy "$f" "${drive_names[i]}":/"$drive_movies_path"/"$folder"/ --bwlimit="$bw_limit" &
else
rclone --config "$rclone_config" copy "$f" "${drive_names[i]}":/Movies/"$folder"/ &
rclone --config "$rclone_config" copy "$f" "${drive_names[i]}":/"$drive_movies_path"/"$folder"/ --bwlimit="$bw_limit" &
fi
done

Expand Down
101 changes: 51 additions & 50 deletions upload-shows.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

#!/bin/bash

##################################################################################
Expand All @@ -11,64 +12,64 @@ cd "$plexidrive_dir"

# Read in configuration file
if [ -e ./plexidrive.conf ] ; then
source ./plexidrive.conf
source ./plexidrive.conf
else
echo "Configuration file - plexidrive.conf - not found."
echo "$(date +%F_%T) Configuration file - plexidrive.conf - not found." >> "$plexidrive_dir/upload-error"
exit 1
echo "Configuration file - plexidrive.conf - not found."
echo "$(date +%F_%T) Configuration file - plexidrive.conf - not found." >> "$plexidrive_dir/upload-error"
exit 1
fi

# Loop through to see if any files need uploading
IFS=$'\n';
for f in $(find "$local_tvshow_path" -regextype posix-egrep -regex ".*\.($file_types)$"); do
for f in $(find "$local_tvshow_path" -mmin +"$min_age" -regextype posix-egrep -regex ".*\.($file_types)$"); do

# Set up variables and directory
path=${f%/*}
cd "$path"
show=`echo ${path#$local_tvshow_path} | cut -d'/' -f1`
season=`echo ${path#$local_tvshow_path} | cut -d'/' -f2`
f=${f##*/}
echo "File: $f"
# Set up variables and directory
path=${f%/*}
cd "$path"
show=`echo ${path#$local_tvshow_path} | cut -d'/' -f1`
season=`echo ${path#$local_tvshow_path} | cut -d'/' -f2`
f=${f##*/}
echo "File: $f"

# Upload file to each Google drive account
for (( i=0; i<${num_of_gdrives}; i++ ));
do
echo "Starting upload to ${drive_names[i]}..."
if [ -z "$rclone_config" ]
then
rclone copy "$f" "${drive_names[i]}":/TV\ Shows/"$show"/"$season"/ &
else
rclone --config "$rclone_config" copy "$f" "${drive_names[i]}":/TV\ Shows/"$show"/"$season"/ &
fi
done
# Upload file to each Google drive account
for (( i=0; i<${num_of_gdrives}; i++ ));
do
echo "Starting upload to ${drive_names[i]}..."
if [ -z "$rclone_config" ]
then
rclone copy "$f" "${drive_names[i]}":/"$drive_tvshow_path"/"$show"/"$season"/ --bwlimit="$bw_limit" &
else
rclone --config "$rclone_config" copy "$f" "${drive_names[i]}":/"$drive_tvshow_path"/"$show"/"$season"/ --bwlimit="$bw_limit" &
fi
done

# Wait until all uploads have finished before continuing
FAIL=0
for job in `jobs -p`
do
wait $job || let "FAIL+=1"
done
# Wait until all uploads have finished before continuing
FAIL=0
for job in `jobs -p`
do
wait $job || let "FAIL+=1"
done

# Check exit code of upload to make sure no errors occurred
if [ "$FAIL" != "0" ] ; then
echo "Upload failed. ($FAIL)"
echo "$(date +%F_%T) Upload of $f failed - $FAIL." >> "$plexidrive_dir/upload-error"
exit 1
fi
echo "Done upload."
# Check exit code of upload to make sure no errors occurred
if [ "$FAIL" != "0" ] ; then
echo "Upload failed. ($FAIL)"
echo "$(date +%F_%T) Upload of $f failed - $FAIL." >> "$plexidrive_dir/upload-error"
exit 1
fi
echo "Done upload."

# Add season folder to list of directories for plex to scan
desc="$show:$season:"
check=`cat $plexidrive_dir/plex-scan | grep $desc`
if [ -z "$check" ]
then
echo "tv:$desc" >> "$plexidrive_dir/plex-scan"
fi
# Add season folder to list of directories for plex to scan
desc="$show:$season:"
check=`cat $plexidrive_dir/plex-scan | grep $desc`
if [ -z "$check" ]
then
echo "tv:$desc" >> "$plexidrive_dir/plex-scan"
fi

# Delete local file after successful upload, if enabled
if [ "$delete_after_upload" = true ] ; then
# Delete the local file
rm "$f"
fi
done
# Delete local file after successful upload, if enabled
if [ "$delete_after_upload" = true ] ; then
# Delete the local file
rm "$f"
fi
done