trying parse different url, but failed

This commit is contained in:
Julian Freeman
2025-12-02 10:29:39 -04:00
parent ee4880a83b
commit 068bc1c79e
5 changed files with 219 additions and 24 deletions

View File

@@ -26,6 +26,17 @@ watch(() => settingsStore.settings.download_path, (newPath) => {
}
}, { immediate: true })
// Detect Mix URL
watch(() => analysisStore.url, (newUrl) => {
if (newUrl && newUrl.includes('v=') && newUrl.includes('list=')) {
analysisStore.isMix = true
} else {
analysisStore.isMix = false
// Reset scanMix if URL changes to non-mix
analysisStore.scanMix = false
}
})
async function analyze() {
if (!analysisStore.url) return
analysisStore.loading = true
@@ -33,7 +44,29 @@ async function analyze() {
analysisStore.metadata = null
try {
const res = await invoke('fetch_metadata', { url: analysisStore.url })
let urlToScan = analysisStore.url;
let parseMix = false;
if (analysisStore.isMix) {
if (analysisStore.scanMix) {
// Keep URL as is, tell backend to limit scan
parseMix = true;
} else {
// Strip list param
try {
const u = new URL(urlToScan);
u.searchParams.delete('list');
u.searchParams.delete('index');
u.searchParams.delete('start_radio');
urlToScan = u.toString();
} catch (e) {
// Fallback regex if URL parsing fails
urlToScan = urlToScan.replace(/&list=[^&]+/, '');
}
}
}
const res = await invoke('fetch_metadata', { url: urlToScan, parseMixPlaylist: parseMix })
analysisStore.metadata = res
} catch (e: any) {
analysisStore.error = e.toString()
@@ -55,8 +88,28 @@ async function startDownload() {
{ title: analysisStore.metadata.title, thumbnail: "", id: analysisStore.metadata.id } :
analysisStore.metadata;
// Note: We might want to pass the *cleaned* URL if it was cleaned during analyze
// But for now we pass the original URL or whatever was scanned.
// Actually, if we scanned as a single video (unchecked), we should probably download as single video.
// The user might expect the same result as analysis.
// Let's reconstruct the URL logic or just use what `analyze` used?
// Since `start_download` just takes a URL string, we should probably use the same logic.
let urlToDownload = analysisStore.url;
if (analysisStore.isMix && !analysisStore.scanMix) {
try {
const u = new URL(urlToDownload);
u.searchParams.delete('list');
u.searchParams.delete('index');
u.searchParams.delete('start_radio');
urlToDownload = u.toString();
} catch (e) {
urlToDownload = urlToDownload.replace(/&list=[^&]+/, '');
}
}
const id = await invoke<string>('start_download', {
url: analysisStore.url,
url: urlToDownload,
options: analysisStore.options,
metadata: metaToSend
})
@@ -104,6 +157,22 @@ async function startDownload() {
<span v-else>Analyze</span>
</button>
</div>
<!-- Mix Toggle -->
<div v-if="analysisStore.isMix" class="mt-4 flex items-center gap-3">
<button
@click="analysisStore.scanMix = !analysisStore.scanMix"
class="w-12 h-6 rounded-full relative transition-colors duration-200 ease-in-out flex-shrink-0"
:class="analysisStore.scanMix ? 'bg-blue-600' : 'bg-gray-300 dark:bg-zinc-600'"
>
<span
class="absolute top-1 left-1 w-4 h-4 bg-white rounded-full transition-transform duration-200"
:class="analysisStore.scanMix ? 'translate-x-6' : 'translate-x-0'"
/>
</button>
<span class="text-sm font-medium text-zinc-700 dark:text-gray-300">Scan Playlist (Max 20)</span>
</div>
<p v-if="analysisStore.error" class="mt-3 text-red-500 text-sm">{{ analysisStore.error }}</p>
</div>
@@ -185,4 +254,4 @@ async function startDownload() {
</div>
</div>
</template>
</template>