-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetplainsubs_batch.sh
More file actions
executable file
·39 lines (34 loc) · 1.12 KB
/
getplainsubs_batch.sh
File metadata and controls
executable file
·39 lines (34 loc) · 1.12 KB
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
#!/bin/sh
# Requires yt-dlp, install/update with "$ pip install -U yt-dlp"
# Assumes that urls.txt contains
#
# url1
# url2
# ...
# urlN
#
# where each url is e.g. https://www.youtube.com/watch?v=0123456789A
# Last line must end with newline too, otherwise "while read url" skips it.
if [ "$(uname)" == "Darwin" ]; then
GEPLSU_DATE_ALIAS=gdate
GEPLSU_SED_ALIAS=gsed
else
GEPLSU_DATE_ALIAS=date
GEPLSU_SED_ALIAS=sed
fi
GEPLSU_DOWNLOADER_ALIAS=yt-dlp
GEPLSU_FORMAT=ttml
GEPLSU_LANG=ru-orig
GEPLSU_LIST="urls.txt"
GEPLSU_TEMPLATE=sub
while read url; do
echo "Downloading from $url ..."
TIMESTAMP="$($GEPLSU_DOWNLOADER_ALIAS --no-download --write-auto-subs --sub-langs $GEPLSU_LANG --sub-format $GEPLSU_FORMAT -o $GEPLSU_TEMPLATE --print timestamp --no-simulate $url)"
FILENAME="$($GEPLSU_DATE_ALIAS -d @$TIMESTAMP +D_%Y_%m_%d_T_%H_%M_%S).txt"
echo "Renaming to $FILENAME ..."
mv $GEPLSU_TEMPLATE.$GEPLSU_LANG.$GEPLSU_FORMAT $FILENAME
echo "Cleaning..."
$GEPLSU_SED_ALIAS -i -r -z -e 's/<[^>]*>//g' -e 's/\n[\n]+//g' -e 's/\n/ /g' -e 's/\[[^]]*\]//g' -e 's/[ ]+/ /g' -e 's/"/"/g' $FILENAME
echo "Done"
echo ""
done < "$GEPLSU_LIST"