This repository has been archived by the owner on Feb 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathupload-movies.sh
79 lines (68 loc) · 2.27 KB
/
upload-movies.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
###################################################################################
################################### PLEXiDRIVE ####################################
################################## MOVIE UPLOADS ##################################
###################################################################################
# Directory where this file exists
plexidrive_dir=`dirname $(realpath -s $0)`
cd "$plexidrive_dir"
# Read in configuration file
if [ -e ./plexidrive.conf ] ; then
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
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
# Set up variables and folder
path=${f%/*}
cd "$path"
f=${f##*/}
folder=`echo ${path#$local_movies_path} | cut -d'/' -f1`
in_root=false
if [ -z "$folder" ]
then
in_root=true # Denote movie is in the movie root folder
folder=${f%.*} # Make the folder name the name of the movie (minus the file extension)
fi
echo "File: $f"
# Upload file to every 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]}":/Movies/"$folder"/ &
else
rclone --config "$rclone_config" copy "$f" "${drive_names[i]}":/Movies/"$folder"/ &
fi
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."
# Add movie's folder to list of directories for plex to scan
echo "mov:$folder" >> "$plexidrive_dir/plex-scan"
# Delete local file after successful upload, if enabled
if [ "$delete_after_upload" = true ] ; then
# Delete the local folder
if [ "$in_root" = "true" ]
then
rm $f # delete file if in local movie directory
else
rm -rf $path # delete movie folder
fi
fi
done