Skip to content

Commit

Permalink
Fixes #222 Audio Skips
Browse files Browse the repository at this point in the history
  • Loading branch information
n-ce committed Dec 3, 2024
1 parent c6ae572 commit 96777ae
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
"hls.js": "^1.5.17",
"imsc": "^1.1.5",
"solid-js": "^1.9.3",
"sortablejs": "^1.15.3"
"sortablejs": "^1.15.6"
},
"devDependencies": {
"@netlify/edge-functions": "^2.11.1",
"@types/node": "^22.9.3",
"@types/node": "^22.10.1",
"@types/sortablejs": "^1.15.8",
"autoprefixer": "^10.4.20",
"eruda": "^3.4.1",
"typescript": "^5.7.2",
"vite": "^5.4.11",
"vite-plugin-pwa": "^0.21.0",
"vite-plugin-solid": "^2.10.2"
"vite": "^6.0.2",
"vite-plugin-pwa": "^0.21.1",
"vite-plugin-solid": "^2.11.0"
},
"browserslist": [
"defaults"
Expand Down
2 changes: 2 additions & 0 deletions src/lib/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const store: {
supportsOpus: Promise<boolean>,
data: Piped | undefined,
legacy: boolean,
fallback: string,
proxy: string
},
queue: string[]
Expand Down Expand Up @@ -48,6 +49,7 @@ export const store: {
}).then(res => res.supported),
data: undefined,
legacy: !('OffscreenCanvas' in window),
fallback: '',
proxy: ''
},
queue: [],
Expand Down
9 changes: 6 additions & 3 deletions src/modules/getStreamData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,17 @@ export async function getData(
const pi = store.api.piped;

const res = await Promise.any(
pi.map(fetchDataFromPiped)
pi
.filter((_, i) => i < (h ? pi.length : store.api.unified))
.map(fetchDataFromPiped)
)
.catch(() => h ? {} : Promise.any(
iv.map(fetchDataFromInvidious)
)
.catch(() => {
if (!prefetch)
return fetchDataFromPiped('https://video-api-transform.vercel.app/api');
if (!prefetch && store.player.fallback)
return fetchDataFromPiped(store.player.fallback)
.catch(() => getData(id))
})
);

Expand Down
10 changes: 8 additions & 2 deletions src/modules/setAudioStreams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,21 @@ export function setAudioStreams(audioStreams: {
}

function proxyHandler(url: string) {
const useProxy = url.startsWith('https://ymd') || isMusic || getSaved('enforceProxy');
const useProxy = isMusic || getSaved('enforceProxy');

const oldUrl = new URL(url);
const origin = oldUrl.origin;

if (url.startsWith('https://ymd'))
return url;

if (url.startsWith('https://redirector'))
return url.replace(origin, store.player.proxy) + '&host=' + origin.slice(8);

return useProxy ? url : url.replace(origin, `https://${oldUrl.searchParams.get('host')}`);
return url.replace(origin,
useProxy ?
store.api.invidious[store.api.index] : `https://${oldUrl.searchParams.get('host')}`
);

}

Expand Down
10 changes: 8 additions & 2 deletions src/modules/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,21 @@ export default async function() {
a.invidious.push(iv);

} else {
const apiUrl = 'https://raw.githubusercontent.com/n-ce/Uma/main/dynamic_instances.json';
await fetch(apiUrl)
const ytifyApi =
(window as Window & typeof globalThis & { ytifyApi: string }
).ytifyApi;

if (!ytifyApi) return;

await fetch(ytifyApi)
.then(res => res.json())
.then(data => {
a.piped = data.piped;
a.invidious = data.invidious;
a.unified = data.unified;
store.downloadAPI = data.cobalt;
store.player.proxy = data.proxy;
store.player.fallback = data.fallback;
});
}

Expand Down

0 comments on commit 96777ae

Please sign in to comment.