-
-
Save LordH3lmchen/dc35e8df3dc41d126683f18fe44ebe17 to your computer and use it in GitHub Desktop.
#!/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 |
Good evening. It's good my script works. Resuming what I had written, and with your answers, I resumed the script on my phone. I noticed a lot of writing errors because of .... my bluetooth keyboard. He repeated characters to me !!! I rewrote with the virtual keyboard of the phone by simplifying and it works!
Thanks to those who answered me, problem solved!
Hello,
Since I cannot do a pull request so I'm suggesting that you add this function right after 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
}
And then call yt_shorts
right before the youtube-dl
call in switch cases y)
and u)
.
Reason: youtube-dl cannot work on "youtube shorts" links directly, so some modification is needed given that the url is from a youtube short video.
I'm not OP but could you maybe do a gits so i could see how it should be?
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.
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.
Does anyone know any forks that use pre-installed bash instead of zsh?
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
Cool, I'll give it a try this week and see if I love it. Thanks for the script ♥
open source is awesome
I answer myself. $ 1 represents the url of the link, well from what I understand. From then on we could also write:
$ apt update && apt upgrade -y
$ apt install python -y
$ pip install --upgrade pip
$ pip install youtube-dl
$ mkdir -p /sdcard/Youtube
$ mkdir ~/bin
$ echo 'youtube-dl --no-mtime -o /sdcard/Youtube/%(title)s.%(ext)s -f "best [height <= 1080]"' $1' > ~ / bin / termux- url-opener
Are we not using the youtube-dl "config" file? That's right, isn't it?
Thank you.