diff --git a/netlify/edge-functions/opengraph.ts b/netlify/edge-functions/opengraph.ts index b24b6790..9b3ec5bb 100644 --- a/netlify/edge-functions/opengraph.ts +++ b/netlify/edge-functions/opengraph.ts @@ -12,7 +12,7 @@ export default async (request: Request, context: Context) => { const response = await context.next(); const page = await response.text(); - const instance = 'https://inv.nadeko.net'; + const instance = 'https://invidious.jing.rocks'; const data = await fetch(instance + '/api/v1/videos/' + id).then(res => res.json()); const music = data.author.endsWith(' - Topic') ? 'https://wsrv.nl?w=180&h=180&fit=cover&url=' : ''; const thumbnail = music + data.videoThumbnails.find((v: { quality: string }) => v.quality === 'medium').url; diff --git a/package.json b/package.json index 182ffc4c..c04925fa 100644 --- a/package.json +++ b/package.json @@ -11,17 +11,17 @@ "dependencies": { "hls.js": "^1.5.15", "imsc": "^1.1.5", - "solid-js": "^1.8.22", + "solid-js": "^1.9.1", "sortablejs": "^1.15.3" }, "devDependencies": { - "@netlify/edge-functions": "^2.10.0", - "@types/node": "^22.5.5", + "@netlify/edge-functions": "^2.11.0", + "@types/node": "^22.7.2", "@types/sortablejs": "^1.15.8", "autoprefixer": "^10.4.20", "eruda": "^3.3.0", "typescript": "^5.6.2", - "vite": "^5.4.6", + "vite": "^5.4.8", "vite-plugin-pwa": "^0.20.5", "vite-plugin-solid": "^2.10.2" }, diff --git a/src/lib/store.ts b/src/lib/store.ts index 1e132cc3..4df14d58 100644 --- a/src/lib/store.ts +++ b/src/lib/store.ts @@ -22,6 +22,7 @@ export const store: { invidious: string[], hyperpipe: string, index: number, + unified: number }, loadImage: 'off' | 'lazy' | 'eager', linkHost: string, @@ -59,7 +60,8 @@ export const store: { piped: [], invidious: [], hyperpipe: 'https://hyperpipeapi.onrender.com', - index: 0 + index: 0, + unified: 0 }, loadImage: getSaved('imgLoad') as 'off' | 'lazy' || 'eager', linkHost: getSaved('linkHost') || location.origin, diff --git a/src/lib/utils.ts b/src/lib/utils.ts index c1bafdba..45526879 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -84,7 +84,7 @@ export async function errorHandler( if ( message !== 'No Data Found' && - store.api.index < store.api.invidious.length - 1 + store.api.index < store.api.unified - 1 ) { store.api.index++; redoAction(); diff --git a/src/modules/getStreamData.ts b/src/modules/getStreamData.ts index ec2f68bb..339b8c17 100644 --- a/src/modules/getStreamData.ts +++ b/src/modules/getStreamData.ts @@ -44,7 +44,7 @@ export async function getData( uploader: data.author, duration: data.lengthSeconds, uploaderUrl: data.authorUrl, - category: data.genre, + category: data.genre || 'non-music', liveStream: data.liveNow, subtitles: [], relatedStreams: data.recommendedVideos.map(v => ({ @@ -72,7 +72,7 @@ export async function getData( const res = await Promise.any( pi - .filter((_, i) => i < (h ? pi : iv).length) + .filter((_, i) => i < (h ? pi.length : store.api.unified)) .map(fetchDataFromPiped) ) .catch(() => h ? {} : Promise.any( diff --git a/src/modules/setAudioStreams.ts b/src/modules/setAudioStreams.ts index f62d0aa1..f0cb0a34 100644 --- a/src/modules/setAudioStreams.ts +++ b/src/modules/setAudioStreams.ts @@ -35,8 +35,10 @@ export function setAudioStreams(audioStreams: { if (proxyViaPiped && useProxy) return url; const oldUrl = new URL(url); - const proxy = getSaved('custom_instance_2') ? store.api.invidious[0] : 'https://invidious.fdn.fr'; + const isIvUrl = store.api.invidious.includes(oldUrl.origin); + if (isIvUrl && useProxy) return url; + const proxy = store.api.invidious[store.api.index]; const host = useProxy ? proxy : `https://${oldUrl.searchParams.get('host')}`; diff --git a/src/modules/start.ts b/src/modules/start.ts index 9a533d8d..97b221dd 100644 --- a/src/modules/start.ts +++ b/src/modules/start.ts @@ -23,6 +23,7 @@ export default async function() { .then(data => { a.piped = data.piped; a.invidious = data.invidious; + a.unified = data.unified; }); } @@ -46,9 +47,21 @@ export default async function() { audio.play(); }); h.on(mod.default.Events.ERROR, (_, d) => { + if (d.details === 'manifestLoadError') { - notify(d.details); - player(id); + const hlsUrl = store.player.data!.hls; + const piProxy = (new URL(hlsUrl)).origin; + const defProxy = 'https://invidious.fdn.fr'; + if (piProxy === defProxy) { + notify(d.details); + return; + } + const newUrl = hlsUrl.replace(piProxy, defProxy); + h.loadSource(newUrl); + } + else { + notify('load error, retrying...') + player(store.stream.id); } }) diff --git a/src/scripts/audioEvents.ts b/src/scripts/audioEvents.ts index 40edd29a..c78cd036 100644 --- a/src/scripts/audioEvents.ts +++ b/src/scripts/audioEvents.ts @@ -173,31 +173,31 @@ audio.oncanplaythrough = function() { getData(nextItem); } -audio.onerror = async function() { - +audio.onerror = function() { audio.pause(); if (getSaved('custom_instance_2')) - return notify('Proxy Failed to decrypt stream'); + return notify('Proxy failed to decrypt stream'); - if (store.player.HLS) - return player(store.stream.id); + if (store.player.HLS || getSaved('proxyViaInvidious') === 'false') { + notify('PipedProxy failed to decrypt stream, Retrying...'); + player(store.stream.id); + return; + } + /* + Error Proxies + Normal : Unified Invidious Proxied + Negative : Non-Unified Invidious Proxied + */ - const data = store.player.data as Piped; - const adaptiveUrl = data.audioStreams[0].url; - const piProxy = new URL(adaptiveUrl).origin; - const ivProxy = new URL(audio.src).origin; + const ivProxy = (new URL(audio.src)).origin; const defProxy = 'https://invidious.fdn.fr'; - - audio.src = audio.src.replace( - ivProxy, - ivProxy === defProxy ? - store.api.invidious[store.api.index] : - ivProxy !== piProxy ? - piProxy : defProxy - ); - + if (ivProxy === defProxy) { + playButton.classList.replace(playButton.className, 'ri-stop-circle-fill'); + notify('Could not play stream in any ways..'); + } + else audio.src = audio.src.replace(ivProxy, defProxy); }