52 lines
1.5 KiB
JavaScript
52 lines
1.5 KiB
JavaScript
import fs from "fs";
|
|
import path from "path";
|
|
import { fileURLToPath } from "url";
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
|
const seccionesDir = path.join(__dirname, "descargas", "secciones");
|
|
const videosOfflineDir = path.join(__dirname, "descargas", "videos_offline");
|
|
const mapaPath = path.join(__dirname, ".mapa_videos.json");
|
|
|
|
if (!fs.existsSync(videosOfflineDir)) fs.mkdirSync(videosOfflineDir, { recursive: true });
|
|
|
|
let mapa = {};
|
|
try {
|
|
if (fs.existsSync(mapaPath)) {
|
|
mapa = JSON.parse(fs.readFileSync(mapaPath, "utf-8"));
|
|
}
|
|
} catch (e) {}
|
|
|
|
// Find all MX_video_*.mp4 in secciones
|
|
function findVideos(dir) {
|
|
let results = [];
|
|
const list = fs.readdirSync(dir);
|
|
for (const file of list) {
|
|
const filePath = path.join(dir, file);
|
|
const stat = fs.statSync(filePath);
|
|
if (stat && stat.isDirectory()) {
|
|
results = results.concat(findVideos(filePath));
|
|
} else if (file.startsWith("MX_video_") ) {
|
|
results.push(filePath);
|
|
}
|
|
}
|
|
return results;
|
|
}
|
|
|
|
const videos = findVideos(seccionesDir);
|
|
for (const vidPath of videos) {
|
|
const filename = path.basename(vidPath);
|
|
// Extact ID: MX_video_1175436659.mp4
|
|
const match = filename.match(/MX_video_(\d+)/);
|
|
if (match) {
|
|
const vimeoID = match[1];
|
|
const newPath = path.join(videosOfflineDir, filename);
|
|
fs.renameSync(vidPath, newPath);
|
|
console.log(`Movido: ${filename} a videos_offline`);
|
|
mapa[vimeoID] = filename;
|
|
}
|
|
}
|
|
|
|
fs.writeFileSync(mapaPath, JSON.stringify(mapa, null, 2));
|
|
console.log("Mapa de videos actualizado.");
|