diff --git a/app/2015ytm.js b/app/2015ytm.js index 07b53119..2ab20402 100644 --- a/app/2015ytm.js +++ b/app/2015ytm.js @@ -168,6 +168,7 @@ if (APP_STOP_TEXT_SELECTION_expflag == undefined) { localStorage.setItem("APP_STOP_TEXT_SELECTION", "true"); APP_STOP_TEXT_SELECTION_expflag = localStorage.getItem("APP_STOP_TEXT_SELECTION"); } +ERACAST_MODE_option = localStorage.getItem("ERACAST_MODE"); newErrorHtml = ``; + if (APP_NEW_ERROR_SCREEN_expflag == "true"){error.innerHTML=newErrorHtml}; + pageCont.before(error); + error.querySelector("button").onclick = function(){ + renderData(); + error.remove(); + }; + return; + }); + } catch (e) { + console.error('EraCast mode failed:', e); + } + return;//EraCast mode + } + const getHomeData3 = new XMLHttpRequest(); getHomeData3.open('GET', APIbaseURL + 'api/v1/popular', true); @@ -720,7 +877,7 @@ function renderDataTrending(homeShelfTrendingType, shelfTitle) { shelf.appendChild(verticalList); data.forEach(function(item) { - renderCompactMediaItem(verticalList, "shelf", item.videoId, item.videoThumbnails[3].url, item.lengthSeconds, item.title, item.author, item.authorId, item.publishedText, item.viewCount, item.type); + renderCompactMediaItem(verticalList, "shelf", item.videoId, ERACAST_MODE_option ? item.videoThumbnails[0].url : item.videoThumbnails[3].url, item.lengthSeconds, item.title, item.author, item.authorId, item.publishedText, item.viewCount, item.type); }); if (data.length > 3) { diff --git a/app/index.html b/app/index.html index cb80a8d0..13813c6d 100644 --- a/app/index.html +++ b/app/index.html @@ -73,6 +73,8 @@ + + diff --git a/app/player.js b/app/player.js index 47b5855a..011102e0 100644 --- a/app/player.js +++ b/app/player.js @@ -827,11 +827,67 @@ const playerxhttpr = new XMLHttpRequest(); /* playerxhttpr.open('GET', 'https://inv.tux.pizza/api/v1/videos/' + YTmVideoId, true); */ /* playerxhttpr.open('GET', 'https://invidious.nerdvpn.de/api/v1/videos/' + YTmVideoId, true); playerxhttpr.setRequestHeader('Authorization','Basic eXRtMTU6SlFKNTNLckxBRVk2RTVxaGdjbTM4UGtTenczYlpYbWs='); */ +if (ERACAST_MODE_option == "true") { + window.fetchEraCast1080WebmUrl(YTmVideoId).then(function(data) { + video.poster = data.thumbnail[3].url; + video.innerHTML = ``; + video.dataset.title = data.title; + /* storyboardURL = "https://inv.tux.pizza" + data.storyboards[2].url; */ + SBVideo.src = data.formats[0].url; + +/* const sbxhttpr = new XMLHttpRequest(); + +sbxhttpr.open('GET', storyboardURL, true); + +sbxhttpr.send(); + +sbxhttpr.onerror = function(){ + console.error('Unable to retrieve the storyboard for this video (' + sbxhttpr.status + ')'); +}; + +sbxhttpr.onload = function() { + if (sbxhttpr.status === 200) { + SBData = sbxhttpr.response; + } else { + sbxhttpr.onerror(); + }; +}; */ + + data.formats.forEach(function(item) { + const lastFS = data.formats.slice(-1)[0] + const vidSource = document.createElement("source"); + vidSource.src = item.url; + vidSource.type = item.mimeType; + vidSource.setAttribute("label", item.qualityLabel); + vidSource.setAttribute("selected", false); + if (item == lastFS) { + vidSource.setAttribute("selected", true); + }; + video.appendChild(vidSource); + if (vidSource.getAttribute("selected", "true")) { + video.src = item.url; + }; + }); + if (data.captions) { + data.captions.captionTracks.forEach(function(item) { + const vidTrack = document.createElement("track"); + vidTrack.kind = "captions"; + vidTrack.src = item.baseUrl; + vidTrack.srclang = item.languageCode; + vidTrack.label = item.name; + video.appendChild(vidTrack); + }); + }; + }); +} else { playerxhttpr.open('GET', APIbaseURLNew + 'dl?cgeo=US&id=' + YTmVideoId, true); playerxhttpr.setRequestHeader('x-rapidapi-key', '4b0791fe33mshce00ad033774274p196706jsn957349df7a8f'); playerxhttpr.setRequestHeader('x-rapidapi-host', 'yt-api.p.rapidapi.com'); + playerxhttpr.send(); +} + playerxhttpr.onerror = function(){ videoPlayer.classList.add("player-has-error"); diff --git a/app/settings.js b/app/settings.js index 362540ac..136f79fc 100644 --- a/app/settings.js +++ b/app/settings.js @@ -218,7 +218,16 @@ function settingsPage() { }; settingBlocks = [ - settingBooleanDark + settingBooleanDark, + { + "type": "boolean", + "title": EraCast_text_string, + "subtitle": EraCastDesc_text_string, + "pressed": ERACAST_MODE_option == "true", + "pressed-default": false, + "disabled": false, + "lsitem": "ERACAST_MODE" + } ]; settingBlocks.forEach(function(item){ if (item.type == "boolean") { diff --git a/app/watch.js b/app/watch.js index a782e031..bfff90c4 100644 --- a/app/watch.js +++ b/app/watch.js @@ -22,50 +22,8 @@ function renderWatchPage(parent) { insertYTmPlayer(playerCont2); - const getWatchData = new XMLHttpRequest(); - /* getWatchData.open('GET', APIbaseURL + 'api/v1/videos/' + playerVideoId, true); */ - /* getWatchData.open('GET', APIbaseURLWatch + 'api/v1/videos/' + playerVideoId, true); */ - /* getWatchData.setRequestHeader('Authorization','Basic eXRtMTU6SlFKNTNLckxBRVk2RTVxaGdjbTM4UGtTenczYlpYbWs='); */ - getWatchData.open('GET', APIbaseURLNew + 'video/info?extend=1&geo=US&id=' + playerVideoId, true); - getWatchData.setRequestHeader('x-rapidapi-key', '4b0791fe33mshce00ad033774274p196706jsn957349df7a8f'); - getWatchData.setRequestHeader('x-rapidapi-host', 'yt-api.p.rapidapi.com'); - - getWatchData.onerror = function(event) { - console.error("An error occurred with this operation (" + getWatchData.status + ")"); - - contItem.remove(); - - const error = document.createElement("div"); - error.classList.add('error-container'); - error.innerHTML = `
- -There was an error connecting to the server -
-
`; - if (APP_NEW_ERROR_SCREEN_expflag == "true"){error.innerHTML=newErrorHtml}; - /* if (JSON.parse(getWatchData.response)) { - const data = JSON.parse(getWatchData.response); - if (data.error) { - error.querySelector(".error-text").textContent = data.error; - } - } */ - const errorBtn = error.querySelector("button"); - errorBtn.onclick = function(){renderWatchPage(parent)}; - parent.appendChild(error); - if (JSON.parse(getWatchData.response)) { - const data = JSON.parse(getWatchData.response); - if (data.error) { - error.querySelector(".error-text").textContent = data.error; - } - } - return; - }; - - getWatchData.send(); - - getWatchData.onload = function() { - if (getWatchData.status === 200) { - const data = JSON.parse(getWatchData.response); + const fetchAndRenderWatchData = function(data) { + console.log(data); playerNextVideoId = data.relatedVideos.data[0].videoId; @@ -486,7 +444,7 @@ function renderWatchPage(parent) { videoOwner.innerHTML = `
- +

${data.channelTitle}

@@ -576,6 +534,73 @@ function renderWatchPage(parent) { parent.innerHTML = ""; parent.appendChild(scwnr); + }; + + const showWatchError = function(status) { + console.error("An error occurred with this operation (" + status + ")"); + + contItem.remove(); + + const error = document.createElement("div"); + error.classList.add('error-container'); + error.innerHTML = `
+ +There was an error connecting to the server +
+
`; + if (APP_NEW_ERROR_SCREEN_expflag == "true"){error.innerHTML=newErrorHtml}; + const errorBtn = error.querySelector("button"); + errorBtn.onclick = function(){renderWatchPage(parent)}; + parent.appendChild(error); + return error; + }; + + // EraCast path + console.log("Go!"); + if (ERACAST_MODE_option == "true") { + console.log("Using EraCast for watch data"); + (async function() { + try { + if (typeof window.fetchEraCastVideoInfo !== 'function') throw new Error('fetchEraCastVideoInfo missing'); + console.log('Fetching EraCast watch data for video ID:', playerVideoId); + const data = await window.fetchEraCastVideoInfo(playerVideoId); + console.log('EraCast watch data received:', data); + if (!data || Object.keys(data).length === 0) throw new Error('Empty EraCast response'); + fetchAndRenderWatchData(data); + } catch (e) { + console.error('EraCast watch data error:', e); + showWatchError(0); + } + })(); + return; + } + + // Default (YouTube/RapidAPI) path + const getWatchData = new XMLHttpRequest(); + /* getWatchData.open('GET', APIbaseURL + 'api/v1/videos/' + playerVideoId, true); */ + /* getWatchData.open('GET', APIbaseURLWatch + 'api/v1/videos/' + playerVideoId, true); */ + /* getWatchData.setRequestHeader('Authorization','Basic eXRtMTU6SlFKNTNLckxBRVk2RTVxaGdjbTM4UGtTenczYlpYbWs='); */ + getWatchData.open('GET', APIbaseURLNew + 'video/info?extend=1&geo=US&id=' + playerVideoId, true); + getWatchData.setRequestHeader('x-rapidapi-key', '4b0791fe33mshce00ad033774274p196706jsn957349df7a8f'); + getWatchData.setRequestHeader('x-rapidapi-host', 'yt-api.p.rapidapi.com'); + + getWatchData.onerror = function(event) { + const error = showWatchError(getWatchData.status); + if (JSON.parse(getWatchData.response)) { + const data = JSON.parse(getWatchData.response); + if (data.error) { + error.querySelector(".error-text").textContent = data.error; + } + } + return; + }; + + getWatchData.send(); + + getWatchData.onload = function() { + if (getWatchData.status === 200) { + const data = JSON.parse(getWatchData.response); + fetchAndRenderWatchData(data); } else { getWatchData.onerror(); }