Skip to content

Instantly share code, notes, and snippets.

@LordH3lmchen
Last active May 4, 2024 03:59
Show Gist options
  • Star 55 You must be signed in to star a gist
  • Fork 24 You must be signed in to fork a gist
  • Save LordH3lmchen/dc35e8df3dc41d126683f18fe44ebe17 to your computer and use it in GitHub Desktop.
Save LordH3lmchen/dc35e8df3dc41d126683f18fe44ebe17 to your computer and use it in GitHub Desktop.
termux-url-opener
#!/data/data/com.termux/files/usr/bin/bash
#
# This is a termux-url-opener script to do diffrent tasks on my Android phone
#
#
#
# How to use this script
#############################
#
# Install git
# ➜ ~ pkg install git
#
# clone this script
# ➜ ~ git clone https://gist.github.com/dc35e8df3dc41d126683f18fe44ebe17.git $HOME/termux-url-opener
#
# Create the bin directory
# ➜ ~ mkdir bin
#
# Link the script
# ➜ ~ ln -s $HOME/termux-url-opener/termux-url-opener $HOME/bin/termux-url-opener
# ➜ ~ ln -s $HOME/termux-url-opener/termux-url-opener $HOME/bin/termux-file-editor
#
# run the following command to enable the termux storage features
# ➜ termux-setup-storage
#
# https://wiki.termux.com/wiki/Termux-setup-storage
#
# the script downloads the needed tools on first use.
for PACKAGE in wget ffmpeg python
do
which $PACKAGE > /dev/null
if [ ! $? -eq 0 ]; then
echo "Installing $PACKAGE"
pkg install $PACKAGE
fi
done
which transmission-daemon > /dev/null
if [ ! $? -eq 0 ]; then
pkg install transmission
fi
for PYPI_PKG in yt-dlp scdl
do
pip show $PYPI_PKG
if [ ! $? -eq 0 ]; then
pip install $PYPI_PKG
fi
done
if [! -w $HOME/Downloads ]; then #create Downloads Link for transmission
ln -s $HOME/storage/downloads $HOME/Downloads
fi
url=$1
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 "t) download torrent"
echo "w) wget file to download-folder"
echo "x) nothing"
read CHOICE
case $CHOICE in
y)
yt-dlp -o "/storage/emulated/0/Movies/%(title)s.%(ext)s" $url
;;
u)
echo "Artist"
read artist
echo "Title"
read title
echo "Album"
read album
yt-dlp --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
;;
t)
echo "running torrents"
transmission-remote 127.0.0.1 -l
if [ ! $? eq 0 ]; then # start daemon if necessary
transmission-daemon
sleep 3
fi
echo "use transmission-remote to manage your downloads (read the manpage)"
transmission-remote 127.0.0.1 -a $(cat $url)
;;
x)
echo "bye"
;;
esac
@Dan1jel
Copy link

Dan1jel commented Sep 17, 2022

I'm not OP but could you maybe do a gits so i could see how it should be?

@nasseef20
Copy link

@Harjeet13x
Copy link

I have a problem where s the script bro , sorry I am new In this field , Problem = when I give command nvim termux-url-opener
Here comes a interface with purple ~ sign .
I don't what to do next .pls sir tell me.

@LordH3lmchen
Copy link
Author

Neovim works like vi or vim.

Use your preferred Editor. nano is probably simpler.

Instead of youtube_dl you could use yt-dlp its a fork that works better.

If you don't want to copy pasta the script. Install git and clone the gist.

@TehDomic
Copy link

Does anyone know any forks that use pre-installed bash instead of zsh?

@LordH3lmchen
Copy link
Author

LordH3lmchen commented Mar 20, 2023

Does anyone know any forks that use pre-installed bash instead of zsh?

I think it should work with bash as it is. Just replace the zsh with bash. There is nothing zsh specific in this script. Zsh and Bash are POSIX shells.

#!/data/data/com.termux/files/usr/bin/bash

I've updated the script.

I switched to yt-dlp. It is more reliable and works with more websites. The script installs needed tools automatically now. I've added transmission as option t) in the script

Also if you install the script with git you can update it with "git pull" to the latest version. I modified the instructions to use git. This should eliminate the problems with encoding issues. (Who uses MS Windows anyway?)

install git & copy the git clone command from the instructions o a termux session

@TehDomic
Copy link

Cool, I'll give it a try this week and see if I love it. Thanks for the script ♥

@naranyala
Copy link

open source is awesome

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