Git Komut Rehberi & Terminal Asistanı
Sıfırdan Yeni Bir Depo Başlatın:
Mevcut Bir Git Deposu veya Klasörü Gönderin:
Hataları Geri Alma, İptal & Temizlik:
Son commit'i geri al (yapılan değişiklikleri korur):
git reset --soft HEAD~1
Yapılan yerel değişiklikleri iptal et (çalışma ağacını temizler):
git restore .
Takip edilmeyen gereksiz dosyaları sil:
git clean -fd
Değişiklikleri geçici sakla ve geri getir (stash):
git stash git stash pop
Dal (Branch) ve Sürüm Etiketleri:
Yeni dal aç ve geçiş yap:
git checkout -b yeni-ozellik git push -u origin yeni-ozellik
Sürüm etiketi (tag) oluştur ve gönder:
git tag -a v1.0.0 -m "Sürüm 1.0.0" git push origin --tags
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e90d928bf1 | ||
|
|
b6bc8b639e |
@@ -3,48 +3,248 @@ const path = require('path');
|
|||||||
const http = require('http');
|
const http = require('http');
|
||||||
const https = require('https');
|
const https = require('https');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const os = require('os');
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
|
|
||||||
const searchCache = new Map();
|
const searchCache = new Map();
|
||||||
const CACHE_TTL = 30 * 60 * 1000; // 30 minutes
|
const CACHE_TTL = 30 * 60 * 1000; // 30 minutes
|
||||||
|
|
||||||
let cachedYtDlpPath = null;
|
let cachedYtDlpPath = null;
|
||||||
function resolveYtDlpPath(logger, customPath) {
|
let cachedYtDlpCustomSetting = null;
|
||||||
if (customPath && String(customPath).trim() && fs.existsSync(String(customPath).trim())) {
|
let autoDownloadPromise = null;
|
||||||
return String(customPath).trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cachedYtDlpPath && (cachedYtDlpPath === 'yt-dlp' || fs.existsSync(cachedYtDlpPath))) {
|
function isExecutableFile(filePath) {
|
||||||
return cachedYtDlpPath;
|
if (!filePath || typeof filePath !== 'string') return false;
|
||||||
}
|
|
||||||
|
|
||||||
if (process.env.YTDLP_PATH && fs.existsSync(process.env.YTDLP_PATH)) {
|
|
||||||
cachedYtDlpPath = process.env.YTDLP_PATH;
|
|
||||||
return cachedYtDlpPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
const isWin = process.platform === 'win32';
|
|
||||||
const candidates = isWin
|
|
||||||
? [
|
|
||||||
'D:\\yaktube_storage\\bin\\yt-dlp.exe',
|
|
||||||
'C:\\laragon\\bin\\yt-dlp.exe',
|
|
||||||
path.join(process.cwd(), 'bin', 'yt-dlp.exe'),
|
|
||||||
'yt-dlp.exe'
|
|
||||||
]
|
|
||||||
: ['/usr/local/bin/yt-dlp', '/usr/bin/yt-dlp', '/bin/yt-dlp', path.join(process.cwd(), 'bin', 'yt-dlp'), 'yt-dlp'];
|
|
||||||
|
|
||||||
for (const candidate of candidates) {
|
|
||||||
try {
|
try {
|
||||||
if (candidate.includes(path.sep) && fs.existsSync(candidate)) {
|
const stat = fs.statSync(filePath);
|
||||||
cachedYtDlpPath = candidate;
|
if (!stat.isFile() || stat.size < 1024) return false;
|
||||||
if (logger) logger.info(`[YakTube OnDemand] Auto-detected yt-dlp binary at: ${cachedYtDlpPath}`);
|
if (process.platform !== 'win32') {
|
||||||
return cachedYtDlpPath;
|
try {
|
||||||
|
fs.accessSync(filePath, fs.constants.X_OK);
|
||||||
|
} catch (_) {
|
||||||
|
try {
|
||||||
|
fs.chmodSync(filePath, 0o755);
|
||||||
|
} catch (__) {}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function discoverDynamicCandidatePaths(peertubeHelpers) {
|
||||||
|
const isWin = process.platform === 'win32';
|
||||||
|
const binNames = isWin ? ['yt-dlp.exe', 'yt-dlp'] : ['yt-dlp', 'yt-dlp_linux', 'yt-dlp_macos'];
|
||||||
|
const searchDirs = new Set();
|
||||||
|
|
||||||
|
function addWithParents(startDir, maxUp = 4) {
|
||||||
|
if (!startDir || typeof startDir !== 'string') return;
|
||||||
|
let cur = path.resolve(startDir);
|
||||||
|
for (let i = 0; i <= maxUp; i++) {
|
||||||
|
searchDirs.add(cur);
|
||||||
|
searchDirs.add(path.join(cur, 'bin'));
|
||||||
|
searchDirs.add(path.join(cur, 'storage', 'bin'));
|
||||||
|
const parent = path.dirname(cur);
|
||||||
|
if (!parent || parent === cur) break;
|
||||||
|
cur = parent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. PeerTube plugin data directory & its parent storage directory (e.g. /var/www/peertube/storage/bin/yt-dlp or /data/bin/yt-dlp)
|
||||||
|
try {
|
||||||
|
if (
|
||||||
|
peertubeHelpers &&
|
||||||
|
peertubeHelpers.plugin &&
|
||||||
|
typeof peertubeHelpers.plugin.getDataDirectoryPath === 'function'
|
||||||
|
) {
|
||||||
|
addWithParents(peertubeHelpers.plugin.getDataDirectoryPath(), 4);
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
// 2. Plugin installation directory (__dirname) & working directory (process.cwd())
|
||||||
|
addWithParents(__dirname, 4);
|
||||||
|
addWithParents(process.cwd(), 3);
|
||||||
|
|
||||||
|
// 3. System PATH environment variable directories (pure Node.js `which` / `where` equivalent)
|
||||||
|
const pathEnv = process.env.PATH || process.env.Path || '';
|
||||||
|
for (const dir of pathEnv.split(path.delimiter)) {
|
||||||
|
const cleanDir = dir.trim();
|
||||||
|
if (cleanDir) searchDirs.add(cleanDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Common Linux, Docker, macOS, and Windows binary locations
|
||||||
|
if (isWin) {
|
||||||
|
searchDirs.add('D:\\yaktube_storage\\bin');
|
||||||
|
searchDirs.add('C:\\yaktube_storage\\bin');
|
||||||
|
searchDirs.add('C:\\laragon\\bin');
|
||||||
|
searchDirs.add('C:\\ProgramData\\chocolatey\\bin');
|
||||||
|
if (process.env.LOCALAPPDATA) {
|
||||||
|
searchDirs.add(path.join(process.env.LOCALAPPDATA, 'Microsoft', 'WinGet', 'Links'));
|
||||||
|
}
|
||||||
|
if (process.env.USERPROFILE) {
|
||||||
|
searchDirs.add(path.join(process.env.USERPROFILE, 'scoop', 'shims'));
|
||||||
|
searchDirs.add(path.join(process.env.USERPROFILE, 'AppData', 'Local', 'Microsoft', 'WinGet', 'Links'));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
searchDirs.add('/var/www/peertube/storage/bin');
|
||||||
|
searchDirs.add('/var/lib/peertube/storage/bin');
|
||||||
|
searchDirs.add('/data/bin');
|
||||||
|
searchDirs.add('/usr/local/bin');
|
||||||
|
searchDirs.add('/usr/bin');
|
||||||
|
searchDirs.add('/bin');
|
||||||
|
searchDirs.add('/snap/bin');
|
||||||
|
searchDirs.add('/opt/homebrew/bin');
|
||||||
|
searchDirs.add('/home/peertube/.local/bin');
|
||||||
|
try {
|
||||||
|
const home = os.homedir();
|
||||||
|
if (home) searchDirs.add(path.join(home, '.local', 'bin'));
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
cachedYtDlpPath = isWin ? 'D:\\yaktube_storage\\bin\\yt-dlp.exe' : 'yt-dlp';
|
const candidates = [];
|
||||||
|
for (const dir of searchDirs) {
|
||||||
|
for (const bName of binNames) {
|
||||||
|
candidates.push(path.join(dir, bName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return candidates;
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveYtDlpPath(logger, customPath, peertubeHelpers) {
|
||||||
|
const cleanCustom = customPath ? String(customPath).trim() : '';
|
||||||
|
if (cleanCustom && isExecutableFile(cleanCustom)) {
|
||||||
|
if (cachedYtDlpPath !== cleanCustom) {
|
||||||
|
cachedYtDlpPath = cleanCustom;
|
||||||
|
cachedYtDlpCustomSetting = cleanCustom;
|
||||||
|
if (logger) logger.info(`[YakTube OnDemand] Using custom configured yt-dlp binary at: ${cachedYtDlpPath}`);
|
||||||
|
}
|
||||||
return cachedYtDlpPath;
|
return cachedYtDlpPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cachedYtDlpPath && cachedYtDlpCustomSetting === cleanCustom && isExecutableFile(cachedYtDlpPath)) {
|
||||||
|
return cachedYtDlpPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.env.YTDLP_PATH && isExecutableFile(process.env.YTDLP_PATH)) {
|
||||||
|
cachedYtDlpPath = process.env.YTDLP_PATH;
|
||||||
|
cachedYtDlpCustomSetting = cleanCustom;
|
||||||
|
if (logger) logger.info(`[YakTube OnDemand] Using YTDLP_PATH binary at: ${cachedYtDlpPath}`);
|
||||||
|
return cachedYtDlpPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
const candidates = discoverDynamicCandidatePaths(peertubeHelpers);
|
||||||
|
for (const candidate of candidates) {
|
||||||
|
if (isExecutableFile(candidate)) {
|
||||||
|
cachedYtDlpPath = candidate;
|
||||||
|
cachedYtDlpCustomSetting = cleanCustom;
|
||||||
|
if (logger)
|
||||||
|
logger.info(`[YakTube OnDemand] Auto-detected yt-dlp binary (${process.platform}) at: ${cachedYtDlpPath}`);
|
||||||
|
return cachedYtDlpPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trigger background auto-download if not found on disk yet
|
||||||
|
ensureYtDlpBinaryDownloaded(logger, peertubeHelpers).catch(() => {});
|
||||||
|
|
||||||
|
return process.platform === 'win32' ? 'yt-dlp.exe' : 'yt-dlp';
|
||||||
|
}
|
||||||
|
|
||||||
|
function downloadFileFollowRedirects(url, destPath, maxRedirects = 5) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (maxRedirects < 0) return reject(new Error('Too many redirects'));
|
||||||
|
const client = url.startsWith('https') ? https : http;
|
||||||
|
const req = client.get(
|
||||||
|
url,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
'User-Agent': 'YakTube-OnDemand-Plugin/1.7 (PeerTube)'
|
||||||
|
},
|
||||||
|
timeout: 60000
|
||||||
|
},
|
||||||
|
res => {
|
||||||
|
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
||||||
|
res.resume();
|
||||||
|
const nextUrl = new URL(res.headers.location, url).toString();
|
||||||
|
return resolve(downloadFileFollowRedirects(nextUrl, destPath, maxRedirects - 1));
|
||||||
|
}
|
||||||
|
if (res.statusCode !== 200) {
|
||||||
|
res.resume();
|
||||||
|
return reject(new Error(`HTTP ${res.statusCode} when downloading yt-dlp`));
|
||||||
|
}
|
||||||
|
const tmpPath = `${destPath}.tmp-${process.pid}`;
|
||||||
|
const fileStream = fs.createWriteStream(tmpPath, { mode: 0o755 });
|
||||||
|
res.pipe(fileStream);
|
||||||
|
fileStream.on('finish', () => {
|
||||||
|
fileStream.close(() => {
|
||||||
|
try {
|
||||||
|
if (process.platform !== 'win32') {
|
||||||
|
fs.chmodSync(tmpPath, 0o755);
|
||||||
|
}
|
||||||
|
fs.renameSync(tmpPath, destPath);
|
||||||
|
resolve(destPath);
|
||||||
|
} catch (err) {
|
||||||
|
reject(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
fileStream.on('error', err => {
|
||||||
|
try {
|
||||||
|
fs.unlinkSync(tmpPath);
|
||||||
|
} catch (_) {}
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
req.on('error', reject);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function ensureYtDlpBinaryDownloaded(logger, peertubeHelpers) {
|
||||||
|
if (autoDownloadPromise) return autoDownloadPromise;
|
||||||
|
autoDownloadPromise = (async () => {
|
||||||
|
try {
|
||||||
|
const isWin = process.platform === 'win32';
|
||||||
|
const isMac = process.platform === 'darwin';
|
||||||
|
const assetName = isWin ? 'yt-dlp.exe' : isMac ? 'yt-dlp_macos' : 'yt-dlp';
|
||||||
|
const targetFileName = isWin ? 'yt-dlp.exe' : 'yt-dlp';
|
||||||
|
|
||||||
|
let targetDir = path.join(__dirname, 'bin');
|
||||||
|
try {
|
||||||
|
if (
|
||||||
|
peertubeHelpers &&
|
||||||
|
peertubeHelpers.plugin &&
|
||||||
|
typeof peertubeHelpers.plugin.getDataDirectoryPath === 'function'
|
||||||
|
) {
|
||||||
|
targetDir = path.join(peertubeHelpers.plugin.getDataDirectoryPath(), 'bin');
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
fs.mkdirSync(targetDir, { recursive: true });
|
||||||
|
const targetPath = path.join(targetDir, targetFileName);
|
||||||
|
if (isExecutableFile(targetPath)) {
|
||||||
|
cachedYtDlpPath = targetPath;
|
||||||
|
return targetPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
const downloadUrl = `https://github.com/yt-dlp/yt-dlp/releases/latest/download/${assetName}`;
|
||||||
|
if (logger) {
|
||||||
|
logger.info(`[YakTube OnDemand] yt-dlp not found on system; auto-downloading ${assetName} to ${targetPath}...`);
|
||||||
|
}
|
||||||
|
await downloadFileFollowRedirects(downloadUrl, targetPath);
|
||||||
|
if (isExecutableFile(targetPath)) {
|
||||||
|
cachedYtDlpPath = targetPath;
|
||||||
|
if (logger) logger.info(`[YakTube OnDemand] Successfully auto-installed yt-dlp at: ${targetPath}`);
|
||||||
|
return targetPath;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
if (logger) logger.warn(`[YakTube OnDemand] Auto-download of yt-dlp warning: ${e.message}`);
|
||||||
|
} finally {
|
||||||
|
autoDownloadPromise = null;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
})();
|
||||||
|
return autoDownloadPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCached(q) {
|
function getCached(q) {
|
||||||
@@ -700,6 +900,7 @@ async function register({ registerHook, getRouter, registerSetting, settingsMana
|
|||||||
if (settingsManager && typeof settingsManager.onSettingsChange === 'function') {
|
if (settingsManager && typeof settingsManager.onSettingsChange === 'function') {
|
||||||
settingsManager.onSettingsChange(loadPluginSettings);
|
settingsManager.onSettingsChange(loadPluginSettings);
|
||||||
}
|
}
|
||||||
|
resolveYtDlpPath(logger, customYtDlpPath, peertubeHelpers);
|
||||||
|
|
||||||
// Helper to run SQL queries via PeerTube's built-in Sequelize instance (works on ANY PeerTube server without bridge.js)
|
// Helper to run SQL queries via PeerTube's built-in Sequelize instance (works on ANY PeerTube server without bridge.js)
|
||||||
async function dbQuery(sql, bindParams = []) {
|
async function dbQuery(sql, bindParams = []) {
|
||||||
@@ -780,79 +981,164 @@ async function register({ registerHook, getRouter, registerSetting, settingsMana
|
|||||||
throw new Error('Could not resolve or generate admin OAuth token');
|
throw new Error('Could not resolve or generate admin OAuth token');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function classifyVideoCategoryAndChannel(title, currentCategory, tags, description) {
|
||||||
|
const rawT = String(title || '');
|
||||||
|
const t = rawT.toLocaleLowerCase('tr');
|
||||||
|
const tagStr = Array.isArray(tags) ? tags.filter(Boolean).join(' ').toLocaleLowerCase('tr') : '';
|
||||||
|
const descStr = String(description || '')
|
||||||
|
.slice(0, 400)
|
||||||
|
.toLocaleLowerCase('tr');
|
||||||
|
const combined = `${t} ${tagStr}`;
|
||||||
|
const fullText = `${combined} ${descStr}`;
|
||||||
|
|
||||||
|
const cat = currentCategory ? Number(currentCategory) : null;
|
||||||
|
|
||||||
|
// 1. Music (Category 1 -> YakTube Müzik)
|
||||||
|
const musicPattern =
|
||||||
|
/\b(müzik|muzik|music|musik|muziek|musiqi|müzikleri|muzikleri|şarkı|sarki|şarkılar|sarkilar|klip|video\s*klip|official\s*video|official\s*music|official\s*audio|audio|karaoke|kareoke|akustik|acoustic|enstrümantal|enstrumantal|instrumental|sözleri|sozleri|lyrics|lyric|remix|mix|mashup|cover|ai\s*cover|freestyle|konser|canlı\s*performans|performans|netd|sony\s*music|dmc|poll\s*production|mahzen|tfb\s*records|dokuz\s*sekiz|avrupa\s*müzik|pasaj\s*müzik|türkçe\s*pop|turkce\s*pop|arabesk|rap|hip\s*hop|boombesk|chillebesk|halay|türkü|turku|türküleri|ilahi|kaside|fon\s*müziği|melodi|beat|feat\.?|ft\.?|mv|kpop|k-pop|aespa|sechskies|starakor|star\s*akor|akor|akorları|altyapı|alt\s*yapı)\b/i;
|
||||||
|
|
||||||
|
const knownMusicArtists =
|
||||||
|
/\b(tarkan|sezen\s*aksu|gülşen|gulsen|ebru\s*yaşar|ebru\s*yasar|derya\s*uluğ|derya\s*ulug|asil\s*gök|ferhat\s*göçer|ferhat\s*gocer|sertab\s*erener|candan\s*erçetin|bahadır\s*tatlıöz|reynmen|semicenk|burak\s*bulut|kurtuluş\s*kuş|tekir|mehmet\s*elmas|yıldırım\s*elmas|ahmet\s*kaya|ibrahim\s*tatlıses|müslüm\s*gürses|orhan\s*gencebay|barış\s*manço|cem\s*karaca|mabel\s*matiz|hadise|aleyna\s*tilki|simge|ziynet\s*sali|hande\s*yener|demet\s*akalı|mustafa\s*sandal|kenan\s*doğulu|yalın|teoman|duman|mor\s*ve\s*ötesi|manga|sagopa|ceza|ezhel|uzi|cakal|çakal|lvbel|blok3|poizi|wegh|dedublüman|melek\s*mosso|zeynep\s*bastık|melike\s*şahin|karsu|maya\s*perest|siyam|zeyd|gökhan\s*türkmen|emre\s*aydın|oğuzhan\s*koç|murat\s*boz|edis|buray|ilyas\s*yalçıntaş|tuğçe\s*kandemir|bilal\s*sonses|sancak|taladro|canfeza|no\.?\s*1|şehinşah|hidra|allame|contra|norm\s*ender|ben\s*fero|motive|ati242|girl\s*in\s*red|tate\s*mcrae|rose|giselle|sunghoon|serkan\s*nişancı|yiğit\s*mahzuni|afşin\s*akyol)\b/i;
|
||||||
|
|
||||||
|
if (cat === 1 || /[🎶🎵🎤🎧🎼]/.test(rawT) || musicPattern.test(combined) || knownMusicArtists.test(combined)) {
|
||||||
|
return { category: 1, bucket: 'music', keywords: ['muzik', 'müzik', 'music'] };
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Podcast & Sohbet (-> YakTube Podcast & Sohbet)
|
||||||
|
const podcastPattern =
|
||||||
|
/\b(podcast|röportaj|roportaj|sohbet|söyleşi|soylesi|açık\s*mikrofon|konuk|bölüm\s*sohbet|talk\s*show|interview|in\s*your\s*dreams)\b/i;
|
||||||
|
if (podcastPattern.test(combined)) {
|
||||||
|
return { category: cat || 8, bucket: 'podcast', keywords: ['podcast', 'sohbet'] };
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Teknoloji, Bilim & Eğitim (Categories 12, 13, 15 -> YakTube Teknoloji & Eğitim)
|
||||||
|
const techEduPattern =
|
||||||
|
/\b(teknoloji|technology|bilim|science|yazılım|software|kodlama|coding|programlama|linux|windows|android|ios|iphone|samsung|yapay\s*zeka|artificial\s*intelligence|chatgpt|gemini|bitcoin|kripto|crypto|blockchain|donanım|inceleme|review|rehber|tutorial|how\s*to|nasıl\s*yapılır|eğitim|egitim|education|educational|ders|lecture|kurs|matematik|fizik|kimya|ingilizce|english\s*listening|learn\s*english|qcomputing|quantum|developer|open\s*source|kde|ubuntu|debian|seo|search\s*console|marketing)\b/i;
|
||||||
|
if (cat === 12 || cat === 13 || cat === 15 || techEduPattern.test(combined)) {
|
||||||
|
return { category: cat || 13, bucket: 'tech', keywords: ['teknoloji', 'tekno', 'egitim', 'eğitim', 'tech'] };
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Oyun, Spor & Araçlar (Categories 3, 5, 7 -> YakTube Oyun & Spor)
|
||||||
|
const gameSportPattern =
|
||||||
|
/\b(oyun|gaming|game|gameplay|walkthrough|playthrough|steam|playstation|xbox|nintendo|minecraft|valorant|csgo|cs2|pubg|gta|roblox|fortnite|league\s*of\s*legends|osu|twitch|spor|sport|sports|futbol|football|soccer|basketbol|voleybol|şampiyonlar\s*ligi|champions\s*league|galatasaray|fenerbahçe|fenerbahce|beşiktaş|besiktas|trabzonspor|man\s*utd|manchester|real\s*madrid|barcelona|maç\s*özeti|highlights|fitness|workout|gym|yoga|stretching|wwe|undertaker|red\s*bull|extreme\s*sports|araba|araç|aracı|otomobil|sürüş|multijet|gokart|go\s*kart|karting|motor|f1|formula\s*1)\b/i;
|
||||||
|
if (cat === 3 || cat === 5 || cat === 7 || gameSportPattern.test(combined)) {
|
||||||
|
return { category: cat || 5, bucket: 'game_sport', keywords: ['oyun', 'spor', 'game', 'sport'] };
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. Eğlence, Komedi, Film & Dizi (Categories 2, 9, 10 -> YakTube Eğlence & Dizi)
|
||||||
|
const entertainmentPattern =
|
||||||
|
/\b(komedi|comedy|mizah|komik|funny|skeç|skec|parodi|parodie|şaka|prank|eğlence|eglence|entertainment|film|movie|sinema|cinema|fragman|trailer|dizi|series|drama|episode|ep\.\s*\d+|bölüm|bolum|dramatizeme|kısa\s*film|short\s*film|animasyon|animation|anime|çizgi\s*film|tiyatro|stand\s*up|dans|dance|koreografi|choreography|tiktok\s*compilation|challenge|show)\b/i;
|
||||||
|
if (cat === 2 || cat === 9 || cat === 10 || entertainmentPattern.test(combined)) {
|
||||||
|
return { category: cat || 10, bucket: 'entertainment', keywords: ['eglence', 'eğlence', 'dizi', 'komedi'] };
|
||||||
|
}
|
||||||
|
|
||||||
|
// 6. Haber, Gündem, Gezi, Doğa & Yaşam (Categories 4, 6, 8, 11, 14, 16, 17, 18 -> YakTube Haber & Yaşam)
|
||||||
|
const newsLifePattern =
|
||||||
|
/\b(haber|haberler|gazete|gazetesi|news|gündem|siyaset|politika|ekonomi|belgesel|documentary|gezi|seyahat|travel|vlog|doğa|doga|nature|kamp|hayvan|animal|kedi|cat|köpek|dog|yemek|mutfak|tarif|food|cooking|moda|fashion|style|outfit|wear|trend|alışveriş|haul|yaşam|lifestyle|sağlık|health|çocuk|kids|sanat|art)\b/i;
|
||||||
|
if ([4, 6, 11, 14, 16, 17, 18].includes(cat) || newsLifePattern.test(combined) || newsLifePattern.test(fullText)) {
|
||||||
|
return { category: cat || 8, bucket: 'news_life', keywords: ['yasam', 'yaşam', 'haber', 'gezi'] };
|
||||||
|
}
|
||||||
|
|
||||||
|
// 7. Artist - Song fallback for "Artist - Song Title" format
|
||||||
|
if (/^[^\-|]{2,35}\s*[\-\u2010-\u2015]\s*[^\-|]{2,60}$/.test(rawT.trim())) {
|
||||||
|
return { category: 1, bucket: 'music', keywords: ['muzik', 'müzik', 'music'] };
|
||||||
|
}
|
||||||
|
|
||||||
|
return { category: cat || 8, bucket: 'general', keywords: ['genel', 'general', 'main'] };
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadOfficialChannels() {
|
||||||
|
const allAdminChannels = await dbQuery(
|
||||||
|
`SELECT vc.id, vc.name, act."preferredUsername" AS handle, a.name AS "accountName", u.id AS "userId"
|
||||||
|
FROM "videoChannel" vc
|
||||||
|
INNER JOIN "actor" act ON act."videoChannelId" = vc.id
|
||||||
|
INNER JOIN "account" a ON vc."accountId" = a.id
|
||||||
|
INNER JOIN "user" u ON a."userId" = u.id
|
||||||
|
WHERE u.role = 0 AND act."serverId" IS NULL
|
||||||
|
ORDER BY vc.id ASC`
|
||||||
|
);
|
||||||
|
const yaktubeChannels = allAdminChannels.filter(
|
||||||
|
c =>
|
||||||
|
(c.accountName && c.accountName.toLowerCase() === 'yaktube') ||
|
||||||
|
(c.handle && c.handle.toLowerCase().startsWith('yaktube_')) ||
|
||||||
|
Number(c.userId) === 1
|
||||||
|
);
|
||||||
|
return yaktubeChannels.length > 0 ? yaktubeChannels : allAdminChannels;
|
||||||
|
}
|
||||||
|
|
||||||
|
function pickChannelIdFromList(channels, decision) {
|
||||||
|
if (!channels || channels.length === 0) return '1';
|
||||||
|
for (const kw of decision.keywords || []) {
|
||||||
|
const found = channels.find(
|
||||||
|
c =>
|
||||||
|
(c.handle && c.handle.toLocaleLowerCase('tr').includes(kw)) ||
|
||||||
|
(c.name && c.name.toLocaleLowerCase('tr').includes(kw))
|
||||||
|
);
|
||||||
|
if (found) return String(found.id);
|
||||||
|
}
|
||||||
|
const genel =
|
||||||
|
channels.find(
|
||||||
|
c =>
|
||||||
|
(c.handle && c.handle.toLowerCase().includes('genel')) ||
|
||||||
|
(c.name && c.name.toLocaleLowerCase('tr').includes('genel'))
|
||||||
|
) || channels[0];
|
||||||
|
return String(genel.id);
|
||||||
|
}
|
||||||
|
|
||||||
// Universal Channel Resolver (Works on any PeerTube instance + smart category mapping)
|
// Universal Channel Resolver (Works on any PeerTube instance + smart category mapping)
|
||||||
async function resolveTargetChannelId(title, explicitChannelId) {
|
async function resolveTargetChannelId(title, explicitChannelId) {
|
||||||
if (explicitChannelId) return String(explicitChannelId);
|
if (explicitChannelId) return String(explicitChannelId);
|
||||||
if (customChannelId) return String(customChannelId);
|
if (customChannelId) return String(customChannelId);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const channels = await dbQuery(
|
const channels = await loadOfficialChannels();
|
||||||
`SELECT vc.id, vc.name, a."displayName"
|
|
||||||
FROM "videoChannel" vc
|
|
||||||
INNER JOIN "account" a ON vc."accountId" = a.id
|
|
||||||
INNER JOIN "user" u ON a."userId" = u.id
|
|
||||||
WHERE u.role = 0
|
|
||||||
ORDER BY vc.id ASC`
|
|
||||||
);
|
|
||||||
|
|
||||||
if (channels.length > 0) {
|
if (channels.length > 0) {
|
||||||
const t = String(title || '').toLowerCase();
|
const decision = classifyVideoCategoryAndChannel(title, null, [], '');
|
||||||
const findCh = keyword =>
|
return pickChannelIdFromList(channels, decision);
|
||||||
channels.find(
|
|
||||||
c =>
|
|
||||||
(c.name && c.name.toLowerCase().includes(keyword)) ||
|
|
||||||
(c.displayName && c.displayName.toLowerCase().includes(keyword))
|
|
||||||
);
|
|
||||||
|
|
||||||
if (
|
|
||||||
t.includes('podcast') ||
|
|
||||||
t.includes('röportaj') ||
|
|
||||||
t.includes('roportaj') ||
|
|
||||||
t.includes('sohbet') ||
|
|
||||||
t.includes('bölüm') ||
|
|
||||||
t.includes('episode')
|
|
||||||
) {
|
|
||||||
const podCh = findCh('podcast') || findCh('sohbet');
|
|
||||||
if (podCh) return String(podCh.id);
|
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
if (
|
if (logger) logger.warn('[YakTube OnDemand] resolveTargetChannelId warning: ' + e.message);
|
||||||
t.includes('bitcoin') ||
|
|
||||||
t.includes('kripto') ||
|
|
||||||
t.includes('yazılım') ||
|
|
||||||
t.includes('kodlama') ||
|
|
||||||
t.includes('ders') ||
|
|
||||||
t.includes('rehber') ||
|
|
||||||
t.includes('tutorial') ||
|
|
||||||
t.includes('teknoloji') ||
|
|
||||||
t.includes('inceleme')
|
|
||||||
) {
|
|
||||||
const techCh = findCh('tekno') || findCh('tech') || findCh('egitim');
|
|
||||||
if (techCh) return String(techCh.id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
|
||||||
t.includes('müzik') ||
|
|
||||||
t.includes('muzik') ||
|
|
||||||
t.includes('music') ||
|
|
||||||
t.includes('şarkı') ||
|
|
||||||
t.includes('klip') ||
|
|
||||||
t.includes('official') ||
|
|
||||||
t.includes('feat') ||
|
|
||||||
t.includes('remix') ||
|
|
||||||
t.includes(' - ')
|
|
||||||
) {
|
|
||||||
const musicCh = findCh('muzik') || findCh('müzik') || findCh('music');
|
|
||||||
if (musicCh) return String(musicCh.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
return String(channels[0].id);
|
|
||||||
}
|
|
||||||
} catch (e) {}
|
|
||||||
|
|
||||||
return '1';
|
return '1';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Post-import synchronizer: once yt-dlp populates a video's YouTube category & tags, ensure it is in the right channel
|
||||||
|
async function syncVideoChannelAndCategory(videoId) {
|
||||||
|
if (!videoId || customChannelId) return;
|
||||||
|
try {
|
||||||
|
const rows = await dbQuery(
|
||||||
|
`SELECT v.id, v.name, v.category, v."channelId", v.description,
|
||||||
|
(SELECT array_agg(t.name) FROM "videoTag" vt INNER JOIN "tag" t ON t.id = vt."tagId" WHERE vt."videoId" = v.id) AS tags
|
||||||
|
FROM "video" v
|
||||||
|
WHERE v.id = $1 AND v.remote = false
|
||||||
|
LIMIT 1`,
|
||||||
|
[Number(videoId)]
|
||||||
|
);
|
||||||
|
if (rows.length === 0) return;
|
||||||
|
const v = rows[0];
|
||||||
|
const channels = await loadOfficialChannels();
|
||||||
|
if (channels.length === 0) return;
|
||||||
|
|
||||||
|
const decision = classifyVideoCategoryAndChannel(v.name, v.category, v.tags, v.description);
|
||||||
|
const targetChannelId = Number(pickChannelIdFromList(channels, decision));
|
||||||
|
const targetCategory = decision.category || v.category || 8;
|
||||||
|
|
||||||
|
if (
|
||||||
|
(targetChannelId && targetChannelId !== Number(v.channelId) && Number(v.channelId) === 1) ||
|
||||||
|
(!v.category && targetCategory)
|
||||||
|
) {
|
||||||
|
await dbQuery(
|
||||||
|
`UPDATE "video"
|
||||||
|
SET "channelId" = $1,
|
||||||
|
category = COALESCE(category, $2)
|
||||||
|
WHERE id = $3`,
|
||||||
|
[targetChannelId || v.channelId, targetCategory, v.id]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
// Helper to check if request is from an authenticated PeerTube user
|
// Helper to check if request is from an authenticated PeerTube user
|
||||||
async function isRequestAuthenticated(req, res, bodyAuthFlag) {
|
async function isRequestAuthenticated(req, res, bodyAuthFlag) {
|
||||||
if (bodyAuthFlag === true) return true;
|
if (bodyAuthFlag === true) return true;
|
||||||
@@ -1176,7 +1462,7 @@ async function register({ registerHook, getRouter, registerSetting, settingsMana
|
|||||||
return resolve({ results: filteredCached.slice(0, maxCount), cached: true });
|
return resolve({ results: filteredCached.slice(0, maxCount), cached: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
const ytdlpPath = resolveYtDlpPath(logger, customYtDlpPath);
|
const ytdlpPath = resolveYtDlpPath(logger, customYtDlpPath, peertubeHelpers);
|
||||||
const args = [
|
const args = [
|
||||||
`ytsearch${maxCount}:${cleanQ}`,
|
`ytsearch${maxCount}:${cleanQ}`,
|
||||||
'--dump-single-json',
|
'--dump-single-json',
|
||||||
@@ -2431,6 +2717,7 @@ async function register({ registerHook, getRouter, registerSetting, settingsMana
|
|||||||
try {
|
try {
|
||||||
const data = JSON.parse(body);
|
const data = JSON.parse(body);
|
||||||
if (data && data.video) {
|
if (data && data.video) {
|
||||||
|
syncVideoChannelAndCategory(data.video.id).catch(() => {});
|
||||||
return resolve({
|
return resolve({
|
||||||
status: 200,
|
status: 200,
|
||||||
payload: {
|
payload: {
|
||||||
@@ -2522,6 +2809,10 @@ async function register({ registerHook, getRouter, registerSetting, settingsMana
|
|||||||
(video.files && video.files.length > 0) ||
|
(video.files && video.files.length > 0) ||
|
||||||
(video.streamingPlaylists && video.streamingPlaylists.length > 0);
|
(video.streamingPlaylists && video.streamingPlaylists.length > 0);
|
||||||
|
|
||||||
|
if ((isPublished || isTranscoding) && video.id) {
|
||||||
|
await syncVideoChannelAndCategory(video.id);
|
||||||
|
}
|
||||||
|
|
||||||
let errorMessage = null;
|
let errorMessage = null;
|
||||||
if (isFailed && video.id) {
|
if (isFailed && video.id) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "peertube-plugin-yaktube-ondemand",
|
"name": "peertube-plugin-yaktube-ondemand",
|
||||||
"version": "1.7.12",
|
"version": "1.7.14",
|
||||||
"description": "Accessible On-Demand YouTube Import, Live Streams, Smart Recommendations, Sleep Timer, Touch Gestures, Voice Assistant & A11y Engine for PeerTube",
|
"description": "Accessible On-Demand YouTube Import, Live Streams, Smart Recommendations, Sleep Timer, Touch Gestures, Voice Assistant & A11y Engine for PeerTube",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
"library": "./main.js",
|
"library": "./main.js",
|
||||||
|
|||||||
Reference in New Issue
Block a user