support multiple input
This commit is contained in:
@@ -12,6 +12,9 @@ export const useAnalysisStore = defineStore('analysis', () => {
|
|||||||
const isMix = ref(false)
|
const isMix = ref(false)
|
||||||
const scanMix = ref(false)
|
const scanMix = ref(false)
|
||||||
|
|
||||||
|
// Input mode state
|
||||||
|
const isBatchMode = ref(false)
|
||||||
|
|
||||||
const options = ref({
|
const options = ref({
|
||||||
is_audio_only: false,
|
is_audio_only: false,
|
||||||
quality: 'best',
|
quality: 'best',
|
||||||
@@ -55,5 +58,5 @@ export const useAnalysisStore = defineStore('analysis', () => {
|
|||||||
scanMix.value = false
|
scanMix.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
return { url, loading, error, metadata, options, isMix, scanMix, toggleEntry, setAllEntries, invertSelection, reset }
|
return { url, loading, error, metadata, options, isMix, scanMix, isBatchMode, toggleEntry, setAllEntries, invertSelection, reset }
|
||||||
})
|
})
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { watch } from 'vue'
|
import { watch } from 'vue'
|
||||||
import { invoke } from '@tauri-apps/api/core'
|
import { invoke } from '@tauri-apps/api/core'
|
||||||
import { Loader2 } from 'lucide-vue-next'
|
import { Loader2, List, Link } from 'lucide-vue-next'
|
||||||
import { useQueueStore } from '../stores/queue'
|
import { useQueueStore } from '../stores/queue'
|
||||||
import { useSettingsStore } from '../stores/settings'
|
import { useSettingsStore } from '../stores/settings'
|
||||||
import { useAnalysisStore } from '../stores/analysis'
|
import { useAnalysisStore } from '../stores/analysis'
|
||||||
@@ -68,36 +68,100 @@ async function analyze() {
|
|||||||
analysisStore.metadata = null
|
analysisStore.metadata = null
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let urlToScan = analysisStore.url;
|
if (analysisStore.isBatchMode) {
|
||||||
let parseMix = false;
|
// Batch Mode Logic
|
||||||
|
const lines = analysisStore.url.split('\n').map(l => l.trim()).filter(l => l);
|
||||||
|
const validLinks = lines.filter(l => {
|
||||||
|
if (!(l.startsWith('http://') || l.startsWith('https://'))) return false;
|
||||||
|
|
||||||
if (analysisStore.isMix) {
|
// Allow if it has NO list param
|
||||||
if (analysisStore.scanMix) {
|
if (!l.includes('list=')) return true;
|
||||||
// Keep URL as is, tell backend to limit scan
|
|
||||||
parseMix = true;
|
// Allow if it has list param BUT ALSO has v= (video in playlist/mix)
|
||||||
} else {
|
if (l.includes('list=') && l.includes('v=')) return true;
|
||||||
// Strip list param
|
|
||||||
try {
|
// Otherwise ignore (pure playlist)
|
||||||
const u = new URL(urlToScan);
|
return false;
|
||||||
u.searchParams.delete('list');
|
});
|
||||||
u.searchParams.delete('index');
|
|
||||||
u.searchParams.delete('start_radio');
|
if (validLinks.length === 0) {
|
||||||
urlToScan = u.toString();
|
throw new Error("未找到有效的单个视频链接(已忽略纯播放列表链接)。");
|
||||||
} catch (e) {
|
|
||||||
// Fallback regex if URL parsing fails
|
|
||||||
urlToScan = urlToScan.replace(/&list=[^&]+/, '');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const results: any[] = [];
|
||||||
|
|
||||||
|
// Process sequentially to be safe
|
||||||
|
for (let link of validLinks) {
|
||||||
|
try {
|
||||||
|
// If it's a mix/playlist context (has v= and list=), strip the list param to treat as single video
|
||||||
|
if (link.includes('list=') && link.includes('v=')) {
|
||||||
|
try {
|
||||||
|
const u = new URL(link);
|
||||||
|
u.searchParams.delete('list');
|
||||||
|
u.searchParams.delete('index');
|
||||||
|
u.searchParams.delete('start_radio');
|
||||||
|
link = u.toString();
|
||||||
|
} catch (e) {
|
||||||
|
link = link.replace(/&list=[^&]+/, '');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure we don't accidentally trigger mix parsing on single links if logic fails
|
||||||
|
const res = await invoke<any>('fetch_metadata', { url: link, parseMixPlaylist: false });
|
||||||
|
|
||||||
|
// Only add if it's a single video (no entries)
|
||||||
|
if (!res.entries) {
|
||||||
|
results.push(res);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.warn(`Failed to parse ${link}`, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (results.length === 0) {
|
||||||
|
throw new Error("所有链接解析失败或均为播放列表。");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construct synthetic playlist
|
||||||
|
analysisStore.metadata = {
|
||||||
|
id: 'batch_download_' + Date.now(),
|
||||||
|
title: `批量解析结果 (${results.length} 个视频)`,
|
||||||
|
entries: results.map(e => ({ ...e, selected: true }))
|
||||||
|
};
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Single Link Mode
|
||||||
|
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<any>('fetch_metadata', { url: urlToScan, parseMixPlaylist: parseMix })
|
||||||
|
|
||||||
|
// Initialize selected state for playlist entries
|
||||||
|
if (res.entries) {
|
||||||
|
res.entries = res.entries.map((e: any) => ({ ...e, selected: true }))
|
||||||
|
}
|
||||||
|
|
||||||
|
analysisStore.metadata = res
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await invoke<any>('fetch_metadata', { url: urlToScan, parseMixPlaylist: parseMix })
|
|
||||||
|
|
||||||
// Initialize selected state for playlist entries
|
|
||||||
if (res.entries) {
|
|
||||||
res.entries = res.entries.map((e: any) => ({ ...e, selected: true }))
|
|
||||||
}
|
|
||||||
|
|
||||||
analysisStore.metadata = res
|
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
analysisStore.error = e.toString()
|
analysisStore.error = e.toString()
|
||||||
} finally {
|
} finally {
|
||||||
@@ -189,26 +253,53 @@ async function startDownload() {
|
|||||||
|
|
||||||
<!-- Input Section -->
|
<!-- Input Section -->
|
||||||
<div class="bg-white dark:bg-zinc-900 p-6 rounded-2xl shadow-sm border border-gray-200 dark:border-zinc-800 mb-8">
|
<div class="bg-white dark:bg-zinc-900 p-6 rounded-2xl shadow-sm border border-gray-200 dark:border-zinc-800 mb-8">
|
||||||
<div class="flex gap-4">
|
|
||||||
<input
|
<!-- Input Area with Batch Toggle -->
|
||||||
v-model="analysisStore.url"
|
<div class="flex flex-col gap-3">
|
||||||
type="text"
|
<div class="flex justify-end mb-1">
|
||||||
placeholder="https://youtube.com/watch?v=..."
|
<button
|
||||||
class="flex-1 bg-gray-50 dark:bg-zinc-800 border-none rounded-xl px-4 py-3 text-zinc-900 dark:text-white focus:ring-2 focus:ring-blue-500 outline-none"
|
@click="analysisStore.isBatchMode = !analysisStore.isBatchMode"
|
||||||
@keyup.enter="analyze"
|
class="text-xs font-medium flex items-center gap-1.5 px-3 py-1.5 rounded-lg transition-colors"
|
||||||
/>
|
:class="analysisStore.isBatchMode ? 'bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400' : 'bg-gray-100 text-gray-600 dark:bg-zinc-800 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-zinc-700'"
|
||||||
<button
|
>
|
||||||
@click="analyze"
|
<List v-if="analysisStore.isBatchMode" class="w-3.5 h-3.5" />
|
||||||
:disabled="analysisStore.loading"
|
<Link v-else class="w-3.5 h-3.5" />
|
||||||
class="bg-blue-600 hover:bg-blue-700 text-white px-6 py-3 rounded-xl font-medium transition-colors disabled:opacity-50 flex items-center gap-2 shrink-0"
|
{{ analysisStore.isBatchMode ? '切换到单链接模式' : '批量输入模式' }}
|
||||||
>
|
</button>
|
||||||
<Loader2 v-if="analysisStore.loading" class="animate-spin w-5 h-5" />
|
</div>
|
||||||
<span v-else>解析</span>
|
|
||||||
</button>
|
<div class="flex gap-4 items-start">
|
||||||
|
<div class="flex-1 relative">
|
||||||
|
<textarea
|
||||||
|
v-if="analysisStore.isBatchMode"
|
||||||
|
v-model="analysisStore.url"
|
||||||
|
placeholder="每行输入一个链接..."
|
||||||
|
rows="5"
|
||||||
|
class="w-full bg-gray-50 dark:bg-zinc-800 border-none rounded-xl px-4 py-3 text-zinc-900 dark:text-white focus:ring-2 focus:ring-blue-500 outline-none resize-none font-mono text-sm leading-relaxed"
|
||||||
|
></textarea>
|
||||||
|
<input
|
||||||
|
v-else
|
||||||
|
v-model="analysisStore.url"
|
||||||
|
type="text"
|
||||||
|
placeholder="https://youtube.com/watch?v=..."
|
||||||
|
class="w-full bg-gray-50 dark:bg-zinc-800 border-none rounded-xl px-4 py-3 text-zinc-900 dark:text-white focus:ring-2 focus:ring-blue-500 outline-none"
|
||||||
|
@keyup.enter="analyze"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button
|
||||||
|
@click="analyze"
|
||||||
|
:disabled="analysisStore.loading"
|
||||||
|
class="bg-blue-600 hover:bg-blue-700 text-white px-6 py-3 rounded-xl font-medium transition-colors disabled:opacity-50 flex items-center gap-2 shrink-0 h-[48px]"
|
||||||
|
>
|
||||||
|
<Loader2 v-if="analysisStore.loading" class="animate-spin w-5 h-5" />
|
||||||
|
<span v-else>解析</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Mix Toggle -->
|
<!-- Mix Toggle (Only in Single Mode) -->
|
||||||
<div v-if="analysisStore.isMix" class="mt-4 flex items-center gap-3">
|
<div v-if="!analysisStore.isBatchMode && analysisStore.isMix" class="mt-4 flex items-center gap-3">
|
||||||
<button
|
<button
|
||||||
@click="analysisStore.scanMix = !analysisStore.scanMix"
|
@click="analysisStore.scanMix = !analysisStore.scanMix"
|
||||||
class="w-12 h-6 rounded-full relative transition-colors duration-200 ease-in-out flex-shrink-0"
|
class="w-12 h-6 rounded-full relative transition-colors duration-200 ease-in-out flex-shrink-0"
|
||||||
|
|||||||
Reference in New Issue
Block a user