Update aliases; add script to compress videos
This commit is contained in:
parent
d77395e6f3
commit
0f25624066
138
aliases
138
aliases
|
@ -78,19 +78,49 @@ function dl_youtube_vid {
|
|||
return
|
||||
fi
|
||||
|
||||
local name_format=$(youtube-dl.exe --get-filename -o "%(upload_date)s-%(title)s-youtube-%(id)s.%(ext)s" $url)
|
||||
name_format="${name_format:0:4}-${name_format:4:2}-${name_format:6}"
|
||||
local filename=$(youtube-dl.exe --get-filename -o "%(upload_date)s-%(title)s-youtube-%(id)s.%(ext)s" $url)
|
||||
filename="${filename:0:4}-${filename:4:2}-${filename:6}"
|
||||
|
||||
if [[ $format == "" ]]; then
|
||||
echo "Downloading default format"
|
||||
youtube-dl.exe -o "$name_format" $opts $url
|
||||
youtube-dl.exe -o "$filename" $opts $url
|
||||
else
|
||||
youtube-dl.exe -f $format -o "$name_format" $opts $url
|
||||
youtube-dl.exe -f $format -o "$filename" $opts $url
|
||||
fi
|
||||
|
||||
cd ..
|
||||
}
|
||||
|
||||
# Download YouTube video and flip horizontally.
|
||||
function dl_youtube_vid_and_hflip {
|
||||
local format="$1"
|
||||
local url="$2"
|
||||
shift 2
|
||||
local opts="$@"
|
||||
opts+=" --all-subs --embed-subs"
|
||||
|
||||
make_vid_dir_and_cd_into $url
|
||||
if [[ $? -ne 0 ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
local filename=$(youtube-dl.exe --get-filename -o "%(upload_date)s-%(title)s-youtube-%(id)s.%(ext)s" $url)
|
||||
filename="${filename:0:4}-${filename:4:2}-${filename:6}"
|
||||
|
||||
if [[ $format == "" ]]; then
|
||||
echo "Downloading default format"
|
||||
youtube-dl.exe -o "$filename" $opts $url
|
||||
else
|
||||
youtube-dl.exe -f $format -o "$filename" $opts $url
|
||||
fi
|
||||
|
||||
# Flip
|
||||
ffmpeg -i "$filename" -vf hflip -c:a copy "copy_${filename}"
|
||||
mv "copy_${filename}" "$filename"
|
||||
|
||||
cd ..
|
||||
}
|
||||
|
||||
function dl_youtube_playlist {
|
||||
local format="$1"
|
||||
local url="$2"
|
||||
|
@ -103,7 +133,7 @@ function dl_youtube_playlist {
|
|||
local opts="$@"
|
||||
opts+=" --all-subs --embed-subs"
|
||||
|
||||
make_vid_dir_and_cd_into $url $dir_name
|
||||
make_vid_dir_and_cd_into $url "$dir_name"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
return
|
||||
fi
|
||||
|
@ -117,6 +147,8 @@ function dl_youtube_playlist {
|
|||
else
|
||||
youtube-dl.exe -f $format -o "$name_format" $opts $url
|
||||
fi
|
||||
|
||||
cd ..
|
||||
}
|
||||
|
||||
# Download Twitch videos
|
||||
|
@ -132,9 +164,9 @@ function dl_twitch_vid {
|
|||
fi
|
||||
|
||||
local name_format="%(upload_date)s-%(title)s-twitch-%(id)s"
|
||||
local video_file=$(youtube-dl.exe --get-filename -o "$name_format.%(ext)s" $url)
|
||||
video_file="${video_file:0:4}-${video_file:4:2}-${video_file:6}"
|
||||
youtube-dl.exe -f "$format" -o "$video_file" $opts $url
|
||||
local filename=$(youtube-dl.exe --get-filename -o "$name_format.%(ext)s" $url)
|
||||
filename="${filename:0:4}-${filename:4:2}-${filename:6}"
|
||||
youtube-dl.exe -f "$format" -o "$filename" $opts $url
|
||||
|
||||
error=$?
|
||||
if [[ $error -eq 0 ]]; then
|
||||
|
@ -143,10 +175,48 @@ function dl_twitch_vid {
|
|||
rechat.exe -d $url "$chat_file.json"
|
||||
rechat.exe -p "$chat_file.json" "$chat_file.txt" -b -o
|
||||
mv "$chat_file.txt" "${chat_file:0:4}-${chat_file:4:2}-${chat_file:6}.txt"
|
||||
tt "$chat_file.json"
|
||||
rm "$chat_file.json"
|
||||
else
|
||||
echo "Error: Failed to download '$url'"
|
||||
fi
|
||||
|
||||
cd ..
|
||||
}
|
||||
|
||||
# Download Twitch videos
|
||||
function dl_twitch_vid_compressed {
|
||||
local format="$1"
|
||||
local url="$2"
|
||||
shift 2
|
||||
local opts="$@"
|
||||
|
||||
make_vid_dir_and_cd_into $url
|
||||
if [[ $? -ne 0 ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
local name_format="%(upload_date)s-%(title)s-twitch-%(id)s"
|
||||
local filename=$(youtube-dl.exe --get-filename -o "$name_format.%(ext)s" $url)
|
||||
filename="${filename:0:4}-${filename:4:2}-${filename:6}"
|
||||
|
||||
youtube-dl.exe -f "$format" -o "$filename" $opts $url
|
||||
|
||||
error=$?
|
||||
if [[ $error -eq 0 ]]; then
|
||||
# Download Twitch chat transcript
|
||||
local chat_file=$(youtube-dl.exe --get-filename -o "$name_format" $url)
|
||||
rechat.exe -d $url "$chat_file.json"
|
||||
rechat.exe -p "$chat_file.json" "$chat_file.txt" -b -o
|
||||
mv "$chat_file.txt" "${chat_file:0:4}-${chat_file:4:2}-${chat_file:6}.txt"
|
||||
rm "$chat_file.json"
|
||||
|
||||
compress-video "$filename" 25 "temp"
|
||||
extension="${filename##*.}"
|
||||
mv temp.$extension "$filename"
|
||||
else
|
||||
echo "Error: Failed to download '$url'"
|
||||
fi
|
||||
|
||||
cd ..
|
||||
}
|
||||
|
||||
|
@ -164,10 +234,52 @@ function dl_twitch_chat {
|
|||
rechat.exe -d $url "$chat_file.json"
|
||||
rechat.exe -p "$chat_file.json" "$chat_file.txt" -b -o
|
||||
mv "$chat_file.txt" "${chat_file:0:4}-${chat_file:4:2}-${chat_file:6}.txt"
|
||||
tt "$chat_file.json"
|
||||
rm "$chat_file.json"
|
||||
|
||||
cd ..
|
||||
}
|
||||
|
||||
# Download video.
|
||||
function dl_mp4 {
|
||||
local url="$1"
|
||||
local filename="$2"
|
||||
|
||||
echo "$RANDOM"
|
||||
temp_name="temp_${RANDOM}.mp4"
|
||||
|
||||
echo "Downloading: $filename"
|
||||
curl "$url" -o $temp_name
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "Error: failed to download."
|
||||
return
|
||||
fi
|
||||
|
||||
mv $temp_name "$filename.mp4"
|
||||
}
|
||||
|
||||
# Download Instagram video and flip horizontally.
|
||||
function dl_instagram_vid_and_hflip {
|
||||
local url="$1"
|
||||
local filename="$2"
|
||||
|
||||
echo "$RANDOM"
|
||||
temp_name="temp_${RANDOM}.mp4"
|
||||
|
||||
echo "Downloading: $filename"
|
||||
curl "$url" -o $temp_name
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "Error: failed to download."
|
||||
return
|
||||
fi
|
||||
|
||||
# Flip
|
||||
ffmpeg -i $temp_name -vf hflip -c:a copy "copy_$temp_name"
|
||||
mv copy_${temp_name} "$filename.mp4"
|
||||
rm $temp_name
|
||||
}
|
||||
|
||||
function activate_virtualenv {
|
||||
if [ -f venv/bin/activate ]; then . venv/bin/activate;
|
||||
elif [ -f ../venv/bin/activate ]; then . ../venv/bin/activate;
|
||||
|
@ -386,12 +498,17 @@ alias yt-download-playlist-720='dl_youtube_playlist "136+140"'
|
|||
alias yt-download-playlist-tiny='dl_youtube_playlist "160+140"'
|
||||
alias yt-download-audio='youtube-dl.exe -f "140"'
|
||||
|
||||
alias yt-download-and-hflip='dl_youtube_vid_and_hflip "137+140"' # 1080p
|
||||
alias ig-download-and-hflip='dl_instagram_vid_and_hflip '
|
||||
alias download-mp4='dl_mp4'
|
||||
|
||||
alias tw-download-chat='dl_twitch_chat'
|
||||
alias tw-dl='youtube-dl.exe -f "1080" -o "%(upload_date)s-%(title)s-twitch-%(id)s.%(ext)s"'
|
||||
alias tw-dl2='youtube-dl.exe -o "%(upload_date)s-%(title)s-twitch-%(id)s.%(ext)s"'
|
||||
alias tw-download-custom='dl_twitch_vid '
|
||||
alias tw-download='dl_twitch_vid "1080p"'
|
||||
alias tw-download-60='dl_twitch_vid "1080p60"'
|
||||
alias tw-download-60-compressed='dl_twitch_vid_compressed "1080p60"'
|
||||
alias tw-download-720='dl_twitch_vid "720p-1"'
|
||||
alias tw-download-720-60='dl_twitch_vid "720p60"'
|
||||
alias tw-download-4k='dl_twitch_vid "2160p"'
|
||||
|
@ -426,6 +543,7 @@ alias ga='git add -A'
|
|||
alias gaa='git add -A; gdcc'
|
||||
alias gap='git add -Ap'
|
||||
alias gau='git add --update'
|
||||
alias gaup='git add --update -p'
|
||||
alias gb='git branch -v'
|
||||
alias gbd='git branch -D'
|
||||
alias gbdr='git branch -Dr'
|
||||
|
|
64
bin/compress-video
Normal file
64
bin/compress-video
Normal file
|
@ -0,0 +1,64 @@
|
|||
#!/bin/bash
|
||||
|
||||
if which tput >/dev/null 2>&1; then
|
||||
ncolors=$(tput colors)
|
||||
fi
|
||||
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
|
||||
RED="$(tput setaf 1)"
|
||||
GREEN="$(tput setaf 2)"
|
||||
YELLOW="$(tput setaf 3)"
|
||||
BLUE="$(tput setaf 4)"
|
||||
BOLD="$(tput bold)"
|
||||
NORMAL="$(tput sgr0)"
|
||||
else
|
||||
RED=""
|
||||
GREEN=""
|
||||
YELLOW=""
|
||||
BLUE=""
|
||||
BOLD=""
|
||||
NORMAL=""
|
||||
fi
|
||||
|
||||
if [[ $1 == "" ]]; then
|
||||
printf "\n${BOLD}Usage: $0 <filename> <optional crf value> <optional output name>\n - If you want to encode a range of CRF values then use -1 as the crf value.${NORMAL}\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
filename=$(basename -- "$1")
|
||||
extension="${filename##*.}"
|
||||
filename="${filename%.*}"
|
||||
|
||||
use_crf=$2
|
||||
default_crf=25 # Programming vids have pretty crisp text @ crf 25.
|
||||
|
||||
output_name="$3"
|
||||
|
||||
function encode() {
|
||||
crf=$1
|
||||
if [[ $output_name == "" ]]; then
|
||||
output="${filename}_REDUCED_CRF-${crf}.$extension"
|
||||
else
|
||||
output="${output_name}.$extension"
|
||||
fi
|
||||
|
||||
printf "\n${YELLOW}${BOLD}Encoding with crf $crf | output: $output${NORMAL}\n"
|
||||
ffmpeg -i "$filename.$extension" -c:v libx264 -crf $crf -preset veryfast -profile:v baseline -level 3.0 -strict -2 "$output"
|
||||
printf "\n${GREEN}${BOLD}Done encoding with crf $crf${NORMAL}\n\n"
|
||||
}
|
||||
|
||||
|
||||
if [[ $use_crf == "" ]]; then
|
||||
use_crf=$default_crf
|
||||
fi
|
||||
|
||||
if [[ $use_crf == -1 ]]; then
|
||||
printf "\n${YELLOW}${BOLD}Encoding using a range of crf values.${NORMAL}\n"
|
||||
|
||||
# Bigger crf values == bigger compression.
|
||||
for crf in {25..28}
|
||||
do
|
||||
encode $crf
|
||||
done
|
||||
else
|
||||
encode $use_crf
|
||||
fi
|
20
gitconfig
20
gitconfig
|
@ -45,34 +45,34 @@
|
|||
#
|
||||
|
||||
# Style 1
|
||||
#lg = log --graph --pretty=format:'%C(yellow bold)%h %Creset%C(white dim)[%Creset%an%Creset%C(white dim)]%Creset%C(yellow bold)%d %Creset%C(white bold)%s %C(white dim)<%ad|%cr>%Creset' --date=relative
|
||||
#lg = log --graph --date=relative --pretty=format:'%C(yellow bold)%h %Creset%C(white dim)[%Creset%an%Creset%C(white dim)]%Creset%C(yellow bold)%d %Creset%C(white bold)%s %C(white dim)<%ad|%cr>%Creset'
|
||||
|
||||
# Style 2
|
||||
#lg = log --graph --pretty=format:'%C(yellow bold)%h [%Creset%an%Creset%C(yellow bold)]%d %Creset%C(white bold)%s %C(white dim)<%ad|%cr>%Creset' --date=relative
|
||||
#lg = log --graph --date=relative --pretty=format:'%C(yellow bold)%h [%Creset%an%Creset%C(yellow bold)]%d %Creset%C(white bold)%s %C(white dim)<%ad|%cr>%Creset'
|
||||
|
||||
# Style 3
|
||||
#lg = log --graph --pretty=format:'%C(yellow bold)%h %Creset<%an> %C(yellow bold)%d %Creset%C(white bold)%s %C(white dim)<%ad|%cr>%Creset' --date=relative
|
||||
#lg = log --graph --date=relative --pretty=format:'%C(yellow bold)%h %Creset<%an> %C(yellow bold)%d %Creset%C(white bold)%s %C(white dim)<%ad|%cr>%Creset'
|
||||
|
||||
# Style 4
|
||||
#lg = log --graph --pretty=format:'%C(yellow bold)%h %Creset[%an] %C(yellow bold)|%d %Creset%C(white bold)%s %C(white dim)<%ad|%cr>%Creset' --date=relative
|
||||
#lg = log --graph --date=relative --pretty=format:'%C(yellow bold)%h %Creset[%an] %C(yellow bold)|%d %Creset%C(white bold)%s %C(white dim)<%ad|%cr>%Creset'
|
||||
|
||||
# Style 5
|
||||
#lg = log --graph --pretty=format:'%C(yellow bold)%h|%Creset%an%Creset%C(yellow bold)|%d %Creset%C(white bold)%s %C(white dim)<%ad|%cr>%Creset' --date=relative
|
||||
#lg = log --graph --date=relative --pretty=format:'%C(yellow bold)%h|%Creset%an%Creset%C(yellow bold)|%d %Creset%C(white bold)%s %C(white dim)<%ad|%cr>%Creset'
|
||||
|
||||
# Style 6
|
||||
#lg = log --graph --pretty=format:'%C(yellow bold)%h|%Creset%C(yellow dim)%an%Creset%C(yellow bold)|%d %Creset%C(white bold)%s %C(white dim)<%ad|%cr>%Creset' --date=relative
|
||||
#lg = log --graph --date=relative --pretty=format:'%C(yellow bold)%h|%Creset%C(yellow dim)%an%Creset%C(yellow bold)|%d %Creset%C(white bold)%s %C(white dim)<%ad|%cr>%Creset'
|
||||
|
||||
# Style 7
|
||||
lg = log --graph --pretty=format:'%C(yellow bold)%h %Creset%C(yellow dim)%an %Creset%C(yellow bold)| %Creset%C(white bold)%s %C(white dim)[%ad|%cr] %Creset%C(yellow bold)%d %C(cyan bold)%<(8,trunc)%GK%Creset' --date=relative
|
||||
lg = log --graph --date=relative --pretty=format:'%C(yellow bold)%h %Creset%C(yellow dim)%an %Creset%C(yellow bold)| %Creset%C(white bold)%s %C(white dim)[%ad|%cr] %Creset%C(yellow bold)%d %C(cyan bold)%<(8,trunc)%GK%Creset'
|
||||
|
||||
# Style 8
|
||||
#lg = log --graph --pretty=format:'%C(yellow bold)%h%Creset%C(white dim)|%Creset%an%Creset%C(white dim) >%Creset%C(yellow bold)%d %Creset%C(white bold)%s %C(white dim)<%ad|%cr>%Creset' --date=relative
|
||||
#lg = log --graph --date=relative --pretty=format:'%C(yellow bold)%h%Creset%C(white dim)|%Creset%an%Creset%C(white dim) >%Creset%C(yellow bold)%d %Creset%C(white bold)%s %C(white dim)<%ad|%cr>%Creset'
|
||||
|
||||
# Style 9
|
||||
#lg = log --graph --pretty=format:'%C(yellow bold)%h%C(black bold)|%C(white dim)%an%Creset%C(yellow bold) >%d %Creset%C(white bold)%s %C(black bold)<%ad|%cr>%Creset' --date=relative
|
||||
#lg = log --graph --date=relative --pretty=format:'%C(yellow bold)%h%C(black bold)|%C(white dim)%an%Creset%C(yellow bold) >%d %Creset%C(white bold)%s %C(black bold)<%ad|%cr>%Creset'
|
||||
|
||||
# Style 10
|
||||
#lg = log --graph --pretty=format:'%C(yellow bold)%h %Creset%C(yellow dim)%an%Creset%C(yellow bold) >%d %Creset%C(white bold)%s %C(white dim)<%ad|%cr>%Creset' --date=relative
|
||||
#lg = log --graph --date=relative --pretty=format:'%C(yellow bold)%h %Creset%C(yellow dim)%an%Creset%C(yellow bold) >%d %Creset%C(white bold)%s %C(white dim)<%ad|%cr>%Creset'
|
||||
|
||||
start = !git init && git commit --allow-empty -m \"Initial commit\"
|
||||
[rerere]
|
||||
|
|
Loading…
Reference in New Issue
Block a user