: ' Changes
Fri Feb 23 2024 Added version() and changed "files" to "mkindex"
Sun Oct 29 2023 added random color output for fun
'
[ "$1" == "-D" ] && DEBUG=1 && shift 1
PS4='$SECONDS $LINENO: '
DOW=$(date +%a)
TODAY=$(date +%m/%d)
DOM=$(date +%d)
OS=$(uname -s)
NAME=${0##*/}
R=$(tput setaf 1)
BR=$(tput setaf 1; tput bold)
G=$(tput setaf 2)
BG=$(tput setaf 2; tput bold)
Y=$(tput setaf 3)
BY=$(tput setaf 3; tput bold)
B=$(tput setaf 4)
BM=$(tput setaf 5; tput bold)
BC=$(tput setaf 6; tput bold)
BL=$(tput setaf 7; tput bold)
BLD=$(tput bold)
N=$(tput sgr0)
SIT=$(tput sitm)
RIT=$(tput ritm)
UL=$(tput smul)
NL=$(tput rmul)
RV=$(tput rev)
ROWS=$(tput lines)
COLS=$(tput cols)
ren(){
[ "$DEBUG" == "1" ] && set -x
[ "$(pwd)" == "$HOME" ] && return
for FILE in "$@"
do
[ -z "$FILE" ] && return
NEW=$(echo "$FILE"|tr [A-Z] [a-z] | sed 's/[[:blank:]]/-/g;s/[^[:alnum:].-]/-/g' |tr -cs '[:alnum:]'| sed 's/\-\./.'/);
[ "$FILE" != "$NEW" ] && mv -v "$FILE" "$NEW" 2>/dev/null
done
}
bl(){
[ "$DEBUG" == "1" ] && set -x
echo ""
}
html(){
vim -f +"syn on" +"set nonu" +"set foldenable!" +"set nospell" +"run! syntax/2html.vim" +"wq" +"q" $1
}
log(){
[ "$DEBUG" == "1" ] && set -x
logger -i -t "$NAME" "$*"
}
pause(){
[ "$DEBUG" == "1" ] && set -x
[ "$1" == "-nt" ] && TMOUT="" && shift
echo "$BY";
if [ $# -gt 0 ]
then
read -t $1 -r -p "${C}Hit any key (${BY}$1${C} second timeout)${N}" -n 1 FOO;
else
read -r -p "${C}Hit any key${N}" -n 1 FOO;
fi;
bl
}
xtitle(){
printf "\033]0;%s\007" "$*"
}
version(){
grep -E '^# Updated' $0
bl
sed -n "/' Changes/,/^ *$/p" <$0 |grep -E -v 'sed -n|exit 0|}'
exit 0
}
if [ "$1" == "-E" ]
then
vim $0
sed -i -e "7s/.*/# Updated....: $(date)/" $0
log "Updated $0"
html $0
cp $0 /var/www/unix
mv $0.html /var/www/unix
cp $0 /var/gopher/scripts
exit
fi
if [ "$1" == "-h" ] || [ "$1" == "--help" ]
then
fmt -s -w $(tput cols) <<END
$NAME {option}
A youtube-dl wrapper for URLs from the Internet.
{URLs} # One or more URLs passed as an argument. Should be quoted as they tend to have reserved charicters.
-a # Add file to ~/Downloads/get.txt, does not download.
-d # Used when called from Vim, which I have assigned <F3> in my .vimrc
If no option in passed, then it will look for get.txt in the current directory and parse the URLs, one per line. If a file named unnamed.txt is found, it will rename it, and do likewise.
- Supports most video sites including Rumble (took some effort)
- Will download mp3, mp4, avi, jpg, jpeg, png, and webm files using wget
- Can be configured with vim/gvim to use as front end (see below)
Add the 3 lines below to your .vimrc to intagrate it (change the location of "get" path):
" This calls my download manager. I make a list in vim, hit F3 and it
" downloads them. It will then terminate vim/gvim.
map <F3> <ESC>:w ~/Downloads/get.txt<CR>:term ++close /home/mitch/bin/get -d<CR>
END
exit
fi
if [ "$1" == "-v" ] || [ "$1" == "--version" ]
then
version
fi
command -v wget >/dev/null || sudo apt install wget -yyq
command -v ffmpeg >/dev/null || sudo apt install wget -yyq
command -v exiftool >/dev/null || sudo apt install libimage-exiftool-perl -qyy
command -v youtube-dl >/dev/null || sudo pip install --upgrade youtube_dl
command -v lm >/dev/null || echo "Missing lm, download from http://crn.hopto.org/unix/lm"
[ "$DEBUG" == 1 ] && set -x
[ "$1" == "-d" ] && VIM=kill
[ "$1" == "-d" ] && cd /home/mitch/Downloads && shift 1
[ "$1" == "-a" ] && echo "$2" >> ~/Downloads/get.txt && exit
[ -f untitled.txt ] && mv untitled.txt get.txt
while [ "$#" -gt 0 ]
do
echo $1 >>get.txt
shift 1
done
TC="$(wc -l<get.txt)"
CC=1
for INPUT in $(cat get.txt)
do
echo "${BG}Getting:${N} $CC ${BG}of${N} $TC"
tput setaf $((RANDOM % 256))
log "$CC of $TC: $INPUT"
if [[ "$INPUT" == *"rumble"* ]]
then
youtube-dl --console-title --no-check-certificate -f mp4-480p/webm-480p/mp4-360p/mp4-720p/mp4-1080p $(curl -s "$INPUT" | tr -d '\n'|awk -F "embedUrl" '{print $2}'|awk -F '"' '{print $3}')
echo "${N}"
elif [ "$(echo "$INPUT" | grep -c -E 'mp4|mp3|avi|webm|jpg|jpeg|png')" -eq 0 ]
then
URL="$(echo "$INPUT"|cut -d'&' -f 1)"
youtube-dl --console-title -f mp4 --output "%(title)s.%(ext)s" "$URL" |tee /tmp/$$.vid
echo "${N}"
else
FILE="${INPUT##*/}"
xtitle "Get: $FILE"
wget "$INPUT" ||pause
echo "${N}"
fi
if [ -f /tmp/$$.vid ]
then
TITLE=$(grep Destination /tmp/$$.vid| cut -d: -f2)
gio trash /tmp/$$.vid
log "$CC of $TC: $TITLE"
else
log "$CC of $TC"
fi
let "CC = CC + 1"
done
gio trash get.txt
/home/mitch/bin/rn * >/dev/null
lm
exiftool -n -q -p '${Duration;our $sum;$_=ConvertDuration($sum+=$_) }' ./*.mp4 2>/dev/null| tail -n1
log "$TC Download(s) completed"
[ "$VIM" = "kill" ] && kill $PPID
exit 0