feat: support custom endpoint for stream extraction

This commit is contained in:
Shiny Nematoda 2024-11-25 14:19:49 +00:00
parent e263bd4cea
commit 28c9f7686a
5 changed files with 21 additions and 12 deletions

View file

@ -82,16 +82,10 @@ function parseUrl() {
if (loc[2].startsWith('MPRE')) results.getAlbum('?list=' + loc[2]); if (loc[2].startsWith('MPRE')) results.getAlbum('?list=' + loc[2]);
break; break;
case 'charts': case 'charts':
nav.state.page = 'charts';
break;
case 'library': case 'library':
nav.state.page = 'library';
break;
case 'prefs': case 'prefs':
nav.state.page = 'prefs';
break;
case 'restore': case 'restore':
nav.state.page = 'restore'; nav.state.page = base;
break; break;
default: default:
console.log(loc); console.log(loc);

View file

@ -1,3 +1,3 @@
{ {
"date": "2024-07-22" "date": "2024-11-25"
} }

View file

@ -118,6 +118,11 @@ async function setAuth(e) {
setCustom('authapi', e); setCustom('authapi', e);
} }
function setStreamApi(e) {
if (e.target.value) store.setItem('streamapi', e.target.value)
else store.removeItem('streamapi');
}
const verifyApi = computed(() => const verifyApi = computed(() =>
hypInstances.value hypInstances.value
.map(i => i.api_url.replace('https://', '').replace('http://', '')) .map(i => i.api_url.replace('https://', '').replace('http://', ''))
@ -407,6 +412,15 @@ onMounted(() => {
<option value="x">Custom</option> <option value="x">Custom</option>
</select> </select>
<h3>{{ t('instances.streamapi') }}</h3>
<input
class="input text-center"
type="text"
@change="setStreamApi"
:value="getStore('streamapi') || ''"
placeholder="Default (Piped API)"
/>
<div class="table-wrap"> <div class="table-wrap">
<table> <table>
<thead> <thead>
@ -470,7 +484,8 @@ h2,
h3, h3,
label, label,
footer, footer,
.restore { .restore,
.input {
text-align: center; text-align: center;
word-break: break-word; word-break: break-word;
} }

View file

@ -38,8 +38,8 @@ export async function getJson(url, opts) {
return res; return res;
} }
export async function getJsonPiped(path, opts) { export async function getJsonPiped(path, opts, root) {
const root = root ??=
new URLSearchParams(location.search).get('pipedapi') || new URLSearchParams(location.search).get('pipedapi') ||
useStore().getItem('pipedapi') || useStore().getItem('pipedapi') ||
PIPED_INSTANCE; PIPED_INSTANCE;

View file

@ -22,7 +22,7 @@ export const useData = defineStore('data', () => {
async function getSong(e) { async function getSong(e) {
const hash = new URLSearchParams(e.substring(e.indexOf('?'))).get('v'), const hash = new URLSearchParams(e.substring(e.indexOf('?'))).get('v'),
json = await getJsonPiped('/streams/' + hash), json = await getJsonPiped('/streams/' + hash, {}, store.getItem('streamapi')),
unamp = txt => txt?.replace(AMP, '&'); unamp = txt => txt?.replace(AMP, '&');
state.art = unamp(json.thumbnailUrl); state.art = unamp(json.thumbnailUrl);