Skip to content

Instantly share code, notes, and snippets.

@nasseef20
Forked from LordH3lmchen/termux-url-opener
Last active January 4, 2023 14:47
Show Gist options
  • Save nasseef20/9335d7126036ce3da497cc0a1a322afa to your computer and use it in GitHub Desktop.
Save nasseef20/9335d7126036ce3da497cc0a1a322afa to your computer and use it in GitHub Desktop.
termux-url-opener
#!/data/data/com.termux/files/usr/bin/zsh
#
# This is a termux-url-opener script to do diffrent tasks on my Android phone
#
#
#
# How to use this script
#############################
# Create the bin directory
# ➜ ~ mkdir bin
# ➜ ~ cd bin
# Create the script (copy & paste) I use neovim. Use your prefered editor
# ➜ nvim termux-url-opener
#
# Make it executable
# ➜ chmod +x termux-url-opener
#
# Install zsh wget and ffmpeg
# ➜ pkg install zsh wget ffmpeg python
# https://wiki.termux.com/wiki/Shells
#
# Install youtube_dl and scdl with pip
# ➜ pip install youtube_dl
# ➜ pip install scdl mutagen
#
# run the following command to enable the termux storage features
# ➜ termux-setup-storage
# https://wiki.termux.com/wiki/Termux-setup-storage
url=$1
function yt_shorts(){
if [[ "$url" == *"shorts"* ]]; then
    url=${url%?feature=share}
        url=${url#https://youtube.com/shorts/}
        url="https://youtube.com/watch?v="$url
    fi
}
echo "What should I do with $url ?"
echo "y) download youtube video to movies-folder"
echo "u) download youtube video and convert it to mp3 (music-folder)"
echo "s) download with scdl (soundcloud)"
echo "w) wget file to download-folder"
echo "x) nothing"
read CHOICE
case $CHOICE in
y)
yt_shorts
youtube-dl -o "/storage/emulated/0/Movies/%(title)s.%(ext)s" $url
;;
u)
echo "Artist"
read artist
echo "Title"
read title
echo "Album"
read album
yt_shorts
youtube-dl --extract-audio --audio-format mp3 --output "/storage/emulated/0/Music/$artist-$title.%(ext)s" $url
mid3v2 -a $artist -t $title -A $album /storage/emulated/0/Music/$artist-$title.mp3
;;
s)
scdl -l $url --path /storage/emulated/0/Music
echo "s need some work"
;;
w)
cd ~/storage/downloads
wget $url
;;
x)
echo "bye"
;;
esac
@nasseef20
Copy link
Author

Added support for "YouTube shorts", youtube-dl cannot download shorts links ###directly.

@Dan1jel
Copy link

Dan1jel commented Oct 1, 2022

Huge thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment