-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgetTranscript
More file actions
executable file
·69 lines (59 loc) · 1.58 KB
/
getTranscript
File metadata and controls
executable file
·69 lines (59 loc) · 1.58 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
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
#!/usr/bin/env bash
URL="$1"
LANG="en"
if [ -z "$URL" ]; then
echo "❌ Usage: $0 <YouTube URL>"
exit 1
fi
TMP_DIR=$(mktemp -d)
TMP="$TMP_DIR/sub"
yt-dlp --write-auto-subs --sub-lang "$LANG" \
--skip-download --sub-format vtt \
-o "$TMP" "$URL" > /dev/null 2>&1
SUB_FILE=$(ls "$TMP_DIR"/*.vtt 2>/dev/null | head -n1)
if [ ! -f "$SUB_FILE" ]; then
echo "❌ No subtitles found. Try checking the URL or language code."
rm -rf "$TMP_DIR"
exit 1
fi
CLEANED=$(mktemp)
awk '
/^WEBVTT/ { next }
/^NOTE/ { skip=1; next }
/^Kind:/ { next }
/^Language:/ { next }
/^$/ { skip=0; next }
skip { next }
/-->/ { next }
{
gsub(/<[^>]+>/, "")
gsub(/>/, ">")
gsub(/</, "<")
gsub(/&/, "and")
gsub(/ /, " ")
gsub(/\[[^\]]*\]/, "")
gsub(/^[> \t]+/, "")
gsub(/^[ \t]+|[ \t]+$/, "")
gsub(/ +/, " ")
if ($0 == "") next
if ($0 != prev) {
print $0
prev = $0
}
}
' "$SUB_FILE" > "$CLEANED"
if command -v wl-copy >/dev/null && [ "$XDG_SESSION_TYPE" = "wayland" ]; then
wl-copy < "$CLEANED"
echo "✅ Copied using wl-copy (Wayland)"
elif command -v xclip >/dev/null; then
xclip -selection clipboard < "$CLEANED"
echo "✅ Copied using xclip (X11)"
elif command -v xsel >/dev/null; then
xsel --clipboard < "$CLEANED"
echo "✅ Copied using xsel"
else
echo "⚠️ No clipboard tool found — printing to stdout:"
cat "$CLEANED"
fi
rm -rf "$TMP_DIR"
rm -f "$CLEANED"