Compare commits
9 Commits
eada45bd9c
...
v1.1.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1554be25d2 | ||
|
|
05887fd7a3 | ||
|
|
63648f9d7c | ||
|
|
0a439dbd71 | ||
|
|
f164569e89 | ||
|
|
f4bdb85841 | ||
|
|
36bd5061a4 | ||
|
|
dde9ed7718 | ||
|
|
8ae5f4f66c |
@@ -3,8 +3,3 @@
|
|||||||
A simple Youtube downloader.
|
A simple Youtube downloader.
|
||||||
|
|
||||||
Generated by Gemini CLI.
|
Generated by Gemini CLI.
|
||||||
|
|
||||||
## Problems
|
|
||||||
|
|
||||||
1. windows 上打包后运行命令会出现黑窗,而且还是会出现找不到 js-runtimes 的问题,但是 quickjs 是正常下载了
|
|
||||||
2. macos 上未测试
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "stream-capture",
|
"name": "stream-capture",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.1.0",
|
"version": "1.1.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
12
splashscreen.html
Normal file
12
splashscreen.html
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>StreamCapture Loading</title>
|
||||||
|
</head>
|
||||||
|
<body class="font-sans antialiased">
|
||||||
|
<div id="app"></div>
|
||||||
|
<script type="module" src="/src/splash/main.ts"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
3
src-tauri/Cargo.lock
generated
3
src-tauri/Cargo.lock
generated
@@ -3971,9 +3971,10 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "stream-capture"
|
name = "stream-capture"
|
||||||
version = "0.1.0"
|
version = "1.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"base64 0.22.1",
|
||||||
"chrono",
|
"chrono",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"regex",
|
"regex",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "stream-capture"
|
name = "stream-capture"
|
||||||
version = "0.1.0"
|
version = "1.1.0"
|
||||||
description = "A Tauri App"
|
description = "A Tauri App"
|
||||||
authors = ["you"]
|
authors = ["you"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
@@ -19,6 +19,7 @@ tauri-plugin-dialog = "2"
|
|||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
reqwest = { version = "0.12", features = ["json", "rustls-tls", "stream"] }
|
reqwest = { version = "0.12", features = ["json", "rustls-tls", "stream"] }
|
||||||
|
base64 = "0.22"
|
||||||
tokio = { version = "1", features = ["full"] }
|
tokio = { version = "1", features = ["full"] }
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
chrono = { version = "0.4", features = ["serde"] }
|
chrono = { version = "0.4", features = ["serde"] }
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"$schema": "../gen/schemas/desktop-schema.json",
|
"$schema": "../gen/schemas/desktop-schema.json",
|
||||||
"identifier": "default",
|
"identifier": "default",
|
||||||
"description": "Capability for the main window",
|
"description": "Capability for the main window",
|
||||||
"windows": ["main"],
|
"windows": ["main", "splashscreen"],
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"core:default",
|
"core:default",
|
||||||
"opener:default",
|
"opener:default",
|
||||||
|
|||||||
@@ -308,17 +308,19 @@ pub async fn download_ffmpeg(app: &AppHandle) -> Result<PathBuf> {
|
|||||||
for asset in assets {
|
for asset in assets {
|
||||||
if let (Some(name), Some(url)) = (asset.get("name").and_then(|n| n.as_str()), asset.get("browser_download_url").and_then(|u| u.as_str())) {
|
if let (Some(name), Some(url)) = (asset.get("name").and_then(|n| n.as_str()), asset.get("browser_download_url").and_then(|u| u.as_str())) {
|
||||||
let lname = name.to_lowercase();
|
let lname = name.to_lowercase();
|
||||||
if lname.contains("win64") && lname.ends_with(".zip") {
|
// Prefer GPL static build, avoid shared to get a single exe
|
||||||
|
if lname.contains("win64") && lname.contains("gpl") && !lname.contains("shared") && lname.ends_with(".zip") {
|
||||||
download_url = Some(url.to_string());
|
download_url = Some(url.to_string());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if download_url.is_none() {
|
if download_url.is_none() {
|
||||||
// fallback: choose first zip asset
|
// fallback: choose first zip asset that is NOT shared if possible
|
||||||
for asset in assets {
|
for asset in assets {
|
||||||
if let (Some(url), Some(name)) = (asset.get("browser_download_url").and_then(|u| u.as_str()), asset.get("name").and_then(|n| n.as_str())) {
|
if let (Some(url), Some(name)) = (asset.get("browser_download_url").and_then(|u| u.as_str()), asset.get("name").and_then(|n| n.as_str())) {
|
||||||
if name.to_lowercase().ends_with(".zip") {
|
let lname = name.to_lowercase();
|
||||||
|
if lname.ends_with(".zip") && !lname.contains("shared") {
|
||||||
download_url = Some(url.to_string());
|
download_url = Some(url.to_string());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -341,7 +343,8 @@ pub async fn download_ffmpeg(app: &AppHandle) -> Result<PathBuf> {
|
|||||||
if file.is_dir() { continue; }
|
if file.is_dir() { continue; }
|
||||||
let name = file.name().to_string();
|
let name = file.name().to_string();
|
||||||
let filename_only = name.split('/').last().unwrap_or("");
|
let filename_only = name.split('/').last().unwrap_or("");
|
||||||
if filename_only.eq_ignore_ascii_case("ffmpeg.exe") || filename_only.ends_with(".dll") {
|
// Only extract the executable, ignore DLLs
|
||||||
|
if filename_only.eq_ignore_ascii_case("ffmpeg.exe") {
|
||||||
let mut out_file = fs::File::create(bin_dir.join(filename_only))?;
|
let mut out_file = fs::File::create(bin_dir.join(filename_only))?;
|
||||||
std::io::copy(&mut file, &mut out_file)?;
|
std::io::copy(&mut file, &mut out_file)?;
|
||||||
found = true;
|
found = true;
|
||||||
@@ -496,6 +499,21 @@ pub async fn ensure_binaries(app: &AppHandle) -> Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let ffmpeg = get_ffmpeg_path(app)?;
|
||||||
|
if !ffmpeg.exists() {
|
||||||
|
download_ffmpeg(app).await?;
|
||||||
|
} else {
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
{
|
||||||
|
std::process::Command::new("xattr")
|
||||||
|
.arg("-d")
|
||||||
|
.arg("com.apple.quarantine")
|
||||||
|
.arg(&ffmpeg)
|
||||||
|
.output()
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,6 +49,28 @@ pub fn get_ffmpeg_version(app: AppHandle) -> Result<String, String> {
|
|||||||
binary_manager::get_ffmpeg_version(&app).map_err(|e| e.to_string())
|
binary_manager::get_ffmpeg_version(&app).map_err(|e| e.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn fetch_image(url: String) -> Result<String, String> {
|
||||||
|
use base64::{Engine as _, engine::general_purpose};
|
||||||
|
|
||||||
|
let client = reqwest::Client::new();
|
||||||
|
let res = client.get(&url)
|
||||||
|
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36")
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
let bytes = res.bytes().await.map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
// Convert to base64
|
||||||
|
let b64 = general_purpose::STANDARD.encode(&bytes);
|
||||||
|
|
||||||
|
// Simple heuristic for mime type
|
||||||
|
let mime = if url.to_lowercase().ends_with(".png") { "image/png" } else { "image/jpeg" };
|
||||||
|
|
||||||
|
Ok(format!("data:{};base64,{}", mime, b64))
|
||||||
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn fetch_metadata(app: AppHandle, url: String, parse_mix_playlist: bool) -> Result<downloader::MetadataResult, String> {
|
pub async fn fetch_metadata(app: AppHandle, url: String, parse_mix_playlist: bool) -> Result<downloader::MetadataResult, String> {
|
||||||
downloader::fetch_metadata(&app, &url, parse_mix_playlist).await.map_err(|e| e.to_string())
|
downloader::fetch_metadata(&app, &url, parse_mix_playlist).await.map_err(|e| e.to_string())
|
||||||
@@ -111,6 +133,16 @@ pub fn delete_history_item(app: AppHandle, id: String) -> Result<(), String> {
|
|||||||
storage::delete_history_item(&app, &id).map_err(|e| e.to_string())
|
storage::delete_history_item(&app, &id).map_err(|e| e.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn close_splash(app: AppHandle) {
|
||||||
|
if let Some(splash) = app.get_webview_window("splashscreen") {
|
||||||
|
splash.close().unwrap();
|
||||||
|
}
|
||||||
|
if let Some(main) = app.get_webview_window("main") {
|
||||||
|
main.show().unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn open_in_explorer(app: AppHandle, path: String) -> Result<(), String> {
|
pub fn open_in_explorer(app: AppHandle, path: String) -> Result<(), String> {
|
||||||
let path_to_open = if Path::new(&path).exists() {
|
let path_to_open = if Path::new(&path).exists() {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ pub struct VideoMetadata {
|
|||||||
pub thumbnail: String,
|
pub thumbnail: String,
|
||||||
pub duration: Option<f64>,
|
pub duration: Option<f64>,
|
||||||
pub uploader: Option<String>,
|
pub uploader: Option<String>,
|
||||||
|
pub url: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
@@ -150,12 +151,17 @@ fn parse_video_metadata(json: &serde_json::Value) -> VideoMetadata {
|
|||||||
_ => format!("https://i.ytimg.com/vi/{}/mqdefault.jpg", id),
|
_ => format!("https://i.ytimg.com/vi/{}/mqdefault.jpg", id),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let url = json["webpage_url"].as_str()
|
||||||
|
.or_else(|| json["url"].as_str())
|
||||||
|
.map(|s| s.to_string());
|
||||||
|
|
||||||
VideoMetadata {
|
VideoMetadata {
|
||||||
id,
|
id,
|
||||||
title: json["title"].as_str().unwrap_or("Unknown Title").to_string(),
|
title: json["title"].as_str().unwrap_or("Unknown Title").to_string(),
|
||||||
thumbnail,
|
thumbnail,
|
||||||
duration: json["duration"].as_f64(),
|
duration: json["duration"].as_f64(),
|
||||||
uploader: json["uploader"].as_str().map(|s| s.to_string()),
|
uploader: json["uploader"].as_str().map(|s| s.to_string()),
|
||||||
|
url,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,7 +204,7 @@ pub async fn download_video(
|
|||||||
let format_arg = if options.quality == "best" {
|
let format_arg = if options.quality == "best" {
|
||||||
"bestvideo+bestaudio/best".to_string()
|
"bestvideo+bestaudio/best".to_string()
|
||||||
} else {
|
} else {
|
||||||
format!("bestvideo[height<={}]+bestaudio/best[height<={}]", options.quality, options.quality)
|
format!("bestvideo[height<={}]+bestaudio/best[height<={}]/best", options.quality, options.quality)
|
||||||
};
|
};
|
||||||
args.push("-f".to_string());
|
args.push("-f".to_string());
|
||||||
args.push(format_arg);
|
args.push(format_arg);
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ pub fn run() {
|
|||||||
commands::get_ytdlp_version,
|
commands::get_ytdlp_version,
|
||||||
commands::get_quickjs_version,
|
commands::get_quickjs_version,
|
||||||
commands::get_ffmpeg_version,
|
commands::get_ffmpeg_version,
|
||||||
|
commands::fetch_image,
|
||||||
commands::fetch_metadata,
|
commands::fetch_metadata,
|
||||||
commands::start_download,
|
commands::start_download,
|
||||||
commands::get_settings,
|
commands::get_settings,
|
||||||
@@ -24,6 +25,7 @@ pub fn run() {
|
|||||||
commands::get_history,
|
commands::get_history,
|
||||||
commands::clear_history,
|
commands::clear_history,
|
||||||
commands::delete_history_item,
|
commands::delete_history_item,
|
||||||
|
commands::close_splash,
|
||||||
commands::open_in_explorer
|
commands::open_in_explorer
|
||||||
])
|
])
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://schema.tauri.app/config/2",
|
"$schema": "https://schema.tauri.app/config/2",
|
||||||
"productName": "stream-capture",
|
"productName": "StreamCapture",
|
||||||
"version": "0.1.0",
|
"version": "1.1.0",
|
||||||
"identifier": "top.volan.stream-capture",
|
"identifier": "top.volan.stream-capture",
|
||||||
"build": {
|
"build": {
|
||||||
"beforeDevCommand": "pnpm dev",
|
"beforeDevCommand": "pnpm dev",
|
||||||
@@ -12,9 +12,22 @@
|
|||||||
"app": {
|
"app": {
|
||||||
"windows": [
|
"windows": [
|
||||||
{
|
{
|
||||||
"title": "流萤 - 视频下载 v1.0.0",
|
"label": "main",
|
||||||
|
"title": "流萤 - 视频下载 v1.1.0",
|
||||||
"width": 1300,
|
"width": 1300,
|
||||||
"height": 900
|
"height": 900,
|
||||||
|
"visible": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "splashscreen",
|
||||||
|
"title": "StreamCapture Loading",
|
||||||
|
"url": "splashscreen.html",
|
||||||
|
"width": 400,
|
||||||
|
"height": 300,
|
||||||
|
"decorations": false,
|
||||||
|
"center": true,
|
||||||
|
"resizable": false,
|
||||||
|
"alwaysOnTop": true
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"security": {
|
"security": {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// filepath: src/App.vue
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { onMounted } from 'vue'
|
import { onMounted } from 'vue'
|
||||||
import { RouterView, RouterLink, useRoute } from 'vue-router'
|
import { RouterView, RouterLink, useRoute } from 'vue-router'
|
||||||
|
|||||||
44
src/splash/App.vue
Normal file
44
src/splash/App.vue
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { onMounted, ref } from 'vue'
|
||||||
|
import { invoke } from '@tauri-apps/api/core'
|
||||||
|
import { Loader2, DownloadCloud, CheckCircle2, AlertCircle } from 'lucide-vue-next'
|
||||||
|
|
||||||
|
const status = ref('正在初始化...')
|
||||||
|
const isError = ref(false)
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
try {
|
||||||
|
status.value = '正在检查运行环境...'
|
||||||
|
// This command checks and downloads binaries if missing
|
||||||
|
await invoke('init_ytdlp')
|
||||||
|
|
||||||
|
status.value = '准备就绪'
|
||||||
|
setTimeout(async () => {
|
||||||
|
await invoke('close_splash')
|
||||||
|
}, 800)
|
||||||
|
} catch (e: any) {
|
||||||
|
status.value = '启动错误: ' + (e.toString() || '未知错误')
|
||||||
|
isError.value = true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="h-screen w-screen bg-white dark:bg-zinc-900 flex flex-col items-center justify-center select-none cursor-default p-8 text-center overflow-hidden" data-tauri-drag-region>
|
||||||
|
<div class="mb-6 relative w-20 h-20 bg-blue-600 rounded-2xl shadow-xl flex items-center justify-center text-white">
|
||||||
|
<DownloadCloud v-if="!isError" class="w-10 h-10" />
|
||||||
|
<AlertCircle v-else class="w-10 h-10" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h1 class="text-xl font-bold text-zinc-900 dark:text-white mb-6">流萤 - 视频下载</h1>
|
||||||
|
|
||||||
|
<div class="flex flex-col items-center gap-3 w-full max-w-xs">
|
||||||
|
<div class="flex items-center gap-2.5 text-sm font-medium transition-colors duration-300"
|
||||||
|
:class="isError ? 'text-red-500' : 'text-gray-600 dark:text-gray-300'">
|
||||||
|
<Loader2 v-if="!isError && status !== '准备就绪'" class="animate-spin w-4 h-4" />
|
||||||
|
<CheckCircle2 v-if="status === '准备就绪'" class="w-4 h-4 text-green-500" />
|
||||||
|
<span>{{ status }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
5
src/splash/main.ts
Normal file
5
src/splash/main.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import { createApp } from 'vue'
|
||||||
|
import App from './App.vue'
|
||||||
|
import '../style.css'
|
||||||
|
|
||||||
|
createApp(App).mount('#app')
|
||||||
@@ -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'
|
||||||
@@ -61,6 +61,38 @@ watch(() => analysisStore.options.is_audio_only, () => {
|
|||||||
analysisStore.options.output_format = 'original'
|
analysisStore.options.output_format = 'original'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
async function processThumbnail(url: string | undefined): Promise<string | undefined> {
|
||||||
|
if (!url) return undefined;
|
||||||
|
// Check if it's an Instagram URL or similar that needs proxying
|
||||||
|
if (url.includes('instagram.com') || url.includes('fbcdn.net') || url.includes('cdninstagram.com')) {
|
||||||
|
try {
|
||||||
|
return await invoke<string>('fetch_image', { url });
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('Thumbnail fetch failed, falling back to URL', e);
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function processMetadataThumbnails(metadata: any) {
|
||||||
|
if (!metadata) return;
|
||||||
|
|
||||||
|
// Process single video thumbnail
|
||||||
|
if (metadata.thumbnail) {
|
||||||
|
metadata.thumbnail = await processThumbnail(metadata.thumbnail);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process playlist entries
|
||||||
|
if (metadata.entries && Array.isArray(metadata.entries)) {
|
||||||
|
await Promise.all(metadata.entries.map(async (entry: any) => {
|
||||||
|
if (entry.thumbnail) {
|
||||||
|
entry.thumbnail = await processThumbnail(entry.thumbnail);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function analyze() {
|
async function analyze() {
|
||||||
if (!analysisStore.url) return
|
if (!analysisStore.url) return
|
||||||
analysisStore.loading = true
|
analysisStore.loading = true
|
||||||
@@ -68,6 +100,72 @@ async function analyze() {
|
|||||||
analysisStore.metadata = null
|
analysisStore.metadata = null
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (analysisStore.isBatchMode) {
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
// Allow if it has NO list param
|
||||||
|
if (!l.includes('list=')) return true;
|
||||||
|
|
||||||
|
// Allow if it has list param BUT ALSO has v= (video in playlist/mix)
|
||||||
|
if (l.includes('list=') && l.includes('v=')) return true;
|
||||||
|
|
||||||
|
// Otherwise ignore (pure playlist)
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (validLinks.length === 0) {
|
||||||
|
throw new Error("未找到有效的单个视频链接(已忽略纯播放列表链接)。");
|
||||||
|
}
|
||||||
|
|
||||||
|
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("所有链接解析失败或均为播放列表。");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process thumbnails for batch results
|
||||||
|
await Promise.all(results.map(r => processMetadataThumbnails(r)));
|
||||||
|
|
||||||
|
// 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 urlToScan = analysisStore.url;
|
||||||
let parseMix = false;
|
let parseMix = false;
|
||||||
|
|
||||||
@@ -92,12 +190,15 @@ async function analyze() {
|
|||||||
|
|
||||||
const res = await invoke<any>('fetch_metadata', { url: urlToScan, parseMixPlaylist: parseMix })
|
const res = await invoke<any>('fetch_metadata', { url: urlToScan, parseMixPlaylist: parseMix })
|
||||||
|
|
||||||
|
await processMetadataThumbnails(res);
|
||||||
|
|
||||||
// Initialize selected state for playlist entries
|
// Initialize selected state for playlist entries
|
||||||
if (res.entries) {
|
if (res.entries) {
|
||||||
res.entries = res.entries.map((e: any) => ({ ...e, selected: true }))
|
res.entries = res.entries.map((e: any) => ({ ...e, selected: true }))
|
||||||
}
|
}
|
||||||
|
|
||||||
analysisStore.metadata = res
|
analysisStore.metadata = res
|
||||||
|
}
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
analysisStore.error = e.toString()
|
analysisStore.error = e.toString()
|
||||||
} finally {
|
} finally {
|
||||||
@@ -124,7 +225,7 @@ async function startDownload() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const entry of selectedEntries) {
|
for (const entry of selectedEntries) {
|
||||||
const videoUrl = `https://www.youtube.com/watch?v=${entry.id}`
|
const videoUrl = entry.url || `https://www.youtube.com/watch?v=${entry.id}`
|
||||||
const id = await invoke<string>('start_download', {
|
const id = await invoke<string>('start_download', {
|
||||||
url: videoUrl,
|
url: videoUrl,
|
||||||
options: analysisStore.options,
|
options: analysisStore.options,
|
||||||
@@ -189,26 +290,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 Area with Batch Toggle -->
|
||||||
|
<div class="flex flex-col gap-3">
|
||||||
|
<div class="flex justify-end mb-1">
|
||||||
|
<button
|
||||||
|
@click="analysisStore.isBatchMode = !analysisStore.isBatchMode"
|
||||||
|
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'"
|
||||||
|
>
|
||||||
|
<List v-if="analysisStore.isBatchMode" class="w-3.5 h-3.5" />
|
||||||
|
<Link v-else class="w-3.5 h-3.5" />
|
||||||
|
{{ analysisStore.isBatchMode ? '单链接模式' : '批量输入模式' }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<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
|
<input
|
||||||
|
v-else
|
||||||
v-model="analysisStore.url"
|
v-model="analysisStore.url"
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="https://youtube.com/watch?v=..."
|
placeholder="https://..."
|
||||||
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"
|
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"
|
@keyup.enter="analyze"
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
@click="analyze"
|
@click="analyze"
|
||||||
:disabled="analysisStore.loading"
|
: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"
|
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" />
|
<Loader2 v-if="analysisStore.loading" class="animate-spin w-5 h-5" />
|
||||||
<span v-else>解析</span>
|
<span v-else>解析</span>
|
||||||
</button>
|
</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"
|
||||||
|
|||||||
@@ -184,7 +184,9 @@ function setTheme(theme: 'light' | 'dark' | 'system') {
|
|||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<div class="font-medium text-zinc-900 dark:text-white">FFmpeg</div>
|
<div class="font-medium text-zinc-900 dark:text-white">FFmpeg</div>
|
||||||
<div class="text-xs text-gray-500 mt-0.5 font-mono">{{ settingsStore.ffmpegVersion === '未安装' ? '未安装' : '已安装' }}</div>
|
<div class="text-xs text-gray-500 mt-0.5 font-mono" :title="settingsStore.ffmpegVersion">
|
||||||
|
{{ ['Checking...', '未安装', 'Error'].includes(settingsStore.ffmpegVersion) ? settingsStore.ffmpegVersion : '已安装' }}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { defineConfig } from "vite";
|
import { defineConfig } from "vite";
|
||||||
import vue from "@vitejs/plugin-vue";
|
import vue from "@vitejs/plugin-vue";
|
||||||
|
import { resolve } from "path";
|
||||||
|
|
||||||
// @ts-expect-error process is a nodejs global
|
// @ts-expect-error process is a nodejs global
|
||||||
const host = process.env.TAURI_DEV_HOST;
|
const host = process.env.TAURI_DEV_HOST;
|
||||||
@@ -29,4 +30,12 @@ export default defineConfig(async () => ({
|
|||||||
ignored: ["**/src-tauri/**"],
|
ignored: ["**/src-tauri/**"],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
build: {
|
||||||
|
rollupOptions: {
|
||||||
|
input: {
|
||||||
|
main: resolve(__dirname, 'index.html'),
|
||||||
|
splashscreen: resolve(__dirname, 'splashscreen.html'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}));
|
}));
|
||||||
|
|||||||
Reference in New Issue
Block a user