Skip to content

Instantly share code, notes, and snippets.

@ungeskriptet
Created November 20, 2024 08:45
Show Gist options
  • Save ungeskriptet/4e9b1ba079746d77fed536fb3f6a2054 to your computer and use it in GitHub Desktop.
Save ungeskriptet/4e9b1ba079746d77fed536fb3f6a2054 to your computer and use it in GitHub Desktop.
My personal termux-url-opener script
#!/data/data/com.termux/files/usr/bin/bash
function init() {
yes | pkg update
pkg upgrade -y
pkg install -y ffmpeg jq python-pip termux-api which vim
pip install yt-dlp
while [ ! -d "/data/data/com.termux/files/home/storage/pictures" ]; do
echo "Waiting for permissions to be granted"
termux-setup-storage
read -rsn1 -p"Press any key to continue"; echo
done
mkdir -p "/data/data/com.termux/files/home/storage/pictures/Memes"
}
function download() {
NAME="$(yt-dlp -e $1)"
ls "/data/data/com.termux/files/home/storage/pictures/Memes" | grep "$NAME" && rm -f "/data/data/com.termux/files/home/storage/pictures/Memes/"*"$NAME"*
DIR="/data/data/com.termux/files/home/storage/pictures/Memes"
DIR_PREV=$(ls -1 "$DIR")
yt-dlp "$1" -P "$DIR"
DIR_AFTER=$(ls -1 $DIR)
DL_FILE="$DIR/$(comm -13 <(echo "$DIR_PREV") <(echo "$DIR_AFTER"))"
}
function bars() {
FILE_ENDING=${DL_FILE##*.}
OUTPUT=${DL_FILE%.*}_zoomed.${FILE_ENDING}
CROP=$(ffmpeg -i "$DL_FILE" -t 1 -vf "cropdetect" -f null - 2>&1|awk '/crop/{print $NF}'|tail -n1)
echo "$CROP"
echo "Command: ffmpeg -i $DL_FILE -vf $CROP $OUTPUT"
ffmpeg -i "$DL_FILE" -vf "$CROP" "$OUTPUT"
rm -f "$DL_FILE"
mv "$OUTPUT" "$DL_FILE"
ls "$DL_FILE"
}
[ -f /data/data/com.termux/files/usr/bin/yt-dlp ] || init
echo "Downloading: $1"
download $1
while :; do
CHOICE=$(termux-dialog radio -t "Termux URL Opener" -v "Remove black bars,Share,Exit" | jq -r ".index")
case $CHOICE in
0)
[[ -n "$DL_FILE" ]] && bars || termux-dialog confirm -t "Termux URL Opener" -i "File needs to be downloaded first"
;;
1)
[[ -n "$DL_FILE" ]] && termux-share -a send "$DL_FILE" || termux-dialog confirm -t "Termux URL Opener" -i "File needs to be downloaded first"
exit
;;
2)
echo "Exiting"
exit
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment