-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclipMovie.sh
executable file
·90 lines (73 loc) · 1.85 KB
/
clipMovie.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
if test -z $1
then
echo 'missing clip ID as first argument'
exit 1
fi
if test ! -f "src/clips/$1.json"
then
echo 'no JSON file found for this clip ID'
exit 1
fi
clear
echo "Select movie for clip #$1"
echo '========================='
echo 'Is it one of the following movies ?'
lastMovieFiles=$(ls -Art src/movies | tail -n 6)
i=0
movies=()
titles=()
for file in $lastMovieFiles
do
title=$(jq -r .title src/movies/$file)
year=$(jq -r .year src/movies/$file)
echo -e "[$i] $title - \e[37m$year\e[0m"
titles+=("$title")
movie="${file%.*}"
movies+=("$movie")
let i++
done
echo '[ ] Not in the list ! 👻'
read -rsn1 input # get 1 character
case $input in
0|1|2|3|4|5)
echo "Movie: ${titles[$input]}"
movie="${movies[$input]}"
;;
*)
echo 'What is the movie Wikidata identifier ? (press Enter to send, leave empty to abort)'
read movie
if test -z "$movie"
then
echo '❌ cancelling'
sleep 0.5
exit 1
fi
if test -f "src/movies/$movie.json" # If the movie is not already imported
then
echo '📦️ movie is already imported'
title=$(jq -r .title src/movies/$movie.json)
year=$(jq -r .year src/movies/$movie.json)
echo "$title - $year"
echo 'confirmation ? [y]/n'
read -rsn1 input
if test "$input" = 'n'
then
echo '❌ aborted'
sleep 0.5
exit 1
fi
else
./fetchMovie.sh "$movie"
if test $? != 0
then
exit 1
fi
fi
;;
esac
clip=$(jq --arg movie "$movie" '.movie = $movie' src/clips/$1.json)
echo "$clip" > "src/clips/$1.json"
echo '💾 updated'
sleep 0.5
exit 0