Simplify how dates are formatted in yt-dlp video downloads
This commit is contained in:
parent
476a163236
commit
1cac8706c0
72
aliases
72
aliases
|
@ -332,16 +332,16 @@ make_vid_dir_and_cd_into() {
|
|||
if [[ $dir_name == "" ]]; then
|
||||
# @note If the filename contains symbols that are incompatible with
|
||||
# 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
|
||||
return 1
|
||||
fi
|
||||
dir_name="${dir_name:0:4}-${dir_name:4:2}-${dir_name:6}"
|
||||
fi
|
||||
|
||||
printf "${BOLD}Creating directory ${YELLOW}'$dir_name'${NORMAL}\n"
|
||||
mkdir "$dir_name"
|
||||
mkdir "$dir_name" 2>/dev/null
|
||||
cd "$dir_name"
|
||||
|
||||
error=$?
|
||||
|
@ -381,15 +381,16 @@ dl_youtube_vid() {
|
|||
fi
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
local filename=$(yt-dlp.exe --get-filename -o "$name_format.%(ext)s" $url)
|
||||
filename="${filename:0:4}-${filename:4:2}-${filename:6}"
|
||||
local cmd="yt-dlp.exe -f $format -o \"$name_format\" $opts $url"
|
||||
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
|
||||
cd ..
|
||||
|
@ -408,6 +409,10 @@ dl_youtube_vid_and_hflip() {
|
|||
error "Format: $0 <make folder?> <url> <optional args>\n"
|
||||
return
|
||||
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"
|
||||
|
||||
|
@ -418,14 +423,13 @@ dl_youtube_vid_and_hflip() {
|
|||
fi
|
||||
fi
|
||||
|
||||
local filename=$(yt-dlp.exe --get-filename -o "%(upload_date)s-%(title)s-youtube-%(id)s.%(ext)s" $url)
|
||||
filename="${filename:0:4}-${filename:4:2}-${filename:6}"
|
||||
local filename=$(yt-dlp.exe --get-filename -f $format -o "%(upload_date>%Y-%m-%d)s-%(title)s-youtube-%(id)s.%(ext)s" $url)
|
||||
|
||||
if [[ $format == "" ]]; then
|
||||
yt-dlp.exe -o "$filename" $opts $url
|
||||
else
|
||||
yt-dlp.exe -f $format -o "$filename" $opts $url
|
||||
fi
|
||||
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.
|
||||
|
||||
# Removing any trailing subtitle files
|
||||
rm *.vtt *.srt 2>/dev/null
|
||||
|
||||
# Flip
|
||||
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"
|
||||
return
|
||||
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"
|
||||
|
||||
|
@ -457,14 +465,11 @@ dl_youtube_playlist() {
|
|||
fi
|
||||
fi
|
||||
|
||||
printf "${BOLD}Downloading playlist${NORMAL}\n"
|
||||
local name_format="v%(playlist_index)s--%(upload_date)s-%(title)s-youtube-%(id)s.%(ext)s"
|
||||
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"
|
||||
eval $cmd # Need to eval in order to preserve the quotes wrapping the filename format string.
|
||||
|
||||
if [[ $format == "" ]]; then
|
||||
yt-dlp.exe -o "$name_format" $opts $url
|
||||
else
|
||||
yt-dlp.exe -f $format -o "$name_format" $opts $url
|
||||
fi
|
||||
# Removing any trailing subtitle files
|
||||
rm *.vtt *.srt 2>/dev/null
|
||||
|
||||
cd ..
|
||||
}
|
||||
|
@ -477,7 +482,6 @@ actually_dl_twitch_chat() {
|
|||
rechat.exe -d $url "$filename.json"
|
||||
if [[ -f "$filename.json" ]]; then
|
||||
rechat.exe -p "$filename.json" "$filename.txt" -b -o
|
||||
mv "$filename.txt" "${filename:0:4}-${filename:4:2}-${filename:6}.txt"
|
||||
rm "$filename.json"
|
||||
else
|
||||
error "Video doesn't have a chat transcript."
|
||||
|
@ -499,7 +503,7 @@ dl_twitch_chat() {
|
|||
return
|
||||
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 ..
|
||||
}
|
||||
|
@ -546,19 +550,19 @@ dl_twitch_vid() {
|
|||
fi
|
||||
|
||||
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
|
||||
local name_format="%(upload_date)s-shortname-twitch-%(id)s"
|
||||
local name_format="%(upload_date>%Y-%m-%d)s-shortname-twitch-%(id)s"
|
||||
fi
|
||||
|
||||
# Download Twitch chat transcript
|
||||
actually_dl_twitch_chat $url "$(yt-dlp.exe --get-filename -o "$name_format" $opts $url)"
|
||||
|
||||
# Download the video.
|
||||
local filename=$(yt-dlp.exe --get-filename -o "$name_format.%(ext)s" $opts $url)
|
||||
filename="${filename:0:4}-${filename:4:2}-${filename:6}"
|
||||
local filename=$(yt-dlp.exe --get-filename -f $format -o "$name_format.%(ext)s" $opts $url)
|
||||
|
||||
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=$?
|
||||
if [[ $error -eq 0 ]]; then
|
||||
|
@ -609,16 +613,16 @@ dl_vimeo_vid() {
|
|||
fi
|
||||
|
||||
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
|
||||
local name_format="%(upload_date)s-shortname-vimeo-%(id)s"
|
||||
local name_format="%(upload_date>%Y-%m-%d)s-shortname-vimeo-%(id)s"
|
||||
fi
|
||||
|
||||
# Download the video.
|
||||
local filename=$(yt-dlp.exe --get-filename -o "$name_format.%(ext)s" $opts $url)
|
||||
filename="${filename:0:4}-${filename:4:2}-${filename:6}"
|
||||
local filename=$(yt-dlp.exe --get-filename -f $format -o "$name_format.%(ext)s" $opts $url)
|
||||
|
||||
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=$?
|
||||
if [[ $error -eq 0 ]]; then
|
||||
|
|
Loading…
Reference in New Issue
Block a user