feat(track-info): add TrackInfoModal and context menu option
Phase 2 of track-info feature: - Add performers, composer, copyright fields to Track model - Add get_track_info command with parsed performers - Create TrackInfoModal component to display track details and credits - Add "Track info" option to TrackMenu context menu cc
This commit is contained in:
1 parent
eccadb6af9
commit
e767809857
6 files changed
+376
-3
No files matched your search
@@ -140,6 +140,12 @@ pub struct Track {
|
|||||||
pub parental_warning: bool,
|
pub parental_warning: bool,
|
||||||
/// Playlist-specific: ID within the playlist (for removal)
|
/// Playlist-specific: ID within the playlist (for removal)
|
||||||
pub playlist_track_id: Option<u64>,
|
pub playlist_track_id: Option<u64>,
|
||||||
|
/// Performers/credits string from Qobuz (format: "Name, Role - Name, Role")
|
||||||
|
pub performers: Option<String>,
|
||||||
|
/// Composer information
|
||||||
|
pub composer: Option<Artist>,
|
||||||
|
/// Copyright information
|
||||||
|
pub copyright: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
|||||||
@@ -1,10 +1,19 @@
|
|||||||
//! Playlist-related Tauri commands
|
//! Playlist-related Tauri commands
|
||||||
|
|
||||||
|
use serde::Serialize;
|
||||||
use tauri::State;
|
use tauri::State;
|
||||||
|
|
||||||
use crate::api::models::{Playlist, SearchResultsPage};
|
use crate::api::models::{Playlist, SearchResultsPage, Track};
|
||||||
|
use crate::api::performers::{parse_performers, Performer};
|
||||||
use crate::AppState;
|
use crate::AppState;
|
||||||
|
|
||||||
|
/// Track info with parsed performers for display
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub struct TrackInfo {
|
||||||
|
pub track: Track,
|
||||||
|
pub performers: Vec<Performer>,
|
||||||
|
}
|
||||||
|
|
||||||
/// Get user's playlists
|
/// Get user's playlists
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn get_user_playlists(
|
pub async fn get_user_playlists(
|
||||||
@@ -218,3 +227,27 @@ pub async fn subscribe_playlist(
|
|||||||
..new_playlist
|
..new_playlist
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get track info with parsed performers/credits
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn get_track_info(
|
||||||
|
track_id: u64,
|
||||||
|
state: State<'_, AppState>,
|
||||||
|
) -> Result<TrackInfo, String> {
|
||||||
|
log::info!("Command: get_track_info {}", track_id);
|
||||||
|
|
||||||
|
let client = state.client.lock().await;
|
||||||
|
let track = client
|
||||||
|
.get_track(track_id)
|
||||||
|
.await
|
||||||
|
.map_err(|e| format!("Failed to get track: {}", e))?;
|
||||||
|
|
||||||
|
// Parse the performers string if available
|
||||||
|
let performers = track
|
||||||
|
.performers
|
||||||
|
.as_ref()
|
||||||
|
.map(|p| parse_performers(p))
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
Ok(TrackInfo { track, performers })
|
||||||
|
}
|
||||||
@@ -484,6 +484,7 @@ pub fn run() {
|
|||||||
commands::get_tracks_by_ids,
|
commands::get_tracks_by_ids,
|
||||||
commands::get_current_user_id,
|
commands::get_current_user_id,
|
||||||
commands::subscribe_playlist,
|
commands::subscribe_playlist,
|
||||||
|
commands::get_track_info,
|
||||||
// Playlist import commands
|
// Playlist import commands
|
||||||
commands::playlist_import_preview,
|
commands::playlist_import_preview,
|
||||||
commands::playlist_import_execute,
|
commands::playlist_import_execute,
|
||||||
|
|||||||
@@ -0,0 +1,309 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { invoke } from '@tauri-apps/api/core';
|
||||||
|
import Modal from './Modal.svelte';
|
||||||
|
import { Clock, Disc3, Music2, User, Users, Copyright, Loader2 } from 'lucide-svelte';
|
||||||
|
import type { TrackInfo, Performer } from '$lib/types';
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
isOpen: boolean;
|
||||||
|
trackId: number | null;
|
||||||
|
onClose: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
let { isOpen, trackId, onClose }: Props = $props();
|
||||||
|
|
||||||
|
let loading = $state(false);
|
||||||
|
let error = $state<string | null>(null);
|
||||||
|
let trackInfo = $state<TrackInfo | null>(null);
|
||||||
|
|
||||||
|
// Format duration from seconds to MM:SS
|
||||||
|
function formatDuration(seconds: number): string {
|
||||||
|
const mins = Math.floor(seconds / 60);
|
||||||
|
const secs = seconds % 60;
|
||||||
|
return `${mins}:${secs.toString().padStart(2, '0')}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Format sample rate for display
|
||||||
|
function formatSampleRate(rate?: number): string {
|
||||||
|
if (!rate) return '';
|
||||||
|
if (rate >= 1000) {
|
||||||
|
return `${(rate / 1000).toFixed(1)}kHz`.replace('.0kHz', 'kHz');
|
||||||
|
}
|
||||||
|
return `${rate}Hz`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Format quality string
|
||||||
|
function formatQuality(track: TrackInfo['track']): string {
|
||||||
|
const parts: string[] = [];
|
||||||
|
if (track.maximum_bit_depth) {
|
||||||
|
parts.push(`${track.maximum_bit_depth}-bit`);
|
||||||
|
}
|
||||||
|
if (track.maximum_sampling_rate) {
|
||||||
|
parts.push(formatSampleRate(track.maximum_sampling_rate * 1000));
|
||||||
|
}
|
||||||
|
if (parts.length === 0) {
|
||||||
|
return track.hires_streamable ? 'Hi-Res' : 'Lossless';
|
||||||
|
}
|
||||||
|
return parts.join(' / ');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load track info when modal opens
|
||||||
|
$effect(() => {
|
||||||
|
if (isOpen && trackId) {
|
||||||
|
loadTrackInfo(trackId);
|
||||||
|
} else {
|
||||||
|
trackInfo = null;
|
||||||
|
error = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
async function loadTrackInfo(id: number) {
|
||||||
|
loading = true;
|
||||||
|
error = null;
|
||||||
|
try {
|
||||||
|
trackInfo = await invoke<TrackInfo>('get_track_info', { trackId: id });
|
||||||
|
} catch (e) {
|
||||||
|
error = e instanceof Error ? e.message : String(e);
|
||||||
|
trackInfo = null;
|
||||||
|
} finally {
|
||||||
|
loading = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Modal {isOpen} {onClose} title="Track Info" maxWidth="520px">
|
||||||
|
{#snippet children()}
|
||||||
|
{#if loading}
|
||||||
|
<div class="loading-state">
|
||||||
|
<Loader2 size={32} class="spinner" />
|
||||||
|
<span>Loading track info...</span>
|
||||||
|
</div>
|
||||||
|
{:else if error}
|
||||||
|
<div class="error-state">
|
||||||
|
<p>Failed to load track info</p>
|
||||||
|
<span class="error-message">{error}</span>
|
||||||
|
</div>
|
||||||
|
{:else if trackInfo}
|
||||||
|
<div class="track-info">
|
||||||
|
<!-- Track Details Section -->
|
||||||
|
<section class="info-section">
|
||||||
|
<div class="info-row">
|
||||||
|
<Music2 size={16} class="info-icon" />
|
||||||
|
<span class="info-label">Title</span>
|
||||||
|
<span class="info-value">{trackInfo.track.title}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{#if trackInfo.track.performer?.name}
|
||||||
|
<div class="info-row">
|
||||||
|
<User size={16} class="info-icon" />
|
||||||
|
<span class="info-label">Artist</span>
|
||||||
|
<span class="info-value">{trackInfo.track.performer.name}</span>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if trackInfo.track.album?.title}
|
||||||
|
<div class="info-row">
|
||||||
|
<Disc3 size={16} class="info-icon" />
|
||||||
|
<span class="info-label">Album</span>
|
||||||
|
<span class="info-value">{trackInfo.track.album.title}</span>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<div class="info-row">
|
||||||
|
<Clock size={16} class="info-icon" />
|
||||||
|
<span class="info-label">Duration</span>
|
||||||
|
<span class="info-value">{formatDuration(trackInfo.track.duration)}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="info-row">
|
||||||
|
<span class="info-label quality-label">Quality</span>
|
||||||
|
<span class="info-value quality-value">{formatQuality(trackInfo.track)}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{#if trackInfo.track.isrc}
|
||||||
|
<div class="info-row">
|
||||||
|
<span class="info-label">ISRC</span>
|
||||||
|
<span class="info-value mono">{trackInfo.track.isrc}</span>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if trackInfo.track.composer?.name}
|
||||||
|
<div class="info-row">
|
||||||
|
<span class="info-label">Composer</span>
|
||||||
|
<span class="info-value">{trackInfo.track.composer.name}</span>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- Credits Section -->
|
||||||
|
{#if trackInfo.performers.length > 0}
|
||||||
|
<section class="credits-section">
|
||||||
|
<h3 class="section-title">
|
||||||
|
<Users size={16} />
|
||||||
|
Credits
|
||||||
|
</h3>
|
||||||
|
<div class="performers-list">
|
||||||
|
{#each trackInfo.performers as performer}
|
||||||
|
<div class="performer">
|
||||||
|
<span class="performer-name">{performer.name}</span>
|
||||||
|
{#if performer.roles.length > 0}
|
||||||
|
<span class="performer-roles">{performer.roles.join(', ')}</span>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<!-- Copyright Section -->
|
||||||
|
{#if trackInfo.track.copyright}
|
||||||
|
<section class="copyright-section">
|
||||||
|
<div class="copyright">
|
||||||
|
<Copyright size={14} />
|
||||||
|
<span>{trackInfo.track.copyright}</span>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
{/snippet}
|
||||||
|
</Modal>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.loading-state {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 12px;
|
||||||
|
padding: 40px 20px;
|
||||||
|
color: var(--text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-state :global(.spinner) {
|
||||||
|
animation: spin 1s linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes spin {
|
||||||
|
from { transform: rotate(0deg); }
|
||||||
|
to { transform: rotate(360deg); }
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-state {
|
||||||
|
text-align: center;
|
||||||
|
padding: 40px 20px;
|
||||||
|
color: var(--text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-message {
|
||||||
|
display: block;
|
||||||
|
margin-top: 8px;
|
||||||
|
font-size: 13px;
|
||||||
|
color: var(--danger);
|
||||||
|
}
|
||||||
|
|
||||||
|
.track-info {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-section {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-row {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 20px 80px 1fr;
|
||||||
|
gap: 8px;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-row :global(.info-icon) {
|
||||||
|
color: var(--text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-label {
|
||||||
|
font-size: 13px;
|
||||||
|
color: var(--text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.quality-label {
|
||||||
|
grid-column: 1 / 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-value {
|
||||||
|
font-size: 14px;
|
||||||
|
color: var(--text-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-value.mono {
|
||||||
|
font-family: monospace;
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.quality-value {
|
||||||
|
background: var(--bg-tertiary);
|
||||||
|
padding: 2px 8px;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 12px;
|
||||||
|
width: fit-content;
|
||||||
|
}
|
||||||
|
|
||||||
|
.credits-section {
|
||||||
|
border-top: 1px solid var(--bg-tertiary);
|
||||||
|
padding-top: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-title {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--text-primary);
|
||||||
|
margin: 0 0 12px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.performers-list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.performer {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 2px;
|
||||||
|
padding: 8px 12px;
|
||||||
|
background: var(--bg-secondary);
|
||||||
|
border-radius: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.performer-name {
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 500;
|
||||||
|
color: var(--text-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.performer-roles {
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.copyright-section {
|
||||||
|
border-top: 1px solid var(--bg-tertiary);
|
||||||
|
padding-top: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.copyright {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--text-muted);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -15,7 +15,8 @@
|
|||||||
Trash2,
|
Trash2,
|
||||||
CloudDownload,
|
CloudDownload,
|
||||||
RefreshCw,
|
RefreshCw,
|
||||||
Radio
|
Radio,
|
||||||
|
Info
|
||||||
} from 'lucide-svelte';
|
} from 'lucide-svelte';
|
||||||
import { shouldHidePlaylistFeatures } from '$lib/utils/offlineHelpers';
|
import { shouldHidePlaylistFeatures } from '$lib/utils/offlineHelpers';
|
||||||
import {
|
import {
|
||||||
@@ -39,6 +40,7 @@
|
|||||||
onShareSonglink?: () => void;
|
onShareSonglink?: () => void;
|
||||||
onGoToAlbum?: () => void;
|
onGoToAlbum?: () => void;
|
||||||
onGoToArtist?: () => void;
|
onGoToArtist?: () => void;
|
||||||
|
onShowInfo?: () => void;
|
||||||
onDownload?: () => void;
|
onDownload?: () => void;
|
||||||
isTrackDownloaded?: boolean;
|
isTrackDownloaded?: boolean;
|
||||||
onReDownload?: () => void;
|
onReDownload?: () => void;
|
||||||
@@ -59,6 +61,7 @@
|
|||||||
onShareSonglink,
|
onShareSonglink,
|
||||||
onGoToAlbum,
|
onGoToAlbum,
|
||||||
onGoToArtist,
|
onGoToArtist,
|
||||||
|
onShowInfo,
|
||||||
onDownload,
|
onDownload,
|
||||||
isTrackDownloaded = false,
|
isTrackDownloaded = false,
|
||||||
onReDownload,
|
onReDownload,
|
||||||
@@ -99,7 +102,7 @@
|
|||||||
const hasLibrary = $derived(!!(onAddFavorite || onAddToPlaylist || onRemoveFromPlaylist));
|
const hasLibrary = $derived(!!(onAddFavorite || onAddToPlaylist || onRemoveFromPlaylist));
|
||||||
const hasShare = $derived(!!(onShareQobuz || onShareSonglink));
|
const hasShare = $derived(!!(onShareQobuz || onShareSonglink));
|
||||||
const hasDownload = $derived(!!onDownload || isTrackDownloaded);
|
const hasDownload = $derived(!!onDownload || isTrackDownloaded);
|
||||||
const hasNav = $derived(!!(onGoToAlbum || onGoToArtist));
|
const hasNav = $derived(!!(onGoToAlbum || onGoToArtist || onShowInfo));
|
||||||
const hasMenu = $derived(hasPlayback || hasLibrary || hasShare || hasDownload || hasNav);
|
const hasMenu = $derived(hasPlayback || hasLibrary || hasShare || hasDownload || hasNav);
|
||||||
|
|
||||||
function closeMenu(options?: { clearActive?: boolean }) {
|
function closeMenu(options?: { clearActive?: boolean }) {
|
||||||
@@ -516,6 +519,12 @@
|
|||||||
<span>Go to artist</span>
|
<span>Go to artist</span>
|
||||||
</button>
|
</button>
|
||||||
{/if}
|
{/if}
|
||||||
|
{#if onShowInfo}
|
||||||
|
<button class="menu-item" onclick={() => handleAction(onShowInfo)}>
|
||||||
|
<Info size={14} />
|
||||||
|
<span>Track info</span>
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -27,6 +27,21 @@ export interface QobuzTrack {
|
|||||||
maximum_bit_depth?: number;
|
maximum_bit_depth?: number;
|
||||||
maximum_sampling_rate?: number;
|
maximum_sampling_rate?: number;
|
||||||
isrc?: string;
|
isrc?: string;
|
||||||
|
performers?: string;
|
||||||
|
composer?: { id?: number; name: string };
|
||||||
|
copyright?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parsed performer from performers string
|
||||||
|
export interface Performer {
|
||||||
|
name: string;
|
||||||
|
roles: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Track info response with parsed performers
|
||||||
|
export interface TrackInfo {
|
||||||
|
track: QobuzTrack;
|
||||||
|
performers: Performer[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface QobuzAlbum {
|
export interface QobuzAlbum {
|
||||||
|
|||||||
Reference in new issue
Block a user