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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="vi">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="utf-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
| 6 |
+
<title>Collect VTV Nam Bộ Shorts</title>
|
| 7 |
+
<style>
|
| 8 |
+
body{background:#111;color:#eee;font-family:monospace;padding:20px;max-width:900px;margin:0 auto}
|
| 9 |
+
h1{color:#f0c040;font-size:18px;margin-bottom:10px}
|
| 10 |
+
input,button,textarea{font-family:monospace;font-size:13px}
|
| 11 |
+
input{width:100%;padding:8px;background:#222;border:1px solid #444;color:#eee;border-radius:6px;margin:6px 0}
|
| 12 |
+
button{background:#0b6bcb;border:none;color:#fff;padding:10px 20px;border-radius:6px;cursor:pointer;margin:4px}
|
| 13 |
+
button:hover{background:#1a7be0}
|
| 14 |
+
textarea{width:100%;height:300px;background:#222;border:1px solid #444;color:#5cb87a;border-radius:6px;padding:8px;margin:6px 0;resize:vertical}
|
| 15 |
+
.status{padding:10px;background:#1a1a1a;border-radius:6px;margin:10px 0;white-space:pre-wrap;font-size:12px}
|
| 16 |
+
.short-item{padding:6px 10px;background:#1a1a1a;border-radius:4px;margin:4px 0;display:flex;gap:8px;align-items:center}
|
| 17 |
+
.short-item img{width:60px;height:106px;object-fit:cover;border-radius:4px;background:#333}
|
| 18 |
+
.short-item .info{flex:1}
|
| 19 |
+
.short-item .title{font-size:12px;color:#ccc}
|
| 20 |
+
.short-item .id{font-size:10px;color:#777}
|
| 21 |
+
</style>
|
| 22 |
+
</head>
|
| 23 |
+
<body>
|
| 24 |
+
<h1>📱 Collect YouTube Shorts from @vtvnambo</h1>
|
| 25 |
+
<p style="color:#888;font-size:12px">Tool này sẽ fetch trang YouTube của VTV Nam Bộ và extract tất cả shorts. Chạy trên browser của bạn (không qua server).</p>
|
| 26 |
+
|
| 27 |
+
<input type="text" id="proxyUrl" placeholder="CORS proxy (leave empty to try direct)" value="">
|
| 28 |
+
<button onclick="collectShorts()">🚀 Collect Shorts</button>
|
| 29 |
+
<button onclick="collectFromVideos()">📹 Collect from /videos (duration filter)</button>
|
| 30 |
+
<button onclick="exportJSON()">📋 Export JSON</button>
|
| 31 |
+
<button onclick="exportJS()">📄 Export JS Array</button>
|
| 32 |
+
|
| 33 |
+
<div class="status" id="status">Ready...</div>
|
| 34 |
+
<div id="results"></div>
|
| 35 |
+
|
| 36 |
+
<script>
|
| 37 |
+
let collectedShorts = [];
|
| 38 |
+
|
| 39 |
+
async function fetchPage(url, useProxy = false) {
|
| 40 |
+
const el = document.getElementById('status');
|
| 41 |
+
el.textContent = `Fetching: ${url}...`;
|
| 42 |
+
|
| 43 |
+
let fetchUrl = url;
|
| 44 |
+
const proxy = document.getElementById('proxyUrl').value.trim();
|
| 45 |
+
if (proxy) {
|
| 46 |
+
fetchUrl = proxy + encodeURIComponent(url);
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
try {
|
| 50 |
+
const r = await fetch(fetchUrl, {
|
| 51 |
+
headers: {
|
| 52 |
+
'Accept': 'text/html,*/*'
|
| 53 |
+
},
|
| 54 |
+
signal: AbortSignal.timeout(15000)
|
| 55 |
+
});
|
| 56 |
+
if (!r.ok) throw new Error(`HTTP ${r.status}`);
|
| 57 |
+
return await r.text();
|
| 58 |
+
} catch(e) {
|
| 59 |
+
el.textContent += `\nError: ${e.message}`;
|
| 60 |
+
throw e;
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
function extractShortsFromHTML(html) {
|
| 65 |
+
const shorts = [];
|
| 66 |
+
const seen = new Set();
|
| 67 |
+
|
| 68 |
+
// Pattern 1: videoId in JSON data
|
| 69 |
+
const patterns = [
|
| 70 |
+
/"videoId":"([A-Za-z0-9_-]{11})"/g,
|
| 71 |
+
/"videoId"\s*:\s*"([A-Za-z0-9_-]{11})"/g,
|
| 72 |
+
/watch\?v=([A-Za-z0-9_-]{11})/g,
|
| 73 |
+
/\/shorts\/([A-Za-z0-9_-]{11})/g
|
| 74 |
+
];
|
| 75 |
+
|
| 76 |
+
for (const pattern of patterns) {
|
| 77 |
+
let m;
|
| 78 |
+
while ((m = pattern.exec(html)) !== null) {
|
| 79 |
+
const vid = m[1];
|
| 80 |
+
if (seen.has(vid)) continue;
|
| 81 |
+
seen.add(vid);
|
| 82 |
+
|
| 83 |
+
// Try to find title near this video ID
|
| 84 |
+
const start = Math.max(0, m.index - 1500);
|
| 85 |
+
const end = Math.min(html.length, m.index + 1500);
|
| 86 |
+
const snippet = html.substring(start, end);
|
| 87 |
+
|
| 88 |
+
let title = "VTV Nam Bộ Short";
|
| 89 |
+
const titleMatch = snippet.match(/"title"\s*:\s*\{"runs"\s*:\s*\[\{"text"\s*:\s*"([^"]+)"/);
|
| 90 |
+
if (titleMatch) {
|
| 91 |
+
title = titleMatch[1].replace(/\\n/g, ' ').replace(/\\"/g, '"').trim();
|
| 92 |
+
} else {
|
| 93 |
+
const titleMatch2 = snippet.match(/"title"\s*:\s*"([^"]+)"/);
|
| 94 |
+
if (titleMatch2) {
|
| 95 |
+
title = titleMatch2[1].replace(/\\n/g, ' ').trim();
|
| 96 |
+
} else {
|
| 97 |
+
const titleMatch3 = snippet.match(/"accessibilityText"\s*:\s*"([^"]+)"/);
|
| 98 |
+
if (titleMatch3) {
|
| 99 |
+
title = titleMatch3[1].replace(/\\n/g, ' ').trim();
|
| 100 |
+
}
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
// Check if page is shorts page
|
| 105 |
+
const isShortsPage = html.includes('/shorts/') || html.includes('"shorts"');
|
| 106 |
+
const titleLower = title.toLowerCase();
|
| 107 |
+
const isShort = isShortsPage || titleLower.includes('#shorts') || titleLower.includes('#short');
|
| 108 |
+
|
| 109 |
+
shorts.push({
|
| 110 |
+
id: vid,
|
| 111 |
+
title: title,
|
| 112 |
+
channel: 'vtvnambo',
|
| 113 |
+
img: `https://i.ytimg.com/vi/${vid}/hqdefault.jpg`,
|
| 114 |
+
isShort: isShort
|
| 115 |
+
});
|
| 116 |
+
}
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
return shorts;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
async function collectShorts() {
|
| 123 |
+
const el = document.getElementById('status');
|
| 124 |
+
collectedShorts = [];
|
| 125 |
+
|
| 126 |
+
try {
|
| 127 |
+
// Try shorts page
|
| 128 |
+
const html = await fetchPage('https://www.youtube.com/@vtvnambo/shorts');
|
| 129 |
+
const shorts = extractShortsFromHTML(html);
|
| 130 |
+
collectedShorts = shorts;
|
| 131 |
+
|
| 132 |
+
el.textContent = `Found ${shorts.length} videos from /shorts page`;
|
| 133 |
+
displayResults(shorts);
|
| 134 |
+
} catch(e) {
|
| 135 |
+
el.textContent += `\nFailed. Try using a CORS proxy like https://corsproxy.io/?`;
|
| 136 |
+
}
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
async function collectFromVideos() {
|
| 140 |
+
const el = document.getElementById('status');
|
| 141 |
+
collectedShorts = [];
|
| 142 |
+
|
| 143 |
+
try {
|
| 144 |
+
const html = await fetchPage('https://www.youtube.com/@vtvnambo/videos');
|
| 145 |
+
const all = extractShortsFromHTML(html);
|
| 146 |
+
|
| 147 |
+
// First page might have limited results, try to find continuation
|
| 148 |
+
collectedShorts = all;
|
| 149 |
+
|
| 150 |
+
el.textContent = `Found ${all.length} videos from /videos page`;
|
| 151 |
+
displayResults(all);
|
| 152 |
+
} catch(e) {
|
| 153 |
+
el.textContent += `\nFailed. Try using a CORS proxy.`;
|
| 154 |
+
}
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
function displayResults(shorts) {
|
| 158 |
+
const el = document.getElementById('results');
|
| 159 |
+
let h = `<h3 style="color:#5cb87a;margin:10px 0">${shorts.length} shorts found:</h3>`;
|
| 160 |
+
|
| 161 |
+
shorts.forEach(s => {
|
| 162 |
+
h += `<div class="short-item">
|
| 163 |
+
<img src="${s.img}" onerror="this.style.background='#333'">
|
| 164 |
+
<div class="info">
|
| 165 |
+
<div class="title">${s.isShort ? '📱' : '🎬'} ${s.title}</div>
|
| 166 |
+
<div class="id">${s.id}</div>
|
| 167 |
+
</div>
|
| 168 |
+
</div>`;
|
| 169 |
+
});
|
| 170 |
+
|
| 171 |
+
el.innerHTML = h;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
function exportJSON() {
|
| 175 |
+
if (!collectedShorts.length) return alert('Chưa collect được shorts nào!');
|
| 176 |
+
const json = JSON.stringify(collectedShorts, null, 2);
|
| 177 |
+
document.getElementById('status').textContent = json;
|
| 178 |
+
navigator.clipboard.writeText(json).then(() => alert('Đã copy JSON!'));
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
function exportJS() {
|
| 182 |
+
if (!collectedShorts.length) return alert('Chưa collect được shorts nào!');
|
| 183 |
+
let js = 'const VTV_SHORTS = [\n';
|
| 184 |
+
collectedShorts.forEach(s => {
|
| 185 |
+
js += ` {"id":"${s.id}","title":${JSON.stringify(s.title)},"channel":"vtvnambo"},\n`;
|
| 186 |
+
});
|
| 187 |
+
js += '];';
|
| 188 |
+
document.getElementById('status').textContent = js;
|
| 189 |
+
navigator.clipboard.writeText(js).then(() => alert('Đã copy JS!'));
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
// Auto-collect on load
|
| 193 |
+
setTimeout(collectShorts, 500);
|
| 194 |
+
</script>
|
| 195 |
+
</body>
|
| 196 |
+
</html>
|