بواسطة morbah |
لم تفهم نقطة معينة؟
اسأل المساعد الذكي وسيجيبك بناءً على محتوى هذا المقال.
<!--DOCTYPE html-->
<html lang="ar">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>أداة تحميل فيديوهات يوتيوب</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
}
input {
width: 60%;
padding: 10px;
margin: 10px 0;
}
button {
padding: 10px;
cursor: pointer;
}
.video-container {
margin-top: 20px;
}
img {
width: 320px;
height: auto;
margin-top: 10px;
}
</style>
</head>
<body>
<h2>أداة تحميل فيديوهات يوتيوب</h2>
<input type="text" id="videoUrl" placeholder="أدخل رابط الفيديو">
<button onclick="fetchVideo()">جلب الفيديو</button>
<div class="video-container" id="videoContainer"></div>
<script>
function fetchVideo() {
const url = document.getElementById('videoUrl').value;
if (!url.includes('youtube.com') && !url.includes('youtu.be')) {
alert('يرجى إدخال رابط يوتيوب صحيح');
return;
}
// استخراج معرف الفيديو من الرابط
const videoId = url.includes('v=') ? url.split('v=')[1].split('&')[0] : url.split('/').pop();
const thumbnailUrl = `https://img.youtube.com/vi/${videoId}/hqdefault.jpg`;
// استدعاء API من السيرفر الوسيط للحصول على رابط التحميل المباشر
// يجب أن تقوم بتوفير سيرفر يقوم بمعالجة الفيديو باستخدام أدوات مثل youtube-dl أو غيرها،
// وإرجاع رابط مباشر للملف بصيغة JSON { "downloadUrl": "رابط_التنزيل" }
fetch(`https://example.com/api/getDownloadLink?videoId=${videoId}`)
.then(response => response.json())
.then(data => {
if (data.downloadUrl) {
document.getElementById('videoContainer').innerHTML = `
<img src="${thumbnailUrl}" alt="صورة مصغرة للفيديو">
<br>
<button onclick="downloadVideo('${data.downloadUrl}')">تحميل الفيديو</button>
`;
} else {
alert('فشل في جلب رابط التنزيل.');
}
})
.catch(error => {
console.error('Error fetching download link:', error);
alert('حدث خطأ أثناء جلب رابط التنزيل.');
});
}
function downloadVideo(downloadUrl) {
// إنشاء رابط تحميل مؤقت وتحفيز النقر عليه لتنزيل الفيديو مباشرة
const a = document.createElement('a');
a.href = downloadUrl;
a.setAttribute('download', 'video.mp4'); // يمكنك تغيير اسم الملف حسب الحاجة
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
</script>
</body>
</html>
الكاتب : morbah
انا مهتم بمجال التقنية والربح من الانترنت واتطلع لنشر المزيد من المقالات التي تفيدكم
تعليقات
إرسال تعليق