Compare commits

..
6 Commits
5 changed files with 3992 additions and 180 deletions
+55
View File
@@ -0,0 +1,55 @@
name: Publish PeerTube Plugin to npm
on:
push:
branches:
- main
- master
tags:
- 'v*'
release:
types:
- published
workflow_dispatch:
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '24'
- name: Syntax check main plugin entrypoint
run: node --check main.js
- name: Check npm version and publish if new
shell: bash
env:
NPM_TOKEN_SECRET: ${{ secrets.NPM_TOKEN }}
run: |
PKG_NAME=$(node -p "require('./package.json').name")
PKG_VER=$(node -p "require('./package.json').version")
PUBLISHED=$(npm view "${PKG_NAME}@${PKG_VER}" version 2>/dev/null || true)
if [ "$PUBLISHED" = "$PKG_VER" ]; then
echo "Version ${PKG_VER} of ${PKG_NAME} is already on npm. Skipping publish."
exit 0
fi
if [ -n "$NPM_TOKEN_SECRET" ]; then
printf "//registry.npmjs.org/:_authToken=%s\n" "$NPM_TOKEN_SECRET" > ~/.npmrc
npm publish --access public
else
npm install -g npm@latest
npm -v
npm publish --provenance --access public
fi
+2610 -151
View File
File diff suppressed because it is too large Load Diff
+586 -17
View File
@@ -2999,6 +2999,333 @@ async function register({ registerHook, getRouter, registerSetting, settingsMana
const videoOriginCache = new Map();
const VIDEO_ORIGIN_CACHE_TTL_MS = 10 * 60 * 1000;
const transcriptMemoryCache = new Map();
const inFlightTranscriptRequests = new Map();
const TRANSCRIPT_OK_TTL_MS = 12 * 60 * 60 * 1000;
const TRANSCRIPT_EMPTY_TTL_MS = 10 * 60 * 1000;
function resolveTranscriptStorageRoot() {
try {
if (
peertubeHelpers &&
peertubeHelpers.plugin &&
typeof peertubeHelpers.plugin.getDataDirectoryPath === 'function'
) {
const dataDir = peertubeHelpers.plugin.getDataDirectoryPath();
const candidate = path.resolve(dataDir, '..', '..', '..');
if (fs.existsSync(candidate)) return candidate;
}
} catch (e) {}
if (fs.existsSync('D:\\yaktube_storage')) return 'D:\\yaktube_storage';
return process.cwd();
}
function extractYouTubeIdFromText(str) {
if (!str || typeof str !== 'string') return null;
const match =
str.match(/[?&]v=([a-zA-Z0-9_-]{11})/) ||
str.match(/youtu\.be\/([a-zA-Z0-9_-]{11})/) ||
str.match(/shorts\/([a-zA-Z0-9_-]{11})/) ||
str.match(/embed\/([a-zA-Z0-9_-]{11})/);
return match ? match[1] : null;
}
function extractYouTubeIdFromRow(row) {
if (!row) return null;
return extractYouTubeIdFromText(row.targetUrl) || extractYouTubeIdFromText(row.description);
}
function fetchRemoteTextWithLimit(targetUrl, timeoutMs = 9000, maxRedirects = 4, maxBytes = 4 * 1024 * 1024) {
return new Promise((resolve, reject) => {
if (maxRedirects <= 0) return reject(new Error('Too many redirects'));
let parsed;
try {
parsed = new URL(targetUrl);
} catch (e) {
return reject(e);
}
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
return reject(new Error('Unsupported protocol'));
}
const lib = parsed.protocol === 'https:' ? https : http;
const req = lib.get(
targetUrl,
{
timeout: timeoutMs,
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/131.0.0.0 Safari/537.36',
Accept: 'application/json, text/vtt, text/plain, */*'
}
},
res => {
if ([301, 302, 307, 308].includes(res.statusCode) && res.headers.location) {
res.resume();
const nextUrl = new URL(res.headers.location, targetUrl).toString();
return resolve(fetchRemoteTextWithLimit(nextUrl, timeoutMs, maxRedirects - 1, maxBytes));
}
if (res.statusCode !== 200) {
res.resume();
return reject(new Error('HTTP ' + res.statusCode));
}
const chunks = [];
let received = 0;
res.on('data', chunk => {
received += chunk.length;
if (received > maxBytes) {
req.destroy(new Error('Response too large'));
return;
}
chunks.push(chunk);
});
res.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
res.on('error', reject);
}
);
req.on('timeout', () => req.destroy(new Error('Timeout')));
req.on('error', reject);
});
}
function parseTimeTokenToSeconds(token) {
if (!token || typeof token !== 'string') return NaN;
const parts = token.trim().replace(',', '.').split(':');
if (parts.length === 2) {
const m = parseInt(parts[0], 10);
const s = parseFloat(parts[1]);
if (isNaN(m) || isNaN(s)) return NaN;
return m * 60 + s;
}
if (parts.length === 3) {
const h = parseInt(parts[0], 10);
const m = parseInt(parts[1], 10);
const s = parseFloat(parts[2]);
if (isNaN(h) || isNaN(m) || isNaN(s)) return NaN;
return h * 3600 + m * 60 + s;
}
return NaN;
}
function decodeSubtitleEntities(str) {
return String(str || '')
.replace(/<\d{2}:\d{2}(?::\d{2})?\.\d+>/g, '')
.replace(/<\/?[^>]+(>|$)/g, ' ')
.replace(/&amp;/g, '&')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&quot;/g, '"')
.replace(/&#39;|&apos;/g, "'")
.replace(/&nbsp;/g, ' ')
.replace(/\s+/g, ' ')
.trim();
}
function parseChaptersFromDescription(description, maxDurationSec) {
if (!description || typeof description !== 'string') return [];
const lines = description.split(/\r?\n/);
const seenStarts = new Set();
const chapters = [];
for (const rawLine of lines) {
const line = rawLine.trim();
if (!line || line.length > 220) continue;
const mPrefix = line.match(/^[\[\(\*•\-–—\s]*((?:\d{1,2}:)?\d{1,2}:\d{2})[\]\)\*:\-\s–—]+(.+)$/);
const mSuffix = !mPrefix ? line.match(/^(.+?)[\s\-\–—:\(\[]+((?:\d{1,2}:)?\d{1,2}:\d{2})[\)\]\s]*$/) : null;
const timeStr = mPrefix ? mPrefix[1] : mSuffix ? mSuffix[2] : null;
let title = mPrefix ? mPrefix[2] : mSuffix ? mSuffix[1] : '';
if (!timeStr) continue;
const startSec = Math.floor(parseTimeTokenToSeconds(timeStr));
if (isNaN(startSec) || startSec < 0) continue;
if (maxDurationSec > 0 && startSec > maxDurationSec + 5) continue;
title = title.replace(/^[\-\–—:\s•]+|[\-\–—:\s•]+$/g, '').trim();
if (!title || title.length < 2) continue;
if (seenStarts.has(startSec)) continue;
seenStarts.add(startSec);
chapters.push({ title, start: startSec });
}
chapters.sort((a, b) => a.start - b.start);
return chapters.length >= 2 ? chapters : [];
}
function parseJson3Subtitles(rawText) {
const parsed = JSON.parse(rawText);
const events = Array.isArray(parsed && parsed.events) ? parsed.events : [];
const cues = [];
for (const ev of events) {
if (!ev || !Array.isArray(ev.segs)) continue;
const text = ev.segs
.map(s => (s && s.utf8 ? s.utf8 : ''))
.join('')
.replace(/\n+/g, ' ');
const clean = decodeSubtitleEntities(text);
if (!clean || clean === '[Müzik]' || clean === '[Music]') {
if (!clean) continue;
}
const start = Number(((ev.tStartMs || 0) / 1000).toFixed(2));
const dur = ev.dDurationMs ? ev.dDurationMs / 1000 : 3;
const end = Number((start + Math.max(0.5, dur)).toFixed(2));
if (
cues.length > 0 &&
cues[cues.length - 1].text === clean &&
Math.abs(start - cues[cues.length - 1].start) < 2
) {
cues[cues.length - 1].end = Math.max(cues[cues.length - 1].end, end);
continue;
}
cues.push({ start, end, text: clean });
}
return cues;
}
function parseVttOrSrtSubtitles(rawText) {
const normalized = String(rawText || '')
.replace(/^\uFEFF/, '')
.replace(/\r\n/g, '\n')
.replace(/\r/g, '\n');
const blocks = normalized.split(/\n{2,}/);
const cues = [];
for (const block of blocks) {
const lines = block
.split('\n')
.map(l => l.trim())
.filter(Boolean);
if (!lines.length) continue;
if (/^(WEBVTT|Kind:|Language:|NOTE\b|STYLE\b)/i.test(lines[0])) continue;
const timeIdx = lines.findIndex(l => l.includes('-->'));
if (timeIdx === -1) continue;
const parts = lines[timeIdx].split('-->');
if (parts.length < 2) continue;
const start = parseTimeTokenToSeconds(parts[0].trim().split(/\s+/)[0]);
const end = parseTimeTokenToSeconds(parts[1].trim().split(/\s+/)[0]);
if (isNaN(start)) continue;
const rawBody = lines.slice(timeIdx + 1).join(' ');
const clean = decodeSubtitleEntities(rawBody);
if (!clean) continue;
const safeStart = Number(start.toFixed(2));
const safeEnd = Number((!isNaN(end) && end > start ? end : start + 3).toFixed(2));
if (cues.length > 0 && cues[cues.length - 1].text === clean) {
cues[cues.length - 1].end = Math.max(cues[cues.length - 1].end, safeEnd);
continue;
}
cues.push({ start: safeStart, end: safeEnd, text: clean });
}
return cues;
}
function parseSubtitlePayload(rawText) {
if (!rawText || typeof rawText !== 'string') return [];
const trimmed = rawText.trim();
if (!trimmed) return [];
if (trimmed.startsWith('{')) {
try {
return parseJson3Subtitles(trimmed);
} catch (e) {}
}
return parseVttOrSrtSubtitles(trimmed);
}
function pickPreferredCaptionTrack(ytInfo, preferredLang, videoLang) {
const manual = ytInfo && ytInfo.subtitles && typeof ytInfo.subtitles === 'object' ? ytInfo.subtitles : {};
const auto =
ytInfo && ytInfo.automatic_captions && typeof ytInfo.automatic_captions === 'object'
? ytInfo.automatic_captions
: {};
const pickFormat = tracks => {
for (const ext of ['json3', 'vtt', 'srt']) {
const hit = tracks.find(t => t && t.ext === ext && t.url);
if (hit) return hit;
}
return tracks.find(t => t && t.url) || null;
};
const isTranslatedUrl = url => Boolean(url && String(url).includes('tlang='));
const hasNativeTrack = tracks => tracks.some(t => t && t.url && !isTranslatedUrl(t.url));
const availableLanguages = [];
const seenLangCodes = new Set();
const pushLang = (code, tracks, isAuto) => {
if (!code || code === 'live_chat' || seenLangCodes.has(code) || !Array.isArray(tracks) || !tracks.length) return;
seenLangCodes.add(code);
availableLanguages.push({
code,
name: tracks[0].name || code,
auto: isAuto
});
};
// 1. Always surface manual subtitles & native (-orig / non-tlang) auto tracks first
for (const code of Object.keys(manual)) pushLang(code, manual[code], false);
for (const code of Object.keys(auto)) {
if (code.endsWith('-orig') || hasNativeTrack(auto[code] || [])) {
pushLang(code, auto[code], true);
}
}
for (const code of ['tr', 'en', 'de', 'fr', 'es', 'ar']) {
if (auto[code]) pushLang(code, auto[code], true);
}
const req = preferredLang ? String(preferredLang).trim().toLowerCase() : '';
const vLang = videoLang ? String(videoLang).trim().toLowerCase() : '';
const candidates = [];
const addedCandidateKeys = new Set();
const pushCandidate = (code, isAuto, tracks) => {
const track = pickFormat(tracks || []);
if (!track || !track.url) return;
const key = (isAuto ? 'a:' : 'm:') + code;
if (addedCandidateKeys.has(key)) return;
addedCandidateKeys.add(key);
candidates.push({ code, isAuto, track });
};
const matchKey = (keys, lang) =>
lang ? keys.find(k => k.toLowerCase() === lang) || keys.find(k => k.toLowerCase().startsWith(lang + '-')) : null;
const manualKeys = Object.keys(manual).filter(
k => k !== 'live_chat' && Array.isArray(manual[k]) && manual[k].length
);
const autoKeys = Object.keys(auto).filter(k => k !== 'live_chat' && Array.isArray(auto[k]) && auto[k].length);
// 2. Manual tracks in priority order
for (const p of [req, 'tr', vLang, 'en', 'en-US', 'en-GB']) {
const mk = matchKey(manualKeys, p);
if (mk) pushCandidate(mk, false, manual[mk]);
}
if (manualKeys.length > 0 && !req) {
pushCandidate(manualKeys[0], false, manual[manualKeys[0]]);
}
// 3. If explicit language requested in auto, add it (non-tlang checked below first if same)
const nativeAutoKeys = autoKeys.filter(k => k.endsWith('-orig') || hasNativeTrack(auto[k]));
if (req) {
const akNative = matchKey(nativeAutoKeys, req);
if (akNative) pushCandidate(akNative, true, auto[akNative]);
}
// 4. Native ASR tracks WITHOUT tlang= (prevents YouTube HTTP 429 rate-limit!)
for (const p of ['tr', vLang, 'en']) {
const nk = matchKey(nativeAutoKeys, p);
if (nk) pushCandidate(nk, true, auto[nk]);
}
for (const nk of nativeAutoKeys) {
pushCandidate(nk, true, auto[nk]);
}
// 5. Fallback translated auto track only if explicitly requested or zero native candidates exist
if (req) {
const akReq = matchKey(autoKeys, req);
if (akReq) pushCandidate(akReq, true, auto[akReq]);
} else if (candidates.length === 0) {
for (const p of ['tr', vLang, 'en']) {
const ak = matchKey(autoKeys, p);
if (ak) pushCandidate(ak, true, auto[ak]);
}
}
return {
chosen: candidates[0] || null,
candidates: candidates.slice(0, 4),
availableLanguages: availableLanguages.slice(0, 12)
};
}
router.get('/video-origin/:uuid', async (req, res) => {
if (isCrawlerBotRequest(req)) {
@@ -3042,23 +3369,7 @@ async function register({ registerHook, getRouter, registerSetting, settingsMana
}
const row = rows[0];
let youtubeId = null;
if (row.targetUrl) {
const match =
row.targetUrl.match(/[?&]v=([^&]+)/) ||
row.targetUrl.match(/youtu\.be\/([^?]+)/) ||
row.targetUrl.match(/shorts\/([^?]+)/);
if (match) youtubeId = match[1];
}
if (!youtubeId && row.description) {
const match =
row.description.match(/youtube\.com\/watch\?v=([a-zA-Z0-9_-]{11})/) ||
row.description.match(/youtu\.be\/([a-zA-Z0-9_-]{11})/) ||
row.description.match(/shorts\/([a-zA-Z0-9_-]{11})/);
if (match) youtubeId = match[1];
}
const youtubeId = extractYouTubeIdFromRow(row);
const payload = {
ok: true,
@@ -3076,6 +3387,264 @@ async function register({ registerHook, getRouter, registerSetting, settingsMana
}
});
// 6b. Akıllı Transkript & Bölüm (Chapters) Çekici
router.get('/video-transcript/:uuid', async (req, res) => {
if (isCrawlerBotRequest(req)) {
return res.json({ ok: false, botIgnored: true, cues: [], chapters: [] });
}
const rawParam = (req.params.uuid || '').trim();
if (!rawParam) return res.status(400).json({ ok: false, error: 'UUID required' });
const resolvedUuid = shortToUuid(rawParam);
const reqLang = String(req.query.lang || '')
.trim()
.toLowerCase();
const forceRefresh = req.query.refresh === '1' || req.query.refresh === 'true';
const queryYtId =
req.query.youtubeId && /^[a-zA-Z0-9_-]{11}$/.test(String(req.query.youtubeId).trim())
? String(req.query.youtubeId).trim()
: null;
const cacheKey = `${resolvedUuid}__${reqLang || 'auto'}__${queryYtId || 'db'}`;
if (!forceRefresh) {
const memHit = transcriptMemoryCache.get(cacheKey);
if (memHit) {
const ttl = memHit.hasContent ? TRANSCRIPT_OK_TTL_MS : TRANSCRIPT_EMPTY_TTL_MS;
if (Date.now() - memHit.time < ttl) {
return res.json(memHit.payload);
}
}
}
const storageRoot = resolveTranscriptStorageRoot();
const transcriptCacheDir = path.join(storageRoot, 'cache', 'transcripts');
const diskCachePath = path.join(
transcriptCacheDir,
`${resolvedUuid.replace(/[^a-zA-Z0-9_-]/g, '_')}_${reqLang || 'auto'}.json`
);
if (!forceRefresh && fs.existsSync(diskCachePath)) {
try {
const st = await fs.promises.stat(diskCachePath);
if (Date.now() - st.mtimeMs < 7 * 24 * 60 * 60 * 1000) {
const diskPayload = JSON.parse(await fs.promises.readFile(diskCachePath, 'utf8'));
if (diskPayload && diskPayload.ok) {
transcriptMemoryCache.set(cacheKey, {
time: Date.now(),
hasContent:
(diskPayload.cues && diskPayload.cues.length > 0) ||
(diskPayload.chapters && diskPayload.chapters.length > 0),
payload: diskPayload
});
return res.json(diskPayload);
}
}
} catch (e) {}
}
if (inFlightTranscriptRequests.has(cacheKey)) {
try {
const shared = await inFlightTranscriptRequests.get(cacheKey);
return res.json(shared);
} catch (err) {
return res.status(500).json({ ok: false, error: err.message });
}
}
const workPromise = (async () => {
let row = null;
if (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(resolvedUuid)) {
const rows = await dbQuery(
`SELECT v.id, v.uuid, v.name, v.description, v.duration, v.language, vi."targetUrl"
FROM "video" v
LEFT JOIN "videoImport" vi ON vi."videoId" = v.id
WHERE v.uuid = $1::uuid
LIMIT 1`,
[resolvedUuid]
);
if (rows[0]) row = rows[0];
} else if (/^\d+$/.test(rawParam)) {
const rows = await dbQuery(
`SELECT v.id, v.uuid, v.name, v.description, v.duration, v.language, vi."targetUrl"
FROM "video" v
LEFT JOIN "videoImport" vi ON vi."videoId" = v.id
WHERE v.id = $1::int
LIMIT 1`,
[parseInt(rawParam, 10)]
);
if (rows[0]) row = rows[0];
}
if (!row && !queryYtId) {
return { ok: false, error: 'Video not found', cues: [], chapters: [] };
}
let cues = [];
let chapters = row ? parseChaptersFromDescription(row.description, Number(row.duration || 0)) : [];
let language = row && row.language ? row.language : null;
let languageName = language || '';
let isAutoGenerated = false;
let source = chapters.length > 0 ? 'description' : 'none';
let availableLanguages = [];
const youtubeId = queryYtId || extractYouTubeIdFromRow(row);
// 1. Try local/remote PeerTube videoCaption rows if not requesting a different language
if (row && row.id) {
try {
const capRows = await dbQuery(
`SELECT id, language, filename, "fileUrl", "automaticallyGenerated"
FROM "videoCaption"
WHERE "videoId" = $1
ORDER BY CASE WHEN language = $2 THEN 0 WHEN language = 'tr' THEN 1 WHEN language = 'en' THEN 2 ELSE 3 END, "automaticallyGenerated" ASC, id ASC
LIMIT 6`,
[row.id, reqLang || 'tr']
);
for (const cap of capRows) {
availableLanguages.push({
code: cap.language,
name: cap.language,
auto: Boolean(cap.automaticallyGenerated)
});
}
const matchedCap = reqLang
? capRows.find(c => String(c.language || '').toLowerCase() === reqLang)
: capRows[0];
if (matchedCap) {
let capText = '';
const localCapPath = matchedCap.filename
? path.join(storageRoot, 'captions', path.basename(matchedCap.filename))
: '';
const cachedCapPath = matchedCap.filename
? path.join(storageRoot, 'cache', 'video-captions', path.basename(matchedCap.filename))
: '';
if (localCapPath && fs.existsSync(localCapPath)) {
capText = await fs.promises.readFile(localCapPath, 'utf8');
} else if (cachedCapPath && fs.existsSync(cachedCapPath)) {
capText = await fs.promises.readFile(cachedCapPath, 'utf8');
} else if (matchedCap.fileUrl) {
capText = await fetchRemoteTextWithLimit(matchedCap.fileUrl, 7000);
}
const parsedLocalCues = parseSubtitlePayload(capText);
if (parsedLocalCues.length > 0) {
cues = parsedLocalCues;
language = matchedCap.language;
languageName = matchedCap.language;
isAutoGenerated = Boolean(matchedCap.automaticallyGenerated);
source = 'peertube-caption';
}
}
} catch (capErr) {}
}
// 2. Fallback to live YouTube subtitle & chapter extraction via yt-dlp when cues or chapters are still needed
if (youtubeId && (cues.length === 0 || chapters.length === 0 || reqLang)) {
try {
const ytdlpPath = resolveYtDlpPath(logger, customYtDlpPath, peertubeHelpers);
const ytUrl = `https://www.youtube.com/watch?v=${youtubeId}`;
const rawJsonStr = await new Promise((resolve, reject) => {
execFile(
ytdlpPath,
['--dump-single-json', '--skip-download', '--no-warnings', '--socket-timeout', '8', ytUrl],
{ maxBuffer: 14 * 1024 * 1024, timeout: 15000 },
(err, stdout) => {
if (err || !stdout) return reject(err || new Error('Empty yt-dlp output'));
resolve(stdout);
}
);
});
const startIdx = rawJsonStr.indexOf('{');
const endIdx = rawJsonStr.lastIndexOf('}');
if (startIdx !== -1 && endIdx !== -1) {
const ytInfo = JSON.parse(rawJsonStr.substring(startIdx, endIdx + 1));
if (Array.isArray(ytInfo.chapters) && ytInfo.chapters.length > 0) {
chapters = ytInfo.chapters
.filter(c => c && c.title && c.start_time !== undefined)
.map(c => ({
title: String(c.title).trim(),
start: Math.max(0, Math.floor(Number(c.start_time || 0))),
end: c.end_time !== undefined ? Math.floor(Number(c.end_time)) : null
}));
} else if (chapters.length === 0 && ytInfo.description) {
chapters = parseChaptersFromDescription(ytInfo.description, Number(ytInfo.duration || 0));
}
if (cues.length === 0 || reqLang) {
const picked = pickPreferredCaptionTrack(ytInfo, reqLang, row && row.language);
if (picked.availableLanguages.length > 0) {
availableLanguages = picked.availableLanguages;
}
const candList = Array.isArray(picked.candidates)
? picked.candidates
: picked.chosen
? [picked.chosen]
: [];
for (const cand of candList) {
if (!cand || !cand.track || !cand.track.url) continue;
try {
const subText = await fetchRemoteTextWithLimit(cand.track.url, 9000);
const ytCues = parseSubtitlePayload(subText);
if (ytCues.length > 0) {
cues = ytCues;
language = cand.code;
languageName = (cand.track && cand.track.name) || cand.code;
isAutoGenerated = cand.isAuto;
source = cand.isAuto ? 'youtube-auto' : 'youtube-manual';
break;
}
} catch (subFetchErr) {}
}
}
}
} catch (ytErr) {
if (logger) {
logger.warn(`[YakTube Transcript] Extract warning for ${resolvedUuid}: ${ytErr.message}`);
}
}
}
const payload = {
ok: true,
uuid: (row && row.uuid) || resolvedUuid,
title: (row && row.name) || '',
youtubeId: youtubeId || null,
language,
languageName,
isAutoGenerated,
source,
cues,
chapters,
availableLanguages
};
const hasCues = cues.length > 0;
const hasContent = hasCues || (chapters.length > 0 && availableLanguages.length === 0);
if (transcriptMemoryCache.size > 400) transcriptMemoryCache.clear();
transcriptMemoryCache.set(cacheKey, {
time: Date.now(),
hasContent,
payload
});
if (hasCues || (chapters.length > 0 && availableLanguages.length === 0)) {
try {
await fs.promises.mkdir(transcriptCacheDir, { recursive: true });
await fs.promises.writeFile(diskCachePath, JSON.stringify(payload), 'utf8');
} catch (diskErr) {}
}
return payload;
})().finally(() => {
inFlightTranscriptRequests.delete(cacheKey);
});
inFlightTranscriptRequests.set(cacheKey, workPromise);
try {
const result = await workPromise;
return res.json(result);
} catch (err) {
return res.status(500).json({ ok: false, error: err.message, cues: [], chapters: [] });
}
});
// 7. YouTube Original Comments Route
router.get('/youtube-comments', async (req, res) => {
const videoId = (req.query.id || req.query.v || '').trim();
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "peertube-plugin-yaktube-ondemand",
"version": "1.7.17",
"version": "1.8.0",
"description": "Accessible On-Demand YouTube Import, Live Streams, Smart Recommendations, Sleep Timer, Touch Gestures, Voice Assistant & A11y Engine for PeerTube",
"main": "main.js",
"library": "./main.js",
+740 -11
View File
@@ -75,13 +75,13 @@ a[href*='joinpeertube'] {
.yaktube-ondemand-section {
margin: 24px 0;
padding: 20px;
background: rgba(22, 22, 30, 0.92);
background: rgba(18, 20, 28, 0.96);
border: 1px solid rgba(255, 143, 55, 0.35);
border-radius: 16px;
backdrop-filter: blur(10px);
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
color: #fff;
font-family: inherit;
overflow-anchor: none;
}
.yaktube-header {
@@ -153,16 +153,14 @@ a[href*='joinpeertube'] {
display: flex;
flex-direction: column;
transition:
transform 0.2s ease,
border-color 0.2s ease,
box-shadow 0.2s ease;
}
.yaktube-card:hover,
.yaktube-card:focus-within {
transform: translateY(-4px);
border-color: rgba(255, 143, 55, 0.6);
box-shadow: 0 10px 22px rgba(255, 143, 55, 0.18);
border-color: rgba(255, 143, 55, 0.65);
box-shadow: 0 8px 20px rgba(255, 143, 55, 0.18);
}
.yaktube-thumb-wrap {
@@ -180,11 +178,6 @@ a[href*='joinpeertube'] {
width: 100%;
height: 100%;
object-fit: cover;
transition: transform 0.3s ease;
}
.yaktube-card:hover .yaktube-thumb-img {
transform: scale(1.05);
}
.yaktube-duration-badge {
@@ -1953,3 +1946,739 @@ label[for='auto-play-video'],
visibility: hidden !important;
pointer-events: none !important;
}
/* ============================================================================
5. Live Audio Studio, Spectrum & A-B Loop (v1.8.0)
============================================================================ */
.yaktube-studio-modal {
max-width: 520px !important;
width: 94vw !important;
background: #141824 !important;
color: #f8fafc !important;
border: 1px solid rgba(255, 143, 55, 0.35) !important;
border-radius: 16px !important;
padding: 20px !important;
box-shadow: 0 20px 50px rgba(0, 0, 0, 0.75) !important;
}
.yaktube-studio-spectrum {
display: block;
width: 100%;
max-width: 100%;
height: 64px;
border-radius: 10px;
background: rgba(15, 23, 42, 0.85);
border: 1px solid rgba(255, 255, 255, 0.08);
margin: 10px 0 14px 0;
}
.yaktube-studio-warn {
background: rgba(59, 130, 246, 0.16);
border: 1px solid rgba(96, 165, 250, 0.45);
color: #bfdbfe;
border-radius: 10px;
padding: 10px 12px;
font-size: 13px;
margin-bottom: 10px;
}
.yaktube-studio-presets {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-bottom: 14px;
}
.yaktube-studio-preset-btn {
background: #1e293b;
color: #e2e8f0;
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 999px;
padding: 6px 12px;
font-size: 13px;
font-weight: 600;
cursor: pointer;
transition: all 0.15s ease;
}
.yaktube-studio-preset-btn:hover,
.yaktube-studio-preset-btn:focus-visible {
border-color: #ff8f37;
outline: 2px solid #ff8f37;
outline-offset: 2px;
}
.yaktube-studio-preset-btn.active {
background: linear-gradient(135deg, #ff8f37 0%, #ea580c 100%);
color: #0b0f19;
font-weight: 800;
border-color: #ff8f37;
}
.yaktube-studio-sliders {
display: flex;
flex-direction: column;
gap: 10px;
margin-bottom: 14px;
}
.yaktube-studio-row {
display: flex;
flex-direction: column;
gap: 4px;
font-size: 13px;
color: #cbd5e1;
}
.yaktube-studio-row span {
display: flex;
justify-content: space-between;
align-items: center;
}
.yaktube-studio-row input[type='range'] {
width: 100%;
accent-color: #ff8f37;
cursor: pointer;
}
.yaktube-studio-footer {
display: flex;
justify-content: space-between;
align-items: center;
gap: 12px;
flex-wrap: wrap;
border-top: 1px solid rgba(255, 255, 255, 0.1);
padding-top: 12px;
}
.yaktube-studio-check {
display: flex;
align-items: center;
gap: 8px;
font-size: 13px;
color: #e2e8f0;
cursor: pointer;
}
.yaktube-ab-loop-pill {
position: fixed;
bottom: 20px;
left: 20px;
z-index: 99990;
display: flex;
align-items: center;
gap: 10px;
background: rgba(15, 23, 42, 0.96);
color: #f8fafc;
border: 1.5px solid #ff8f37;
border-radius: 999px;
padding: 8px 14px;
font-size: 13px;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
}
.yaktube-ab-clear-btn {
background: rgba(255, 143, 55, 0.18);
color: #ff8f37;
border: 1px solid rgba(255, 143, 55, 0.5);
border-radius: 999px;
padding: 3px 10px;
font-size: 12px;
font-weight: 700;
cursor: pointer;
}
/* ============================================================================
6. Smart Transcript Chapters, Playback Queue & Background Import (v1.8.0)
============================================================================ */
.yaktube-transcript-langs,
.yaktube-transcript-chapters {
padding: 10px 14px;
border-bottom: 1px solid rgba(255, 255, 255, 0.08);
background: rgba(15, 23, 42, 0.5);
}
.yaktube-transcript-langs {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.yaktube-transcript-lang-btn {
background: #1e293b;
color: #cbd5e1;
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 999px;
padding: 4px 10px;
font-size: 12px;
cursor: pointer;
}
.yaktube-transcript-lang-btn.active {
background: #ff8f37;
color: #0b0f19;
font-weight: 700;
border-color: #ff8f37;
}
.yaktube-chapters-title {
font-size: 12px;
font-weight: 700;
color: #ff8f37;
margin-bottom: 8px;
}
.yaktube-chapters-row {
display: flex;
flex-wrap: wrap;
gap: 8px;
max-height: 120px;
overflow-y: auto;
}
.yaktube-chapter-chip {
background: rgba(30, 41, 59, 0.9);
color: #f1f5f9;
border: 1px solid rgba(255, 143, 55, 0.3);
border-radius: 8px;
padding: 5px 10px;
font-size: 12px;
cursor: pointer;
display: inline-flex;
align-items: center;
gap: 6px;
}
.yaktube-chapter-chip:hover,
.yaktube-chapter-chip:focus-visible {
background: rgba(255, 143, 55, 0.22);
border-color: #ff8f37;
outline: 2px solid #ff8f37;
}
.yaktube-chapter-time {
font-family: monospace;
color: #ff8f37;
font-weight: 700;
}
.yaktube-transcript-loading {
padding: 10px 14px;
font-size: 13px;
color: #93c5fd;
background: rgba(59, 130, 246, 0.1);
}
.yaktube-card-actions {
display: flex;
align-items: stretch;
gap: 6px;
margin-top: 8px;
flex-wrap: wrap;
}
.yaktube-card-actions > .yaktube-import-btn,
.yaktube-card-actions > .yaktube-play-btn {
flex: 1 1 auto;
margin-top: 0 !important;
}
.yaktube-queue-add-btn {
background: rgba(30, 41, 59, 0.95);
color: #fde68a;
border: 1px solid rgba(255, 143, 55, 0.45);
border-radius: 8px;
padding: 6px 10px;
font-size: 12px;
font-weight: 700;
cursor: pointer;
transition: all 0.15s ease;
}
.yaktube-queue-add-btn:hover,
.yaktube-queue-add-btn:focus-visible {
background: #ff8f37;
color: #0b0f19;
outline: 2px solid #ff8f37;
outline-offset: 2px;
}
.yaktube-floating-queue-btn {
position: fixed;
bottom: 20px;
right: 20px;
z-index: 99985;
background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
color: #ff8f37;
border: 1.5px solid #ff8f37;
border-radius: 999px;
padding: 10px 16px;
font-size: 13px;
font-weight: 800;
cursor: pointer;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
}
.yaktube-floating-queue-btn:focus-visible {
outline: 3px solid #fff;
outline-offset: 2px;
}
.yaktube-queue-modal {
max-width: 580px !important;
width: 95vw !important;
background: #141824 !important;
color: #f8fafc !important;
border: 1px solid rgba(255, 143, 55, 0.35) !important;
border-radius: 16px !important;
padding: 20px !important;
}
.yaktube-queue-scroll {
max-height: 55vh;
overflow-y: auto;
margin: 10px 0 14px 0;
}
.yaktube-queue-list {
list-style: none;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
gap: 8px;
}
.yaktube-queue-item {
display: flex;
align-items: center;
gap: 10px;
background: rgba(30, 41, 59, 0.72);
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 10px;
padding: 8px 10px;
}
.yaktube-queue-num {
width: 24px;
height: 24px;
border-radius: 50%;
background: rgba(255, 143, 55, 0.2);
color: #ff8f37;
display: inline-flex;
align-items: center;
justify-content: center;
font-weight: 800;
font-size: 12px;
flex-shrink: 0;
}
.yaktube-queue-thumb {
width: 68px;
height: 40px;
object-fit: cover;
border-radius: 6px;
flex-shrink: 0;
}
.yaktube-queue-meta {
flex: 1 1 auto;
min-width: 0;
}
.yaktube-queue-item-title {
font-size: 13px;
font-weight: 700;
color: #f8fafc;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.yaktube-queue-item-sub {
font-size: 11px;
color: #94a3b8;
margin-top: 2px;
}
.yaktube-queue-item-actions {
display: flex;
gap: 4px;
flex-shrink: 0;
}
.yaktube-queue-act-btn {
background: #0f172a;
color: #f8fafc;
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 6px;
padding: 4px 7px;
cursor: pointer;
font-size: 12px;
}
.yaktube-queue-act-btn:hover,
.yaktube-queue-act-btn:focus-visible {
border-color: #ff8f37;
outline: 2px solid #ff8f37;
}
.yaktube-bg-import-pill {
position: fixed;
bottom: 70px;
right: 20px;
z-index: 99992;
max-width: 360px;
background: rgba(15, 23, 42, 0.97);
color: #f8fafc;
border: 1.5px solid #38bdf8;
border-radius: 12px;
padding: 12px 14px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7);
display: flex;
flex-direction: column;
gap: 8px;
}
.yaktube-bg-import-pill.ready {
border-color: #10b981;
}
.yaktube-bg-import-text {
font-size: 13px;
line-height: 1.4;
}
.yaktube-bg-import-actions {
display: flex;
align-items: center;
gap: 8px;
flex-wrap: wrap;
}
.yaktube-bg-import-go-btn {
background: #10b981;
color: #052e16;
text-decoration: none;
padding: 5px 12px;
border-radius: 8px;
font-weight: 800;
font-size: 12px;
}
.yaktube-bg-import-sub-btn,
.yaktube-bg-import-close-btn {
background: #1e293b;
color: #e2e8f0;
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 8px;
padding: 5px 10px;
font-size: 12px;
cursor: pointer;
}
/* ============================================================================
7. Continue Watching Shelf, Command Palette & Admin Server Cockpit (v1.8.0)
============================================================================ */
.yaktube-cmd-palette-trigger-btn {
width: 34px;
height: 34px;
border-radius: 50%;
background: rgba(30, 41, 59, 0.9);
color: #ff8f37;
border: 1px solid rgba(255, 143, 55, 0.45);
font-weight: 800;
font-size: 14px;
cursor: pointer;
display: inline-flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
margin-left: 4px;
}
.yaktube-cmd-palette-trigger-btn:hover,
.yaktube-cmd-palette-trigger-btn:focus-visible {
background: #ff8f37;
color: #0b0f19;
outline: 2px solid #ff8f37;
outline-offset: 2px;
}
.yaktube-continue-shelf {
margin: 14px 0 22px 0;
padding: 16px;
background: linear-gradient(135deg, rgba(15, 23, 42, 0.92) 0%, rgba(30, 41, 59, 0.85) 100%);
border: 1px solid rgba(255, 143, 55, 0.28);
border-radius: 16px;
}
.yaktube-continue-header {
display: flex;
justify-content: space-between;
align-items: center;
gap: 10px;
margin-bottom: 12px;
flex-wrap: wrap;
}
.yaktube-continue-header h3 {
margin: 0;
font-size: 16px;
font-weight: 800;
color: #ff8f37;
}
.yaktube-continue-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
gap: 12px;
}
.yaktube-continue-card {
background: rgba(15, 23, 42, 0.85);
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 12px;
overflow: hidden;
display: flex;
flex-direction: column;
}
.yaktube-continue-thumb-link {
position: relative;
display: block;
aspect-ratio: 16 / 9;
background: #020617;
overflow: hidden;
}
.yaktube-continue-thumb-link img {
width: 100%;
height: 100%;
object-fit: cover;
}
.yaktube-continue-badge {
position: absolute;
bottom: 8px;
right: 8px;
background: rgba(2, 6, 23, 0.88);
color: #fde68a;
font-size: 11px;
font-weight: 700;
padding: 2px 7px;
border-radius: 6px;
}
.yaktube-continue-progress {
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 4px;
background: rgba(255, 255, 255, 0.2);
}
.yaktube-continue-progress > div {
height: 100%;
background: linear-gradient(90deg, #ff8f37, #ea580c);
}
.yaktube-continue-body {
padding: 10px 12px;
display: flex;
flex-direction: column;
gap: 6px;
flex: 1 1 auto;
}
.yaktube-continue-title {
color: #f8fafc;
text-decoration: none;
font-size: 13px;
font-weight: 700;
line-height: 1.35;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
.yaktube-continue-sub {
font-size: 11px;
color: #94a3b8;
}
.yaktube-continue-actions {
display: flex;
align-items: center;
gap: 6px;
margin-top: auto;
}
.yaktube-continue-resume-btn {
flex: 1 1 auto;
text-align: center;
background: linear-gradient(135deg, #ff8f37 0%, #ea580c 100%);
color: #0b0f19 !important;
text-decoration: none !important;
font-weight: 800;
font-size: 12px;
padding: 6px 10px;
border-radius: 8px;
}
.yaktube-cw-remove-btn {
background: #1e293b;
color: #cbd5e1;
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 8px;
padding: 6px 8px;
font-size: 12px;
cursor: pointer;
}
.yaktube-cmd-modal {
max-width: 580px !important;
width: 95vw !important;
background: #0f172a !important;
color: #f8fafc !important;
border: 1.5px solid #ff8f37 !important;
border-radius: 16px !important;
padding: 18px !important;
}
.yaktube-cmd-input {
width: 100%;
box-sizing: border-box;
margin: 10px 0 12px 0;
padding: 10px 14px;
border-radius: 10px;
border: 1px solid rgba(255, 143, 55, 0.5);
background: #1e293b;
color: #fff;
font-size: 14px;
}
.yaktube-cmd-input:focus {
outline: 2px solid #ff8f37;
}
.yaktube-cmd-list {
list-style: none;
margin: 0;
padding: 0;
max-height: 50vh;
overflow-y: auto;
display: flex;
flex-direction: column;
gap: 6px;
}
.yaktube-cmd-item {
display: flex;
justify-content: space-between;
align-items: center;
gap: 10px;
padding: 10px 12px;
border-radius: 10px;
background: rgba(30, 41, 59, 0.65);
cursor: pointer;
font-size: 13px;
font-weight: 600;
}
.yaktube-cmd-item:hover,
.yaktube-cmd-item.selected {
background: rgba(255, 143, 55, 0.24);
outline: 2px solid #ff8f37;
}
.yaktube-cmd-empty {
text-align: center;
padding: 20px;
color: #94a3b8;
}
.yaktube-cockpit-modal {
max-width: 720px !important;
width: 96vw !important;
background: #0f172a !important;
color: #f8fafc !important;
border: 1.5px solid rgba(56, 189, 248, 0.55) !important;
border-radius: 16px !important;
padding: 20px !important;
}
.yaktube-cockpit-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
gap: 10px;
text-align: left;
margin-bottom: 16px;
}
.yaktube-cockpit-card {
background: rgba(30, 41, 59, 0.82);
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 12px;
padding: 12px;
}
.yaktube-cockpit-label {
font-size: 12px;
color: #94a3b8;
margin-bottom: 4px;
}
.yaktube-cockpit-val {
font-size: 18px;
font-weight: 800;
color: #ff8f37;
}
.yaktube-cockpit-sub {
font-size: 11px;
color: #cbd5e1;
margin-top: 3px;
}
.yaktube-cockpit-section-title {
text-align: left;
font-size: 13px;
font-weight: 700;
color: #38bdf8;
margin: 8px 0 6px 0;
}
.yaktube-cockpit-issues {
list-style: none;
margin: 0 0 14px 0;
padding: 0;
max-height: 150px;
overflow-y: auto;
text-align: left;
display: flex;
flex-direction: column;
gap: 6px;
}
.yaktube-cockpit-issues li {
background: rgba(30, 41, 59, 0.6);
padding: 7px 10px;
border-radius: 8px;
font-size: 12px;
display: flex;
flex-direction: column;
gap: 2px;
}
.yaktube-cockpit-actions {
display: flex;
gap: 10px;
flex-wrap: wrap;
justify-content: flex-end;
border-top: 1px solid rgba(255, 255, 255, 0.1);
padding-top: 12px;
}