jackz

jackz / ytdl-bulk

Last active 1 month ago

Like 0

acquires links from stdin, downloads with yt-dlp and then rsyncs to media folder

jackz revised this gist 1 month ago · 310e900

No changes

jackz revised this gist 1 month ago · 8bdab30

1 file changed, 66 insertions

ytdl-bulk.sh (file created)
@@ -0,0 +1,66 @@
1 + #!/bin/sh
2 + set -e
3 + TMP_PATH=/tmp/yt-dl #$(mktemp -d)
4 + mkdir $TMP_PATH || true
5 + DEST=/mnt/hs2/main/media/storage/music/
6 +
7 + # Exit if the temp directory wasn't created successfully.
8 + if [ ! -e "$TMP_PATH" ]; then
9 + >&2 echo "Failed to create temp directory"
10 + exit 1
11 + fi
12 +
13 +
14 + for url in "$@"
15 + do
16 + yt-dlp "$url" \
17 + -x --audio-format m4a \
18 + -o "${TMP_PATH}/%(title)s [%(id)s].%(ext)s" \
19 + --embed-metadata \
20 + --embed-thumbnail \
21 + --embed-subs \
22 + --sub-langs en-US* \
23 + --write-auto-sub \
24 + --sponsorblock-remove all
25 +
26 + done
27 + rsync -r --remove-source-files --ignore-existing --progress -v "${TMP_PATH}/" "$DEST"
28 +
29 + trap "exit 1" HUP INT PIPE QUIT TERM
30 + trap 'rm -rf "$TEMPD"' EXIT
31 + root@lambda:~# cat ytdl-bulk.sh
32 + #!/bin/sh
33 + set -e
34 +
35 + TMP_PATH=/tmp/yt-dl
36 + mkdir -p "$TMP_PATH" || true
37 + DEST=/mnt/hs2/main/media/storage/music/
38 +
39 + echo "TMP: $TMP_PATH"
40 + echo "DEST: $DEST"
41 +
42 + if [ ! -e "$TMP_PATH" ]; then
43 + >&2 echo "Failed to create temp directory"
44 + exit 1
45 + fi
46 +
47 + trap 'rm -rf "$TMP_PATH"; exit 1' HUP INT PIPE QUIT TERM
48 +
49 + echo waiting for links...
50 +
51 + # Read URLs from stdin, one per line. No shell interpretation of & etc.
52 + while IFS= read -r url || [ -n "$url" ]; do
53 + [ -z "$url" ] && continue
54 + yt-dlp "$url" \
55 + -x --audio-format m4a \
56 + -o "${TMP_PATH}/%(title)s [%(id)s].%(ext)s" \
57 + --embed-metadata \
58 + --embed-thumbnail \
59 + --embed-subs \
60 + --sub-langs en-US* \
61 + --write-auto-sub \
62 + --sponsorblock-remove all
63 + done
64 + echo syncing files...
65 + rsync -r --remove-source-files --ignore-existing --progress -v "${TMP_PATH}/" "$DEST"
66 + echo goodbye