diff --git a/client.js b/client.js index af47634..d93e0a7 100644 --- a/client.js +++ b/client.js @@ -3584,7 +3584,7 @@ try { var customUrl = '/api-custom' + cleanPath; if (!preferredApiPrefix) { - preferredApiPrefix = isOfficialYakTubeServer() ? '/api-custom' : '/plugins/yaktube-ondemand/router'; + preferredApiPrefix = '/plugins/yaktube-ondemand/router'; } var primaryUrl = preferredApiPrefix + cleanPath; @@ -3614,6 +3614,7 @@ try { // --- Guest Video Import Quota & PeerTube Login Redirect Engine --- var cachedGuestImportLimit = null; var cachedCategories = null; + var cachedSmartPrefetchMode = 'auto-when-no-local'; function fetchGuestImportLimit() { if (cachedGuestImportLimit !== null && cachedCategories !== null) { @@ -3627,6 +3628,9 @@ try { if (d && typeof d.yaknetSsoEnabled === 'boolean') { cachedYakNetSsoEnabled = d.yaknetSsoEnabled; } + if (d && typeof d.smartPrefetchMode === 'string') { + cachedSmartPrefetchMode = d.smartPrefetchMode; + } if (d && Array.isArray(d.categories) && d.categories.length > 0) { cachedCategories = d.categories; try { @@ -5564,12 +5568,146 @@ try { } } catch (e) {} - // 7.5. Reactive Hybrid Related Videos Engine (Watch Page) + // 7.5. YouTube-Style Smart Recommendation, History Profiler & Up-Next Engine (Watch Page) var currentActiveVideoKey = null; var isFetchingRelated = false; var relatedShowAll = false; var cachedRelatedResults = []; var cachedRelatedQuery = ''; + var smartHasLocalMatch = false; + var smartPrefetchCandidate = null; + var smartPrefetchState = { + videoKey: null, + status: 'idle', // 'idle' | 'preparing' | 'ready' | 'failed' + pollTimer: null, + readyUrl: null, + readyTitle: null + }; + var upNextCountdownTimer = null; + + function cleanVideoTopicString(rawTitle) { + if (!rawTitle) return ''; + return String(rawTitle) + .replace(/YakTube/gi, '') + .replace(/[\(\[].*?[\)\]]/g, '') + .replace( + /official\s*video|video\s*klip|klip|hd|4k|lyric\s*video|audio|remix|feat\.?|ft\.?|şarkı\s*sözleri/gi, + '' + ) + .replace(/\s+/g, ' ') + .trim(); + } + + function recordWatchedVideo(uuid, rawTitle, rawChannel) { + if (!rawTitle || rawTitle.length < 3) return; + try { + var cleanTopic = cleanVideoTopicString(rawTitle); + var words = cleanTopic.split(/\s+/).filter(function (w) { + return w.length >= 2; + }); + var compactTopic = words.slice(0, 4).join(' ') || cleanTopic; + if (!compactTopic || compactTopic.length < 3) return; + + var rawList = localStorage.getItem('yaktube_watch_history'); + var list = []; + if (rawList) { + try { + var parsed = JSON.parse(rawList); + if (Array.isArray(parsed)) list = parsed; + } catch (e) {} + } + + list = list.filter(function (entry) { + if (!entry) return false; + if (uuid && entry.uuid === uuid) return false; + if (entry.topic && entry.topic.toLowerCase() === compactTopic.toLowerCase()) return false; + return true; + }); + + list.unshift({ + uuid: uuid || '', + title: rawTitle, + topic: compactTopic, + channel: rawChannel || '', + ts: Date.now() + }); + + if (list.length > 25) list = list.slice(0, 25); + localStorage.setItem('yaktube_watch_history', JSON.stringify(list)); + } catch (e) {} + } + + function getUserInterestHistory(excludeTopic) { + var interests = []; + var seen = {}; + var normExclude = (excludeTopic || '').toLowerCase().trim(); + if (normExclude) seen[normExclude] = true; + + var defaultPlaceholders = { + tarkan: true, + 'barış manço': true, + 'yapay zeka': true, + 'canlı haber': true + }; + + // 1. Recent watched video topics + try { + var rawWatch = localStorage.getItem('yaktube_watch_history'); + if (rawWatch) { + var watchList = JSON.parse(rawWatch); + if (Array.isArray(watchList)) { + watchList.forEach(function (w) { + var t = w && (w.topic || w.title) ? String(w.topic || w.title).trim() : ''; + var low = t.toLowerCase(); + if (t.length >= 3 && !seen[low]) { + seen[low] = true; + interests.push(t); + } + }); + } + } + } catch (e) {} + + // 2. Recent user search queries + try { + var searches = getRecentSearches(); + if (Array.isArray(searches)) { + var hasRealSearches = searches.some(function (s) { + return s && !defaultPlaceholders[String(s).toLowerCase().trim()]; + }); + searches.forEach(function (s) { + var term = String(s || '').trim(); + var low = term.toLowerCase(); + if (hasRealSearches && defaultPlaceholders[low]) return; + if (term.length >= 3 && !seen[low]) { + seen[low] = true; + interests.push(term); + } + }); + } + } catch (e) {} + + return interests.slice(0, 8); + } + + function suppressUnrelatedNativeRecommendations() { + try { + // Prevent PeerTube's native player from auto-redirecting to unrelated foreign/federated videos on video end + localStorage.setItem('auto-play-video', 'false'); + sessionStorage.setItem('auto-play-video', 'false'); + } catch (e) {} + + var recContainers = document.querySelectorAll('my-recommended-videos, .other-videos, .video-watch-next'); + recContainers.forEach(function (rec) { + Array.from(rec.children).forEach(function (child) { + if (child.id === 'yaktube-hybrid-related-container' || child.id === 'yaktube-upnext-overlay') { + return; + } + child.style.setProperty('display', 'none', 'important'); + child.setAttribute('aria-hidden', 'true'); + }); + }); + } function renderRelatedCards(container, results, query) { var count = results ? results.length : 0; @@ -5579,67 +5717,78 @@ try { } container.style.display = 'block'; + suppressUnrelatedNativeRecommendations(); + var limit = relatedShowAll ? count : Math.min(count, 12); var displayed = results.slice(0, limit); var cardsHtml = ''; displayed.forEach(function (item) { var isLocal = !!item.isDownloaded; - var statusBadge = isLocal - ? '✅ ' + - getInstanceName() + - "'da İzle" - : '⚡ Canlı Keşif'; + var badgeLabel = item.reasonBadge || (isLocal ? '✅ ' + getInstanceName() + "'da İzle" : '🔥 Benzer İçerik'); + var isHistoryMatch = badgeLabel.indexOf('Geçmişinize Göre') !== -1; - var actionButton = isLocal - ? '▶️ Hemen İzle' - : ''; + var badgeStyle = isLocal + ? 'background: linear-gradient(135deg, #10b981 0%, #059669 100%); color: #fff;' + : isHistoryMatch + ? 'background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%); color: #fff;' + : 'background: linear-gradient(135deg, #ff8f37 0%, #ff5e3a 100%); color: #fff;'; + + var statusBadge = + '' + + escapeHtml(badgeLabel) + + ''; + + var safeTitleAttr = (item.title || '').replace(/"/g, '"'); + var actionButton = + isLocal && item.localVideo && item.localVideo.url + ? '▶️ Hemen İzle' + : ''; var cardLabel = - item.title + - (isLocal ? ' (' + getInstanceName() + ' kütüphanenizde mevcut)' : ' (Canlı YouTube keşfi)') + - ', ' + - item.channel + - ' kanalı, Süre: ' + - item.durationFormatted; + item.title + ' (' + badgeLabel + '), ' + item.channel + ' kanalı, Süre: ' + (item.durationFormatted || ''); cardsHtml += '