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
/
plex-scan.sh
71 lines (59 loc) · 2.55 KB
/
plex-scan.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
#!/bin/bash
##################################################################################
################################### PLEXiDRIVE ###################################
#################################### PLEX SCAN ###################################
##################################################################################
# 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
# Log
echo "+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+" >> "$plexidrive_dir/plex-scan.log"
echo "$(date +%F_%T) Starting plex scan." >> "$plexidrive_dir/plex-scan.log"
# Check if file is empty
if [ -s "$plexidrive_dir/plex-scan" ]
then
# Check if each mount path are sucessfully mounted, if enabled
if [[ ! -d "$plex_tvshow_path" && "$enable_show_uploads" = "true" ]] || [[ ! -d "$plex_movies_path" && "$enable_movie_uploads" = "true" ]]
then
echo "At least one plex path is not mounted."
echo "$(date +%F_%T) plex-scan: at least one plex path is not mounted" >> "$plexidrive_dir/plex-scan.log"
echo "$(date +%F_%T) plex-scan: at least one plex path is not mounted" >> "$plexidrive_dir/upload-error"
exit 1 # exit the script
fi
unset n
while read -r line; do
echo $line
IFS=':' read -a current <<< "$line"
if [ "tv" = "${current[0]}" ]
then
# Dealing with a TV show
show="${current[1]}"
season="${current[2]}"
echo "Plex Scanner: Scanning $season of $show."
path="$plex_tvshow_path/$show/$season/"
export LD_LIBRARY_PATH=/usr/lib/plexmediaserver:/usr/lib/plexmediaserver/lib
/usr/lib/plexmediaserver/Plex\ Media\ Scanner --scan --refresh -c "$plex_tvshow_section_num" -d "$path"
echo "Plex Scanner: Done scanning $season of $show."
elif [ "mov" = "${current[0]}" ]
then
# Dealing with a movie
folder="${current[1]}"
path="$plex_movies_path/$folder"
echo "Plex Scanner: Scanning the movie - $folder."
export LD_LIBRARY_PATH=/usr/lib/plexmediaserver:/usr/lib/plexmediaserver/lib
/usr/lib/plexmediaserver/Plex\ Media\ Scanner --scan --refresh -c "$plex_movies_section_num" -d "$path"
echo "Plex Scanner: Done scanning movie - $folder."
fi
echo "- Scanned: $line" >> "$plexidrive_dir/plex-scan.log"
: $[n++]
done < "$plexidrive_dir/plex-scan"
sed -i "1,$n d" "$plexidrive_dir/plex-scan"
fi