Skip to content

Instantly share code, notes, and snippets.

@goncalomb

goncalomb/ytdl-max-dump.sh

Last active Aug 20, 2020
Embed
What would you like to do?
download all youtube channel videos with maximum information
#!/bin/bash
# Copyright (c) 2020 Gonçalo Baltazar <me@goncalomb.com>
# MIT License
# download all youtube channel videos with maximum information
# pip3 install --upgrade youtube-dl
# ffmpeg -y -loglevel repeat+info -i file:video.xyz -i file:audio.xyz -c copy -map 0:v:0 -map 1:a:0 file:out.mkv
set -e
cd -- "$(dirname -- "$0")"
[ -f ".ytdl-max-dump-lock" ] && echo "already running or last execution did not end correctly" && exit 1
# example from `man flock`
[ "${FLOCKER}" != "$0" ] && exec env FLOCKER="$0" flock -en "$0" "$0" "$@" || :
mkdir -p data data/channel
now() {
date +%s.%N
}
ytdl() {
youtube-dl \
--no-continue \
--write-description \
--write-info-json \
--write-annotations \
--write-thumbnail \
--write-all-thumbnails \
--all-subs \
--write-sub \
--write-pages \
--playlist-reverse \
-o '%(id)s.%(ext)s' \
--download-archive archive.txt \
-f bestvideo+bestaudio/best \
--ffmpeg-location=/dev/null \
--keep-video \
-i \
-v \
"$@"
}
CH="$1"
cd data/channel
mkdir -p "$CH" "$CH/data" "$CH/runs"
cd "$CH"
CH_DIR=$(pwd)
START=$(now)
RUN_DIR="$CH_DIR/runs/$START"
mkdir -p "$RUN_DIR" "$RUN_DIR/dump"
end() {
now > "$RUN_DIR/end"
cd "$CH_DIR/data"
find . -maxdepth 1 -name '*.dump' -print0 | xargs -r0 mv -t "$RUN_DIR/dump"
rm ../../../../.ytdl-max-dump-lock
}
trap end EXIT
touch ../../../.ytdl-max-dump-lock
cd data
ytdl "https://www.youtube.com/channel/$CH" 2>&1 | tee "$RUN_DIR/log.txt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.