UNPKG

summarizely-cli

Version:

YouTube summarizer that respects your existing subscriptions. No API keys required.

70 lines 2.28 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.toIsoCompact = toIsoCompact; exports.ensureDir = ensureDir; exports.writeToLatestDir = writeToLatestDir; exports.tmpDir = tmpDir; exports.youtubeIdFromUrl = youtubeIdFromUrl; const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const os_1 = __importDefault(require("os")); function toIsoCompact(d = new Date()) { // YYYY-MM-DDTHH-mm-ssZ return d.toISOString().replace(/:/g, '-'); } function ensureDir(dir) { fs_1.default.mkdirSync(dir, { recursive: true }); } function writeToLatestDir(outputDir, files) { try { const latestDir = path_1.default.join(outputDir, '_latest'); // Clean and recreate the _latest directory try { fs_1.default.rmSync(latestDir, { recursive: true, force: true }); } catch { } ensureDir(latestDir); // Copy all specified files for (const file of files) { try { fs_1.default.copyFileSync(file.source, path_1.default.join(latestDir, file.name)); } catch { // Individual file copy failures don't stop the process } } } catch { // Failing to update _latest is not critical } } function tmpDir(prefix) { return fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), prefix)); } function youtubeIdFromUrl(u) { try { const url = new URL(u); if (url.hostname === 'youtu.be') return url.pathname.slice(1) || null; if (/(^|\.)youtube\.com$/.test(url.hostname)) { // Check for watch?v= format const v = url.searchParams.get('v'); if (v) return v; // Check for /embed/ format if (url.pathname.startsWith('/embed/')) { const id = url.pathname.slice(7).split('/')[0]; return id || null; } return null; } return null; } catch { return null; } } //# sourceMappingURL=utils.js.map