My termux-url-opener script with yt-dlp
Install the Termux:API app
cd ~
termux-setup-storage
pkg update
pkg upgrade
pkg install python3 aria2 ffmpeg jq termux-api wget nano deno
mkdir -p yt-dlp
wget https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -O yt-dlp/
chmod +x yt-dlp/yt-dlp
termux-fix-shebang yt-dlp/yt-dlp # optional workaround for 'bad interpreter' errors while using termux-url-opener
echo 'export PATH="$PATH:$HOME/yt-dlp"' >> .bashrc # or use global $PREFIX/etc/bash.bashrc
source .bashrc
mkdir ~/bin
wget https://github.com/kairusds/termux-url-opener/raw/master/termux-url-opener -P ~/bin
termux-fix-shebang ~/bin/termux-url-opener # optional workaround for 'bad interpreter' errors while using termux-url-opener
chmod +x ~/bin/termux-url-opener- Install and run a Firefox-based browser for Android: Original Firefox, Iceraven or IronFox
- Install the Get cookies.txt LOCALLY Firefox extension
- Open a Private Tab by clicking the Tabs icon > then the Mask icon, and login to YouTube. WARNING: USE A THROWAWAY ACCOUNT FOR THIS SINCE THERE'S A SMALL CHANCE YOUR YOUTUBE/GOOGLE ACCOUNT COULD GET BANNED.
- Enable "Get cookies.txt LOCALLY" for Private tabs on the Extensions menu by pressing the 3-dots menu icon > Extensions > Find and tap "Get cookies.txt LOCALLY" > Enable "Run in private browsing". Then, click Permissions > Enable "Allow for all sites" to effectively activate the extension.
- While on the same YouTube private tab with the logged in account, click "Get cookies.txt LOCALLY" from the same Extensions menu from step 4 then press "Copy".
- In Termux, run
nano ~/yt-dlp/.youtube.com_cookies.txtand hold-tap the Termux screen then Press Paste. Afterwards, Press Ctrl+X > Press Y > Press Enter to save the file. - Disable "Get cookies.txt LOCALLY" under Extensions Manager from the same Extensions menu in step 4 > Find and click "Get cookies.txt LOCALLY" > Toggle Enabled. (This is not mandatory but still a great security practice in case the extension gets compromised)
yt-dlp should be working fine now if you setup the cookies correctly.
From the YouTube app or any app, click Share > More > Termux and it should give you an option to download the shared link via MP3 or Video from the Termux app.
(For the YouTube app, if the More button is not visible, scroll the app icons list horizontally to the right.)
The downloaded MP3 files are stored in the Music folder on your internal storage, and the videos are stored on the Movies folder.
- If you keep getting
Permission deniederrors, just grant the Storage permission again for the Termux app manually on the app info page. Runningtermux-setup-storageagain if you already ran the command once wipes your entire internal storage. You can also disablePause app activity if unusedor an option named along those lines in Termux's app info page, so the app's storage permissions won't get revoked if you don't use it for a long time. - For faster fixes/updates, switch to the nightly channel instead by running these commands:
# Change to nightly branch
yt-dlp --update-to nightly
# Update everyday/whenever you encounter issues
yt-dlp -U