feat(playlist-import): multipart playlists for 2000+ track imports
Qobuz limits playlists to 2000 tracks. When matched tracks exceed this limit, the importer now automatically splits into multiple playlists named "Playlist (Part 1)", "Playlist (Part 2)", etc. - models.rs: qobuz_playlist_id -> qobuz_playlist_ids Vec, add parts_created - importer.rs: chunk matched tracks by 2000, create playlist per chunk - Frontend: show parts count in summary, move all parts to folder - i18n: add partsCreated key in en/es/de/fr
This commit is contained in:
1 parent
595d6d46f5
commit
4bbf97a131
7 files changed
+89
-38
No files matched your search
@@ -9,6 +9,7 @@ use crate::playlist_import::models::{ImportPlaylist, ImportProgress, ImportSumma
|
|||||||
use crate::playlist_import::providers::{detect_provider, fetch_playlist};
|
use crate::playlist_import::providers::{detect_provider, fetch_playlist};
|
||||||
|
|
||||||
const ADD_CHUNK_SIZE: usize = 50;
|
const ADD_CHUNK_SIZE: usize = 50;
|
||||||
|
const QOBUZ_PLAYLIST_TRACK_LIMIT: usize = 2000;
|
||||||
|
|
||||||
pub async fn preview_public_playlist(
|
pub async fn preview_public_playlist(
|
||||||
url: &str,
|
url: &str,
|
||||||
@@ -44,57 +45,89 @@ pub async fn import_public_playlist(
|
|||||||
let total_tracks = playlist.tracks.len() as u32;
|
let total_tracks = playlist.tracks.len() as u32;
|
||||||
let skipped_tracks = total_tracks.saturating_sub(matched_count);
|
let skipped_tracks = total_tracks.saturating_sub(matched_count);
|
||||||
|
|
||||||
let mut qobuz_playlist_id = None;
|
let mut qobuz_playlist_ids = Vec::new();
|
||||||
|
|
||||||
if !matched_track_ids.is_empty() {
|
if !matched_track_ids.is_empty() {
|
||||||
// Phase: creating
|
let base_name = name_override.unwrap_or(&playlist.name);
|
||||||
let _ = app.emit("import:phase", serde_json::json!({ "phase": "creating" }));
|
|
||||||
|
|
||||||
let name = name_override.unwrap_or(&playlist.name);
|
|
||||||
let description = playlist
|
let description = playlist
|
||||||
.description
|
.description
|
||||||
.clone()
|
.clone()
|
||||||
.or_else(|| Some(format!("Imported from {}", playlist.provider.as_str())));
|
.or_else(|| Some(format!("Imported from {}", playlist.provider.as_str())));
|
||||||
|
|
||||||
let created = client
|
// Split into parts if more than QOBUZ_PLAYLIST_TRACK_LIMIT tracks
|
||||||
.create_playlist(name, description.as_deref(), is_public)
|
let parts: Vec<&[u64]> = matched_track_ids
|
||||||
.await
|
.chunks(QOBUZ_PLAYLIST_TRACK_LIMIT)
|
||||||
.map_err(|e| PlaylistImportError::Qobuz(e.to_string()))?;
|
.collect();
|
||||||
|
let total_parts = parts.len();
|
||||||
|
|
||||||
qobuz_playlist_id = Some(created.id);
|
for (part_idx, part_tracks) in parts.iter().enumerate() {
|
||||||
|
// Phase: creating (per part)
|
||||||
|
let _ = app.emit("import:phase", serde_json::json!({ "phase": "creating" }));
|
||||||
|
|
||||||
// Phase: adding
|
let playlist_name = if total_parts == 1 {
|
||||||
let _ = app.emit("import:phase", serde_json::json!({ "phase": "adding" }));
|
base_name.to_string()
|
||||||
|
} else {
|
||||||
|
format!("{} (Part {})", base_name, part_idx + 1)
|
||||||
|
};
|
||||||
|
|
||||||
let chunks: Vec<&[u64]> = matched_track_ids.chunks(ADD_CHUNK_SIZE).collect();
|
let part_desc = if total_parts == 1 {
|
||||||
let total_chunks = chunks.len() as u32;
|
description.clone()
|
||||||
|
} else {
|
||||||
|
Some(format!(
|
||||||
|
"Part {} of {} — {}",
|
||||||
|
part_idx + 1,
|
||||||
|
total_parts,
|
||||||
|
description.as_deref().unwrap_or("")
|
||||||
|
))
|
||||||
|
};
|
||||||
|
|
||||||
for (i, chunk) in chunks.iter().enumerate() {
|
let created = client
|
||||||
client
|
.create_playlist(&playlist_name, part_desc.as_deref(), is_public)
|
||||||
.add_tracks_to_playlist(created.id, chunk)
|
|
||||||
.await
|
.await
|
||||||
.map_err(|e| PlaylistImportError::Qobuz(e.to_string()))?;
|
.map_err(|e| PlaylistImportError::Qobuz(e.to_string()))?;
|
||||||
|
|
||||||
let _ = app.emit(
|
qobuz_playlist_ids.push(created.id);
|
||||||
"import:progress",
|
|
||||||
ImportProgress {
|
// Phase: adding
|
||||||
phase: "adding".to_string(),
|
let _ = app.emit("import:phase", serde_json::json!({ "phase": "adding" }));
|
||||||
current: (i as u32) + 1,
|
|
||||||
total: total_chunks,
|
let chunks: Vec<&[u64]> = part_tracks.chunks(ADD_CHUNK_SIZE).collect();
|
||||||
matched_so_far: matched_count,
|
let total_chunks = chunks.len() as u32;
|
||||||
current_track: None,
|
|
||||||
},
|
for (i, chunk) in chunks.iter().enumerate() {
|
||||||
);
|
client
|
||||||
|
.add_tracks_to_playlist(created.id, chunk)
|
||||||
|
.await
|
||||||
|
.map_err(|e| PlaylistImportError::Qobuz(e.to_string()))?;
|
||||||
|
|
||||||
|
let _ = app.emit(
|
||||||
|
"import:progress",
|
||||||
|
ImportProgress {
|
||||||
|
phase: "adding".to_string(),
|
||||||
|
current: (i as u32) + 1,
|
||||||
|
total: total_chunks,
|
||||||
|
matched_so_far: matched_count,
|
||||||
|
current_track: if total_parts > 1 {
|
||||||
|
Some(format!("Part {}/{}", part_idx + 1, total_parts))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let parts_created = qobuz_playlist_ids.len() as u32;
|
||||||
|
|
||||||
Ok(ImportSummary {
|
Ok(ImportSummary {
|
||||||
provider: playlist.provider,
|
provider: playlist.provider,
|
||||||
playlist_name: playlist.name,
|
playlist_name: playlist.name,
|
||||||
total_tracks,
|
total_tracks,
|
||||||
matched_tracks: matched_count,
|
matched_tracks: matched_count,
|
||||||
skipped_tracks,
|
skipped_tracks,
|
||||||
qobuz_playlist_id,
|
qobuz_playlist_ids,
|
||||||
|
parts_created,
|
||||||
matches,
|
matches,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -57,7 +57,8 @@ pub struct ImportSummary {
|
|||||||
pub total_tracks: u32,
|
pub total_tracks: u32,
|
||||||
pub matched_tracks: u32,
|
pub matched_tracks: u32,
|
||||||
pub skipped_tracks: u32,
|
pub skipped_tracks: u32,
|
||||||
pub qobuz_playlist_id: Option<u64>,
|
pub qobuz_playlist_ids: Vec<u64>,
|
||||||
|
pub parts_created: u32,
|
||||||
pub matches: Vec<TrackMatch>,
|
pub matches: Vec<TrackMatch>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,8 @@
|
|||||||
total_tracks: number;
|
total_tracks: number;
|
||||||
matched_tracks: number;
|
matched_tracks: number;
|
||||||
skipped_tracks: number;
|
skipped_tracks: number;
|
||||||
qobuz_playlist_id?: number | null;
|
qobuz_playlist_ids: number[];
|
||||||
|
parts_created: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -255,12 +256,21 @@
|
|||||||
lastImportedUrl = previewUrl;
|
lastImportedUrl = previewUrl;
|
||||||
pushLog(`Imported ${result.matched_tracks} of ${result.total_tracks} tracks into QBZ.`, 'success');
|
pushLog(`Imported ${result.matched_tracks} of ${result.total_tracks} tracks into QBZ.`, 'success');
|
||||||
|
|
||||||
if (result.qobuz_playlist_id) {
|
if (result.qobuz_playlist_ids.length > 0) {
|
||||||
pushLog('Playlist created in Qobuz\u2122.', 'success');
|
if (result.parts_created > 1) {
|
||||||
|
pushLog(
|
||||||
|
$t('playlistImport.partsCreated', { values: { count: result.parts_created } }),
|
||||||
|
'success'
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
pushLog('Playlist created in Qobuz\u2122.', 'success');
|
||||||
|
}
|
||||||
|
|
||||||
// Move to folder if selected
|
// Move all parts to folder if selected
|
||||||
if (selectedFolderId) {
|
if (selectedFolderId) {
|
||||||
await movePlaylistToFolder(result.qobuz_playlist_id, selectedFolderId);
|
for (const playlistId of result.qobuz_playlist_ids) {
|
||||||
|
await movePlaylistToFolder(playlistId, selectedFolderId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pushLog('No matching tracks found.', 'error');
|
pushLog('No matching tracks found.', 'error');
|
||||||
@@ -438,6 +448,9 @@
|
|||||||
<div class="summary-row">{$t('playlistImport.playlistLabel', { values: { name: summary.playlist_name } })}</div>
|
<div class="summary-row">{$t('playlistImport.playlistLabel', { values: { name: summary.playlist_name } })}</div>
|
||||||
<div class="summary-row">{$t('playlistImport.tracksMatched', { values: { matched: summary.matched_tracks, total: summary.total_tracks } })}</div>
|
<div class="summary-row">{$t('playlistImport.tracksMatched', { values: { matched: summary.matched_tracks, total: summary.total_tracks } })}</div>
|
||||||
<div class="summary-row">{$t('playlistImport.skipped', { values: { count: summary.skipped_tracks } })}</div>
|
<div class="summary-row">{$t('playlistImport.skipped', { values: { count: summary.skipped_tracks } })}</div>
|
||||||
|
{#if summary.parts_created > 1}
|
||||||
|
<div class="summary-row">{$t('playlistImport.partsCreated', { values: { count: summary.parts_created } })}</div>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1323,6 +1323,7 @@
|
|||||||
"matchingPhase": "Qobuz-Katalog durchsuchen...",
|
"matchingPhase": "Qobuz-Katalog durchsuchen...",
|
||||||
"creatingPhase": "Playlist erstellen...",
|
"creatingPhase": "Playlist erstellen...",
|
||||||
"addingPhase": "Titel zur Playlist hinzufugen...",
|
"addingPhase": "Titel zur Playlist hinzufugen...",
|
||||||
"addingProgress": "Titel hinzufugen: {current} / {total}"
|
"addingProgress": "Titel hinzufugen: {current} / {total}",
|
||||||
|
"partsCreated": "Aufgeteilt in {count} Playlists (Qobuz-Limit: 2000 Titel)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1525,6 +1525,7 @@
|
|||||||
"matchingPhase": "Searching Qobuz catalog...",
|
"matchingPhase": "Searching Qobuz catalog...",
|
||||||
"creatingPhase": "Creating playlist...",
|
"creatingPhase": "Creating playlist...",
|
||||||
"addingPhase": "Adding tracks to playlist...",
|
"addingPhase": "Adding tracks to playlist...",
|
||||||
"addingProgress": "Adding tracks: {current} / {total}"
|
"addingProgress": "Adding tracks: {current} / {total}",
|
||||||
|
"partsCreated": "Split into {count} playlists (Qobuz 2000-track limit)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1525,6 +1525,7 @@
|
|||||||
"matchingPhase": "Buscando en el catalogo de Qobuz...",
|
"matchingPhase": "Buscando en el catalogo de Qobuz...",
|
||||||
"creatingPhase": "Creando playlist...",
|
"creatingPhase": "Creando playlist...",
|
||||||
"addingPhase": "Agregando tracks a la playlist...",
|
"addingPhase": "Agregando tracks a la playlist...",
|
||||||
"addingProgress": "Agregando tracks: {current} / {total}"
|
"addingProgress": "Agregando tracks: {current} / {total}",
|
||||||
|
"partsCreated": "Dividida en {count} playlists (limite de 2000 tracks en Qobuz)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1323,6 +1323,7 @@
|
|||||||
"matchingPhase": "Recherche dans le catalogue Qobuz...",
|
"matchingPhase": "Recherche dans le catalogue Qobuz...",
|
||||||
"creatingPhase": "Creation de la playlist...",
|
"creatingPhase": "Creation de la playlist...",
|
||||||
"addingPhase": "Ajout des titres a la playlist...",
|
"addingPhase": "Ajout des titres a la playlist...",
|
||||||
"addingProgress": "Ajout des titres : {current} / {total}"
|
"addingProgress": "Ajout des titres : {current} / {total}",
|
||||||
|
"partsCreated": "Divisee en {count} playlists (limite Qobuz : 2000 titres)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user