YouTube video download
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<link rel="shortcut icon" href="https://cdn-icons-png.flaticon.com/512/1384/1384060.png" type="image/x-icon" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Downloadib</title>
<style>
body {
font-family: Arial, sans-serif;
background: #f4f4f4;
margin: 0;
padding: 0;
color: #333;
min-height: 100vh;
position: relative;
padding-bottom: 60px;
box-sizing: border-box;
}
.logo {
text-align: center;
margin: 20px 0;
padding: 0 15px;
}
.logo img {
max-width: 200px;
height: auto;
}
form {
display: flex;
justify-content: center;
margin-bottom: 20px;
padding: 0 15px;
}
.bar {
display: flex;
align-items: center;
background: white;
border-radius: 30px;
padding: 5px 15px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
width: 100%;
max-width: 500px;
}
.searchbar {
border: none;
outline: none;
padding: 10px;
width: 100%;
font-size: 16px;
border-radius: 30px;
}
.search-button {
background: none;
border: none;
cursor: pointer;
padding: 5px 10px;
}
.search-icon {
width: 24px;
height: 24px;
}
.container {
text-align: center;
padding: 20px;
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 20px;
}
.item {
background: white;
border-radius: 8px;
padding: 15px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
max-width: 300px;
text-align: left;
width: 100%;
}
.thumbnail {
width: 100%;
border-radius: 5px;
margin-bottom: 10px;
max-height: 180px;
object-fit: cover;
}
.info {
padding: 0 10px;
}
.name {
font-weight: bold;
margin-bottom: 10px;
font-size: 16px;
}
.action {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
}
.video-resolution {
color: #666;
font-size: 14px;
margin-right: 10px;
}
.download-btn {
background-color: #ff0000;
color: white;
border: none;
padding: 8px 15px;
border-radius: 4px;
cursor: pointer;
display: flex;
align-items: center;
gap: 8px;
font-weight: bold;
text-decoration: none;
font-size: 14px;
}
.download-btn:hover {
background-color: #cc0000;
}
.download-icon {
width: 18px;
height: 18px;
}
.link-box {
width: 100%;
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 12px;
background: #f9f9f9;
margin-top: 8px;
cursor: pointer;
}
.link-box:hover {
background: #f0f0f0;
}
.copy-message {
color: green;
font-size: 12px;
margin-top: 5px;
display: none;
}
.center {
text-align: center;
}
footer {
background: #222;
color: white;
padding: 10px 0;
position: absolute;
width: 100%;
bottom: 0;
text-align: center;
}
@media screen and (max-width: 490px) {
.searchbar {
font-size: 14px;
}
.bar {
padding: 8px 15px;
}
.item {
max-width: 100%;
}
}
</style>
</head>
<body>
<div class="logo">
<img alt="Downloadib" src="https://cdn-icons-png.flaticon.com/512/1384/1384060.png" />
</div>
<form onsubmit="getData(event)">
<div class="bar">
<input class="searchbar" type="text" title="Search" placeholder="Enter YouTube video link here" required />
<button type="submit" class="search-button">
<img src="https://cdn-icons-png.flaticon.com/512/149/149852.png" class="search-icon" alt="Search" />
</button>
</div>
</form>
<div class="container">
<h3 class="center">Your Videos Will Appear Here!</h3>
</div>
<footer>
<h4 class="center">© CodeWithAli all rights reserved</h4>
</footer>
<script>
// Paste YouTube URL from clipboard on page load
document.addEventListener('DOMContentLoaded', async () => {
try {
const text = await navigator.clipboard.readText();
const isYouTubeLink =
text.includes('youtube.com/watch?v=') || text.includes('youtu.be/');
if (isYouTubeLink) {
document.querySelector('.searchbar').value = text;
}
} catch (err) {
console.warn('Clipboard access denied or unsupported.', err);
}
});
const getData = async (e) => {
e.preventDefault();
let querry = document.getElementsByClassName('searchbar')[0].value;
let id = '';
if (querry == '') {
alert('Please enter a YouTube URL');
return;
}
try {
if (querry.includes('watch?v=')) {
id = querry.split('=')[1].split('&')[0]; // Handle cases with additional parameters
} else if (querry.includes('youtu.be/')) {
id = querry.split('youtu.be/')[1].split('?')[0];
} else {
let lastSlashIndex = querry.lastIndexOf('/');
id = querry.slice(lastSlashIndex + 1);
}
console.log('Extracted ID:', id);
const url = `https://ytstream-download-youtube-videos.p.rapidapi.com/dl?id=${id}`;
const options = {
method: 'GET',
headers: {
'X-RapidAPI-Key': 'd40c265118mshdc90194a533aa99p18842bjsn18247c206e8e',
'X-RapidAPI-Host': 'ytstream-download-youtube-videos.p.rapidapi.com',
},
};
document.querySelector('.container h3').textContent = 'Loading...';
const response = await fetch(url, options);
const result = await response.json();
console.log(result);
if (result.formats && result.formats.length > 0) {
setData(result);
} else {
document.querySelector('.container h3').textContent = 'No download options found for this video';
}
} catch (error) {
console.error('Error:', error);
document.querySelector('.container h3').textContent =
'Error processing your request. Please check the URL and try again.';
}
};
const setData = (data) => {
let container = document.querySelector('.container');
container.innerHTML = '';
// Add video title
const title = document.createElement('h2');
title.textContent = data.title;
title.style.textAlign = 'center';
title.style.width = '100%';
title.style.marginBottom = '20px';
container.appendChild(title);
// Add thumbnail
const thumbContainer = document.createElement('div');
thumbContainer.style.textAlign = 'center';
thumbContainer.style.width = '100%';
thumbContainer.style.marginBottom = '20px';
const thumbnail = document.createElement('img');
thumbnail.src =
data.thumbnail[data.thumbnail.length - 1].url ||
'https://via.placeholder.com/500x300?text=No+Thumbnail';
thumbnail.className = 'thumbnail';
thumbnail.style.maxWidth = '500px';
thumbContainer.appendChild(thumbnail);
container.appendChild(thumbContainer);
// Add download options
for (let i = 0; i < data.formats.length; i++) {
let item = document.createElement('div');
item.className = 'item';
const resolution = document.createElement('span');
resolution.className = 'video-resolution';
resolution.textContent = data.formats[i].qualityLabel || 'Unknown Quality';
const downloadBtn = document.createElement('a');
downloadBtn.href = data.formats[i].url;
downloadBtn.download = `${data.title} - ${data.formats[i].qualityLabel || 'video'}.mp4`;
downloadBtn.className = 'download-btn';
downloadBtn.innerHTML = `
Download
<img src="https://cdn-icons-png.flaticon.com/512/724/724933.png" class="download-icon" alt="Download">
`;
// Create link box container
const linkContainer = document.createElement('div');
// Create link box
const linkBox = document.createElement('input');
linkBox.className = 'link-box';
linkBox.type = 'text';
linkBox.value = data.formats[i].url;
linkBox.readOnly = true;
linkBox.onclick = function() {
this.select();
document.execCommand('copy');
// Show copy message
const copyMsg = this.nextElementSibling;
copyMsg.style.display = 'block';
setTimeout(() => {
copyMsg.style.display = 'none';
}, 2000);
};
// Create copy message
const copyMessage = document.createElement('div');
copyMessage.className = 'copy-message';
copyMessage.textContent = 'Link copied to clipboard!';
linkContainer.appendChild(linkBox);
linkContainer.appendChild(copyMessage);
const actionDiv = document.createElement('div');
actionDiv.className = 'action';
actionDiv.appendChild(resolution);
actionDiv.appendChild(downloadBtn);
item.appendChild(actionDiv);
item.appendChild(linkContainer);
container.appendChild(item);
}
};
</script>
</body>
</html>
-----------------------------------------------------------------------------------------------------------------------
How to do Python Scripting (run a python py file)
-----------------------------------------------------------------------------------------------------------------------
بہت اچھا سوال! آئیے بچوں کے انداز میں آسان زبان میں سمجھاتے ہیں کہ Python میں yt-dlp کو کیسے استعمال کرتے ہیں تاکہ YouTube ویڈیوز ڈاؤن لوڈ کی جا سکیں۔
🎒 مرحلہ وار طریقہ (بچوں کے لیے آسان انداز میں)
✅ 1. Python انسٹال کریں
اگر آپ کے پاس Python نہیں ہے تو پہلے python.org سے Python انسٹال کریں۔
✅ 2. yt-dlp
انسٹال کریں
📦 یہ ایک پیکج ہے جو ویڈیو ڈاؤن لوڈ کرنے کے لیے استعمال ہوتا ہے۔
👇 ٹرمینل (یا Command Prompt) میں لکھیں:
pip install yt-dlp
✅ 3. Python فائل بنائیں
اپنے کمپیوٹر پر کوئی فولڈر بنائیں، جیسے:
C:\Users\Ayesha\Videos\yt-dlp-folder
پھر اس فولڈر کے اندر ایک Python فائل بنائیں جس کا نام رکھیں:
video_downloader.py
یعنی .py فائل Python code کے لیے ہوتی ہے۔
✅ 4. Python کوڈ لکھیں
اب اس .py
فائل میں یہ کوڈ لکھیں:
import yt_dlp
# جس ویڈیو کا لنک ڈاؤن لوڈ کرنا ہے
video_url = 'https://www.youtube.com/watch?v=abc123xyz' # ← یہاں اپنا یوٹیوب لنک لکھیں
# ڈاؤن لوڈ کرنے کا سیٹ اپ
ydl_opts = {
'format': 'best',
'outtmpl': '%(title)s.%(ext)s', # ویڈیو کا نام ویسا ہی ہوگا جیسا یوٹیوب پر ہے
}
# ویڈیو ڈاؤن لوڈ کرنا
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
ydl.download([video_url])
✅ 5. فائل کو رن (چلائیں)
🔧 اب ٹرمینل یا Command Prompt میں جائیں، اور اسی فولڈر میں جا کر یہ لکھیں:
python video_downloader.py
🎉 اب ویڈیو ڈاؤن لوڈ ہونا شروع ہو جائے گی!
🧠 بچوں کے لیے یاد رکھنے کی باتیں:
🔹 چیز | 🔍 مطلب |
---|---|
.py |
Python کوڈ فائل کا آخری حصہ |
import yt_dlp |
Python کو کہہ رہے ہیں کہ وہ yt-dlp والا دماغ استعمال کرے |
video_url |
جس ویڈیو کو ڈاؤن لوڈ کرنا ہے اس کا لنک |
ydl_opts |
کچھ خاص ہدایات کیسے ڈاؤن لوڈ کرنا ہے |
yt_dlp.YoutubeDL |
ڈاؤن لوڈر شروع کرنے کا طریقہ |
اگر آپ چاہیں تو میں اس کو گرافیکل یوزر انٹرفیس (GUI) میں بھی تبدیل کر سکتا ہوں تاکہ بچے بٹن دبائیں اور ویڈیو ڈاؤن لوڈ ہو جائے۔
کیا آپ کو وہ بھی چاہیے؟
Comments
Post a Comment