forked from Keelrleek/SoulStream
dj sets + lyrics: a mix that names its own tracks, and words pulled off the separated voice
This commit is contained in:
1 parent
4efe85b6bf
commit
1dd8573808
41 files changed
+9288
-647
No files matched your search
+181
-10
@@ -1,4 +1,4 @@
|
||||
//! Playlist commands: CRUD over the occurrence model, covers (custom +
|
||||
//! Playlist commands: CRUD over the occurrence model, covers (custom +
|
||||
//! composed mosaic), file import with staged preview, and export profiles.
|
||||
//!
|
||||
//! Boundaries, per the architecture audit: parsing happens in
|
||||
@@ -246,6 +246,13 @@ pub struct AddItemInput {
|
||||
pub source_line: Option<String>,
|
||||
#[serde(default)]
|
||||
pub note: Option<String>,
|
||||
/// Catalog track id for a stream row — the identity anchor (exact id,
|
||||
/// never a name match).
|
||||
#[serde(default)]
|
||||
pub track_id: Option<String>,
|
||||
/// Cover URL for a stream row, which has no local file to read art from.
|
||||
#[serde(default)]
|
||||
pub art_url: Option<String>,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -269,6 +276,8 @@ pub async fn playlist_add_items(
|
||||
start_ms: t.start_ms,
|
||||
source_line: t.source_line,
|
||||
note: t.note,
|
||||
track_id: t.track_id,
|
||||
art_url: t.art_url,
|
||||
..Default::default()
|
||||
})
|
||||
.collect();
|
||||
@@ -318,7 +327,8 @@ pub async fn playlist_set_order(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Repair one row — attach a found local file or corrected metadata.
|
||||
/// Repair one row — attach a found local file, corrected metadata, or a
|
||||
/// stream row's catalog anchor (track id + cover URL).
|
||||
#[tauri::command]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub async fn playlist_relink_item(
|
||||
@@ -332,6 +342,8 @@ pub async fn playlist_relink_item(
|
||||
duration_secs: Option<u32>,
|
||||
path: Option<String>,
|
||||
art_path: Option<String>,
|
||||
track_id: Option<String>,
|
||||
art_url: Option<String>,
|
||||
) -> Result<(), String> {
|
||||
let l = lib.library.clone();
|
||||
tauri::async_runtime::spawn_blocking(move || {
|
||||
@@ -344,6 +356,8 @@ pub async fn playlist_relink_item(
|
||||
duration_secs,
|
||||
path.as_deref(),
|
||||
art_path.as_deref(),
|
||||
track_id.as_deref(),
|
||||
art_url.as_deref(),
|
||||
now_secs(),
|
||||
)
|
||||
})
|
||||
@@ -583,7 +597,9 @@ pub struct DraftEntry {
|
||||
pub duration_secs: Option<u32>,
|
||||
pub start_ms: Option<i64>,
|
||||
pub raw: String,
|
||||
/// "local" (matched a library file) | "unresolved".
|
||||
/// "local" (matched a library file) | "stream" (full identity, no local
|
||||
/// file — becomes a Soulseek stream on commit) | "unresolved" (identity
|
||||
/// too thin to play: ID rows, title-only lines).
|
||||
pub resolution: String,
|
||||
/// How the local match was made: "path" | "relinked" | "tags" — evidence
|
||||
/// the preview shows so an exact path match reads differently from a
|
||||
@@ -591,6 +607,18 @@ pub struct DraftEntry {
|
||||
pub matched_by: Option<String>,
|
||||
pub path: Option<String>,
|
||||
pub art_path: Option<String>,
|
||||
/// Catalog identity, attached by the review's verification pass (the
|
||||
/// modal matches stream rows against the Deezer-backed catalog — Kyle:
|
||||
/// verify against "the streaming library part, not Soulseek"). Flows
|
||||
/// into the committed row so it plays as a catalog track with artwork.
|
||||
#[serde(default)]
|
||||
pub track_id: Option<i64>,
|
||||
#[serde(default)]
|
||||
pub art_url: Option<String>,
|
||||
/// The heard release's ISRC, when this row came from the listener door
|
||||
/// — lets the review resolve the catalog by exact recording id.
|
||||
#[serde(default)]
|
||||
pub isrc: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
@@ -604,7 +632,13 @@ pub struct ImportDraft {
|
||||
pub entries: Vec<DraftEntry>,
|
||||
pub warnings: Vec<String>,
|
||||
pub resolved_count: u32,
|
||||
/// Rows that will play as Soulseek streams (identified, not owned).
|
||||
pub stream_count: u32,
|
||||
pub unresolved_count: u32,
|
||||
/// A suggested cover image URL (the YouTube doors set the video's own
|
||||
/// thumbnail). Commit installs it as the playlist's custom cover —
|
||||
/// failure-soft, a cover is never worth failing an import over.
|
||||
pub cover_url: Option<String>,
|
||||
}
|
||||
|
||||
/// Open a playlist file and stage it for review. Parsing and resolution only —
|
||||
@@ -769,6 +803,9 @@ pub async fn playlist_import_folder(
|
||||
matched_by: Some(if indexed.is_some() { "path" } else { "file" }.into()),
|
||||
path: Some(path_string),
|
||||
art_path: indexed.and_then(|r| r.art_path.clone()),
|
||||
track_id: None,
|
||||
art_url: None,
|
||||
isrc: None,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
@@ -782,7 +819,9 @@ pub async fn playlist_import_folder(
|
||||
entries,
|
||||
warnings: Vec::new(),
|
||||
resolved_count: resolved,
|
||||
stream_count: 0,
|
||||
unresolved_count: 0,
|
||||
cover_url: None,
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -875,6 +914,38 @@ pub async fn playlist_import_text(
|
||||
resolve_draft(&lib, parsed, "Pasted tracklist".into(), None).await
|
||||
}
|
||||
|
||||
/// Stage a YouTube DJ set for review: fetch the video's own tracklist
|
||||
/// evidence (chapters → description → top comments, the research bundle's
|
||||
/// declared-data rungs), then run it through the exact pasted-tracklist
|
||||
/// pipeline — same parser, same resolution, same review modal, same commit.
|
||||
/// No audio is fetched and nothing is guessed: a set with no posted
|
||||
/// tracklist says so instead of inventing one.
|
||||
#[tauri::command]
|
||||
pub async fn playlist_import_youtube(
|
||||
lib: State<'_, LibraryState>,
|
||||
url: String,
|
||||
) -> Result<ImportDraft, String> {
|
||||
let fetched = crate::youtube_setlist::fetch(&url).await?;
|
||||
let parsed = playlist_formats::parse_text(fetched.tracklist.as_bytes())?;
|
||||
let source = if fetched.author.is_empty() {
|
||||
fetched.title.clone()
|
||||
} else {
|
||||
format!("{} — {}", fetched.author, fetched.title)
|
||||
};
|
||||
let mut draft = resolve_draft(&lib, parsed, source, None).await?;
|
||||
draft.format = "youtube".into();
|
||||
draft.name = Some(fetched.title);
|
||||
// The video's own thumbnail is the playlist's default face.
|
||||
if let Some(id) = crate::youtube_setlist::video_id_from_url(&url) {
|
||||
draft.cover_url = Some(format!("https://i.ytimg.com/vi/{id}/maxresdefault.jpg"));
|
||||
}
|
||||
draft
|
||||
.warnings
|
||||
.insert(0, format!("Tracklist from {}.", fetched.provenance));
|
||||
draft.warnings.extend(fetched.warnings);
|
||||
Ok(draft)
|
||||
}
|
||||
|
||||
/// Commit a reviewed draft as a new playlist, atomically.
|
||||
#[tauri::command]
|
||||
pub async fn playlist_import_commit(
|
||||
@@ -884,6 +955,7 @@ pub async fn playlist_import_commit(
|
||||
description: Option<String>,
|
||||
kind: String,
|
||||
entries: Vec<DraftEntry>,
|
||||
cover_url: Option<String>,
|
||||
) -> Result<i64, String> {
|
||||
let trimmed = name.trim().to_string();
|
||||
if trimmed.is_empty() {
|
||||
@@ -897,16 +969,25 @@ pub async fn playlist_import_commit(
|
||||
artist: e.artist,
|
||||
album: e.album,
|
||||
duration_secs: e.duration_secs,
|
||||
kind: if e.resolution == "local" && e.path.is_some() {
|
||||
"local".into()
|
||||
// Empty lets the insert classify: a matched path is local, an
|
||||
// unmatched row with full identity is a stream, the rest stay
|
||||
// unresolved placeholders. The one kind the command DOES assert
|
||||
// is "segment" — a listener row that plays a slice of the set's
|
||||
// own recording; the classifier would read its path as "local".
|
||||
kind: if e.resolution == "segment" {
|
||||
"segment".into()
|
||||
} else {
|
||||
"unresolved".into()
|
||||
String::new()
|
||||
},
|
||||
path: e.path.filter(|p| !p.is_empty()),
|
||||
art_path: e.art_path,
|
||||
source_line: (!e.raw.is_empty()).then_some(e.raw),
|
||||
start_ms: e.start_ms,
|
||||
note: None,
|
||||
// Catalog identity from the review's verification pass rides
|
||||
// into the row: the playlist plays it as a catalog track.
|
||||
track_id: e.track_id.map(|id| id.to_string()),
|
||||
art_url: e.art_url,
|
||||
})
|
||||
.collect();
|
||||
let l = lib.library.clone();
|
||||
@@ -919,9 +1000,74 @@ pub async fn playlist_import_commit(
|
||||
.map_err(|e| e.to_string())?
|
||||
.map_err(|e| e.to_string())?;
|
||||
changed(&app);
|
||||
if let Some(url) = cover_url {
|
||||
// Failure-soft: the playlist is already real; a cover is never
|
||||
// worth failing it over.
|
||||
match set_cover_from_url(&app, &lib, id, &url).await {
|
||||
Ok(()) => changed(&app),
|
||||
Err(e) => log::debug!("import cover fetch failed: {e}"),
|
||||
}
|
||||
}
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
/// Download an image URL and install it as the playlist's custom cover —
|
||||
/// the same square master `playlist_cover_pick` writes. YouTube's
|
||||
/// maxresdefault 404s on some videos, so that URL falls back to hqdefault.
|
||||
async fn set_cover_from_url(
|
||||
app: &tauri::AppHandle,
|
||||
lib: &State<'_, LibraryState>,
|
||||
id: i64,
|
||||
url: &str,
|
||||
) -> Result<(), String> {
|
||||
let client = reqwest::Client::builder()
|
||||
.user_agent("SoulStream/0.1")
|
||||
.timeout(std::time::Duration::from_secs(15))
|
||||
.build()
|
||||
.map_err(|e| e.to_string())?;
|
||||
let mut candidates = vec![url.to_string()];
|
||||
if let Some(rest) = url.strip_suffix("maxresdefault.jpg") {
|
||||
candidates.push(format!("{rest}hqdefault.jpg"));
|
||||
}
|
||||
let mut bytes: Option<Vec<u8>> = None;
|
||||
for candidate in candidates {
|
||||
if let Ok(resp) = client.get(&candidate).send().await {
|
||||
if resp.status().is_success() {
|
||||
if let Ok(body) = resp.bytes().await {
|
||||
// YouTube's CDN can answer a missing size with a tiny
|
||||
// gray placeholder instead of a 404 — refuse those.
|
||||
if body.len() > 4096 {
|
||||
bytes = Some(body.to_vec());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let bytes = bytes.ok_or("no usable image answered")?;
|
||||
let dir = covers_dir(app)?;
|
||||
let target = dir.join(format!("{id}.jpg"));
|
||||
let jpeg = tauri::async_runtime::spawn_blocking(move || -> Result<Vec<u8>, String> {
|
||||
let img =
|
||||
image::load_from_memory(&bytes).map_err(|e| format!("not a usable image: {e}"))?;
|
||||
Ok(square_jpeg(&img, COVER_MASTER_EDGE))
|
||||
})
|
||||
.await
|
||||
.map_err(|e| e.to_string())??;
|
||||
let temp = dir.join(format!("{id}.importing"));
|
||||
std::fs::write(&temp, &jpeg).map_err(|e| e.to_string())?;
|
||||
std::fs::rename(&temp, &target).map_err(|e| e.to_string())?;
|
||||
let l = lib.library.clone();
|
||||
let stored = target.to_string_lossy().into_owned();
|
||||
tauri::async_runtime::spawn_blocking(move || {
|
||||
l.set_playlist_cover(id, Some(&stored), now_secs())
|
||||
})
|
||||
.await
|
||||
.map_err(|e| e.to_string())?
|
||||
.map_err(|e| e.to_string())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Resolve parsed entries against the local library, in memory.
|
||||
///
|
||||
/// The ladder, strongest evidence first (identity rules: an exact locator
|
||||
@@ -931,7 +1077,7 @@ pub async fn playlist_import_commit(
|
||||
/// 3. a unique basename match in the library index;
|
||||
/// 4. a unique normalized (artist, title) tag match;
|
||||
/// 5. a unique normalized title match, when the entry names no artist.
|
||||
async fn resolve_draft(
|
||||
pub(crate) async fn resolve_draft(
|
||||
lib: &State<'_, LibraryState>,
|
||||
parsed: playlist_formats::ParsedPlaylist,
|
||||
source_name: String,
|
||||
@@ -980,7 +1126,7 @@ async fn resolve_draft(
|
||||
};
|
||||
|
||||
let mut entries = Vec::new();
|
||||
let (mut resolved, mut unresolved) = (0u32, 0u32);
|
||||
let (mut resolved, mut streams, mut unresolved) = (0u32, 0u32, 0u32);
|
||||
let mut any_start = false;
|
||||
for entry in &parsed.entries {
|
||||
let ParsedEntry {
|
||||
@@ -1022,6 +1168,9 @@ async fn resolve_draft(
|
||||
matched_by: Some("path".into()),
|
||||
path: Some(abs),
|
||||
art_path: None,
|
||||
track_id: None,
|
||||
art_url: None,
|
||||
isrc: None,
|
||||
});
|
||||
resolved += 1;
|
||||
continue;
|
||||
@@ -1090,10 +1239,26 @@ async fn resolve_draft(
|
||||
matched_by: Some(how.into()),
|
||||
path: Some(row.path.clone()),
|
||||
art_path: row.art_path.clone(),
|
||||
track_id: None,
|
||||
art_url: None,
|
||||
isrc: None,
|
||||
});
|
||||
}
|
||||
None => {
|
||||
unresolved += 1;
|
||||
// No library file — but a row with FULL identity becomes a
|
||||
// STREAM on commit (the insert classifier's rule), so the
|
||||
// preview says so instead of "unresolved": Kyle read that
|
||||
// label as "not identified" on a fully-recognized set.
|
||||
// "unresolved" now means what it says: identity too thin
|
||||
// to play (ID rows, title-only lines).
|
||||
let full_identity = title.is_some()
|
||||
&& artist.as_deref().map(|a| !a.trim().is_empty()).unwrap_or(false)
|
||||
&& title.as_deref() != Some("ID");
|
||||
if full_identity {
|
||||
streams += 1;
|
||||
} else {
|
||||
unresolved += 1;
|
||||
}
|
||||
entries.push(DraftEntry {
|
||||
ordinal: *ordinal,
|
||||
title: title.clone().unwrap_or_else(|| "Unknown".into()),
|
||||
@@ -1102,10 +1267,13 @@ async fn resolve_draft(
|
||||
duration_secs: *duration_secs,
|
||||
start_ms: *start_ms,
|
||||
raw: raw.clone(),
|
||||
resolution: "unresolved".into(),
|
||||
resolution: if full_identity { "stream" } else { "unresolved" }.into(),
|
||||
matched_by: None,
|
||||
path: None,
|
||||
art_path: None,
|
||||
track_id: None,
|
||||
art_url: None,
|
||||
isrc: None,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1119,7 +1287,9 @@ async fn resolve_draft(
|
||||
entries,
|
||||
warnings: parsed.warnings,
|
||||
resolved_count: resolved,
|
||||
stream_count: streams,
|
||||
unresolved_count: unresolved,
|
||||
cover_url: None,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1277,3 +1447,4 @@ pub async fn playlist_export(
|
||||
.map_err(|e| e.to_string())??;
|
||||
Ok(Some(dest))
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user