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 | |
|---|---|---|---|
|
|
b40267b7da | ||
|
|
b5e8ea28ce | ||
|
|
18f8a601e8 | ||
|
|
e90d928bf1 | ||
|
|
b6bc8b639e |
@@ -4465,26 +4465,400 @@ try {
|
|||||||
var container = document.getElementById('yaktube-ondemand-container');
|
var container = document.getElementById('yaktube-ondemand-container');
|
||||||
var nativeResults = searchMount.querySelector('.search-result');
|
var nativeResults = searchMount.querySelector('.search-result');
|
||||||
|
|
||||||
|
function ensureSearchContainerMounted() {
|
||||||
|
var curSearchMount = document.querySelector('my-search, my-search-results') || searchMount;
|
||||||
|
var curNative = curSearchMount ? curSearchMount.querySelector('.search-result') : null;
|
||||||
|
var el = document.getElementById('yaktube-ondemand-container');
|
||||||
|
if (!el) {
|
||||||
|
el = document.createElement('div');
|
||||||
|
el.id = 'yaktube-ondemand-container';
|
||||||
|
el.className = 'yaktube-ondemand-section';
|
||||||
|
el.setAttribute('role', 'region');
|
||||||
|
el.setAttribute('aria-label', 'Canlı YouTube ve ' + getInstanceName() + ' Arama Sonuçları');
|
||||||
|
}
|
||||||
|
if (curSearchMount && el.parentElement !== curSearchMount) {
|
||||||
|
curSearchMount.insertBefore(el, curNative || curSearchMount.firstChild);
|
||||||
|
}
|
||||||
|
return el;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderSearchOutcome(ytData, localData, activeContainer) {
|
||||||
|
var targetContainer = activeContainer || ensureSearchContainerMounted();
|
||||||
|
ytData = ytData || {};
|
||||||
|
localData = localData || {};
|
||||||
|
|
||||||
|
if (typeof ytData.guestImportLimit === 'number') {
|
||||||
|
cachedGuestImportLimit = ytData.guestImportLimit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ytData && ytData.blocked) {
|
||||||
|
var safetyMsg =
|
||||||
|
ytData.message ||
|
||||||
|
'Bu arama terimi veya içerik, Çocuk ve Aile Güvenliği (Child & Family Safety) politikaları gereğince filtrelenmiştir.';
|
||||||
|
targetContainer.innerHTML =
|
||||||
|
'<div class="yaktube-header" style="border-left: 4px solid #ef4444; background: rgba(239, 68, 68, 0.08); padding: 18px 20px; border-radius: 8px; margin-bottom: 24px;">' +
|
||||||
|
'<div class="yaktube-header-left">' +
|
||||||
|
'<span class="yaktube-badge" style="background:#ef4444; color:#fff; font-weight:700;">🛡️ Çocuk ve Aile Güvenliği Koruması</span>' +
|
||||||
|
'<h2 class="yaktube-title-h3" style="margin:8px 0 4px; font-size:1.15rem; color:#f87171;">Arama Filtrelendi</h2>' +
|
||||||
|
'<p style="margin:0; font-size:0.95rem; color:#cbd5e1;">' +
|
||||||
|
escapeHtml(safetyMsg) +
|
||||||
|
'</p>' +
|
||||||
|
'</div>' +
|
||||||
|
'</div>';
|
||||||
|
announce(safetyMsg, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var rawYtResults = ytData.results || [];
|
||||||
|
var uniqueYtResults = [];
|
||||||
|
var seenIds = {};
|
||||||
|
|
||||||
|
rawYtResults.forEach(function (item) {
|
||||||
|
if (item && item.id && !seenIds[item.id] && item.title) {
|
||||||
|
seenIds[item.id] = true;
|
||||||
|
uniqueYtResults.push(item);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var ytCount = uniqueYtResults.length;
|
||||||
|
var localResults = localData.data || [];
|
||||||
|
var localTotal = typeof localData.total === 'number' ? localData.total : localResults.length;
|
||||||
|
|
||||||
|
if (ytCount === 0 && localResults.length === 0) {
|
||||||
|
var emptyTitle = ytData.searchError
|
||||||
|
? 'YouTube bağlantısı geçici olarak zaman aşımına uğradı'
|
||||||
|
: '"' + escapeHtml(query) + '" için Sonuç Bulunamadı';
|
||||||
|
var retryHtml = ytData.searchError
|
||||||
|
? '<div style="padding:14px 0;"><button type="button" id="yaktube-retry-search-btn" class="yaktube-shortcuts-btn" style="background:#ff8f37;color:#000;border:none;font-weight:700;">🔄 YouTube Aramasını Tekrar Dene</button></div>'
|
||||||
|
: '';
|
||||||
|
targetContainer.innerHTML =
|
||||||
|
'<div class="yaktube-header">' +
|
||||||
|
'<div class="yaktube-header-left">' +
|
||||||
|
'<span class="yaktube-badge">⚡ Canlı YouTube & Web Arama</span>' +
|
||||||
|
'<h2 class="yaktube-title-h3" style="margin:0; font-size:1.15rem;">' +
|
||||||
|
emptyTitle +
|
||||||
|
'</h2>' +
|
||||||
|
'</div>' +
|
||||||
|
'<button class="yaktube-shortcuts-btn" id="yaktube-open-shortcuts" aria-label="Klavye Kısayolları Kılavuzunu Aç">' +
|
||||||
|
'⌨️ Kısayollar (?)' +
|
||||||
|
'</button>' +
|
||||||
|
'</div>' +
|
||||||
|
retryHtml;
|
||||||
|
var rBtn = document.getElementById('yaktube-retry-search-btn');
|
||||||
|
if (rBtn) {
|
||||||
|
rBtn.addEventListener('click', function () {
|
||||||
|
window.__yaktube_last_search_snapshot__ = null;
|
||||||
|
lastQuery = null;
|
||||||
|
checkAndInjectSearchResults();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
var scBtn = document.getElementById('yaktube-open-shortcuts');
|
||||||
|
if (scBtn) scBtn.addEventListener('click', toggleShortcutsModal);
|
||||||
|
announce(
|
||||||
|
ytData.searchError
|
||||||
|
? 'YouTube bağlantısı geçici olarak yanıt vermedi.'
|
||||||
|
: query + ' için eşleşen video bulunamadı.'
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var visibleYtCount = Math.min(12, ytCount);
|
||||||
|
|
||||||
|
function renderAll() {
|
||||||
|
var ytHeaderHtml = '';
|
||||||
|
var ytCardsHtml = '';
|
||||||
|
var ytLoadMoreHtml = '';
|
||||||
|
|
||||||
|
if (ytCount > 0) {
|
||||||
|
var countText = ytCount === 1 ? '1 Video Bulundu' : ytCount + ' Video Bulundu';
|
||||||
|
ytHeaderHtml =
|
||||||
|
'<div class="yaktube-header">' +
|
||||||
|
'<div class="yaktube-header-left">' +
|
||||||
|
'<span class="yaktube-badge">⚡ Canlı YouTube & Web Arama</span>' +
|
||||||
|
'<h2 class="yaktube-title-h3" style="margin:0; font-size:1.15rem;">"' +
|
||||||
|
escapeHtml(query) +
|
||||||
|
'" için ' +
|
||||||
|
countText +
|
||||||
|
'</h2>' +
|
||||||
|
'</div>' +
|
||||||
|
'<button class="yaktube-shortcuts-btn" id="yaktube-open-shortcuts" aria-label="Klavye Kısayolları Kılavuzunu Aç">' +
|
||||||
|
'⌨️ Kısayollar (?)' +
|
||||||
|
'</button>' +
|
||||||
|
'</div>';
|
||||||
|
|
||||||
|
var visibleResults = uniqueYtResults.slice(0, visibleYtCount);
|
||||||
|
visibleResults.forEach(function (item) {
|
||||||
|
if (item && item.title && item.channel) {
|
||||||
|
saveVideoChannelMeta(
|
||||||
|
item.title,
|
||||||
|
item.channel,
|
||||||
|
item.id || '',
|
||||||
|
(item.localVideo && item.localVideo.uuid) || ''
|
||||||
|
);
|
||||||
|
}
|
||||||
|
var isLocal = !!item.isDownloaded;
|
||||||
|
var isLive = !!item.isLive;
|
||||||
|
|
||||||
|
var statusBadge = '';
|
||||||
|
if (isLive) {
|
||||||
|
statusBadge =
|
||||||
|
'<span class="yaktube-badge" style="background: #dc2626; color: #fff; margin-bottom: 6px; display: inline-block; font-weight: 700;">🔴 CANLI YAYIN</span>';
|
||||||
|
} else if (isLocal) {
|
||||||
|
statusBadge =
|
||||||
|
'<span class="yaktube-badge" style="background: linear-gradient(135deg, #10b981 0%, #059669 100%); margin-bottom: 6px; display: inline-block;">✅ ' +
|
||||||
|
escapeHtml(getInstanceName()) +
|
||||||
|
"'da Mevcut</span>";
|
||||||
|
}
|
||||||
|
|
||||||
|
var actionButton = '';
|
||||||
|
if (isLive) {
|
||||||
|
actionButton =
|
||||||
|
'<button class="yaktube-live-btn" data-url="' +
|
||||||
|
escapeHtml(item.url) +
|
||||||
|
'" data-title="' +
|
||||||
|
escapeHtml(item.title) +
|
||||||
|
'" style="background: linear-gradient(135deg, #ef4444 0%, #b91c1c 100%); color: #fff; border: none; padding: 8px 14px; border-radius: 6px; font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;" aria-label="' +
|
||||||
|
escapeHtml(item.title) +
|
||||||
|
' canlı yayınını hemen izle">🔴 Canlı Yayını İzle</button>';
|
||||||
|
} else if (isLocal && item.localVideo && item.localVideo.url) {
|
||||||
|
actionButton =
|
||||||
|
'<a href="' +
|
||||||
|
escapeHtml(item.localVideo.url) +
|
||||||
|
'" class="yaktube-play-btn" aria-label="' +
|
||||||
|
escapeHtml(item.title) +
|
||||||
|
' videosunu ' +
|
||||||
|
escapeHtml(getInstanceName()) +
|
||||||
|
'\'dan hemen izle">▶️ ' +
|
||||||
|
escapeHtml(getInstanceName()) +
|
||||||
|
"'dan İzle</a>";
|
||||||
|
} else {
|
||||||
|
actionButton =
|
||||||
|
'<button class="yaktube-import-btn" data-url="' +
|
||||||
|
escapeHtml(item.url) +
|
||||||
|
'" data-title="' +
|
||||||
|
escapeHtml(item.title) +
|
||||||
|
'" aria-label="' +
|
||||||
|
escapeHtml(item.title) +
|
||||||
|
' videosunu ' +
|
||||||
|
escapeHtml(getInstanceName()) +
|
||||||
|
'\'a aktar ve izle">📥 ' +
|
||||||
|
escapeHtml(getInstanceName()) +
|
||||||
|
"'a Aktar & İzle</button>";
|
||||||
|
}
|
||||||
|
|
||||||
|
var durationText = isLive ? 'CANLI' : item.durationFormatted || formatClockTime(item.duration);
|
||||||
|
var cardLabel =
|
||||||
|
item.title +
|
||||||
|
(isLive ? ' (Canlı Yayın)' : isLocal ? ' (' + getInstanceName() + ' kütüphanenizde mevcut)' : '') +
|
||||||
|
', ' +
|
||||||
|
item.channel +
|
||||||
|
' kanalı, Süre: ' +
|
||||||
|
durationText;
|
||||||
|
|
||||||
|
ytCardsHtml +=
|
||||||
|
'<div class="yaktube-card" role="article" tabindex="0" aria-label="' +
|
||||||
|
escapeHtml(cardLabel) +
|
||||||
|
'">' +
|
||||||
|
'<div class="yaktube-thumb-wrap">' +
|
||||||
|
'<img class="yaktube-thumb-img" src="' +
|
||||||
|
escapeHtml(item.thumbnail) +
|
||||||
|
'" alt="' +
|
||||||
|
escapeHtml(item.title) +
|
||||||
|
'" loading="lazy" />' +
|
||||||
|
'<span class="yaktube-duration-badge" style="' +
|
||||||
|
(isLive ? 'background:#dc2626;font-weight:700;' : '') +
|
||||||
|
'" aria-label="Süre">' +
|
||||||
|
escapeHtml(durationText) +
|
||||||
|
'</span>' +
|
||||||
|
'</div>' +
|
||||||
|
'<div class="yaktube-info">' +
|
||||||
|
'<div>' +
|
||||||
|
statusBadge +
|
||||||
|
'<h3 class="yaktube-video-name" title="' +
|
||||||
|
escapeHtml(item.title) +
|
||||||
|
'" style="margin:0; font-size:13px; font-weight:600; line-height:1.35;">' +
|
||||||
|
escapeHtml(item.title) +
|
||||||
|
'</h3>' +
|
||||||
|
'<div class="yaktube-channel-name">' +
|
||||||
|
escapeHtml(item.channel) +
|
||||||
|
'</div>' +
|
||||||
|
'</div>' +
|
||||||
|
actionButton +
|
||||||
|
'</div>' +
|
||||||
|
'</div>';
|
||||||
|
});
|
||||||
|
|
||||||
|
if (visibleYtCount < ytCount) {
|
||||||
|
ytLoadMoreHtml =
|
||||||
|
'<div style="text-align: center; margin: 20px 0 10px 0;">' +
|
||||||
|
'<button id="yaktube-load-more-btn" class="yaktube-load-more-btn" style="background: #1e293b; color: #ff8f37; border: 1px solid #ff8f37; padding: 10px 24px; border-radius: 8px; font-weight: 700; font-size: 14px; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; transition: all 0.2s ease; box-shadow: 0 4px 12px rgba(0,0,0,0.3);" aria-label="Daha fazla video yükle">' +
|
||||||
|
'➕ Daha Fazla Video Göster (' +
|
||||||
|
visibleYtCount +
|
||||||
|
' / ' +
|
||||||
|
ytCount +
|
||||||
|
')' +
|
||||||
|
'</button>' +
|
||||||
|
'</div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var localShelfHtml = '';
|
||||||
|
if (localResults.length > 0) {
|
||||||
|
var localCardsHtml = '';
|
||||||
|
localResults.forEach(function (lItem) {
|
||||||
|
var lThumb =
|
||||||
|
lItem.thumbnailPath ||
|
||||||
|
(lItem.thumbnails && lItem.thumbnails[0]
|
||||||
|
? lItem.thumbnails[0].fileUrl
|
||||||
|
: '/client/assets/images/default-thumbnail.jpg');
|
||||||
|
var lDuration = formatClockTime(lItem.duration);
|
||||||
|
var lChannel =
|
||||||
|
(lItem.channel && (lItem.channel.displayName || lItem.channel.name)) ||
|
||||||
|
(lItem.account && (lItem.account.displayName || lItem.account.name)) ||
|
||||||
|
getInstanceName();
|
||||||
|
var lWatchUrl = lItem.url || '/videos/watch/' + (lItem.shortUUID || lItem.uuid);
|
||||||
|
var lViews = (lItem.views || 0) + ' görüntüleme';
|
||||||
|
var lLabel =
|
||||||
|
lItem.name +
|
||||||
|
', ' +
|
||||||
|
lChannel +
|
||||||
|
', ' +
|
||||||
|
getInstanceName() +
|
||||||
|
' yerel sunucusunda mevcut, Süre: ' +
|
||||||
|
lDuration;
|
||||||
|
|
||||||
|
localCardsHtml +=
|
||||||
|
'<div class="yaktube-card yaktube-local-card" role="article" tabindex="0" aria-label="' +
|
||||||
|
escapeHtml(lLabel) +
|
||||||
|
'">' +
|
||||||
|
'<a href="' +
|
||||||
|
escapeHtml(lWatchUrl) +
|
||||||
|
'" style="text-decoration:none; color:inherit; display:flex; flex-direction:column; height:100%;">' +
|
||||||
|
'<div class="yaktube-thumb-wrap">' +
|
||||||
|
'<img class="yaktube-thumb-img" src="' +
|
||||||
|
escapeHtml(lThumb) +
|
||||||
|
'" alt="' +
|
||||||
|
escapeHtml(lItem.name) +
|
||||||
|
'" loading="lazy" onerror="this.src=\'/client/assets/images/default-thumbnail.jpg\'" />' +
|
||||||
|
'<span class="yaktube-duration-badge" aria-label="Süre">' +
|
||||||
|
escapeHtml(lDuration) +
|
||||||
|
'</span>' +
|
||||||
|
'</div>' +
|
||||||
|
'<div class="yaktube-info">' +
|
||||||
|
'<div>' +
|
||||||
|
'<span class="yaktube-badge" style="background: linear-gradient(135deg, #10b981 0%, #059669 100%); margin-bottom: 6px; display: inline-block;">✅ ' +
|
||||||
|
escapeHtml(getInstanceName()) +
|
||||||
|
"'da Mevcut</span>" +
|
||||||
|
'<h3 class="yaktube-video-name" title="' +
|
||||||
|
escapeHtml(lItem.name) +
|
||||||
|
'" style="margin:0; font-size:13px; font-weight:600; line-height:1.35;">' +
|
||||||
|
escapeHtml(lItem.name) +
|
||||||
|
'</h3>' +
|
||||||
|
'<div class="yaktube-channel-name">' +
|
||||||
|
escapeHtml(lChannel) +
|
||||||
|
' • ' +
|
||||||
|
escapeHtml(lViews) +
|
||||||
|
'</div>' +
|
||||||
|
'</div>' +
|
||||||
|
'<div class="yaktube-play-btn" style="margin-top:8px;">▶️ ' +
|
||||||
|
escapeHtml(getInstanceName()) +
|
||||||
|
"'dan Hemen İzle</div>" +
|
||||||
|
'</div>' +
|
||||||
|
'</a>' +
|
||||||
|
'</div>';
|
||||||
|
});
|
||||||
|
|
||||||
|
localShelfHtml =
|
||||||
|
'<div id="yaktube-local-shelf" class="yaktube-local-shelf" role="region" aria-label="' +
|
||||||
|
escapeHtml(getInstanceName()) +
|
||||||
|
' Yerel Kütüphanesi">' +
|
||||||
|
'<div class="yaktube-header" style="margin-top: 24px; border-bottom-color: rgba(16, 185, 129, 0.3);">' +
|
||||||
|
'<div class="yaktube-header-left">' +
|
||||||
|
'<span class="yaktube-badge" style="background: linear-gradient(135deg, #10b981 0%, #059669 100%);">✅ Yerel Kütüphane</span>' +
|
||||||
|
'<h2 class="yaktube-title-h3" style="margin:0; font-size:1.15rem;">"' +
|
||||||
|
escapeHtml(query) +
|
||||||
|
'" için ' +
|
||||||
|
escapeHtml(getInstanceName()) +
|
||||||
|
' Sunucusunda ' +
|
||||||
|
localTotal +
|
||||||
|
' Video Bulundu</h2>' +
|
||||||
|
'</div>' +
|
||||||
|
'<span class="yaktube-local-shelf-sub">Doğrudan sunucumuzda barındırılan, yüksek hızlı ve anında izlenebilen videolar</span>' +
|
||||||
|
'</div>' +
|
||||||
|
'<div class="yaktube-grid">' +
|
||||||
|
localCardsHtml +
|
||||||
|
'</div>' +
|
||||||
|
'</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
targetContainer.innerHTML =
|
||||||
|
ytHeaderHtml +
|
||||||
|
(ytCount > 0 ? '<div class="yaktube-grid">' + ytCardsHtml + '</div>' : '') +
|
||||||
|
ytLoadMoreHtml +
|
||||||
|
localShelfHtml;
|
||||||
|
|
||||||
|
var sBtn = document.getElementById('yaktube-open-shortcuts');
|
||||||
|
if (sBtn) {
|
||||||
|
sBtn.addEventListener('click', toggleShortcutsModal);
|
||||||
|
}
|
||||||
|
|
||||||
|
var loadMoreBtn = document.getElementById('yaktube-load-more-btn');
|
||||||
|
if (loadMoreBtn) {
|
||||||
|
loadMoreBtn.addEventListener('click', function () {
|
||||||
|
visibleYtCount = Math.min(visibleYtCount + 6, ytCount);
|
||||||
|
renderAll();
|
||||||
|
announce(visibleYtCount + ' adet video gösteriliyor.');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
targetContainer.querySelectorAll('.yaktube-live-btn').forEach(function (btn) {
|
||||||
|
btn.addEventListener('click', function (e) {
|
||||||
|
var liveUrl = e.currentTarget.getAttribute('data-url');
|
||||||
|
var liveTitle = e.currentTarget.getAttribute('data-title');
|
||||||
|
handleLiveStream(liveUrl, liveTitle);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
targetContainer.querySelectorAll('.yaktube-import-btn').forEach(function (btn) {
|
||||||
|
btn.addEventListener('click', function (e) {
|
||||||
|
var videoUrl = e.currentTarget.getAttribute('data-url');
|
||||||
|
var videoTitle = e.currentTarget.getAttribute('data-title');
|
||||||
|
handleImport(videoUrl, e.currentTarget, videoTitle);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
renderAll();
|
||||||
|
}
|
||||||
|
|
||||||
if (queryKey === lastQueryKey) {
|
if (queryKey === lastQueryKey) {
|
||||||
if (container && container.parentElement !== searchMount) {
|
if (container) {
|
||||||
searchMount.insertBefore(container, nativeResults || searchMount.firstChild);
|
if (container.parentElement !== searchMount) {
|
||||||
|
searchMount.insertBefore(container, nativeResults || searchMount.firstChild);
|
||||||
|
}
|
||||||
|
ensureFediverseBridge(query, currentSearchTarget);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// If Angular re-rendered <my-search> and wiped #yaktube-ondemand-container, restore instantly!
|
||||||
|
if (!isSearching) {
|
||||||
|
var snap = window.__yaktube_last_search_snapshot__;
|
||||||
|
if (snap && snap.key === queryKey) {
|
||||||
|
var restoredContainer = ensureSearchContainerMounted();
|
||||||
|
renderSearchOutcome(snap.ytData, snap.localData, restoredContainer);
|
||||||
|
ensureFediverseBridge(query, currentSearchTarget);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lastQuery = null;
|
||||||
|
lastSearchTarget = null;
|
||||||
|
} else {
|
||||||
|
container = ensureSearchContainerMounted();
|
||||||
|
ensureFediverseBridge(query, currentSearchTarget);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
ensureFediverseBridge(query, currentSearchTarget);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
lastQuery = query;
|
lastQuery = query;
|
||||||
lastSearchTarget = currentSearchTarget;
|
lastSearchTarget = currentSearchTarget;
|
||||||
|
container = ensureSearchContainerMounted();
|
||||||
if (!container) {
|
|
||||||
container = document.createElement('div');
|
|
||||||
container.id = 'yaktube-ondemand-container';
|
|
||||||
container.className = 'yaktube-ondemand-section';
|
|
||||||
container.setAttribute('role', 'region');
|
|
||||||
container.setAttribute('aria-label', 'Canlı YouTube ve ' + getInstanceName() + ' Arama Sonuçları');
|
|
||||||
searchMount.insertBefore(container, nativeResults || searchMount.firstChild);
|
|
||||||
} else if (container.parentElement !== searchMount) {
|
|
||||||
searchMount.insertBefore(container, nativeResults || searchMount.firstChild);
|
|
||||||
}
|
|
||||||
|
|
||||||
container.innerHTML =
|
container.innerHTML =
|
||||||
'<div class="yaktube-header">' +
|
'<div class="yaktube-header">' +
|
||||||
@@ -4525,359 +4899,49 @@ try {
|
|||||||
|
|
||||||
Promise.all([
|
Promise.all([
|
||||||
fetchPluginJson('/youtube-search?q=' + encodeURIComponent(query), fetchOpts).catch(function (err) {
|
fetchPluginJson('/youtube-search?q=' + encodeURIComponent(query), fetchOpts).catch(function (err) {
|
||||||
if (err && err.name === 'AbortError') return { results: [] };
|
if (err && err.name === 'AbortError') return { results: [], aborted: true };
|
||||||
console.warn('[YakTube] YouTube search fetch error:', err);
|
console.warn('[YakTube] YouTube search fetch error:', err);
|
||||||
return { results: [] };
|
return { results: [], searchError: true };
|
||||||
}),
|
}),
|
||||||
fetch('/api/v1/search/videos?search=' + encodeURIComponent(query) + '&isLocal=true&count=12', fetchOpts)
|
fetch('/api/v1/search/videos?search=' + encodeURIComponent(query) + '&isLocal=true&count=12', fetchOpts)
|
||||||
.then(function (res) {
|
.then(function (res) {
|
||||||
return res.json();
|
return res.json();
|
||||||
})
|
})
|
||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
if (err && err.name === 'AbortError') return { total: 0, data: [] };
|
if (err && err.name === 'AbortError') return { total: 0, data: [], aborted: true };
|
||||||
console.warn('[YakTube] Local videos search fetch error:', err);
|
console.warn('[YakTube] Local videos search fetch error:', err);
|
||||||
return { total: 0, data: [] };
|
return { total: 0, data: [] };
|
||||||
})
|
})
|
||||||
])
|
])
|
||||||
.then(function (responses) {
|
.then(function (responses) {
|
||||||
|
if (abortCtrl && abortCtrl.signal && abortCtrl.signal.aborted) return;
|
||||||
var ytData = responses[0] || {};
|
var ytData = responses[0] || {};
|
||||||
var localData = responses[1] || {};
|
var localData = responses[1] || {};
|
||||||
if (typeof ytData.guestImportLimit === 'number') {
|
if (ytData.aborted || localData.aborted) return;
|
||||||
cachedGuestImportLimit = ytData.guestImportLimit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ytData && ytData.blocked) {
|
window.__yaktube_last_search_snapshot__ = { key: queryKey, ytData: ytData, localData: localData };
|
||||||
var safetyMsg =
|
var activeContainer = ensureSearchContainerMounted();
|
||||||
ytData.message ||
|
renderSearchOutcome(ytData, localData, activeContainer);
|
||||||
'Bu arama terimi veya içerik, Çocuk ve Aile Güvenliği (Child & Family Safety) politikaları gereğince filtrelenmiştir.';
|
|
||||||
container.innerHTML =
|
|
||||||
'<div class="yaktube-header" style="border-left: 4px solid #ef4444; background: rgba(239, 68, 68, 0.08); padding: 18px 20px; border-radius: 8px; margin-bottom: 24px;">' +
|
|
||||||
'<div class="yaktube-header-left">' +
|
|
||||||
'<span class="yaktube-badge" style="background:#ef4444; color:#fff; font-weight:700;">🛡️ Çocuk ve Aile Güvenliği Koruması</span>' +
|
|
||||||
'<h2 class="yaktube-title-h3" style="margin:8px 0 4px; font-size:1.15rem; color:#f87171;">Arama Filtrelendi</h2>' +
|
|
||||||
'<p style="margin:0; font-size:0.95rem; color:#cbd5e1;">' +
|
|
||||||
escapeHtml(safetyMsg) +
|
|
||||||
'</p>' +
|
|
||||||
'</div>' +
|
|
||||||
'</div>';
|
|
||||||
announce(safetyMsg, true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var rawYtResults = ytData.results || [];
|
|
||||||
var uniqueYtResults = [];
|
|
||||||
var seenIds = {};
|
|
||||||
|
|
||||||
rawYtResults.forEach(function (item) {
|
|
||||||
if (item && item.id && !seenIds[item.id] && item.title) {
|
|
||||||
seenIds[item.id] = true;
|
|
||||||
uniqueYtResults.push(item);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var ytCount = uniqueYtResults.length;
|
|
||||||
var localResults = localData.data || [];
|
|
||||||
var localTotal = typeof localData.total === 'number' ? localData.total : localResults.length;
|
|
||||||
|
|
||||||
if (ytCount === 0 && localResults.length === 0) {
|
|
||||||
container.innerHTML =
|
|
||||||
'<div class="yaktube-header">' +
|
|
||||||
'<div class="yaktube-header-left">' +
|
|
||||||
'<span class="yaktube-badge">⚡ Canlı YouTube & Web Arama</span>' +
|
|
||||||
'<h2 class="yaktube-title-h3" style="margin:0; font-size:1.15rem;">"' +
|
|
||||||
escapeHtml(query) +
|
|
||||||
'" için Sonuç Bulunamadı</h2>' +
|
|
||||||
'</div>' +
|
|
||||||
'<button class="yaktube-shortcuts-btn" id="yaktube-open-shortcuts" aria-label="Klavye Kısayolları Kılavuzunu Aç">' +
|
|
||||||
'⌨️ Kısayollar (?)' +
|
|
||||||
'</button>' +
|
|
||||||
'</div>';
|
|
||||||
announce(query + ' için YouTube veya yerel sunucuda eşleşen video bulunamadı.');
|
|
||||||
} else {
|
|
||||||
var visibleYtCount = Math.min(12, ytCount);
|
|
||||||
|
|
||||||
function renderAll() {
|
|
||||||
// 1. YouTube Section
|
|
||||||
var ytHeaderHtml = '';
|
|
||||||
var ytCardsHtml = '';
|
|
||||||
var ytLoadMoreHtml = '';
|
|
||||||
|
|
||||||
if (ytCount > 0) {
|
|
||||||
var countText = ytCount === 1 ? '1 Video Bulundu' : ytCount + ' Video Bulundu';
|
|
||||||
ytHeaderHtml =
|
|
||||||
'<div class="yaktube-header">' +
|
|
||||||
'<div class="yaktube-header-left">' +
|
|
||||||
'<span class="yaktube-badge">⚡ Canlı YouTube & Web Arama</span>' +
|
|
||||||
'<h2 class="yaktube-title-h3" style="margin:0; font-size:1.15rem;">"' +
|
|
||||||
escapeHtml(query) +
|
|
||||||
'" için ' +
|
|
||||||
countText +
|
|
||||||
'</h2>' +
|
|
||||||
'</div>' +
|
|
||||||
'<button class="yaktube-shortcuts-btn" id="yaktube-open-shortcuts" aria-label="Klavye Kısayolları Kılavuzunu Aç">' +
|
|
||||||
'⌨️ Kısayollar (?)' +
|
|
||||||
'</button>' +
|
|
||||||
'</div>';
|
|
||||||
|
|
||||||
var visibleResults = uniqueYtResults.slice(0, visibleYtCount);
|
|
||||||
visibleResults.forEach(function (item) {
|
|
||||||
if (item && item.title && item.channel) {
|
|
||||||
saveVideoChannelMeta(
|
|
||||||
item.title,
|
|
||||||
item.channel,
|
|
||||||
item.id || '',
|
|
||||||
(item.localVideo && item.localVideo.uuid) || ''
|
|
||||||
);
|
|
||||||
}
|
|
||||||
var isLocal = !!item.isDownloaded;
|
|
||||||
var isLive = !!item.isLive;
|
|
||||||
|
|
||||||
var statusBadge = '';
|
|
||||||
if (isLive) {
|
|
||||||
statusBadge =
|
|
||||||
'<span class="yaktube-badge" style="background: #dc2626; color: #fff; margin-bottom: 6px; display: inline-block; font-weight: 700;">🔴 CANLI YAYIN</span>';
|
|
||||||
} else if (isLocal) {
|
|
||||||
statusBadge =
|
|
||||||
'<span class="yaktube-badge" style="background: linear-gradient(135deg, #10b981 0%, #059669 100%); margin-bottom: 6px; display: inline-block;">✅ ' +
|
|
||||||
escapeHtml(getInstanceName()) +
|
|
||||||
"'da Mevcut</span>";
|
|
||||||
}
|
|
||||||
|
|
||||||
var actionButton = '';
|
|
||||||
if (isLive) {
|
|
||||||
actionButton =
|
|
||||||
'<button class="yaktube-live-btn" data-url="' +
|
|
||||||
escapeHtml(item.url) +
|
|
||||||
'" data-title="' +
|
|
||||||
escapeHtml(item.title) +
|
|
||||||
'" style="background: linear-gradient(135deg, #ef4444 0%, #b91c1c 100%); color: #fff; border: none; padding: 8px 14px; border-radius: 6px; font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;" aria-label="' +
|
|
||||||
escapeHtml(item.title) +
|
|
||||||
' canlı yayınını hemen izle">🔴 Canlı Yayını İzle</button>';
|
|
||||||
} else if (isLocal && item.localVideo && item.localVideo.url) {
|
|
||||||
actionButton =
|
|
||||||
'<a href="' +
|
|
||||||
escapeHtml(item.localVideo.url) +
|
|
||||||
'" class="yaktube-play-btn" aria-label="' +
|
|
||||||
escapeHtml(item.title) +
|
|
||||||
' videosunu ' +
|
|
||||||
escapeHtml(getInstanceName()) +
|
|
||||||
'\'dan hemen izle">▶️ ' +
|
|
||||||
escapeHtml(getInstanceName()) +
|
|
||||||
"'dan İzle</a>";
|
|
||||||
} else {
|
|
||||||
actionButton =
|
|
||||||
'<button class="yaktube-import-btn" data-url="' +
|
|
||||||
escapeHtml(item.url) +
|
|
||||||
'" data-title="' +
|
|
||||||
escapeHtml(item.title) +
|
|
||||||
'" aria-label="' +
|
|
||||||
escapeHtml(item.title) +
|
|
||||||
' videosunu ' +
|
|
||||||
escapeHtml(getInstanceName()) +
|
|
||||||
'\'a aktar ve izle">📥 ' +
|
|
||||||
escapeHtml(getInstanceName()) +
|
|
||||||
"'a Aktar & İzle</button>";
|
|
||||||
}
|
|
||||||
|
|
||||||
var durationText = isLive ? 'CANLI' : item.durationFormatted || formatClockTime(item.duration);
|
|
||||||
var cardLabel =
|
|
||||||
item.title +
|
|
||||||
(isLive ? ' (Canlı Yayın)' : isLocal ? ' (' + getInstanceName() + ' kütüphanenizde mevcut)' : '') +
|
|
||||||
', ' +
|
|
||||||
item.channel +
|
|
||||||
' kanalı, Süre: ' +
|
|
||||||
durationText;
|
|
||||||
|
|
||||||
ytCardsHtml +=
|
|
||||||
'<div class="yaktube-card" role="article" tabindex="0" aria-label="' +
|
|
||||||
escapeHtml(cardLabel) +
|
|
||||||
'">' +
|
|
||||||
'<div class="yaktube-thumb-wrap">' +
|
|
||||||
'<img class="yaktube-thumb-img" src="' +
|
|
||||||
escapeHtml(item.thumbnail) +
|
|
||||||
'" alt="' +
|
|
||||||
escapeHtml(item.title) +
|
|
||||||
'" loading="lazy" />' +
|
|
||||||
'<span class="yaktube-duration-badge" style="' +
|
|
||||||
(isLive ? 'background:#dc2626;font-weight:700;' : '') +
|
|
||||||
'" aria-label="Süre">' +
|
|
||||||
escapeHtml(durationText) +
|
|
||||||
'</span>' +
|
|
||||||
'</div>' +
|
|
||||||
'<div class="yaktube-info">' +
|
|
||||||
'<div>' +
|
|
||||||
statusBadge +
|
|
||||||
'<h3 class="yaktube-video-name" title="' +
|
|
||||||
escapeHtml(item.title) +
|
|
||||||
'" style="margin:0; font-size:13px; font-weight:600; line-height:1.35;">' +
|
|
||||||
escapeHtml(item.title) +
|
|
||||||
'</h3>' +
|
|
||||||
'<div class="yaktube-channel-name">' +
|
|
||||||
escapeHtml(item.channel) +
|
|
||||||
'</div>' +
|
|
||||||
'</div>' +
|
|
||||||
actionButton +
|
|
||||||
'</div>' +
|
|
||||||
'</div>';
|
|
||||||
});
|
|
||||||
|
|
||||||
if (visibleYtCount < ytCount) {
|
|
||||||
ytLoadMoreHtml =
|
|
||||||
'<div style="text-align: center; margin: 20px 0 10px 0;">' +
|
|
||||||
'<button id="yaktube-load-more-btn" class="yaktube-load-more-btn" style="background: #1e293b; color: #ff8f37; border: 1px solid #ff8f37; padding: 10px 24px; border-radius: 8px; font-weight: 700; font-size: 14px; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; transition: all 0.2s ease; box-shadow: 0 4px 12px rgba(0,0,0,0.3);" aria-label="Daha fazla video yükle">' +
|
|
||||||
'➕ Daha Fazla Video Göster (' +
|
|
||||||
visibleYtCount +
|
|
||||||
' / ' +
|
|
||||||
ytCount +
|
|
||||||
')' +
|
|
||||||
'</button>' +
|
|
||||||
'</div>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. Local Videos Shelf
|
|
||||||
var localShelfHtml = '';
|
|
||||||
if (localResults.length > 0) {
|
|
||||||
var localCardsHtml = '';
|
|
||||||
localResults.forEach(function (lItem) {
|
|
||||||
var lThumb =
|
|
||||||
lItem.thumbnailPath ||
|
|
||||||
(lItem.thumbnails && lItem.thumbnails[0]
|
|
||||||
? lItem.thumbnails[0].fileUrl
|
|
||||||
: '/client/assets/images/default-thumbnail.jpg');
|
|
||||||
var lDuration = formatClockTime(lItem.duration);
|
|
||||||
var lChannel =
|
|
||||||
(lItem.channel && (lItem.channel.displayName || lItem.channel.name)) ||
|
|
||||||
(lItem.account && (lItem.account.displayName || lItem.account.name)) ||
|
|
||||||
getInstanceName();
|
|
||||||
var lWatchUrl = lItem.url || '/videos/watch/' + (lItem.shortUUID || lItem.uuid);
|
|
||||||
var lViews = (lItem.views || 0) + ' görüntüleme';
|
|
||||||
var lLabel =
|
|
||||||
lItem.name +
|
|
||||||
', ' +
|
|
||||||
lChannel +
|
|
||||||
', ' +
|
|
||||||
getInstanceName() +
|
|
||||||
' yerel sunucusunda mevcut, Süre: ' +
|
|
||||||
lDuration;
|
|
||||||
|
|
||||||
localCardsHtml +=
|
|
||||||
'<div class="yaktube-card yaktube-local-card" role="article" tabindex="0" aria-label="' +
|
|
||||||
escapeHtml(lLabel) +
|
|
||||||
'">' +
|
|
||||||
'<a href="' +
|
|
||||||
escapeHtml(lWatchUrl) +
|
|
||||||
'" style="text-decoration:none; color:inherit; display:flex; flex-direction:column; height:100%;">' +
|
|
||||||
'<div class="yaktube-thumb-wrap">' +
|
|
||||||
'<img class="yaktube-thumb-img" src="' +
|
|
||||||
escapeHtml(lThumb) +
|
|
||||||
'" alt="' +
|
|
||||||
escapeHtml(lItem.name) +
|
|
||||||
'" loading="lazy" onerror="this.src=\'/client/assets/images/default-thumbnail.jpg\'" />' +
|
|
||||||
'<span class="yaktube-duration-badge" aria-label="Süre">' +
|
|
||||||
escapeHtml(lDuration) +
|
|
||||||
'</span>' +
|
|
||||||
'</div>' +
|
|
||||||
'<div class="yaktube-info">' +
|
|
||||||
'<div>' +
|
|
||||||
'<span class="yaktube-badge" style="background: linear-gradient(135deg, #10b981 0%, #059669 100%); margin-bottom: 6px; display: inline-block;">✅ ' +
|
|
||||||
escapeHtml(getInstanceName()) +
|
|
||||||
"'da Mevcut</span>" +
|
|
||||||
'<h3 class="yaktube-video-name" title="' +
|
|
||||||
escapeHtml(lItem.name) +
|
|
||||||
'" style="margin:0; font-size:13px; font-weight:600; line-height:1.35;">' +
|
|
||||||
escapeHtml(lItem.name) +
|
|
||||||
'</h3>' +
|
|
||||||
'<div class="yaktube-channel-name">' +
|
|
||||||
escapeHtml(lChannel) +
|
|
||||||
' • ' +
|
|
||||||
escapeHtml(lViews) +
|
|
||||||
'</div>' +
|
|
||||||
'</div>' +
|
|
||||||
'<div class="yaktube-play-btn" style="margin-top:8px;">▶️ ' +
|
|
||||||
escapeHtml(getInstanceName()) +
|
|
||||||
"'dan Hemen İzle</div>" +
|
|
||||||
'</div>' +
|
|
||||||
'</a>' +
|
|
||||||
'</div>';
|
|
||||||
});
|
|
||||||
|
|
||||||
localShelfHtml =
|
|
||||||
'<div id="yaktube-local-shelf" class="yaktube-local-shelf" role="region" aria-label="' +
|
|
||||||
escapeHtml(getInstanceName()) +
|
|
||||||
' Yerel Kütüphanesi">' +
|
|
||||||
'<div class="yaktube-header" style="margin-top: 24px; border-bottom-color: rgba(16, 185, 129, 0.3);">' +
|
|
||||||
'<div class="yaktube-header-left">' +
|
|
||||||
'<span class="yaktube-badge" style="background: linear-gradient(135deg, #10b981 0%, #059669 100%);">✅ Yerel Kütüphane</span>' +
|
|
||||||
'<h2 class="yaktube-title-h3" style="margin:0; font-size:1.15rem;">"' +
|
|
||||||
escapeHtml(query) +
|
|
||||||
'" için ' +
|
|
||||||
escapeHtml(getInstanceName()) +
|
|
||||||
' Sunucusunda ' +
|
|
||||||
localTotal +
|
|
||||||
' Video Bulundu</h2>' +
|
|
||||||
'</div>' +
|
|
||||||
'<span class="yaktube-local-shelf-sub">Doğrudan sunucumuzda barındırılan, yüksek hızlı ve anında izlenebilen videolar</span>' +
|
|
||||||
'</div>' +
|
|
||||||
'<div class="yaktube-grid">' +
|
|
||||||
localCardsHtml +
|
|
||||||
'</div>' +
|
|
||||||
'</div>';
|
|
||||||
}
|
|
||||||
|
|
||||||
container.innerHTML =
|
|
||||||
ytHeaderHtml +
|
|
||||||
(ytCount > 0 ? '<div class="yaktube-grid">' + ytCardsHtml + '</div>' : '') +
|
|
||||||
ytLoadMoreHtml +
|
|
||||||
localShelfHtml;
|
|
||||||
|
|
||||||
var sBtn = document.getElementById('yaktube-open-shortcuts');
|
|
||||||
if (sBtn) {
|
|
||||||
sBtn.addEventListener('click', toggleShortcutsModal);
|
|
||||||
}
|
|
||||||
|
|
||||||
var loadMoreBtn = document.getElementById('yaktube-load-more-btn');
|
|
||||||
if (loadMoreBtn) {
|
|
||||||
loadMoreBtn.addEventListener('click', function () {
|
|
||||||
visibleYtCount = Math.min(visibleYtCount + 6, ytCount);
|
|
||||||
renderAll();
|
|
||||||
announce(visibleYtCount + ' adet video gösteriliyor.');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
container.querySelectorAll('.yaktube-live-btn').forEach(function (btn) {
|
|
||||||
btn.addEventListener('click', function (e) {
|
|
||||||
var liveUrl = e.currentTarget.getAttribute('data-url');
|
|
||||||
var liveTitle = e.currentTarget.getAttribute('data-title');
|
|
||||||
handleLiveStream(liveUrl, liveTitle);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
container.querySelectorAll('.yaktube-import-btn').forEach(function (btn) {
|
|
||||||
btn.addEventListener('click', function (e) {
|
|
||||||
var videoUrl = e.currentTarget.getAttribute('data-url');
|
|
||||||
var videoTitle = e.currentTarget.getAttribute('data-title');
|
|
||||||
handleImport(videoUrl, e.currentTarget, videoTitle);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
renderAll();
|
|
||||||
|
|
||||||
|
var ytLen = (ytData.results && ytData.results.length) || 0;
|
||||||
|
var localTotal = typeof localData.total === 'number' ? localData.total : (localData.data || []).length;
|
||||||
|
if (ytLen > 0 || localTotal > 0) {
|
||||||
var announceMsg = '"' + query + '" için arama sonuçları listelendi: ';
|
var announceMsg = '"' + query + '" için arama sonuçları listelendi: ';
|
||||||
if (localTotal > 0) {
|
if (localTotal > 0) {
|
||||||
announceMsg += localTotal + ' adet yerel ' + getInstanceName() + ' videosu, ';
|
announceMsg += localTotal + ' adet yerel ' + getInstanceName() + ' videosu, ';
|
||||||
}
|
}
|
||||||
if (ytCount > 0) {
|
if (ytLen > 0) {
|
||||||
announceMsg += ytCount + ' adet YouTube sonucu ve ';
|
announceMsg += ytLen + ' adet YouTube sonucu ve ';
|
||||||
}
|
}
|
||||||
announceMsg += 'Fediverse sonuçları hazır.';
|
announceMsg += 'Fediverse sonuçları hazır.';
|
||||||
announce(announceMsg);
|
announce(announceMsg);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
|
if (abortCtrl && abortCtrl.signal && abortCtrl.signal.aborted) return;
|
||||||
console.error('[YakTube] Search fetch error:', err);
|
console.error('[YakTube] Search fetch error:', err);
|
||||||
container.innerHTML =
|
var activeContainer = ensureSearchContainerMounted();
|
||||||
|
activeContainer.innerHTML =
|
||||||
'<div class="yaktube-header">' +
|
'<div class="yaktube-header">' +
|
||||||
'<div class="yaktube-header-left">' +
|
'<div class="yaktube-header-left">' +
|
||||||
'<span class="yaktube-badge">⚡ Canlı YouTube & Web Arama</span>' +
|
'<span class="yaktube-badge">⚡ Canlı YouTube & Web Arama</span>' +
|
||||||
@@ -4887,7 +4951,9 @@ try {
|
|||||||
announce('Arama sırasında bir bağlantı sorunu oluştu.');
|
announce('Arama sırasında bir bağlantı sorunu oluştu.');
|
||||||
})
|
})
|
||||||
.finally(function () {
|
.finally(function () {
|
||||||
isSearching = false;
|
if (!abortCtrl || !abortCtrl.signal || !abortCtrl.signal.aborted) {
|
||||||
|
isSearching = false;
|
||||||
|
}
|
||||||
ensureFediverseBridge(query, currentSearchTarget);
|
ensureFediverseBridge(query, currentSearchTarget);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -7071,10 +7137,12 @@ try {
|
|||||||
|
|
||||||
var uuid = match[1];
|
var uuid = match[1];
|
||||||
var existingPanel = document.getElementById('yaktube-watch-comments-panel');
|
var existingPanel = document.getElementById('yaktube-watch-comments-panel');
|
||||||
if (uuid === lastWatchUuid && existingPanel) {
|
if (uuid === lastWatchUuid) {
|
||||||
var nativeComments = document.querySelector('my-video-comments, .video-comments, .comments-block, #comments');
|
if (existingPanel) {
|
||||||
if (nativeComments && existingPanel.previousElementSibling !== nativeComments) {
|
var nativeComments = document.querySelector('my-video-comments, .video-comments, .comments-block, #comments');
|
||||||
nativeComments.insertAdjacentElement('afterend', existingPanel);
|
if (nativeComments && existingPanel.previousElementSibling !== nativeComments) {
|
||||||
|
nativeComments.insertAdjacentElement('afterend', existingPanel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
try {
|
||||||
|
const stat = fs.statSync(filePath);
|
||||||
if (process.env.YTDLP_PATH && fs.existsSync(process.env.YTDLP_PATH)) {
|
if (!stat.isFile() || stat.size < 1024) return false;
|
||||||
cachedYtDlpPath = process.env.YTDLP_PATH;
|
if (process.platform !== 'win32') {
|
||||||
return cachedYtDlpPath;
|
try {
|
||||||
}
|
fs.accessSync(filePath, fs.constants.X_OK);
|
||||||
|
} catch (_) {
|
||||||
const isWin = process.platform === 'win32';
|
try {
|
||||||
const candidates = isWin
|
fs.chmodSync(filePath, 0o755);
|
||||||
? [
|
} catch (__) {}
|
||||||
'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 {
|
|
||||||
if (candidate.includes(path.sep) && fs.existsSync(candidate)) {
|
|
||||||
cachedYtDlpPath = candidate;
|
|
||||||
if (logger) logger.info(`[YakTube OnDemand] Auto-detected yt-dlp binary at: ${cachedYtDlpPath}`);
|
|
||||||
return cachedYtDlpPath;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
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 = [];
|
||||||
return cachedYtDlpPath;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
@@ -160,6 +360,38 @@ const DEFAULT_BLOCKED_KEYWORDS = [
|
|||||||
'hentai',
|
'hentai',
|
||||||
'boob',
|
'boob',
|
||||||
'boobs',
|
'boobs',
|
||||||
|
'prnstars',
|
||||||
|
'pornstar',
|
||||||
|
'pornstars',
|
||||||
|
'brazzers',
|
||||||
|
'brattysis',
|
||||||
|
'nubiles',
|
||||||
|
'naughty america',
|
||||||
|
'sexploitation',
|
||||||
|
'twerking',
|
||||||
|
'gyat',
|
||||||
|
'nalgona',
|
||||||
|
'pawg',
|
||||||
|
'ssbbw',
|
||||||
|
'bimbofication',
|
||||||
|
'femdom',
|
||||||
|
'fetish',
|
||||||
|
'ear licking',
|
||||||
|
'mic licking',
|
||||||
|
'lens licking',
|
||||||
|
'foot tickle',
|
||||||
|
'tickle feet',
|
||||||
|
'foot goddess',
|
||||||
|
'stepsister',
|
||||||
|
'stepmom',
|
||||||
|
'sara jay',
|
||||||
|
'julia ann',
|
||||||
|
'lisa ann',
|
||||||
|
'alexis texas',
|
||||||
|
'lexi belle',
|
||||||
|
'alyx star',
|
||||||
|
'lady sonia',
|
||||||
|
'krazee klipz',
|
||||||
'uyuşturucu',
|
'uyuşturucu',
|
||||||
'uyusturucu',
|
'uyusturucu',
|
||||||
'esrar',
|
'esrar',
|
||||||
@@ -603,8 +835,15 @@ async function register({ registerHook, getRouter, registerSetting, settingsMana
|
|||||||
}
|
}
|
||||||
parsedHomeCategories = parseHomeCategories(rawHomeCategories);
|
parsedHomeCategories = parseHomeCategories(rawHomeCategories);
|
||||||
|
|
||||||
async function loadPluginSettings() {
|
let lastSettingsLoadTime = 0;
|
||||||
|
const SETTINGS_CACHE_TTL_MS = 60 * 1000;
|
||||||
|
|
||||||
|
async function loadPluginSettings(force = false) {
|
||||||
if (!settingsManager || typeof settingsManager.getSetting !== 'function') return;
|
if (!settingsManager || typeof settingsManager.getSetting !== 'function') return;
|
||||||
|
if (!force && lastSettingsLoadTime > 0 && Date.now() - lastSettingsLoadTime < SETTINGS_CACHE_TTL_MS) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lastSettingsLoadTime = Date.now();
|
||||||
try {
|
try {
|
||||||
const val = await settingsManager.getSetting('guest-import-limit');
|
const val = await settingsManager.getSetting('guest-import-limit');
|
||||||
if (val !== undefined && val !== null && String(val).trim() !== '') {
|
if (val !== undefined && val !== null && String(val).trim() !== '') {
|
||||||
@@ -696,10 +935,11 @@ async function register({ registerHook, getRouter, registerSetting, settingsMana
|
|||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
await loadPluginSettings();
|
await loadPluginSettings(true);
|
||||||
if (settingsManager && typeof settingsManager.onSettingsChange === 'function') {
|
if (settingsManager && typeof settingsManager.onSettingsChange === 'function') {
|
||||||
settingsManager.onSettingsChange(loadPluginSettings);
|
settingsManager.onSettingsChange(() => loadPluginSettings(true));
|
||||||
}
|
}
|
||||||
|
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 +1020,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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
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) {}
|
} catch (e) {
|
||||||
|
if (logger) logger.warn('[YakTube OnDemand] resolveTargetChannelId warning: ' + e.message);
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
||||||
@@ -1158,25 +1483,31 @@ async function register({ registerHook, getRouter, registerSetting, settingsMana
|
|||||||
return res.json(result);
|
return res.json(result);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Reusable YouTube Raw Search Helper (with Cache & SafeSearch)
|
const inFlightYouTubeSearches = new Map();
|
||||||
|
|
||||||
|
// Reusable YouTube Raw Search Helper (with Cache, In-Flight Dedupe & SafeSearch)
|
||||||
function searchYouTubeRaw(query, maxCount = 24) {
|
function searchYouTubeRaw(query, maxCount = 24) {
|
||||||
return new Promise((resolve, reject) => {
|
const cleanQ = (query || '').trim();
|
||||||
const cleanQ = (query || '').trim();
|
if (!cleanQ || cleanQ.length < 2) return Promise.resolve({ results: [], cached: false });
|
||||||
if (!cleanQ || cleanQ.length < 2) return resolve({ results: [], cached: false });
|
if (safeSearchEnabled && isContentBlocked(cleanQ, blockedKeywordsList)) {
|
||||||
if (safeSearchEnabled && isContentBlocked(cleanQ, blockedKeywordsList)) {
|
return Promise.resolve({ results: [], cached: false, blocked: true });
|
||||||
return resolve({ results: [], cached: false, blocked: true });
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const cacheKey = `${cleanQ.toLocaleLowerCase('tr')}__${maxCount}`;
|
const cacheKey = `${cleanQ.toLocaleLowerCase('tr')}__${maxCount}`;
|
||||||
const cached = getCached(cacheKey) || (maxCount <= 24 ? getCached(cleanQ) : null);
|
const cached = getCached(cacheKey) || (maxCount <= 24 ? getCached(cleanQ) : null);
|
||||||
if (cached) {
|
if (cached) {
|
||||||
const filteredCached = safeSearchEnabled
|
const filteredCached = safeSearchEnabled
|
||||||
? cached.filter(e => !isContentBlocked(e.title, blockedKeywordsList))
|
? cached.filter(e => !isContentBlocked(e.title, blockedKeywordsList))
|
||||||
: cached;
|
: cached;
|
||||||
return resolve({ results: filteredCached.slice(0, maxCount), cached: true });
|
return Promise.resolve({ results: filteredCached.slice(0, maxCount), cached: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
const ytdlpPath = resolveYtDlpPath(logger, customYtDlpPath);
|
if (inFlightYouTubeSearches.has(cacheKey)) {
|
||||||
|
return inFlightYouTubeSearches.get(cacheKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
const p = new Promise((resolve, reject) => {
|
||||||
|
const ytdlpPath = resolveYtDlpPath(logger, customYtDlpPath, peertubeHelpers);
|
||||||
const args = [
|
const args = [
|
||||||
`ytsearch${maxCount}:${cleanQ}`,
|
`ytsearch${maxCount}:${cleanQ}`,
|
||||||
'--dump-single-json',
|
'--dump-single-json',
|
||||||
@@ -1185,8 +1516,13 @@ async function register({ registerHook, getRouter, registerSetting, settingsMana
|
|||||||
'--no-warnings'
|
'--no-warnings'
|
||||||
];
|
];
|
||||||
|
|
||||||
execFile(ytdlpPath, args, { maxBuffer: 10 * 1024 * 1024, timeout: 15000 }, (error, stdout) => {
|
execFile(ytdlpPath, args, { maxBuffer: 10 * 1024 * 1024, timeout: 30000 }, (error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
|
if (logger) {
|
||||||
|
logger.warn(
|
||||||
|
`[YakTube Search] yt-dlp search error for "${cleanQ}": ${error.message} ${stderr || ''}`.trim()
|
||||||
|
);
|
||||||
|
}
|
||||||
return reject(error);
|
return reject(error);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -1237,7 +1573,12 @@ async function register({ registerHook, getRouter, registerSetting, settingsMana
|
|||||||
return reject(parseErr);
|
return reject(parseErr);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}).finally(() => {
|
||||||
|
inFlightYouTubeSearches.delete(cacheKey);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
inFlightYouTubeSearches.set(cacheKey, p);
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isCrawlerBotRequest(req) {
|
function isCrawlerBotRequest(req) {
|
||||||
@@ -1314,7 +1655,7 @@ async function register({ registerHook, getRouter, registerSetting, settingsMana
|
|||||||
return res.json({ results: enrichedResults, cached, guestImportLimit });
|
return res.json({ results: enrichedResults, cached, guestImportLimit });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (logger) logger.error('YouTube search error: ' + err.message);
|
if (logger) logger.error('YouTube search error: ' + err.message);
|
||||||
return res.status(500).json({ error: 'Search failed', details: err.message });
|
return res.json({ results: [], searchError: true, errorDetails: err.message, guestImportLimit });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1441,6 +1782,38 @@ async function register({ registerHook, getRouter, registerSetting, settingsMana
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let localLibrarySnapshotCache = { time: 0, rows: [] };
|
||||||
|
const LOCAL_LIBRARY_CACHE_TTL_MS = 30 * 1000;
|
||||||
|
|
||||||
|
async function getCachedLocalLibraryRows() {
|
||||||
|
if (
|
||||||
|
localLibrarySnapshotCache.rows.length > 0 &&
|
||||||
|
Date.now() - localLibrarySnapshotCache.time < LOCAL_LIBRARY_CACHE_TTL_MS
|
||||||
|
) {
|
||||||
|
return localLibrarySnapshotCache.rows;
|
||||||
|
}
|
||||||
|
const rows = await dbQuery(
|
||||||
|
`SELECT v.id, v.uuid, v.name, v.category, v.duration, v.views, v."createdAt",
|
||||||
|
(SELECT t.filename FROM "thumbnail" t WHERE t."videoId" = v.id ORDER BY t.width ASC NULLS LAST LIMIT 1) AS "thumbFilename",
|
||||||
|
vi."targetUrl" AS "importUrl",
|
||||||
|
(
|
||||||
|
SELECT tg.name
|
||||||
|
FROM "videoTag" vt2
|
||||||
|
INNER JOIN "tag" tg ON tg.id = vt2."tagId"
|
||||||
|
WHERE vt2."videoId" = v.id
|
||||||
|
ORDER BY vt2."createdAt" ASC
|
||||||
|
LIMIT 1
|
||||||
|
) AS "primaryTag"
|
||||||
|
FROM "video" v
|
||||||
|
LEFT JOIN "videoImport" vi ON vi."videoId" = v.id
|
||||||
|
WHERE v.remote = false AND v.state = 1
|
||||||
|
ORDER BY v.id DESC
|
||||||
|
LIMIT 250`
|
||||||
|
);
|
||||||
|
localLibrarySnapshotCache = { time: Date.now(), rows };
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
|
||||||
router.get('/smart-recommendations', async (req, res) => {
|
router.get('/smart-recommendations', async (req, res) => {
|
||||||
await loadPluginSettings();
|
await loadPluginSettings();
|
||||||
if (isCrawlerBotRequest(req)) {
|
if (isCrawlerBotRequest(req)) {
|
||||||
@@ -1480,14 +1853,26 @@ async function register({ registerHook, getRouter, registerSetting, settingsMana
|
|||||||
|
|
||||||
if (resolvedUuid) {
|
if (resolvedUuid) {
|
||||||
try {
|
try {
|
||||||
const currentRows = await dbQuery(
|
let currentRows = [];
|
||||||
`SELECT v.id, v.uuid, v.name, v.category, v."channelId", vi."targetUrl"
|
if (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(resolvedUuid)) {
|
||||||
FROM "video" v
|
currentRows = await dbQuery(
|
||||||
LEFT JOIN "videoImport" vi ON vi."videoId" = v.id
|
`SELECT v.id, v.uuid, v.name, v.category, v."channelId", vi."targetUrl"
|
||||||
WHERE v.uuid::text = $1 OR v.id::text = $2
|
FROM "video" v
|
||||||
LIMIT 1`,
|
LEFT JOIN "videoImport" vi ON vi."videoId" = v.id
|
||||||
[resolvedUuid, rawUuid]
|
WHERE v.uuid = $1::uuid
|
||||||
);
|
LIMIT 1`,
|
||||||
|
[resolvedUuid]
|
||||||
|
);
|
||||||
|
} else if (/^\d+$/.test(rawUuid)) {
|
||||||
|
currentRows = await dbQuery(
|
||||||
|
`SELECT v.id, v.uuid, v.name, v.category, v."channelId", vi."targetUrl"
|
||||||
|
FROM "video" v
|
||||||
|
LEFT JOIN "videoImport" vi ON vi."videoId" = v.id
|
||||||
|
WHERE v.id = $1::int
|
||||||
|
LIMIT 1`,
|
||||||
|
[parseInt(rawUuid, 10)]
|
||||||
|
);
|
||||||
|
}
|
||||||
if (currentRows.length > 0) {
|
if (currentRows.length > 0) {
|
||||||
currentVideoRow = currentRows[0];
|
currentVideoRow = currentRows[0];
|
||||||
const tagRows = await dbQuery(
|
const tagRows = await dbQuery(
|
||||||
@@ -1495,7 +1880,7 @@ async function register({ registerHook, getRouter, registerSetting, settingsMana
|
|||||||
FROM "videoTag" vt
|
FROM "videoTag" vt
|
||||||
INNER JOIN "tag" t ON t.id = vt."tagId"
|
INNER JOIN "tag" t ON t.id = vt."tagId"
|
||||||
WHERE vt."videoId" = $1
|
WHERE vt."videoId" = $1
|
||||||
ORDER BY vt.id ASC
|
ORDER BY vt."createdAt" ASC
|
||||||
LIMIT 8`,
|
LIMIT 8`,
|
||||||
[currentVideoRow.id]
|
[currentVideoRow.id]
|
||||||
);
|
);
|
||||||
@@ -1741,26 +2126,7 @@ async function register({ registerHook, getRouter, registerSetting, settingsMana
|
|||||||
let hasDirectLocalMatch = false;
|
let hasDirectLocalMatch = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const localRows = await dbQuery(
|
const localRows = await getCachedLocalLibraryRows();
|
||||||
`SELECT DISTINCT ON (v.id)
|
|
||||||
v.id, v.uuid, v.name, v.category, v.duration, v.views, v."createdAt",
|
|
||||||
t.filename AS "thumbFilename",
|
|
||||||
vi."targetUrl" AS "importUrl",
|
|
||||||
(
|
|
||||||
SELECT tg.name
|
|
||||||
FROM "videoTag" vt2
|
|
||||||
INNER JOIN "tag" tg ON tg.id = vt2."tagId"
|
|
||||||
WHERE vt2."videoId" = v.id
|
|
||||||
ORDER BY vt2.id ASC
|
|
||||||
LIMIT 1
|
|
||||||
) AS "primaryTag"
|
|
||||||
FROM "video" v
|
|
||||||
LEFT JOIN "thumbnail" t ON t."videoId" = v.id
|
|
||||||
LEFT JOIN "videoImport" vi ON vi."videoId" = v.id
|
|
||||||
WHERE v.remote = false AND v.state = 1
|
|
||||||
ORDER BY v.id DESC, t.type ASC
|
|
||||||
LIMIT 250`
|
|
||||||
);
|
|
||||||
|
|
||||||
for (const lv of localRows) {
|
for (const lv of localRows) {
|
||||||
if (!lv || !lv.name) continue;
|
if (!lv || !lv.name) continue;
|
||||||
@@ -1899,7 +2265,7 @@ async function register({ registerHook, getRouter, registerSetting, settingsMana
|
|||||||
// 1.5. Score Relevant Fediverse (Remote PeerTube) Videos when federatedRecommendationsMode !== 'disabled'
|
// 1.5. Score Relevant Fediverse (Remote PeerTube) Videos when federatedRecommendationsMode !== 'disabled'
|
||||||
if (federatedRecommendationsMode !== 'disabled') {
|
if (federatedRecommendationsMode !== 'disabled') {
|
||||||
try {
|
try {
|
||||||
const searchPatterns = Array.from(
|
const trgmPatterns = Array.from(
|
||||||
new Set(
|
new Set(
|
||||||
[
|
[
|
||||||
...(artistNorm && artistNorm.length >= 3 ? [artistNorm] : []),
|
...(artistNorm && artistNorm.length >= 3 ? [artistNorm] : []),
|
||||||
@@ -1907,27 +2273,35 @@ async function register({ registerHook, getRouter, registerSetting, settingsMana
|
|||||||
...currentKeywords,
|
...currentKeywords,
|
||||||
...historyKeywords
|
...historyKeywords
|
||||||
]
|
]
|
||||||
|
.map(k =>
|
||||||
|
String(k || '')
|
||||||
|
.toLowerCase()
|
||||||
|
.replace(/[ç]/g, 'c')
|
||||||
|
.replace(/[ğ]/g, 'g')
|
||||||
|
.replace(/[ıİ]/g, 'i')
|
||||||
|
.replace(/[ö]/g, 'o')
|
||||||
|
.replace(/[ş]/g, 's')
|
||||||
|
.replace(/[ü]/g, 'u')
|
||||||
|
.trim()
|
||||||
|
)
|
||||||
.filter(k => k && k.length >= 3)
|
.filter(k => k && k.length >= 3)
|
||||||
.slice(0, 8)
|
.slice(0, 6)
|
||||||
.map(k => `%${k}%`)
|
.map(k => `%${k}%`)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (searchPatterns.length > 0) {
|
if (trgmPatterns.length > 0) {
|
||||||
const fedRows = await dbQuery(
|
const fedRows = await dbQuery(
|
||||||
`SELECT DISTINCT ON (v.id)
|
`SELECT v.id, v.uuid, v.name, v.category, v.language, v.duration, v.views, v."isLive", v.nsfw,
|
||||||
v.id, v.uuid, v.name, v.category, v.language, v.duration, v.views, v."isLive", v.nsfw,
|
(SELECT t.filename FROM "thumbnail" t WHERE t."videoId" = v.id ORDER BY t.width ASC NULLS LAST LIMIT 1) AS "thumbFilename"
|
||||||
t.filename AS "thumbFilename"
|
|
||||||
FROM "video" v
|
FROM "video" v
|
||||||
LEFT JOIN "thumbnail" t ON t."videoId" = v.id
|
|
||||||
WHERE v.remote = true
|
WHERE v.remote = true
|
||||||
AND v.state = 1
|
AND v.state = 1
|
||||||
AND v.privacy = 1
|
AND v.privacy = 1
|
||||||
AND v.nsfw = false
|
AND v.nsfw = false
|
||||||
AND (v.name ILIKE ANY($1) OR v.language = 'tr')
|
AND lower(immutable_unaccent(v.name::text)) LIKE ANY($1)
|
||||||
ORDER BY v.id DESC, t.type ASC
|
LIMIT 40`,
|
||||||
LIMIT 80`,
|
[trgmPatterns]
|
||||||
[searchPatterns]
|
|
||||||
);
|
);
|
||||||
|
|
||||||
for (const fv of fedRows) {
|
for (const fv of fedRows) {
|
||||||
@@ -2431,6 +2805,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: {
|
||||||
@@ -2498,6 +2873,9 @@ async function register({ registerHook, getRouter, registerSetting, settingsMana
|
|||||||
|
|
||||||
// 4. Video Import Status Polling Route
|
// 4. Video Import Status Polling Route
|
||||||
router.get('/status/:id', async (req, res) => {
|
router.get('/status/:id', async (req, res) => {
|
||||||
|
if (isCrawlerBotRequest(req)) {
|
||||||
|
return res.status(403).json({ error: 'Bot requests are not allowed on import status endpoint' });
|
||||||
|
}
|
||||||
const videoId = req.params.id;
|
const videoId = req.params.id;
|
||||||
const { hostname, port, hostHeader } = getLocalServerTarget();
|
const { hostname, port, hostHeader } = getLocalServerTarget();
|
||||||
const reqVideo = http.request(
|
const reqVideo = http.request(
|
||||||
@@ -2522,6 +2900,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 {
|
||||||
@@ -2615,21 +2997,47 @@ async function register({ registerHook, getRouter, registerSetting, settingsMana
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const videoOriginCache = new Map();
|
||||||
|
const VIDEO_ORIGIN_CACHE_TTL_MS = 10 * 60 * 1000;
|
||||||
|
|
||||||
router.get('/video-origin/:uuid', async (req, res) => {
|
router.get('/video-origin/:uuid', async (req, res) => {
|
||||||
|
if (isCrawlerBotRequest(req)) {
|
||||||
|
return res.json({ ok: false, hasYouTubeOrigin: false, botIgnored: true });
|
||||||
|
}
|
||||||
const rawParam = (req.params.uuid || '').trim();
|
const rawParam = (req.params.uuid || '').trim();
|
||||||
if (!rawParam) return res.status(400).json({ error: 'UUID required' });
|
if (!rawParam) return res.status(400).json({ error: 'UUID required' });
|
||||||
const resolvedUuid = shortToUuid(rawParam);
|
const resolvedUuid = shortToUuid(rawParam);
|
||||||
|
|
||||||
|
const cacheHit = videoOriginCache.get(resolvedUuid);
|
||||||
|
if (cacheHit && Date.now() - cacheHit.time < VIDEO_ORIGIN_CACHE_TTL_MS) {
|
||||||
|
if (cacheHit.notFound) return res.status(404).json({ error: 'Video not found' });
|
||||||
|
return res.json(cacheHit.payload);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const rows = await dbQuery(
|
let rows = [];
|
||||||
`SELECT v.id, v.uuid, v.name, v.description, vi."targetUrl"
|
if (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(resolvedUuid)) {
|
||||||
FROM "video" v
|
rows = await dbQuery(
|
||||||
LEFT JOIN "videoImport" vi ON vi."videoId" = v.id
|
`SELECT v.id, v.uuid, v.name, v.description, vi."targetUrl"
|
||||||
WHERE v.uuid::text = $1 OR v.id::text = $2
|
FROM "video" v
|
||||||
LIMIT 1`,
|
LEFT JOIN "videoImport" vi ON vi."videoId" = v.id
|
||||||
[resolvedUuid, rawParam]
|
WHERE v.uuid = $1::uuid
|
||||||
);
|
LIMIT 1`,
|
||||||
|
[resolvedUuid]
|
||||||
|
);
|
||||||
|
} else if (/^\d+$/.test(rawParam)) {
|
||||||
|
rows = await dbQuery(
|
||||||
|
`SELECT v.id, v.uuid, v.name, v.description, 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.length === 0) {
|
if (rows.length === 0) {
|
||||||
|
if (videoOriginCache.size > 2000) videoOriginCache.clear();
|
||||||
|
videoOriginCache.set(resolvedUuid, { time: Date.now(), notFound: true });
|
||||||
return res.status(404).json({ error: 'Video not found' });
|
return res.status(404).json({ error: 'Video not found' });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2652,13 +3060,17 @@ async function register({ registerHook, getRouter, registerSetting, settingsMana
|
|||||||
if (match) youtubeId = match[1];
|
if (match) youtubeId = match[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.json({
|
const payload = {
|
||||||
ok: true,
|
ok: true,
|
||||||
hasYouTubeOrigin: !!youtubeId,
|
hasYouTubeOrigin: !!youtubeId,
|
||||||
youtubeId: youtubeId || null,
|
youtubeId: youtubeId || null,
|
||||||
targetUrl: row.targetUrl || null,
|
targetUrl: row.targetUrl || null,
|
||||||
title: row.name
|
title: row.name
|
||||||
});
|
};
|
||||||
|
if (videoOriginCache.size > 2000) videoOriginCache.clear();
|
||||||
|
videoOriginCache.set(resolvedUuid, { time: Date.now(), notFound: false, payload });
|
||||||
|
|
||||||
|
return res.json(payload);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return res.status(500).json({ error: err.message });
|
return res.status(500).json({ error: err.message });
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "peertube-plugin-yaktube-ondemand",
|
"name": "peertube-plugin-yaktube-ondemand",
|
||||||
"version": "1.7.12",
|
"version": "1.7.17",
|
||||||
"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