-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathingestmedia.sh
executable file
·90 lines (70 loc) · 2.12 KB
/
ingestmedia.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
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
# This script should be run as root.
# Intended to be run as a cron job that
# checks the given directory for new movies
# and copies them to the configured directory.
# Additionally can also run a task after the
# copy. E.g., triggering a refresh of the plex
# library or sending an email.
# Checks for new folders and copies those that
# contain a .ready file and !contain a .copied
# file.
# After copy, a .copied file is created in the
# folders to indicate that the copy was done
# successfully.
# The status files are removed from the destination.
pms=/snap/plexmediaserver/current/Plex\ Media\ Scanner
inputmovies=/mnt/raid/transfer/plex/movies
outputmovies=/mnt/raid/media/movies
intv=/mnt/raid/transfer/plex/tv
outtv=/mnt/raid/media/tv
inputmusicen=/mnt/raid/transfer/plex/music/english
inputmusichi=/mnt/raid/transfer/plex/music/hindi
outputmusicen=/mnt/raid/media/music/english
outputmusicen=/mnt/raid/media/music/hindi
# Copy media function $1 = input, $2 = output
copymedia() {
ret=0
cd /"$1"
for d in */; do
if [ -e "$d".ready -a ! -e "$d".copied -a ! -e "$d".copying ]; then
touch "$d".copying
cp -r -f -v "$d" "$2"
if [ "$?" -eq "0" ]; then
touch "$d".copied
rm "$2"/"$d".ready
rm "$2"/"$d".copying
ret=1
fi
rm "$d".copying
fi
done
return $ret
}
echo $(date)
# Copy new movies copymedia(inputdir, outputdir)
echo "Copying movies..."
copymedia $inputmovies $outputmovies
moviesret=$?
# Copy new music
echo "Copying music..."
copymedia $inputmusicen $outputmusicen
enmusicret=$?
copymedia $inputmusichi $outputmusichi
himusicret=$?
# Copy new TV
copymedia $intv $outtv
tvret=$?
#if [ "$moviesret" -eq "1" ]; then
#"$pms" -scan --refresh --directory "$outputmovies"
#fi
#if [ "$enmusicret" -eq "1" ]; then
#"$pms" --scan --refresh --directory "$outputmusicen"
#fi
#if [ "$himusicret" -eq "1" ]; then
#"$pms" --scan --refresh --directory "$outputmusichi"
#fi
#if [ "$tvret" -eq "1" ]; then
#"$pms" --scan --refresh --directory "$outtv"
#fi
echo "Done"