How to Download Videos and audios from video link (In Android)
Maded by Bismoy Ghosh
1. First need to install Termux:
To install Termux on your Android device, follow these steps:
1. Install from F-Droid (recommended method):
Open your browser and go to F-Droid.
Download the Termux APK from the F-Droid website.
Install the APK by allowing your phone to install apps from unknown sources (you can enable this in your phone's settings under "Security").
2. Install from Google Play Store (older version):
Open the Google Play Store on your device.
Search for "Termux."
Tap "Install" to download and install it.
However, it's recommended to use the F-Droid method since the version on the Google Play Store may not be up to date.
Grant storage permission:
~s: termux-setup-storage
And accept that .
2. Update && Upgrade :
1. apt update
2. apt upgrade
It will update and upgrade all the packages.
3 Install nesseary packages:
1. apt install python
The language we will use is python . This is user friendly easy to understand.
4. Install nesseary pip:
1. pip install yt-dlp
2. pip install ffmpeg
3. pip install flask
5. Create a Directory:
1. mkdir downloader
Go to the directory
2. cd downloader
3. mkdir templates
6. Create a python file (.py):
I am using nano ......
1. nano server.py
7. Paste the full code :
from flask import Flask, request, render_template, send_file
import yt_dlp
import os
app = Flask(__name__)
# Corrected DOWNLOAD_PATH to be a valid folder path
DOWNLOAD_PATH = "/data/data/com.termux/files/home/downloader/downloads"
if not os.path.exists(DOWNLOAD_PATH):
os.makedirs(DOWNLOAD_PATH)
def download_video(url, format_code):
# If the user selects MP3, we'll extract audio only
if format_code == "mp3":
ydl_opts = {
"format": "bestaudio/best", # Best audio format
"outtmpl": f"{DOWNLOAD_PATH}/%(title)s.%(ext)s", # Correct template
"postprocessors": [{
"key": "FFmpegExtractAudio",
"preferredcodec": "mp3",
"preferredquality": "192", # Set audio quality
}],
}
else:
# Download MP4 with the selected resolution
# Added a fallback to "bestvideo+bestaudio" if the selected resolution doesn't exist
ydl_opts = {
"format": f"bestvideo[height<={format_code}]+bestaudio/best", # Best video up to the selected resolution + audio
"outtmpl": f"{DOWNLOAD_PATH}/%(title)s.%(ext)s", # Correct template
"merge_output_format": "mp4", # Force MP4 output
"noplaylist": True, # Avoid playlist download, only the single video
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(url, download=True)
filename = ydl.prepare_filename(info)
# Ensure that the file is saved with the correct extension (MP4 or MP3)
if filename.endswith(".webm"): # This handles possible WebM files
filename = filename.replace(".webm", ".mp3") # Replace WebM with MP4
return filename
@app.route("/", methods=["GET", "POST"])
def index():
if request.method == "POST":
url = request.form.get("url")
format_code = request.form.get("format")
try:
file_path = download_video(url, format_code)
return send_file(file_path, as_attachment=True)
except Exception as e:
return f"Error: {str(e)}"
return render_template("index.html")
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000, debug=True)
___________________________________________________
8. Save the Code:
1. Ctrl + x
2. Ctrl + y
3. Press Enter
9. Go to templates directory:
1. cd templates
10. Create a index.html:
1. nano index.html
Actually we will create a website that can download Multimedia from different websites.
Don't be afraid it will work only in your local server .
11. Paste the code in index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Video Downloader</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">
<style>
body {
background: linear-gradient(135deg, #1f1c2c, #928dab);
color: white;
text-align: center;
padding-top: 50px;
}
.container {
max-width: 500px;
background: rgba(0, 0, 0, 0.7);
padding: 20px;
border-radius: 10px;
box-shadow: 0px 0px 10px rgba(255, 255, 255, 0.2);
}
input, select {
margin-top: 10px;
width: 100%;
padding: 10px;
border-radius: 5px;
border: none;
}
button {
margin-top: 15px;
background: #ff4081;
color: white;
padding: 10px;
border: none;
width: 100%;
font-size: 18px;
cursor: pointer;
}
button:hover {
background: #ff79b0;
}
</style>
</head>
<body>
<div class="container">
<h2><i class="fas fa-download"></i> Video Downloader</h2>
<form method="POST">
<label>Enter Video Link:</label>
<input type="text" name="url" placeholder="Paste video link here..." required>
<label>Select Format:</label>
<select name="format">
<option value="mp3">MP3 (Audio Only)</option>
<option value="144">MP4 (144p)</option>
<option value="360">MP4 (360p)</option>
<option value="720">MP4 (720p)</option>
<option value="1080">MP4 (1080p)</option>
</select>
<button type="submit"><i class="fas fa-download"></i> Download</button>
</form>
</div>
</body>
</html>
___________________________________________________
12. Save and exit the code:
1. Ctrl + x
2. Ctrl + y
3. Press Enter
You can run this now if you had a little bit of python knowledge. But if you want more easier to use this :
Go to termux :
1. cd
2. nano ~/.bashrc
3. Paste this
alias dwnldr="python downloader/server.py"
4. Save this :
1. Ctrl + x
2. Ctrl + y
3. Press Enter
Make this executable for this session:
1. source ~/.bashrc
Now you can run dwnldr in your terminal and open any browser and visit
Command : dwnldr
http://127.0.0.1:5000
After downloading medial file turn off this server :
Press Ctrl + c

Comments
Post a Comment