Opera8 commited on
Commit
52fdf92
·
verified ·
1 Parent(s): 88f6654

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +138 -82
index.html CHANGED
@@ -3,119 +3,175 @@
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>یوتیوب دانلودر حرفه‌ای</title>
 
7
  <script src="https://cdn.tailwindcss.com"></script>
8
  <style>
9
  @import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;700&display=swap');
10
- body { font-family: 'Vazirmatn', sans-serif; background-color: #0f172a; color: white; }
11
- .loader { border: 4px solid #f3f3f3; border-top: 4px solid #3498db; border-radius: 50%; width: 30px; height: 30px; animation: spin 2s linear infinite; display: none; }
12
- @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  </style>
14
  </head>
15
- <body class="flex items-center justify-center min-h-screen">
16
 
17
- <div class="bg-slate-800 p-8 rounded-2xl shadow-2xl w-full max-w-md border border-slate-700">
18
- <h1 class="text-3xl font-bold text-center mb-6 text-blue-400">دانلودر یوتیوب</h1>
19
-
20
- <div class="space-y-4">
21
- <div>
22
- <label class="block text-sm mb-2 text-slate-400">لینک ویدیو یوتیوب را وارد کنید:</label>
23
- <input type="text" id="youtubeUrl" placeholder="https://youtube.com/watch?v=..."
24
- class="w-full p-3 rounded-lg bg-slate-900 border border-slate-600 focus:ring-2 focus:ring-blue-500 outline-none text-left" dir="ltr">
25
- </div>
26
 
27
- <div class="flex gap-2">
28
- <button onclick="download('mp4')" id="btnMp4" class="flex-1 bg-blue-600 hover:bg-blue-700 p-3 rounded-lg font-bold transition-all flex justify-center items-center gap-2">
29
- <span>دانلود ویدیویی (MP4)</span>
30
- </button>
31
- <button onclick="download('mp3')" id="btnMp3" class="flex-1 bg-green-600 hover:bg-green-700 p-3 rounded-lg font-bold transition-all flex justify-center items-center gap-2">
32
- <span>دانلود صوتی (MP3)</span>
33
- </button>
34
  </div>
35
-
36
- <div id="status" class="hidden mt-4 p-4 rounded-lg text-center text-sm"></div>
37
 
38
- <div id="loadingBox" class="hidden flex flex-col items-center mt-4">
39
- <div class="loader mb-2"></div>
40
- <p class="text-blue-400 animate-pulse">در حال پردازش و دریافت از یوتیوب...</p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  </div>
42
  </div>
43
 
44
- <div class="mt-8 text-xs text-slate-500 text-center">
45
- <p>نکته: این سیستم به API خارجی متصل است.</p>
46
- <p>اگر خطا دریافت کردید، احتمالا محدودیت CORS وجود دارد.</p>
 
 
47
  </div>
48
  </div>
49
 
50
  <script>
51
- async function download(type) {
52
- const urlInput = document.getElementById('youtubeUrl').value;
53
- const statusDiv = document.getElementById('status');
54
- const loadingBox = document.getElementById('loadingBox');
55
- const btnMp3 = document.getElementById('btnMp3');
56
- const btnMp4 = document.getElementById('btnMp4');
57
-
58
- if (!urlInput) {
59
- showStatus("لطفا لینک یوتیوب را وارد کنید!", "bg-red-900/50 text-red-300");
60
- return;
61
- }
62
 
63
- // تعیین مسیر API بر اساس انتخاب کاربر
64
- // آدرس پایه که شما دادید
65
- const apiBase = "https://maliksahib1-yt-downloader-api.hf.space";
66
- let endpoint = "";
67
-
68
- if (type === 'mp3') {
69
- endpoint = `${apiBase}/AnotherAPI/new_downloader/YT/mp3/?youtube_url=${encodeURIComponent(urlInput)}`;
70
- } else {
71
- endpoint = `${apiBase}/AnotherAPI/downloader/YT/mp4/?youtube_url=${encodeURIComponent(urlInput)}`;
 
72
  }
73
 
74
- // ظاهر رابط کاربری در حال لودینگ
75
- loadingBox.classList.remove('hidden');
76
- statusDiv.classList.add('hidden');
77
- btnMp3.disabled = true;
78
- btnMp4.disabled = true;
79
 
80
  try {
81
- const response = await fetch(endpoint, {
82
- method: 'POST',
83
- headers: { 'Accept': 'application/json' }
84
- });
85
 
86
- if (!response.ok) {
87
- throw new Error("خطا در پاسخ سرور (ممکن است لینک اشتباه باشد یا سرور محدود شده باشد)");
88
  }
89
 
90
- // دریافت فایل به صورت Blob
91
- const blob = await response.blob();
92
- const url = window.URL.createObjectURL(blob);
93
 
94
- // ایجاد لینک دانلود اتوماتیک
95
- const a = document.createElement('a');
96
- a.href = url;
97
- a.download = type === 'mp3' ? "audio.mp3" : "video.mp4";
98
- document.body.appendChild(a);
99
- a.click();
100
- window.URL.revokeObjectURL(url);
101
-
102
- showStatus("دانلود با موفقیت آغاز شد!", "bg-green-900/50 text-green-300");
 
 
 
 
 
 
 
103
 
104
  } catch (error) {
105
- console.error(error);
106
- showStatus("خطا: " + error.message, "bg-red-900/50 text-red-300");
107
  } finally {
108
- loadingBox.classList.add('hidden');
109
- btnMp3.disabled = false;
110
- btnMp4.disabled = false;
111
  }
112
  }
113
 
114
- function showStatus(msg, classes) {
115
- const statusDiv = document.getElementById('status');
116
- statusDiv.innerText = msg;
117
- statusDiv.className = "mt-4 p-4 rounded-lg text-center text-sm " + classes;
118
- statusDiv.classList.remove('hidden');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  }
120
  </script>
121
  </body>
 
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>یوتیوب دانلودر اختصاصی</title>
7
+ <!-- استفاده از Tailwind CSS برای ظاهر مدرن -->
8
  <script src="https://cdn.tailwindcss.com"></script>
9
  <style>
10
  @import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;700&display=swap');
11
+
12
+ body {
13
+ font-family: 'Vazirmatn', sans-serif;
14
+ background-color: #0f172a;
15
+ color: #f8fafc;
16
+ }
17
+
18
+ .glass-card {
19
+ background: rgba(30, 41, 59, 0.7);
20
+ backdrop-filter: blur(10px);
21
+ border: 1px solid rgba(255, 255, 255, 0.1);
22
+ }
23
+
24
+ .loader {
25
+ border: 3px solid rgba(255, 255, 255, 0.1);
26
+ border-top: 3px solid #ef4444;
27
+ border-radius: 50%;
28
+ width: 24px;
29
+ height: 24px;
30
+ animation: spin 1s linear infinite;
31
+ display: inline-block;
32
+ }
33
+
34
+ @keyframes spin {
35
+ 0% { transform: rotate(0deg); }
36
+ 100% { transform: rotate(360deg); }
37
+ }
38
  </style>
39
  </head>
40
+ <body class="min-h-screen flex items-center justify-center p-4">
41
 
42
+ <div class="glass-card w-full max-w-xl p-8 rounded-3xl shadow-2xl">
43
+ <!-- هدر -->
44
+ <div class="text-center mb-8">
45
+ <h1 class="text-3xl font-extrabold text-red-500 mb-2">YouTube Grabber</h1>
46
+ <p class="text-slate-400 text-sm">متصل به API اختصاصی Akashh89</p>
47
+ </div>
 
 
 
48
 
49
+ <!-- بخش ورودی -->
50
+ <div class="space-y-4">
51
+ <div class="relative">
52
+ <input type="text" id="videoUrl"
53
+ class="w-full bg-slate-900 border border-slate-700 p-4 pr-4 rounded-2xl outline-none focus:ring-2 focus:ring-red-500 transition-all text-left"
54
+ placeholder="https://www.youtube.com/watch?v=..." dir="ltr">
 
55
  </div>
 
 
56
 
57
+ <button onclick="fetchVideoInfo()" id="btnFetch"
58
+ class="w-full bg-red-600 hover:bg-red-700 py-4 rounded-2xl font-bold text-lg transition-all transform active:scale-95 flex justify-center items-center gap-2">
59
+ <span id="btnText">دریافت اطلاعات ویدیو</span>
60
+ <div id="btnLoader" class="loader hidden"></div>
61
+ </button>
62
+ </div>
63
+
64
+ <!-- بخش نمایش نتیجه (در ابتدا مخفی است) -->
65
+ <div id="videoCard" class="hidden mt-8 border-t border-slate-700 pt-6">
66
+ <div class="flex flex-col sm:flex-row gap-4">
67
+ <img id="thumbnail" src="" alt="Thumbnail" class="w-full sm:w-48 rounded-xl shadow-lg object-cover">
68
+ <div class="flex-1">
69
+ <h2 id="videoTitle" class="text-lg font-bold mb-4 leading-tight"></h2>
70
+
71
+ <div class="grid grid-cols-1 gap-2">
72
+ <!-- دکمه‌های دانلود که توسط جاوااسکریپت ساخته می‌شوند -->
73
+ <div id="downloadOptions" class="space-y-2"></div>
74
+ </div>
75
+ </div>
76
  </div>
77
  </div>
78
 
79
+ <!-- نمایش وضعیت و خطاها -->
80
+ <div id="statusMessage" class="hidden mt-4 p-3 rounded-xl text-center text-sm"></div>
81
+
82
+ <div class="mt-8 text-center text-xs text-slate-500 italic">
83
+ توجه: این پنل فقط با لینک مستقیم کار می‌کند و قابلیت جستجو ندارد.
84
  </div>
85
  </div>
86
 
87
  <script>
88
+ // آدرس API که شما پیدا کردید
89
+ const API_BASE = "https://akashh89-ytgrab-new.hf.space";
 
 
 
 
 
 
 
 
 
90
 
91
+ async function fetchVideoInfo() {
92
+ const url = document.getElementById('videoUrl').value;
93
+ const btnText = document.getElementById('btnText');
94
+ const btnLoader = document.getElementById('btnLoader');
95
+ const videoCard = document.getElementById('videoCard');
96
+ const statusMessage = document.getElementById('statusMessage');
97
+
98
+ if (!url) {
99
+ showMessage("لطفاً ابتدا لینک ویدیو را وارد کنید", "bg-yellow-900/50 text-yellow-200");
100
+ return;
101
  }
102
 
103
+ // ریست کردن ظاهر
104
+ statusMessage.classList.add('hidden');
105
+ videoCard.classList.add('hidden');
106
+ btnText.innerText = "در حال ارتباط با سرور...";
107
+ btnLoader.classList.remove('hidden');
108
 
109
  try {
110
+ // مرحله 1: فراخوانی Info API
111
+ const response = await fetch(`${API_BASE}/info?url=${encodeURIComponent(url)}`);
112
+ const data = await response.json();
 
113
 
114
+ if (data.error) {
115
+ throw new Error(data.error);
116
  }
117
 
118
+ // نمایش اطلاعات ویدیو
119
+ document.getElementById('thumbnail').src = data.thumbnail;
120
+ document.getElementById('videoTitle').innerText = data.title;
121
 
122
+ // ساخت دکمه‌های دانلود بر اساس فرمت‌های API
123
+ const optionsContainer = document.getElementById('downloadOptions');
124
+ optionsContainer.innerHTML = ''; // پاک کردن دکمه‌های قبلی
125
+
126
+ // اضافه کردن کیفیت‌های ویدیو (360p و 720p)
127
+ data.video_formats.forEach(fmt => {
128
+ createDownloadBtn(optionsContainer, url, fmt.format_id, `دانلود ویدیو (${fmt.quality})`, 'bg-blue-600');
129
+ });
130
+
131
+ // اضافه کردن کیفیت صدا
132
+ data.audio_formats.forEach(fmt => {
133
+ createDownloadBtn(optionsContainer, url, fmt.format_id, `دانلود صوتی (MP3 - ${fmt.quality}kbps)`, 'bg-green-600');
134
+ });
135
+
136
+ videoCard.classList.remove('hidden');
137
+ showMessage("اطلاعات با موفقیت دریافت شد", "bg-green-900/50 text-green-200");
138
 
139
  } catch (error) {
140
+ showMessage("خطا: " + error.message, "bg-red-900/50 text-red-200");
 
141
  } finally {
142
+ btnText.innerText = "دریافت اطلاعات ویدیو";
143
+ btnLoader.classList.add('hidden');
 
144
  }
145
  }
146
 
147
+ function createDownloadBtn(container, url, formatId, text, colorClass) {
148
+ const btn = document.createElement('button');
149
+ btn.className = `w-full ${colorClass} hover:opacity-90 py-2 px-4 rounded-lg font-bold text-sm transition-all mb-2 flex justify-between items-center`;
150
+
151
+ // لینک نهایی دانلود
152
+ const downloadUrl = `${API_BASE}/download?url=${encodeURIComponent(url)}&format_id=${formatId}`;
153
+
154
+ btn.innerHTML = `
155
+ <span>${text}</span>
156
+ <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
157
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4" />
158
+ </svg>
159
+ `;
160
+
161
+ btn.onclick = () => {
162
+ // باز کردن لینک دانلود در یک برگه جدید برای شروع دانلود خودکار
163
+ window.open(downloadUrl, '_blank');
164
+ showMessage("درخواست دانلود به سرور فرستاده شد. لطفا صبر کنید...", "bg-blue-900/50 text-blue-200");
165
+ };
166
+
167
+ container.appendChild(btn);
168
+ }
169
+
170
+ function showMessage(text, classes) {
171
+ const statusMessage = document.getElementById('statusMessage');
172
+ statusMessage.innerText = text;
173
+ statusMessage.className = `mt-4 p-3 rounded-xl text-center text-sm ${classes}`;
174
+ statusMessage.classList.remove('hidden');
175
  }
176
  </script>
177
  </body>