termux, yt-dlp, android, youtube, mp3

Ai scris sau tradus un tutorial? Aveți sfaturi pas cu pas din experiența proprie? Aici e locul în care să le oferiți.
a
alegatorul
Mesaje: 3
Membru din: 16 Feb 2026, 17:05

termux, yt-dlp, android, youtube, mp3

Mesaj de alegatorul »

Script pentru a folosi termux în android să poți 5rimite un link de youtube spre a-l face mp3, bitrate variabil, HQ.
1. Se instalează termux (google play sau apkmirror)
2. În terminal se aplică codul (automat total)

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

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

############################################################
# FULLY AUTOMATED Termux + yt-dlp Setup
# Android 14 / Samsung One UI 6+
# Zero prompts | Auto-Yes | Non-interactive | Retry-enabled
############################################################

set -e
export DEBIAN_FRONTEND=noninteractive

echo "Starting FULLY AUTOMATED setup..."

############################################################
# 1. Auto Grant Storage Permission
############################################################
echo "Requesting storage permission..."
yes | termux-setup-storage || true

############################################################
# 2. Force Official Termux Mirror (Mirror-Proof)
############################################################
echo "Setting official Termux mirror..."
cat > $PREFIX/etc/apt/sources.list << 'EOF'
deb https://packages.termux.dev/apt/termux-main stable main
EOF

rm -rf $PREFIX/var/lib/apt/lists/*

############################################################
# 3. Update & Upgrade (Auto Yes, Retry if Mirror Syncing)
############################################################
echo "Updating system..."
until pkg update -y; do
echo "Mirror syncing... retrying in 5 seconds..."
sleep 5
done
yes | pkg upgrade -y

############################################################
# 4. Install Required Packages (Auto Yes)
############################################################
echo "Installing required packages..."
yes | pkg install python ffmpeg nano yt-dlp -y

############################################################
# 5. Skip pip upgrade (Termux blocks manual upgrade)
############################################################
echo "Skipping pip upgrade (Termux blocks manual upgrade)."

############################################################
# 6. Create yt-dlp Config
############################################################
echo "Creating yt-dlp configuration..."
mkdir -p ~/.config/yt-dlp

cat > ~/.config/yt-dlp/config << 'EOF'
-o ~/storage/downloads/%(extractor_key)s/%(title)s-%(id)s.%(ext)s
--embed-metadata
--embed-thumbnail
--add-metadata
--no-mtime
--no-playlist
EOF

############################################################
# 7. Create Android Share Script with Retry Logic
############################################################
echo "Creating termux-url-opener with retry support..."
mkdir -p ~/bin

cat > ~/bin/termux-url-opener << 'EOF'
#!/data/data/com.termux/files/usr/bin/bash

url="$1"
attempt=0
max_attempts=3

until [ $attempt -ge $max_attempts ]; do
((attempt++))
echo "Downloading ($attempt/$max_attempts): $url"

yt-dlp "$url" \
-f bestaudio \
-x \
--audio-format mp3 \
--audio-quality 0 \
--no-playlist && break

echo "Download failed, retrying in 5 seconds..."
sleep 5
done

if [ $attempt -eq $max_attempts ]; then
echo "Failed to download $url after $max_attempts attempts."
fi
EOF

chmod +x ~/bin/termux-url-opener

############################################################
# 8. Ensure ~/bin in PATH
############################################################
if ! grep -q 'export PATH=$HOME/bin:$PATH' ~/.bashrc; then
echo 'export PATH=$HOME/bin:$PATH' >> ~/.bashrc
fi

############################################################
# 9. Clean Cache (Optional Optimization)
############################################################
yes | pkg autoremove -y || true
yes | pkg clean || true

############################################################
# 10. DONE - Safe Final Message
############################################################
cat << 'EOF'

============================================
AUTO SETUP COMPLETE
No prompts were required.

You can now:
- Share any supported URL to Termux
- It will auto-download best quality MP3
- Failed downloads auto-retry up to 3 times
- Files saved to: Internal Storage > Downloads

Restart Termux if Share option does not appear.
============================================

EOF

Succes!

Ultima oară modificat 19 Feb 2026, 20:26 de către alegatorul, modificat 1 dată în total.
a
alegatorul
Mesaje: 3
Membru din: 16 Feb 2026, 17:05

Re: termux, yt-dlp, android, youtube, mp3

Mesaj de alegatorul »

Pentru a face calitatea cea mai bună audio, vbr, recodare, se folosește codul următor, în același dosar cu mp3-urile (le va face pe cele noi cu extensia mp3.mp3)

in terminal, in folder for audio reencode:
find . -exec ffmpeg -i {} -q:a 0 {}.mp3 \;

Scrie răspuns