ytdl-bulk.sh
· 1.6 KiB · Bash
Raw
#!/bin/sh
set -e
TMP_PATH=/tmp/yt-dl #$(mktemp -d)
mkdir $TMP_PATH || true
DEST=/mnt/hs2/main/media/storage/music/
# Exit if the temp directory wasn't created successfully.
if [ ! -e "$TMP_PATH" ]; then
>&2 echo "Failed to create temp directory"
exit 1
fi
for url in "$@"
do
yt-dlp "$url" \
-x --audio-format m4a \
-o "${TMP_PATH}/%(title)s [%(id)s].%(ext)s" \
--embed-metadata \
--embed-thumbnail \
--embed-subs \
--sub-langs en-US* \
--write-auto-sub \
--sponsorblock-remove all
done
rsync -r --remove-source-files --ignore-existing --progress -v "${TMP_PATH}/" "$DEST"
trap "exit 1" HUP INT PIPE QUIT TERM
trap 'rm -rf "$TEMPD"' EXIT
root@lambda:~# cat ytdl-bulk.sh
#!/bin/sh
set -e
TMP_PATH=/tmp/yt-dl
mkdir -p "$TMP_PATH" || true
DEST=/mnt/hs2/main/media/storage/music/
echo "TMP: $TMP_PATH"
echo "DEST: $DEST"
if [ ! -e "$TMP_PATH" ]; then
>&2 echo "Failed to create temp directory"
exit 1
fi
trap 'rm -rf "$TMP_PATH"; exit 1' HUP INT PIPE QUIT TERM
echo waiting for links...
# Read URLs from stdin, one per line. No shell interpretation of & etc.
while IFS= read -r url || [ -n "$url" ]; do
[ -z "$url" ] && continue
yt-dlp "$url" \
-x --audio-format m4a \
-o "${TMP_PATH}/%(title)s [%(id)s].%(ext)s" \
--embed-metadata \
--embed-thumbnail \
--embed-subs \
--sub-langs en-US* \
--write-auto-sub \
--sponsorblock-remove all
done
echo syncing files...
rsync -r --remove-source-files --ignore-existing --progress -v "${TMP_PATH}/" "$DEST"
echo goodbye
| 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 |