-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
trailerdl.sh
98 lines (68 loc) · 3.13 KB
/
trailerdl.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
91
92
93
94
95
96
97
98
#!/bin/bash
#################################
# Config #
#################################
#Search this paths (required)
PATHS=( "/mnt/omv1/omv1/filme" "/mnt/omv2/omv2/filme" "/mnt/omv3/omv3/filme" "/mnt/omv4/omv4/filme" )
#Your TheMovieDB API (required)
#Please visit https://developers.themoviedb.org/3 for more information
API=
#Language Code (required)
#Examples: de = German, en = English, etc.
LANGUAGE=de
#Custom path to store the log files. Uncomment this line and change the path. By default the working directory is going to be used.
#LOGPATH="/home/myexampleuser"
#################################
#Functions
downloadTrailer(){
youtube-dl -f mp4 "https://www.youtube.com/watch?v=$ID" -o "$DIR/$FILENAME-trailer.%(ext)s" --restrict-filenames |& tee -a "$LOGPATH/trailerdl.log"
}
log(){
echo "$1" |& tee -a "$LOGPATH/trailerdl.log"
}
missing(){
echo "$1" |& tee -a "$LOGPATH/trailerdl-missing.log" &>/dev/null
}
#################################
#Delete old logs
rm "$LOGPATH/trailerdl.log" &>/dev/null
rm "$LOGPATH/trailerdl-missing.log" &>/dev/null
#Use manually provided language code (optional)
if ! [ -z "$1" ]; then
LANGUAGE="$1"
fi
if [ -z "$LOGPATH" ]; then
LOGPATH=$(pwd)
fi
#Walk defined paths and search for movies without existing local trailer
for i in "${PATHS[@]}"
do
find "$i" -mindepth 1 -maxdepth 2 -type d '!' -exec sh -c 'ls -1 "{}" | egrep -i -q "trailer\.(mp4|avi|mkv)$"' ';' -print | while read DIR
do
FILENAME=$(ls "$DIR" | egrep '\.nfo$' | sed s/".nfo"//g)
if [ -f "$DIR/$FILENAME.nfo" ]; then
#Get TheMovieDB ID from NFO
TMDBID=$(awk -F "[><]" '/tmdbid/{print $3}' "$DIR/$FILENAME.nfo" | awk -F'[ ]' '{print $1}')
log ""
log "Movie Path: $DIR"
log "Processing file: $FILENAME.nfo"
if ! [ -z "$TMDBID" ]; then
log "TheMovieDB: https://www.themoviedb.org/movie/$TMDBID"
#Get trailer YouTube ID from themoviedb.org
JSON=($(curl -s "http://api.themoviedb.org/3/movie/$TMDBID/videos?api_key=$API&language=$LANGUAGE" | jq -r '.results[] | select(.type=="Trailer") | .key'))
ID="${JSON[0]}"
if ! [ -z "$ID" ]; then
#Start download
log "YouTube: https://www.youtube.com/watch?v=$ID"
downloadTrailer
else
log "YouTube: n/a"
missing "Error: Missing YouTube ID - $FILENAME - $DIR - TheMovideDB: https://www.themoviedb.org/movie/$TMDBID"
fi
else
log "TheMovieDB: n/a"
missing "Error: Missing TheMovieDB ID - $FILENAME - $DIR"
fi
fi
done
done