Last active 4 days ago

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

ytdl-bulk.sh Raw
1#!/bin/sh
2set -e
3TMP_PATH=/tmp/yt-dl #$(mktemp -d)
4mkdir $TMP_PATH || true
5DEST=/mnt/hs2/main/media/storage/music/
6
7# Exit if the temp directory wasn't created successfully.
8if [ ! -e "$TMP_PATH" ]; then
9 >&2 echo "Failed to create temp directory"
10 exit 1
11fi
12
13
14for url in "$@"
15do
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
26done
27rsync -r --remove-source-files --ignore-existing --progress -v "${TMP_PATH}/" "$DEST"
28
29trap "exit 1" HUP INT PIPE QUIT TERM
30trap 'rm -rf "$TEMPD"' EXIT
31root@lambda:~# cat ytdl-bulk.sh
32#!/bin/sh
33set -e
34
35TMP_PATH=/tmp/yt-dl
36mkdir -p "$TMP_PATH" || true
37DEST=/mnt/hs2/main/media/storage/music/
38
39echo "TMP: $TMP_PATH"
40echo "DEST: $DEST"
41
42if [ ! -e "$TMP_PATH" ]; then
43 >&2 echo "Failed to create temp directory"
44 exit 1
45fi
46
47trap 'rm -rf "$TMP_PATH"; exit 1' HUP INT PIPE QUIT TERM
48
49echo waiting for links...
50
51# Read URLs from stdin, one per line. No shell interpretation of & etc.
52while 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
63done
64echo syncing files...
65rsync -r --remove-source-files --ignore-existing --progress -v "${TMP_PATH}/" "$DEST"
66echo goodbye