-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay.sh
executable file
Β·181 lines (168 loc) Β· 4.14 KB
/
display.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/bin/bash
if test -z $1
then
clear
echo 'π Type a Clip ID and press enter !'
read clip
./display.sh $clip
exit
fi
clear
# If JSON file does not exit
if test ! -f src/clips/$1.json
then
./clipMetadata.sh $1 # try to create JSON file if MKV exist
if test $? != 0 # this mean clipMetadata failed, (no MKV an no JSON)
then
echo -e "\e[37m[β]prev [β]next [β]id\e[0m"
escape_char=$(printf "\u1b")
read -rsn1 input # get 1 character
if [[ $input == $escape_char ]]; then
read -rsn2 input # read 2 more chars
fi
case $input in
'[C')
n=$(($1+1))
./display.sh $n
exit
;;
'[D')
n=$(($1-1))
./display.sh $n
exit
;;
'[A')
clear
echo 'π Type a Clip ID and press enter !'
read clip
./display.sh $clip
exit
;;
*)
echo 'bye π'
exit
;;
esac
fi
fi
movieId=$(jq -r .movie src/clips/$1.json)
description=$(jq -r .description src/clips/$1.json)
aspectRatio=$(jq -r .aspectRatio src/clips/$1.json)
duration=$(jq -r .duration src/clips/$1.json)
color=$(jq -r .color src/clips/$1.json)
tags=$(cat src/clips/$1.json | jq -r .tags | jq -r 'join(" ")')
collections=()
for collection in src/collections/*
do
if grep -wq $1 "$collection"
then
collections+=("${collection##*/}")
fi
done
if test -n "$movieId" -a "$movieId" != 'null'
then
movieIsDefined=1
if test -f "src/movies/$movieId.json"
then
title=$(jq -r .title src/movies/$movieId.json)
year=$(jq -r .year src/movies/$movieId.json)
movie="$title - $year (#$movieId)"
else
movie="#$movieId (type [M] to fetch movie metadata)"
fi
else
movieIsDefined=0
movie='βοΈ'
fi
if test $aspectRatio = null -o $duration = null -o $color = null
then
./clipMetadata.sh $1
sleep 1
./display.sh $1
exit
fi
hex=$(echo "$color" | awk '{print substr($0,2)}')
r=$(printf '0x%0.2s' "$hex")
g=$(printf '0x%0.2s' ${hex#??})
b=$(printf '0x%0.2s' ${hex#????})
cc=$(echo -e `printf "%03d" "$(((r<75?0:(r-35)/40)*6*6+(g<75?0:(g-35)/40)*6+(b<75?0:(b-35)/40)+16))"`)
cc='\e[38;5;'$cc'm'
color="$ccββ\e[0m"
h=$(tput lines)
h=$(($h-7))
# if the thumbnail as already been generated, use it. Otherwise, read the first frame of movie file.
if test -f "build/assets/thumbnail/$1.webp"
then
timg -gx$h "build/assets/thumbnail/$1.webp"
else
timg -gx$h --frames=1 "src/clips/$1.mkv"
fi
echo -e "\033[1mClip #$1\033[0m β±οΈ $duration s β $aspectRatio π¨ $color <http://localhost:8066/clip/$1/>"
echo 'ποΈ movie:' $movie
echo 'π description:' $description
echo 'ποΈ tags:' "${tags[@]}"
echo "π collections: ${collections[@]}"
# echo ------------------------------------------
echo -e "\e[37m[T]ags [C]ollections [D]escription [M]ovie, [P]lay [β]prev [β]next [β]id\e[0m"
escape_char=$(printf "\u1b")
read -rsn1 input # get 1 character
if [[ $input == $escape_char ]]
then
read -rsn2 input # read 2 more chars
fi
case $input in
t|T)
./clipTags.sh $1
./display.sh $1
exit
;;
c|C)
./clipCollections.sh $1
./display.sh $1
exit
;;
p|P)
echo 'ποΈ play !!'
xdg-open src/clips/$1.mkv
sleep 0.5
./display.sh $1
;;
d|D)
./clipDescription.sh $1
./display.sh $1
exit
;;
m|M)
if test $movieIsDefined = 1
then
clear
./fetchMovie.sh "$movieId"
./display.sh $1
else
./clipMovie.sh $1
./display.sh $1
fi
exit
;;
'[C')
n=$(($1+1))
./display.sh $n
exit
;;
'[D')
n=$(($1-1))
./display.sh $n
exit
;;
'[A')
clear
echo 'π Type a Clip ID and press enter !'
read clip
./display.sh $clip
exit
;;
*)
echo 'bye π'
exit
;;
esac