-
Notifications
You must be signed in to change notification settings - Fork 0
/
reuploader.sh
executable file
·275 lines (239 loc) · 6.62 KB
/
reuploader.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
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#!/usr/bin/env bash
semester_default="LS 20/21"
channel="UCzQzKzGlpX4qBi060qdwIug"
cache_path="/mnt"
NODE_EXEC=${NODE_EXEC:-"node"}
set -e
trap "stty sane" EXIT
export LANG=C.UTF-8
mkdir -p "$cache_path/destreamer"
mkdir -p "$cache_path/sharepoint"
mkdir -p "$cache_path/uploader"
# start the youtube login background job
# job control is turned off by default in scripts (set +m)
python3 youtube_uploader_selenium/login.py --channel="$channel" --username="a" --password="a" --cookies="$cache_path/uploader" --headless >/dev/null &
YT_LOGIN_PID=$!
function sel() {
prompt="$1"
echo "$prompt" >&2
options=("${@:2}")
len="${#options[@]}"
set -e
selection="$(while true; do
IFS=$'\n' eval 'echo -e "${options[*]}"' | fzf --height="$((len + 1))" --reverse --color=16 --no-info
case "$?" in
0) break ;;
1) continue ;;
*) exit "$?" ;;
esac
done)"
echo -e "\e[A$prompt $selection" >&2
echo "$selection"
}
while true; do
template=$(sel "Metadata template:" "přednáška" "cvičení" "seminář" "konzultace" "<custom>")
if [[ "$template" == "<custom>" ]]; then
read -er -p "Video title: " video_title
read -er -p "Video description: " video_description
read -er -p "Playlist: " video_playlist
video_visibility=$(sel "Video visibility:" "unlisted" "public" "private")
else
read -er -p "Subject code: " subject
read -er -p "Lecture number: " lecnum
read -er -p "Date string: " -i "$(date +'%-d. %-m. %Y')" datestr
read -er -p "Semester: " -i "$semester_default" semester
read -er -p "Lecture title: " lectitle
read -er -p "Video description: " video_description
case "$template" in
"přednáška")
category1="přednáška"
categoryN="přednášky"
;;
"cvičení")
category1="cvičení"
categoryN="cvičení"
;;
"seminář")
category1="seminář"
categoryN="semináře"
;;
"konzultace")
category1="konzultace"
categoryN="konzultace"
;;
*)
echo -e "\033[31mUnknown lecture template!\033[0m"
exit 1
;;
esac
test -n "$lectitle" && lectitle=": $lectitle"
subject=$(echo "$subject" | tr '[:lower:]' '[:upper:]')
video_title="$subject $lecnum. $category1 ($datestr)$lectitle"
video_playlist="$subject $categoryN [$semester]"
video_visibility="unlisted"
fi
echo -e "\033[34m"
echo "Title: $video_title"
echo "Description: $video_description"
echo "Playlist: $video_playlist"
echo "Visibility: $video_visibility"
echo -e "\033[0m"
read -r -n 1 -p "Okay? [Y/n] "
echo
if [[ $REPLY =~ ^[YyJj]?$ ]]; then
break
fi
echo
done
if [[ -f "local_video" ]]; then
source="local file"
url="local_video"
else
source=$(
sel "Source:" \
"any video url" \
"google drive" \
"microsoft stream (teams)" \
"sharepoint (teams)" \
"youtube-dl" \
"youtube-dl (livestream)"
)
if [[ "$source" == "youtube-dl (livestream)" ]]; then
read -r -p "Recording time: " -i "2h" -e rectime
fi
read -er -p "URL/URI: " url
echo
fi
# if there are any jobs...
if [[ "$(jobs -r)" ]]; then
echo "Logging in to YouTube..."
fi
# wait for the youtube login job (or just get the exit code if it's finished already)
set +e
wait $YT_LOGIN_PID
status=$?
set -e
# run the youtube login again if the background job failed
while true; do
if [[ "$status" == "7" ]]; then
read -er -p "ČVUT username: " cvut_username
read -ers -p "ČVUT password: " cvut_password
echo
else
break
fi
echo "Logging in to YouTube..."
set +e
python3 youtube_uploader_selenium/login.py --channel="$channel" --username="$cvut_username" --password="$cvut_password" --cookies="$cache_path/uploader" --headless
status="$?"
set -e
done
# not bigger than 1080p, vp9 preferred
ytformat='bestvideo[vcodec^=vp9][height<=1080]+bestaudio/best[vcodec^=vp9][height<=1080]/bestvideo[height<=1080]+bestaudio/best[height<=1080]'
echo
case "$source" in
"local file")
tmp_filename="$url"
;;
"any video url")
tmp_filename="video"
while true; do
set +e
wget --http-user="$http_username" --http-password="$http_password" "$url" -O "$tmp_filename"
status="$?"
set -e
if [[ "$status" == "6" ]]; then
read -er -p "HTTP username: " http_username
read -ers -p "HTTP password: " http_password
echo
else
break
fi
done
tmp_filename=$(readlink -f "$tmp_filename")
;;
"bbb internal player")
echo "bbb-internal is not implemented yet."
exit 1
cd bbb-recorder/
tmp_filename="video.webm"
node export.js "$url" "$tmp_filename"
tmp_filename=$(readlink -f "$tmp_filename")
cd ../
;;
"microsoft stream (teams)")
cd destreamer/
chown user:user -R "$cache_path/destreamer"
while true; do
set +e
sudo -u user NODE_EXEC="$NODE_EXEC" xvfb-run ./destreamer.sh --outputDirectory "." --format mp4 -x -u "[email protected]" -p "$cvut_password" -k -c "$cache_path/destreamer" -i "$url"
status="$?"
set -e
if [[ "$status" == "7" ]]; then
read -er -p "ČVUT username: " cvut_username
read -ers -p "ČVUT password: " cvut_password
echo
else
break
fi
done
tmp_filename=$(ls -t | grep -E "*.mp4$" | head -n1)
tmp_filename=$(readlink -f "$tmp_filename")
cd ../
;;
"youtube-dl")
youtube-dl --fragment-retries infinite "$url" -o "video.%(ext)s"
tmp_filename=$(ls -t | grep -E "video.*$" | head -n1)
tmp_filename=$(readlink -f "$tmp_filename")
;;
"youtube-dl (livestream)")
tmp_filename=$(youtube-dl --get-filename "$url" -o "video.%(ext)s")
set -m # SIGINT is ignored when job control is disabled!!!
youtube-dl --fragment-retries infinite "$url" -o "video.%(ext)s" &
PID=$!
sleep "$rectime"
kill -INT $PID
set +m
# wait for the youtube-dl to spin down
sleep 20s
tmp_filename=$(readlink -f "$tmp_filename")
;;
"sharepoint (teams)")
tmp_filename="sharepoint_downloader/video"
while true; do
set +e
$NODE_EXEC ./sharepoint_downloader/index.js -u "$cvut_username" -p "$cvut_password" --chromeData "$cache_path/sharepoint" -i "$url" -o "$tmp_filename"
status="$?"
set -e
if [[ "$status" == "7" ]]; then
read -er -p "ČVUT username: " cvut_username
read -ers -p "ČVUT password: " cvut_password
echo
else
break
fi
done
tmp_filename=$(readlink -f "$tmp_filename")
;;
"google drive")
tmp_filename="video"
./gdown.pl/gdown.pl "$url" "$tmp_filename"
tmp_filename=$(readlink -f "$tmp_filename")
;;
*)
echo -e "\033[31mUnknown video source!\033[0m"
exit 1
;;
esac
# upload
echo
python3 youtube_uploader_selenium/upload.py \
--video="$tmp_filename" \
--channel="$channel" \
--title="$video_title" \
--description="$video_description" \
--playlist="$video_playlist" \
--privacy="$video_visibility" \
--cookies="$cache_path/uploader" \
--headless
echo -e "\n\033[32mDONE\033[0m"