Upload 6 files
Browse files- .gitattributes +35 -35
- Dockerfile +24 -24
- README.md +10 -10
- app/index.js +287 -0
- app/templates/index.html +241 -0
- package.json +13 -0
.gitattributes
CHANGED
|
@@ -1,35 +1,35 @@
|
|
| 1 |
-
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
-
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
-
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
-
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
-
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
-
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
Dockerfile
CHANGED
|
@@ -1,24 +1,24 @@
|
|
| 1 |
-
#
|
| 2 |
-
FROM node:
|
| 3 |
-
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
#
|
| 16 |
-
#
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
# Expose
|
| 20 |
-
EXPOSE 7860
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
#
|
| 24 |
-
CMD ["
|
|
|
|
| 1 |
+
# Use official Node.js image (using version 18-slim for a small footprint)
|
| 2 |
+
FROM node:18-slim
|
| 3 |
+
|
| 4 |
+
# Set working directory
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Copy package files first
|
| 8 |
+
# This is equivalent to copying requirements.txt.
|
| 9 |
+
# We do this first so Docker caches the "npm install" step if dependencies haven't changed.
|
| 10 |
+
COPY package*.json ./
|
| 11 |
+
|
| 12 |
+
# Install dependencies
|
| 13 |
+
RUN npm install --production
|
| 14 |
+
|
| 15 |
+
# Copy the app folder
|
| 16 |
+
# This copies your 'app' folder from your computer to '/app/app' in the container
|
| 17 |
+
COPY app/ ./app/
|
| 18 |
+
|
| 19 |
+
# Expose port (Hugging Face default)
|
| 20 |
+
EXPOSE 7860
|
| 21 |
+
|
| 22 |
+
# Run the application
|
| 23 |
+
# We use the full path to the file. Assuming your main file is named 'index.js'
|
| 24 |
+
CMD ["node", "app/index.js"]
|
README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
-
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo: pink
|
| 6 |
-
sdk: docker
|
| 7 |
-
pinned: false
|
| 8 |
-
---
|
| 9 |
-
|
| 10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Ytdl
|
| 3 |
+
emoji: 🏃
|
| 4 |
+
colorFrom: yellow
|
| 5 |
+
colorTo: pink
|
| 6 |
+
sdk: docker
|
| 7 |
+
pinned: false
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app/index.js
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const express = require('express');
|
| 2 |
+
const axios = require('axios');
|
| 3 |
+
const path = require('path');
|
| 4 |
+
const FormData = require('form-data');
|
| 5 |
+
const app = express();
|
| 6 |
+
|
| 7 |
+
app.use(express.json());
|
| 8 |
+
|
| 9 |
+
// Serve static files (simulated for this environment)
|
| 10 |
+
app.get('/', (req, res) => {
|
| 11 |
+
res.sendFile(path.join(__dirname,'templates', 'index.html'));
|
| 12 |
+
});
|
| 13 |
+
|
| 14 |
+
const API_HEADERS = {
|
| 15 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
| 16 |
+
"Origin": "https://frame.y2meta-uk.com",
|
| 17 |
+
"Referer": "https://frame.y2meta-uk.com/",
|
| 18 |
+
};
|
| 19 |
+
|
| 20 |
+
// Helper functions
|
| 21 |
+
// Optimized Helper Function (Supports all YouTube formats + Tracking IDs)
|
| 22 |
+
function getVideoId(url) {
|
| 23 |
+
if (!url) return null;
|
| 24 |
+
const regex = /(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/|youtube\.com\/shorts\/)([^"&?\/\s]{11})/;
|
| 25 |
+
const match = url.match(regex);
|
| 26 |
+
return (match && match[1]) ? match[1] : null;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
async function getSanityKey(videoId) {
|
| 32 |
+
// cnv.cx now requires the video id: /v2/sanity/key?id=<videoId>
|
| 33 |
+
const resp = await axios.get("https://cnv.cx/v2/sanity/key", {
|
| 34 |
+
params: { id: videoId },
|
| 35 |
+
headers: { ...API_HEADERS, "Content-Type": "application/json" },
|
| 36 |
+
timeout: 10000
|
| 37 |
+
});
|
| 38 |
+
if (!resp.data || !resp.data.key) throw new Error("No key in response: " + JSON.stringify(resp.data));
|
| 39 |
+
return resp.data.key;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
// --- API: Search ---
|
| 43 |
+
// Helper to convert ISO 8601 duration (PT4M19S) to readable (4:19)
|
| 44 |
+
function parseDuration(isoDuration) {
|
| 45 |
+
if (!isoDuration) return "0:00";
|
| 46 |
+
const match = isoDuration.match(/PT(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?/);
|
| 47 |
+
if (!match) return "0:00";
|
| 48 |
+
const hours = parseInt(match[1] || 0);
|
| 49 |
+
const minutes = parseInt(match[2] || 0);
|
| 50 |
+
const seconds = parseInt(match[3] || 0);
|
| 51 |
+
|
| 52 |
+
if (hours > 0) {
|
| 53 |
+
return `${hours}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
|
| 54 |
+
}
|
| 55 |
+
return `${minutes}:${seconds.toString().padStart(2, '0')}`;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
// --- API: Search ---
|
| 59 |
+
// --- API: Search ---
|
| 60 |
+
app.post('/search', async (req, res) => {
|
| 61 |
+
try {
|
| 62 |
+
const { query } = req.body;
|
| 63 |
+
if (!query) return res.status(400).json({ results: [] });
|
| 64 |
+
|
| 65 |
+
const videoId = getVideoId(query.trim());
|
| 66 |
+
|
| 67 |
+
// --- METHOD 1: FOR URLs (Use MattW API) ---
|
| 68 |
+
if (videoId) {
|
| 69 |
+
console.log("URL detected. Using MattW API for ID:", videoId);
|
| 70 |
+
try {
|
| 71 |
+
const apiUrl = `https://ytapi.apps.mattw.io/v3/videos?key=foo1&part=snippet%2CcontentDetails&id=${videoId}`;
|
| 72 |
+
const response = await axios.get(apiUrl, {
|
| 73 |
+
headers: {
|
| 74 |
+
"Referer": "https://mattw.io/",
|
| 75 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
| 76 |
+
}
|
| 77 |
+
});
|
| 78 |
+
|
| 79 |
+
if (response.data.items && response.data.items.length > 0) {
|
| 80 |
+
const item = response.data.items[0];
|
| 81 |
+
return res.json({
|
| 82 |
+
results: [{
|
| 83 |
+
videoId: videoId,
|
| 84 |
+
title: item.snippet.title,
|
| 85 |
+
duration: parseDuration(item.contentDetails.duration), // Real duration!
|
| 86 |
+
channelName: item.snippet.channelTitle,
|
| 87 |
+
publishedAt: item.snippet.publishedAt,
|
| 88 |
+
thumbnail: [{ url: item.snippet.thumbnails.medium.url }]
|
| 89 |
+
}]
|
| 90 |
+
});
|
| 91 |
+
}
|
| 92 |
+
} catch (e) {
|
| 93 |
+
console.error("MattW URL fetch failed, using basic fallback");
|
| 94 |
+
return res.json({
|
| 95 |
+
results: [{
|
| 96 |
+
videoId: videoId,
|
| 97 |
+
title: "YouTube Video",
|
| 98 |
+
duration: "0:00",
|
| 99 |
+
channelName: "YouTube",
|
| 100 |
+
thumbnail: [{ url: `https://i.ytimg.com/vi/${videoId}/mqdefault.jpg` }]
|
| 101 |
+
}]
|
| 102 |
+
});
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
// --- METHOD 2: FOR TEXT SEARCH (Use Your Original Method) ---
|
| 107 |
+
console.log("Text search detected. Using Original Method:", query);
|
| 108 |
+
try {
|
| 109 |
+
const form = new FormData();
|
| 110 |
+
form.append('search_query', query);
|
| 111 |
+
|
| 112 |
+
const response = await axios.post('https://search.nnmn.store/', form, {
|
| 113 |
+
headers: {
|
| 114 |
+
...form.getHeaders(),
|
| 115 |
+
'accept': '*/*',
|
| 116 |
+
'origin': 'https://v6.www-y2mate.com',
|
| 117 |
+
'referer': 'https://v6.www-y2mate.com/',
|
| 118 |
+
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36'
|
| 119 |
+
},
|
| 120 |
+
timeout: 8000
|
| 121 |
+
});
|
| 122 |
+
|
| 123 |
+
const results = (response.data.items || []).map(item => ({
|
| 124 |
+
videoId: item.id,
|
| 125 |
+
title: item.title,
|
| 126 |
+
duration: item.duration, // Original method provides this (e.g., "4:19")
|
| 127 |
+
channelName: item.channelTitle || 'Unknown',
|
| 128 |
+
publishedAt: 'Recent',
|
| 129 |
+
thumbnail: [{ url: `https://i.ytimg.com/vi/${item.id}/mqdefault.jpg` }]
|
| 130 |
+
}));
|
| 131 |
+
|
| 132 |
+
return res.json({ results });
|
| 133 |
+
|
| 134 |
+
} catch (error) {
|
| 135 |
+
console.error('Original Search Method failed (403/Timeout):', error.message);
|
| 136 |
+
return res.json({
|
| 137 |
+
results: [],
|
| 138 |
+
error: "Search by name is blocked. Please paste a direct YouTube link."
|
| 139 |
+
});
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
} catch (error) {
|
| 143 |
+
console.error('Final Search Error:', error.message);
|
| 144 |
+
return res.json({ results: [] });
|
| 145 |
+
}
|
| 146 |
+
});
|
| 147 |
+
|
| 148 |
+
// --- API: Get Info ---
|
| 149 |
+
|
| 150 |
+
app.post('/get-info', async (req, res) => {
|
| 151 |
+
try {
|
| 152 |
+
const { url } = req.body;
|
| 153 |
+
const videoId = getVideoId(url);
|
| 154 |
+
|
| 155 |
+
if (!videoId) {
|
| 156 |
+
return res.status(400).json({ error: 'Invalid YouTube URL' });
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
console.log("Fetching Full Metadata for ID:", videoId);
|
| 160 |
+
|
| 161 |
+
try {
|
| 162 |
+
// Fetch real info from the same reliable API used in Search
|
| 163 |
+
const apiUrl = `https://ytapi.apps.mattw.io/v3/videos?key=foo1&part=snippet%2CcontentDetails&id=${videoId}`;
|
| 164 |
+
const response = await axios.get(apiUrl, {
|
| 165 |
+
headers: {
|
| 166 |
+
"Referer": "https://mattw.io/",
|
| 167 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
| 168 |
+
},
|
| 169 |
+
timeout: 5000
|
| 170 |
+
});
|
| 171 |
+
|
| 172 |
+
if (response.data.items && response.data.items.length > 0) {
|
| 173 |
+
const item = response.data.items[0];
|
| 174 |
+
|
| 175 |
+
return res.json({
|
| 176 |
+
status: 'success',
|
| 177 |
+
title: item.snippet.title,
|
| 178 |
+
thumbnail: item.snippet.thumbnails.maxres
|
| 179 |
+
? item.snippet.thumbnails.maxres.url
|
| 180 |
+
: item.snippet.thumbnails.high.url,
|
| 181 |
+
video_id: videoId,
|
| 182 |
+
duration: parseDuration(item.contentDetails.duration),
|
| 183 |
+
channel: item.snippet.channelTitle
|
| 184 |
+
});
|
| 185 |
+
}
|
| 186 |
+
} catch (apiErr) {
|
| 187 |
+
console.error("Metadata API failed, using fallback:", apiErr.message);
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
// --- FALLBACK (If API is down or video is restricted) ---
|
| 191 |
+
res.json({
|
| 192 |
+
status: 'success',
|
| 193 |
+
title: `YouTube Video (${videoId})`,
|
| 194 |
+
thumbnail: `https://i.ytimg.com/vi/${videoId}/maxresdefault.jpg`,
|
| 195 |
+
video_id: videoId,
|
| 196 |
+
duration: "0:00",
|
| 197 |
+
channel: "YouTube"
|
| 198 |
+
});
|
| 199 |
+
|
| 200 |
+
} catch (error) {
|
| 201 |
+
console.error('Get-Info Error:', error.message);
|
| 202 |
+
res.status(500).json({ error: 'Internal Server Error' });
|
| 203 |
+
}
|
| 204 |
+
});
|
| 205 |
+
// --- API: Download ---
|
| 206 |
+
app.post('/download', async (req, res) => {
|
| 207 |
+
const { url, type } = req.body;
|
| 208 |
+
const videoId = getVideoId(url);
|
| 209 |
+
if (!videoId) return res.status(400).json({ error: 'Invalid URL' });
|
| 210 |
+
|
| 211 |
+
const isVideo = type === 'video';
|
| 212 |
+
const ext = isVideo ? 'mp4' : 'mp3';
|
| 213 |
+
console.log(`Download request: ${videoId} (${ext})`);
|
| 214 |
+
|
| 215 |
+
try {
|
| 216 |
+
// Step 1: key (bound to this video id)
|
| 217 |
+
let apiKey;
|
| 218 |
+
try {
|
| 219 |
+
apiKey = await getSanityKey(videoId);
|
| 220 |
+
} catch (e) {
|
| 221 |
+
console.error('Key fetch failed:', e.response ? JSON.stringify(e.response.data) : e.message);
|
| 222 |
+
return res.status(503).json({ error: 'Converter key unavailable, try again in a moment' });
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
// Step 2: convert (same payload the y2mate frame uses)
|
| 226 |
+
const payload = new URLSearchParams({
|
| 227 |
+
link: `https://youtu.be/${videoId}`,
|
| 228 |
+
format: ext,
|
| 229 |
+
audioBitrate: "128",
|
| 230 |
+
videoQuality: "720",
|
| 231 |
+
filenameStyle: "pretty",
|
| 232 |
+
vCodec: "h264"
|
| 233 |
+
});
|
| 234 |
+
|
| 235 |
+
let downloadUrl, filename;
|
| 236 |
+
try {
|
| 237 |
+
const convertResp = await axios.post("https://cnv.cx/v2/converter", payload.toString(), {
|
| 238 |
+
headers: {
|
| 239 |
+
...API_HEADERS,
|
| 240 |
+
"key": apiKey,
|
| 241 |
+
"accept": "*/*",
|
| 242 |
+
"Content-Type": "application/x-www-form-urlencoded"
|
| 243 |
+
},
|
| 244 |
+
timeout: 120000
|
| 245 |
+
});
|
| 246 |
+
downloadUrl = convertResp.data && convertResp.data.url;
|
| 247 |
+
filename = convertResp.data && convertResp.data.filename;
|
| 248 |
+
if (!downloadUrl) console.error('Converter response without url:', JSON.stringify(convertResp.data));
|
| 249 |
+
} catch (e) {
|
| 250 |
+
console.error('Converter failed:', e.response ? JSON.stringify(e.response.data) : e.message);
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
// Fallback used by the y2mate frame when cnv.cx fails (mp3 only)
|
| 254 |
+
if (!downloadUrl && !isVideo) {
|
| 255 |
+
downloadUrl = `https://conv.mp3youtube.cc/download/${videoId}`;
|
| 256 |
+
}
|
| 257 |
+
if (!downloadUrl) {
|
| 258 |
+
return res.status(502).json({ error: 'Conversion failed. The video may be restricted or too long.' });
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
// Step 3: stream to client
|
| 262 |
+
const upstreamResponse = await axios({
|
| 263 |
+
method: 'GET',
|
| 264 |
+
url: downloadUrl,
|
| 265 |
+
responseType: 'stream',
|
| 266 |
+
headers: { ...API_HEADERS, "Accept": "*/*" },
|
| 267 |
+
timeout: 60000,
|
| 268 |
+
maxRedirects: 5
|
| 269 |
+
});
|
| 270 |
+
|
| 271 |
+
const safeName = (filename || `${videoId}.${ext}`).replace(/[\r\n"]/g, '').replace(/[^\x20-\x7E]/g, '_');
|
| 272 |
+
res.setHeader('Content-Type', isVideo ? 'video/mp4' : 'audio/mpeg');
|
| 273 |
+
res.setHeader('Content-Disposition', `attachment; filename="${safeName}"; filename*=UTF-8''${encodeURIComponent(filename || safeName)}`);
|
| 274 |
+
if (upstreamResponse.headers['content-length']) {
|
| 275 |
+
res.setHeader('Content-Length', upstreamResponse.headers['content-length']);
|
| 276 |
+
}
|
| 277 |
+
upstreamResponse.data.on('error', err => { console.error('Stream error:', err.message); res.end(); });
|
| 278 |
+
req.on('close', () => upstreamResponse.data.destroy());
|
| 279 |
+
upstreamResponse.data.pipe(res);
|
| 280 |
+
} catch (error) {
|
| 281 |
+
console.error('Download error:', error.response ? error.response.status : error.message);
|
| 282 |
+
if (!res.headersSent) res.status(500).json({ error: 'Download failed: ' + error.message });
|
| 283 |
+
}
|
| 284 |
+
});
|
| 285 |
+
|
| 286 |
+
const PORT = process.env.PORT || 7860;
|
| 287 |
+
app.listen(PORT, () => console.log(`Server running on port ${PORT}`));
|
app/templates/index.html
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>YT Downloader & Search</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
| 9 |
+
<style>
|
| 10 |
+
.loader {
|
| 11 |
+
border-top-color: #ef4444;
|
| 12 |
+
animation: spinner 1s linear infinite;
|
| 13 |
+
}
|
| 14 |
+
@keyframes spinner { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
|
| 15 |
+
.custom-scrollbar::-webkit-scrollbar { width: 6px; }
|
| 16 |
+
.custom-scrollbar::-webkit-scrollbar-track { background: #1f2937; }
|
| 17 |
+
.custom-scrollbar::-webkit-scrollbar-thumb { background: #4b5563; border-radius: 10px; }
|
| 18 |
+
</style>
|
| 19 |
+
</head>
|
| 20 |
+
<body class="bg-gray-900 text-white min-h-screen flex items-center justify-center p-4 font-sans">
|
| 21 |
+
|
| 22 |
+
<div class="w-full max-w-2xl bg-gray-800 rounded-2xl shadow-2xl overflow-hidden border border-gray-700 flex flex-col max-h-[90vh]">
|
| 23 |
+
|
| 24 |
+
<!-- Header -->
|
| 25 |
+
<div class="bg-gray-800 p-6 border-b border-gray-700">
|
| 26 |
+
<h1 class="text-2xl font-bold text-red-500 flex items-center justify-center gap-3">
|
| 27 |
+
<i class="fab fa-youtube"></i> YT Downloader Pro
|
| 28 |
+
</h1>
|
| 29 |
+
<p class="text-gray-400 text-center text-xs mt-1">Search keywords or paste YouTube URLs</p>
|
| 30 |
+
</div>
|
| 31 |
+
|
| 32 |
+
<!-- Input Section -->
|
| 33 |
+
<div class="p-6 space-y-4 flex-shrink-0">
|
| 34 |
+
<div class="relative">
|
| 35 |
+
<input type="text" id="urlInput" placeholder="Enter keywords or video link..."
|
| 36 |
+
class="w-full p-4 pl-12 bg-gray-900 border border-gray-600 rounded-xl focus:outline-none focus:border-red-500 text-white placeholder-gray-500 transition-all shadow-inner">
|
| 37 |
+
<i class="fas fa-search absolute left-4 top-5 text-gray-500"></i>
|
| 38 |
+
</div>
|
| 39 |
+
|
| 40 |
+
<button onclick="handleAction()" id="actionBtn"
|
| 41 |
+
class="w-full bg-red-600 hover:bg-red-700 text-white font-bold py-4 rounded-xl transition-all flex justify-center items-center gap-2 shadow-lg">
|
| 42 |
+
<span>Start Searching</span>
|
| 43 |
+
</button>
|
| 44 |
+
|
| 45 |
+
<div id="errorMsg" class="hidden text-center text-red-400 text-sm bg-red-900/20 p-3 rounded-lg border border-red-900/50"></div>
|
| 46 |
+
</div>
|
| 47 |
+
|
| 48 |
+
<!-- Results Area -->
|
| 49 |
+
<div id="resultsWrapper" class="hidden flex-1 overflow-y-auto p-6 custom-scrollbar bg-gray-900/50">
|
| 50 |
+
<div id="searchResults" class="grid grid-cols-1 gap-4">
|
| 51 |
+
<!-- Search Items Inject Here -->
|
| 52 |
+
</div>
|
| 53 |
+
|
| 54 |
+
<!-- Single Video View -->
|
| 55 |
+
<div id="singleResult" class="hidden space-y-6">
|
| 56 |
+
<div class="rounded-xl overflow-hidden shadow-2xl bg-gray-800 border border-gray-700">
|
| 57 |
+
<img id="mainThumb" src="" class="w-full aspect-video object-cover">
|
| 58 |
+
<div class="p-4">
|
| 59 |
+
<h3 id="mainTitle" class="text-lg font-bold line-clamp-2"></h3>
|
| 60 |
+
<p id="mainChannel" class="text-gray-400 text-sm mt-1"></p>
|
| 61 |
+
</div>
|
| 62 |
+
</div>
|
| 63 |
+
<div class="grid grid-cols-2 gap-4">
|
| 64 |
+
<button onclick="downloadMedia('audio')" class="bg-indigo-600 hover:bg-indigo-700 p-4 rounded-xl flex items-center justify-center gap-2 font-bold transition-all">
|
| 65 |
+
<i class="fas fa-music"></i> MP3
|
| 66 |
+
</button>
|
| 67 |
+
<button onclick="downloadMedia('video')" class="bg-emerald-600 hover:bg-emerald-700 p-4 rounded-xl flex items-center justify-center gap-2 font-bold transition-all">
|
| 68 |
+
<i class="fas fa-video"></i> MP4
|
| 69 |
+
</button>
|
| 70 |
+
</div>
|
| 71 |
+
</div>
|
| 72 |
+
</div>
|
| 73 |
+
|
| 74 |
+
<!-- Progress Overlay -->
|
| 75 |
+
<div id="statusOverlay" class="hidden absolute inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-50 rounded-2xl">
|
| 76 |
+
<div class="text-center">
|
| 77 |
+
<div class="loader ease-linear rounded-full border-4 border-gray-600 border-t-4 h-12 w-12 mx-auto mb-4"></div>
|
| 78 |
+
<p id="statusText" class="font-medium">Processing request...</p>
|
| 79 |
+
</div>
|
| 80 |
+
</div>
|
| 81 |
+
</div>
|
| 82 |
+
|
| 83 |
+
<script>
|
| 84 |
+
const API_BASE = window.location.origin;
|
| 85 |
+
let currentUrl = "";
|
| 86 |
+
|
| 87 |
+
function showStatus(text, show = true) {
|
| 88 |
+
const overlay = document.getElementById('statusOverlay');
|
| 89 |
+
const statusText = document.getElementById('statusText');
|
| 90 |
+
statusText.innerText = text;
|
| 91 |
+
overlay.classList.toggle('hidden', !show);
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
async function handleAction() {
|
| 95 |
+
const input = document.getElementById('urlInput').value.trim();
|
| 96 |
+
if (!input) return showError('Please enter keywords or a URL');
|
| 97 |
+
|
| 98 |
+
// Check if it's a URL
|
| 99 |
+
if (input.includes('youtube.com/') || input.includes('youtu.be/')) {
|
| 100 |
+
loadVideoDirect(input);
|
| 101 |
+
} else {
|
| 102 |
+
searchVideos(input);
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
async function searchVideos(query) {
|
| 107 |
+
const wrapper = document.getElementById('resultsWrapper');
|
| 108 |
+
const searchResults = document.getElementById('searchResults');
|
| 109 |
+
const singleResult = document.getElementById('singleResult');
|
| 110 |
+
|
| 111 |
+
showStatus('Searching...');
|
| 112 |
+
document.getElementById('errorMsg').classList.add('hidden');
|
| 113 |
+
|
| 114 |
+
try {
|
| 115 |
+
const response = await fetch(`${API_BASE}/search`, {
|
| 116 |
+
method: 'POST',
|
| 117 |
+
headers: { 'Content-Type': 'application/json' },
|
| 118 |
+
body: JSON.stringify({ query })
|
| 119 |
+
});
|
| 120 |
+
const data = await response.json();
|
| 121 |
+
|
| 122 |
+
if (!data.results || data.results.length === 0) throw new Error('No results found');
|
| 123 |
+
|
| 124 |
+
searchResults.innerHTML = '';
|
| 125 |
+
// Inside your searchVideos(query) function, update the forEach:
|
| 126 |
+
data.results.forEach(video => {
|
| 127 |
+
const thumb = video.thumbnail[0].url;
|
| 128 |
+
// Use encodeURIComponent or Base64 carefully for titles
|
| 129 |
+
const safeTitle = btoa(unescape(encodeURIComponent(video.title)));
|
| 130 |
+
searchResults.innerHTML += `
|
| 131 |
+
<div onclick="selectVideo('${video.videoId}', '${safeTitle}', '${thumb}')"
|
| 132 |
+
class="flex gap-4 p-3 bg-gray-800 hover:bg-gray-700 rounded-xl cursor-pointer transition-all border border-gray-700 group">
|
| 133 |
+
<div class="relative w-32 h-20 flex-shrink-0">
|
| 134 |
+
<img src="${thumb}" class="w-full h-full object-cover rounded-lg">
|
| 135 |
+
<span class="absolute bottom-1 right-1 bg-black/80 text-[10px] px-1 rounded">${video.duration}</span>
|
| 136 |
+
</div>
|
| 137 |
+
<div class="flex flex-col justify-between overflow-hidden">
|
| 138 |
+
<h4 class="text-sm font-bold line-clamp-2 group-hover:text-red-400">${video.title}</h4>
|
| 139 |
+
<p class="text-[11px] text-gray-500">${video.channelName}</p>
|
| 140 |
+
</div>
|
| 141 |
+
</div>
|
| 142 |
+
`;
|
| 143 |
+
});
|
| 144 |
+
|
| 145 |
+
searchResults.classList.remove('hidden');
|
| 146 |
+
singleResult.classList.add('hidden');
|
| 147 |
+
wrapper.classList.remove('hidden');
|
| 148 |
+
} catch (err) {
|
| 149 |
+
showError(err.message);
|
| 150 |
+
} finally {
|
| 151 |
+
showStatus('', false);
|
| 152 |
+
}
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
function selectVideo(id, titleBase64, thumb) {
|
| 156 |
+
const title = decodeURIComponent(escape(atob(titleBase64)));
|
| 157 |
+
currentUrl = `https://www.youtube.com/watch?v=${id}`;
|
| 158 |
+
|
| 159 |
+
document.getElementById('searchResults').classList.add('hidden');
|
| 160 |
+
document.getElementById('singleResult').classList.remove('hidden');
|
| 161 |
+
|
| 162 |
+
document.getElementById('mainThumb').src = thumb;
|
| 163 |
+
document.getElementById('mainTitle').innerText = title;
|
| 164 |
+
document.getElementById('mainChannel').innerText = "Ready to download";
|
| 165 |
+
|
| 166 |
+
// Scroll to top of results
|
| 167 |
+
document.getElementById('resultsWrapper').scrollTop = 0;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
async function loadVideoDirect(url) {
|
| 171 |
+
showStatus('Fetching video details...');
|
| 172 |
+
try {
|
| 173 |
+
const response = await fetch(`${API_BASE}/get-info`, {
|
| 174 |
+
method: 'POST',
|
| 175 |
+
headers: { 'Content-Type': 'application/json' },
|
| 176 |
+
body: JSON.stringify({ url })
|
| 177 |
+
});
|
| 178 |
+
const data = await response.json();
|
| 179 |
+
if (!response.ok) throw new Error(data.error);
|
| 180 |
+
|
| 181 |
+
currentUrl = url;
|
| 182 |
+
document.getElementById('searchResults').classList.add('hidden');
|
| 183 |
+
document.getElementById('singleResult').classList.remove('hidden');
|
| 184 |
+
document.getElementById('resultsWrapper').classList.remove('hidden');
|
| 185 |
+
|
| 186 |
+
document.getElementById('mainThumb').src = data.thumbnail;
|
| 187 |
+
document.getElementById('mainTitle').innerText = data.title;
|
| 188 |
+
document.getElementById('mainChannel').innerText = "Direct Link detected";
|
| 189 |
+
} catch (err) {
|
| 190 |
+
showError(err.message);
|
| 191 |
+
} finally {
|
| 192 |
+
showStatus('', false);
|
| 193 |
+
}
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
async function downloadMedia(type) {
|
| 197 |
+
showStatus(`Preparing ${type.toUpperCase()} stream...`);
|
| 198 |
+
try {
|
| 199 |
+
const response = await fetch(`${API_BASE}/download`, {
|
| 200 |
+
method: 'POST',
|
| 201 |
+
headers: { 'Content-Type': 'application/json' },
|
| 202 |
+
body: JSON.stringify({ url: currentUrl, type: type })
|
| 203 |
+
});
|
| 204 |
+
|
| 205 |
+
if (!response.ok) {
|
| 206 |
+
const err = await response.json();
|
| 207 |
+
throw new Error(err.error || 'Server conversion failed');
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
showStatus('Downloading to device...');
|
| 211 |
+
const blob = await response.blob();
|
| 212 |
+
const downloadUrl = window.URL.createObjectURL(blob);
|
| 213 |
+
const a = document.createElement('a');
|
| 214 |
+
a.href = downloadUrl;
|
| 215 |
+
|
| 216 |
+
const disposition = response.headers.get('Content-Disposition');
|
| 217 |
+
let filename = `yt_download_${Date.now()}.${type === 'video' ? 'mp4' : 'mp3'}`;
|
| 218 |
+
if (disposition && disposition.includes('filename=')) {
|
| 219 |
+
filename = disposition.split('filename=')[1].replace(/"/g, '');
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
a.download = filename;
|
| 223 |
+
document.body.appendChild(a);
|
| 224 |
+
a.click();
|
| 225 |
+
a.remove();
|
| 226 |
+
} catch (err) {
|
| 227 |
+
showError(err.message);
|
| 228 |
+
} finally {
|
| 229 |
+
showStatus('', false);
|
| 230 |
+
}
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
function showError(msg) {
|
| 234 |
+
const errorDiv = document.getElementById('errorMsg');
|
| 235 |
+
errorDiv.innerText = msg;
|
| 236 |
+
errorDiv.classList.remove('hidden');
|
| 237 |
+
setTimeout(() => errorDiv.classList.add('hidden'), 5000);
|
| 238 |
+
}
|
| 239 |
+
</script>
|
| 240 |
+
</body>
|
| 241 |
+
</html>
|
package.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "proxy-downloader",
|
| 3 |
+
"version": "1.0.0",
|
| 4 |
+
"main": "app/index.js",
|
| 5 |
+
"scripts": {
|
| 6 |
+
"start": "node app/index.js"
|
| 7 |
+
},
|
| 8 |
+
"dependencies": {
|
| 9 |
+
"express": "^4.18.2",
|
| 10 |
+
"axios": "^1.6.2",
|
| 11 |
+
"cors": "^2.8.5"
|
| 12 |
+
}
|
| 13 |
+
}
|