Simplify how dates are formatted in yt-dlp video downloads

This commit is contained in:
Michael Campagnaro 2021-12-09 16:34:32 -05:00
parent 476a163236
commit 1cac8706c0

72
aliases
View File

@ -332,16 +332,16 @@ make_vid_dir_and_cd_into() {
if [[ $dir_name == "" ]]; then if [[ $dir_name == "" ]]; then
# @note If the filename contains symbols that are incompatible with # @note If the filename contains symbols that are incompatible with
# Windows' directory names then add --restrict-filenames to the command. # Windows' directory names then add --restrict-filenames to the command.
dir_name=$(yt-dlp.exe --get-filename -o "%(upload_date)s - %(title)s" $opts $url)
dir_name=$(yt-dlp.exe --get-filename -o "%(upload_date>%Y-%m-%d)s - %(title)s" $opts $url)
if [[ $dir_name == "" ]]; then if [[ $dir_name == "" ]]; then
return 1 return 1
fi fi
dir_name="${dir_name:0:4}-${dir_name:4:2}-${dir_name:6}"
fi fi
printf "${BOLD}Creating directory ${YELLOW}'$dir_name'${NORMAL}\n" printf "${BOLD}Creating directory ${YELLOW}'$dir_name'${NORMAL}\n"
mkdir "$dir_name" mkdir "$dir_name" 2>/dev/null
cd "$dir_name" cd "$dir_name"
error=$? error=$?
@ -381,15 +381,16 @@ dl_youtube_vid() {
fi fi
if [[ $shortname -eq 0 ]]; then if [[ $shortname -eq 0 ]]; then
local name_format="%(upload_date)s-%(title)s-youtube-%(id)s" local name_format="%(upload_date>%Y-%m-%d)s-%(title)s-youtube-%(id)s.%(ext)s"
else else
local name_format="%(upload_date)s-shortname-youtube-%(id)s" local name_format="%(upload_date>%Y-%m-%d)s-shortname-youtube-%(id)s.%(ext)s"
fi fi
local filename=$(yt-dlp.exe --get-filename -o "$name_format.%(ext)s" $url) local cmd="yt-dlp.exe -f $format -o \"$name_format\" $opts $url"
filename="${filename:0:4}-${filename:4:2}-${filename:6}" eval $cmd # Need to eval in order to preserve the quotes wrapping the filename format string.
yt-dlp.exe -f $format -o "$filename" $opts $url # Removing any trailing subtitle files
rm *.vtt *.srt 2>/dev/null
if [[ $make_folder == "1" ]]; then if [[ $make_folder == "1" ]]; then
cd .. cd ..
@ -408,6 +409,10 @@ dl_youtube_vid_and_hflip() {
error "Format: $0 <make folder?> <url> <optional args>\n" error "Format: $0 <make folder?> <url> <optional args>\n"
return return
fi fi
if [[ $format == "" ]]; then
printf "${BOLD}No format given; using best available.${NORMAL}\n"
format="best"
fi
opts+=" --write-sub --sub-lang en --embed-subs" opts+=" --write-sub --sub-lang en --embed-subs"
@ -418,14 +423,13 @@ dl_youtube_vid_and_hflip() {
fi fi
fi fi
local filename=$(yt-dlp.exe --get-filename -o "%(upload_date)s-%(title)s-youtube-%(id)s.%(ext)s" $url) local filename=$(yt-dlp.exe --get-filename -f $format -o "%(upload_date>%Y-%m-%d)s-%(title)s-youtube-%(id)s.%(ext)s" $url)
filename="${filename:0:4}-${filename:4:2}-${filename:6}"
if [[ $format == "" ]]; then local cmd="yt-dlp.exe -f $format -o \"$filename\" $opts $url"
yt-dlp.exe -o "$filename" $opts $url eval $cmd # Need to eval in order to preserve the quotes wrapping the filename format string.
else
yt-dlp.exe -f $format -o "$filename" $opts $url # Removing any trailing subtitle files
fi rm *.vtt *.srt 2>/dev/null
# Flip # Flip
ffmpeg -i "$filename" -vf hflip -c:a copy "copy_${filename}" ffmpeg -i "$filename" -vf hflip -c:a copy "copy_${filename}"
@ -447,6 +451,10 @@ dl_youtube_playlist() {
error "Format: $0 <url> <directory name (optional)> <optional args>\n" error "Format: $0 <url> <directory name (optional)> <optional args>\n"
return return
fi fi
if [[ $format == "" ]]; then
printf "${BOLD}No format given; using best available.${NORMAL}\n"
format="best"
fi
opts+=" --write-sub --sub-lang en --embed-subs" opts+=" --write-sub --sub-lang en --embed-subs"
@ -457,14 +465,11 @@ dl_youtube_playlist() {
fi fi
fi fi
printf "${BOLD}Downloading playlist${NORMAL}\n" local cmd="yt-dlp.exe -f $format -o \"v%(playlist_index)03d--%(upload_date>%Y-%m-%d)s-%(title)s-youtube-%(id)s.%(ext)s\" $opts $url"
local name_format="v%(playlist_index)s--%(upload_date)s-%(title)s-youtube-%(id)s.%(ext)s" eval $cmd # Need to eval in order to preserve the quotes wrapping the filename format string.
if [[ $format == "" ]]; then # Removing any trailing subtitle files
yt-dlp.exe -o "$name_format" $opts $url rm *.vtt *.srt 2>/dev/null
else
yt-dlp.exe -f $format -o "$name_format" $opts $url
fi
cd .. cd ..
} }
@ -477,7 +482,6 @@ actually_dl_twitch_chat() {
rechat.exe -d $url "$filename.json" rechat.exe -d $url "$filename.json"
if [[ -f "$filename.json" ]]; then if [[ -f "$filename.json" ]]; then
rechat.exe -p "$filename.json" "$filename.txt" -b -o rechat.exe -p "$filename.json" "$filename.txt" -b -o
mv "$filename.txt" "${filename:0:4}-${filename:4:2}-${filename:6}.txt"
rm "$filename.json" rm "$filename.json"
else else
error "Video doesn't have a chat transcript." error "Video doesn't have a chat transcript."
@ -499,7 +503,7 @@ dl_twitch_chat() {
return return
fi fi
actually_dl_twitch_chat $url "$(yt-dlp.exe --get-filename -o "%(upload_date)s-%(title)s-twitch-%(id)s" $opts $url)" actually_dl_twitch_chat $url "$(yt-dlp.exe --get-filename -o "%(upload_date>%Y-%m-%d)s-%(title)s-twitch-%(id)s" $opts $url)"
cd .. cd ..
} }
@ -546,19 +550,19 @@ dl_twitch_vid() {
fi fi
if [[ $shortname -eq 0 ]]; then if [[ $shortname -eq 0 ]]; then
local name_format="%(upload_date)s-%(title)s-twitch-%(id)s" local name_format="%(upload_date>%Y-%m-%d)s-%(title)s-twitch-%(id)s"
else else
local name_format="%(upload_date)s-shortname-twitch-%(id)s" local name_format="%(upload_date>%Y-%m-%d)s-shortname-twitch-%(id)s"
fi fi
# Download Twitch chat transcript # Download Twitch chat transcript
actually_dl_twitch_chat $url "$(yt-dlp.exe --get-filename -o "$name_format" $opts $url)" actually_dl_twitch_chat $url "$(yt-dlp.exe --get-filename -o "$name_format" $opts $url)"
# Download the video. # Download the video.
local filename=$(yt-dlp.exe --get-filename -o "$name_format.%(ext)s" $opts $url) local filename=$(yt-dlp.exe --get-filename -f $format -o "$name_format.%(ext)s" $opts $url)
filename="${filename:0:4}-${filename:4:2}-${filename:6}"
yt-dlp.exe -f "$format" -o "$filename" $opts $url local cmd="yt-dlp.exe -f $format -o \"$filename\" $opts $url"
eval $cmd # Need to eval in order to preserve the quotes wrapping the filename format string.
error=$? error=$?
if [[ $error -eq 0 ]]; then if [[ $error -eq 0 ]]; then
@ -609,16 +613,16 @@ dl_vimeo_vid() {
fi fi
if [[ $shortname -eq 0 ]]; then if [[ $shortname -eq 0 ]]; then
local name_format="%(upload_date)s-%(title)s-vimeo-%(id)s" local name_format="%(upload_date>%Y-%m-%d)s-%(title)s-vimeo-%(id)s"
else else
local name_format="%(upload_date)s-shortname-vimeo-%(id)s" local name_format="%(upload_date>%Y-%m-%d)s-shortname-vimeo-%(id)s"
fi fi
# Download the video. # Download the video.
local filename=$(yt-dlp.exe --get-filename -o "$name_format.%(ext)s" $opts $url) local filename=$(yt-dlp.exe --get-filename -f $format -o "$name_format.%(ext)s" $opts $url)
filename="${filename:0:4}-${filename:4:2}-${filename:6}"
yt-dlp.exe -f "$format" -o "$filename" $opts $url local cmd="yt-dlp.exe -f $format -o \"$filename\" $opts $url"
eval $cmd # Need to eval in order to preserve the quotes wrapping the filename format string.
error=$? error=$?
if [[ $error -eq 0 ]]; then if [[ $error -eq 0 ]]; then