-
Notifications
You must be signed in to change notification settings - Fork 10
/
.gregflix-functions
223 lines (172 loc) · 7.23 KB
/
.gregflix-functions
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#!/bin/bash
source $HOME/.tmdb-functions
GREGFLIX_PATH=~/dev/gregflix
GREGFLIX_SCRIPTS_PATH=$GREGFLIX_PATH/resources/scripts
GREGFLIX_DEV_DB_URI="datomic:free://localhost:4334/gregflix?password=123mudar"
GREGFLIX_PROD_DB_URI="datomic:free://gregflix.site:4334/gregflix?password=$GREGFLIX_DATOMIC_DB_PASS"
function changeEncoding {
if file -i "$1.srt" |grep -q "iso-8859-1"; then
iconv -f ISO-8859-1 -t UTF-8 "$1.srt" -o "$1.srt.tmp" &&
mv "$1.srt.tmp" "$1.srt"
fi
}
function 2vtt {
changeEncoding "$1"
srt-vtt "$1.srt"
}
function encodeVideo {
ffmpeg -y -i "$1.mkv" -c:v libx264 -c:a aac -sn "$1.mp4"
2vtt "$1"
}
function encodeAudio {
ffmpeg -y -i "$1.mkv" -c:v copy -c:a aac -sn "$1.mp4"
2vtt "$1"
}
function toMp4 {
ffmpeg -y -i "$1.mkv" -pix_fmt yuv420p -c:v copy -c:a aac -map 0:v -map 0:1 -map 0:1 -sn "$1.mp4"
2vtt "$1"
}
function gregflix-prod-upload-serie {
SERIE_PATH=s3://gregflix/series/$2/s$3/e$4/$1.mp4
TRACK_PATH=s3://gregflix/series/$2/s$3/e$4/$1.srt
VTT_PATH=s3://gregflix/series/$2/s$3/e$4/$1.vtt
s3cmd info $TRACK_PATH >/dev/null 2>&1
if [[ $? -eq 0 ]]; then
echo "Track already uploaded"
else
echo "Uploading track..."
s3cmd put $1.srt s3://gregflix/series/$2/s$3/e$4/$1.srt -P --add-header='content-type':'text/srt' --mime-type='text/srt'
fi
s3cmd info $VTT_PATH >/dev/null 2>&1
if [[ $? -eq 0 ]]; then
echo "VTT already uploaded"
else
echo "Uploading VTT..."
s3cmd put $1.vtt s3://gregflix/series/$2/s$3/e$4/$1.vtt -P --add-header='content-type':'text/vtt' --mime-type='text/vtt'
fi
s3cmd info $SERIE_PATH >/dev/null 2>&1
if [[ $? -eq 0 ]]; then
echo "Serie already uploaded"
else
echo "Uploading video..."
s3cmd put $1.mp4 s3://gregflix/series/$2/s$3/e$4/$1.mp4 -P --add-header='content-type':'video/mp4' --mime-type='video/mp4'
fi
}
function gregflix-prod-upload-movie {
MOVIE_PATH=s3://gregflix/movies/$2/$1.mp4
TRACK_PATH=s3://gregflix/movies/$2/$1.srt
VTT_PATH=s3://gregflix/movies/$2/$1.vtt
s3cmd info $TRACK_PATH >/dev/null 2>&1
if [[ $? -eq 0 ]]; then
echo "Track already uploaded"
else
echo "Uploading track..."
s3cmd put $1.srt $TRACK_PATH -P --add-header='content-type':'text/srt' --mime-type='text/srt'
fi
s3cmd info $VTT_PATH >/dev/null 2>&1
if [[ $? -eq 0 ]]; then
echo "VTT already uploaded"
else
echo "Uploading VTT..."
s3cmd put $1.vtt $VTT_PATH -P --add-header='content-type':'text/vtt' --mime-type='text/vtt'
fi
s3cmd info $MOVIE_PATH >/dev/null 2>&1
if [[ $? -eq 0 ]]; then
echo "Movie already uploaded"
else
echo "Uploading video..."
s3cmd put $1.mp4 $MOVIE_PATH -P --add-header='content-type':'video/mp4' --mime-type='video/mp4'
fi
}
function gregflix-prod-upload-serie-track {
s3cmd put $1.vtt s3://gregflix/series/$2/s$3/e$4/$1.vtt -P --add-header='content-type':'text/vtt' --mime-type='text/vtt'
s3cmd put $1.srt s3://gregflix/series/$2/s$3/e$4/$1.srt -P --add-header='content-type':'text/srt' --mime-type='text/srt'
}
function gregflix-prod-upload-movie-track {
TRACK_PATH=s3://gregflix/movies/$2/$1.srt
VTT_PATH=s3://gregflix/movies/$2/$1.vtt
s3cmd put $1.srt $TRACK_PATH -P --add-header='content-type':'text/srt' --mime-type='text/srt'
s3cmd put $1.vtt $VTT_PATH -P --add-header='content-type':'text/vtt' --mime-type='text/vtt'
}
function gregflix-prod-db-add-movie {
MOVIE_EXISTS=$(cd $GREGFLIX_PATH && lein exec $GREGFLIX_SCRIPTS_PATH/movie_exists.clj $GREGFLIX_PROD_DB_URI $2)
if [ "$MOVIE_EXISTS" = "1" ]; then
echo "Movie already in DB"
return
fi
echo "Inserting into db for $1 - $2 - $3 - $4"
$(cd $GREGFLIX_PATH && lein exec $GREGFLIX_SCRIPTS_PATH/add_movie.clj $GREGFLIX_PROD_DB_URI $1 $2 $3 $4)
echo "Movie inserted successfully!"
}
function gregflix-prod-db-add-serie {
SERIE_EXISTS=$(cd $GREGFLIX_PATH && lein exec $GREGFLIX_SCRIPTS_PATH/serie_exists.clj $GREGFLIX_PROD_DB_URI $2 $4 $5)
if [ "$SERIE_EXISTS" = "1" ]; then
echo "Serie already in DB"
return
fi
echo "Inserting into db for $1 - $2 - $3 - $4 - $5 - $6 - $7"
$(cd $GREGFLIX_PATH && lein exec $GREGFLIX_SCRIPTS_PATH/add_serie.clj $GREGFLIX_PROD_DB_URI $1 $2 $3 $4 $5 $6 $7)
echo "Serie inserted successfully!"
}
function gregflix-prod-process-video {
set -v
if [ "$#" -eq 7 ] || [ "$#" -eq 4 ] || [ "$#" -eq 5 ] || [ "$#" -eq 3 ]; then
if [ ! -f "$3.mp4" ]; then
if mediainfo --Inform="Video;Codec=%CodecID%" "$3.mkv" |grep -q 'MPEG4'; then
toMp4 "$3"
else
encodeVideo "$3"
fi
fi
if [ ! -f "$3.vtt" ]; then
2vtt "$3"
fi
if [ "$#" -eq 7 ] || [ "$#" -eq 5 ]; then
EPISODE_NAME="${6:=$(getEpisodeName $1 $4 $5)}"
EPISODE_NAME=${EPISODE_NAME//\'}
EPISODE_NAME=${EPISODE_NAME//\"}
EPISODE_DESCRIPTION="${7:=$(getEpisodeDescription $1 $4 $5)}"
EPISODE_DESCRIPTION=${EPISODE_DESCRIPTION//\'}
EPISODE_DESCRIPTION=${EPISODE_DESCRIPTION//\"}
echo 'Uploading serie...'
gregflix-prod-upload-serie $3 $2 $4 $5
echo 'Adding to database...'
gregflix-prod-db-add-serie $1 $2 $3 $4 $5 $EPISODE_NAME $EPISODE_DESCRIPTION
else
MOVIE_DESCRIPTION="${4:=$(getMovieDescription $1)}"
echo 'Uploading movie...'
gregflix-prod-upload-movie $3 $2
echo 'Adding to database...'
gregflix-prod-db-add-movie $1 $2 $3 $MOVIE_DESCRIPTION
fi
gregflix-prod-dump
return
fi
echo "inform all parameters:\n\nFor Serie:\n1-Name\n2-Slug\n3-File name\n4-Season\n5-Episode\n6-Episode name\n7-Episode description\n\nFor Movie:\n1-Name\n2-Slug\n3-File name\n4-Description"
return 1
}
function gregflix-dev-db-create-user {
$(cd $GREGFLIX_PATH && lein exec $GREGFLIX_SCRIPTS_PATH/create_user.clj $GREGFLIX_DEV_DB_URI $1 $2 $3)
}
function gregflix-prod-db-create-user {
$(cd $GREGFLIX_PATH && lein exec $GREGFLIX_SCRIPTS_PATH/create_user.clj $GREGFLIX_PROD_DB_URI $1 $2 $3)
}
function gregflix-dev-dump {
docker start datomic
docker exec datomic bin/datomic -Xmx4g -Xms4g backup-db $GREGFLIX_DEV_DB_URI file:backup
docker cp datomic:/datomic/backup ~/Documents/Gregflix/backups/datomic/backup-dev-$(date +%d-%m-%Y)
}
function gregflix-prod-dump {
docker start datomic
docker exec datomic bin/datomic -Xmx4g -Xms4g backup-db $GREGFLIX_PROD_DB_URI file:backup-prod
docker cp datomic:/datomic/backup-prod/ ~/Documents/Gregflix/backups/datomic/backup-prod-$(date +%d-%m-%Y)
}
function gregflix-dev-restore-dump {
docker cp ~/Documents/Gregflix/backups/datomic/backup-prod-$1-$2-$3 datomic:/datomic/backup
docker exec datomic bin/datomic -Xmx4g -Xms4g restore-db file:backup "$GREGFLIX_DEV_DB_URI"
}
function gregflix-prod-restore-dump {
scp -r $1 root@$CAC3_IP:backup-prod
sshcac3 'docker cp backup-prod datomic:/datomic/backup-prod'
sshcac3 'docker exec datomic bin/datomic -Xmx4g -Xms4g restore-db file:backup-prod $GREGFLIX_PROD_DB_URI'
}