feat(link-resolver): cross-platform music link resolution via Odesli
Ctrl+L now accepts URLs from Spotify, Apple Music, Tidal, Deezer, and song.link/album.link in addition to Qobuz. Non-Qobuz track/album URLs are resolved to their Qobuz equivalent via the existing Odesli API integration. Playlist URLs redirect to the Playlist Importer. - Add MusicResource/MusicProvider enums and detect_music_resource() - Add detect_resource() to each provider (spotify, apple, tidal, deezer) - Add v2_resolve_music_link command with Odesli-based cross-resolution - Upgrade LinkResolverModal with platform icon detection and playlist redirect - Update i18n keys in all 4 locales (en, es, de, fr)
This commit is contained in:
1 parent
45a1a6471b
commit
b78b67fa8c
13 files changed
+489
-18
No files matched your search
@@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { t } from '$lib/i18n';
|
||||
import { Link2 } from 'lucide-svelte';
|
||||
import Modal from './Modal.svelte';
|
||||
|
||||
interface ResolvedLink {
|
||||
@@ -8,28 +9,58 @@
|
||||
id: string | number;
|
||||
}
|
||||
|
||||
type MusicLinkResult =
|
||||
| { kind: 'Resolved'; link: ResolvedLink; provider: string | null }
|
||||
| { kind: 'PlaylistDetected'; provider: string }
|
||||
| { kind: 'NotOnQobuz'; provider: string | null };
|
||||
|
||||
type Platform = 'qobuz' | 'spotify' | 'apple' | 'tidal' | 'deezer' | 'songlink' | null;
|
||||
|
||||
interface Props {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
onResolve: (resolved: ResolvedLink) => void;
|
||||
onOpenImporter?: () => void;
|
||||
}
|
||||
|
||||
let { isOpen, onClose, onResolve }: Props = $props();
|
||||
let { isOpen, onClose, onResolve, onOpenImporter }: Props = $props();
|
||||
|
||||
let url = $state('');
|
||||
let error = $state('');
|
||||
let playlistInfo = $state(false);
|
||||
let resolving = $state(false);
|
||||
let inputEl = $state<HTMLInputElement | undefined>(undefined);
|
||||
|
||||
const platformConfig: Record<string, { logo: string; alt: string; color: string }> = {
|
||||
qobuz: { logo: '/qobuz-logo.svg', alt: 'Qobuz', color: '#0170ef' },
|
||||
spotify: { logo: '/spotify-logo.svg', alt: 'Spotify', color: '#1DB954' },
|
||||
apple: { logo: '/apple-music-logo.svg', alt: 'Apple Music', color: '#fa233b' },
|
||||
tidal: { logo: '/tidal-tidal.svg', alt: 'Tidal', color: '#ffffff' },
|
||||
deezer: { logo: '/deezer-logo.svg', alt: 'Deezer', color: '#00c7f2' },
|
||||
};
|
||||
|
||||
function detectPlatform(value: string): Platform {
|
||||
const lower = value.trim().toLowerCase();
|
||||
if (!lower) return null;
|
||||
if (lower.includes('qobuz.com/') || lower.startsWith('qobuzapp://')) return 'qobuz';
|
||||
if (lower.includes('spotify.com/') || lower.startsWith('spotify:')) return 'spotify';
|
||||
if (lower.includes('music.apple.com/')) return 'apple';
|
||||
if (lower.includes('tidal.com/')) return 'tidal';
|
||||
if (lower.includes('deezer.com/')) return 'deezer';
|
||||
if (lower.includes('song.link/') || lower.includes('album.link/') || lower.includes('odesli.co/')) return 'songlink';
|
||||
return null;
|
||||
}
|
||||
|
||||
let detectedPlatform = $derived(detectPlatform(url));
|
||||
|
||||
$effect(() => {
|
||||
if (isOpen && inputEl) {
|
||||
// Focus the input when modal opens
|
||||
setTimeout(() => inputEl?.focus(), 100);
|
||||
}
|
||||
if (!isOpen) {
|
||||
// Reset state when modal closes
|
||||
url = '';
|
||||
error = '';
|
||||
playlistInfo = false;
|
||||
resolving = false;
|
||||
}
|
||||
});
|
||||
@@ -39,12 +70,24 @@
|
||||
if (!trimmed || resolving) return;
|
||||
|
||||
error = '';
|
||||
playlistInfo = false;
|
||||
resolving = true;
|
||||
|
||||
try {
|
||||
const resolved = await invoke<ResolvedLink>('v2_resolve_qobuz_link', { url: trimmed });
|
||||
onResolve(resolved);
|
||||
onClose();
|
||||
const result = await invoke<MusicLinkResult>('v2_resolve_music_link', { url: trimmed });
|
||||
|
||||
switch (result.kind) {
|
||||
case 'Resolved':
|
||||
onResolve(result.link);
|
||||
onClose();
|
||||
break;
|
||||
case 'PlaylistDetected':
|
||||
playlistInfo = true;
|
||||
break;
|
||||
case 'NotOnQobuz':
|
||||
error = $t('linkResolver.notOnQobuz');
|
||||
break;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Link resolve error:', err);
|
||||
error = $t('linkResolver.invalidLink');
|
||||
@@ -53,6 +96,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
function handleOpenImporter() {
|
||||
onClose();
|
||||
onOpenImporter?.();
|
||||
}
|
||||
|
||||
function handleKeydown(event: KeyboardEvent) {
|
||||
if (event.key === 'Enter') {
|
||||
event.preventDefault();
|
||||
@@ -64,6 +112,19 @@
|
||||
<Modal {isOpen} {onClose} title={$t('linkResolver.title')} maxWidth="520px">
|
||||
<div class="link-resolver-body">
|
||||
<div class="input-row">
|
||||
{#if detectedPlatform}
|
||||
<div class="platform-icon">
|
||||
{#if detectedPlatform === 'songlink'}
|
||||
<Link2 size={20} color="var(--text-secondary)" />
|
||||
{:else if platformConfig[detectedPlatform]}
|
||||
<img
|
||||
src={platformConfig[detectedPlatform].logo}
|
||||
alt={platformConfig[detectedPlatform].alt}
|
||||
class="platform-logo"
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
<input
|
||||
bind:this={inputEl}
|
||||
bind:value={url}
|
||||
@@ -83,6 +144,16 @@
|
||||
{resolving ? $t('linkResolver.resolving') : $t('linkResolver.go')}
|
||||
</button>
|
||||
</div>
|
||||
{#if playlistInfo}
|
||||
<div class="playlist-banner">
|
||||
<p class="playlist-text">{$t('linkResolver.playlistDetected')}</p>
|
||||
{#if onOpenImporter}
|
||||
<button class="importer-btn" onclick={handleOpenImporter}>
|
||||
{$t('linkResolver.openPlaylistImporter')}
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
{#if error}
|
||||
<p class="error-text">{error}</p>
|
||||
{/if}
|
||||
@@ -99,6 +170,22 @@
|
||||
.input-row {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.platform-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.platform-logo {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
.link-input {
|
||||
@@ -147,6 +234,39 @@
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.playlist-banner {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
padding: 12px;
|
||||
background: var(--bg-secondary);
|
||||
border: 1px solid var(--bg-tertiary);
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.playlist-text {
|
||||
color: var(--text-secondary);
|
||||
font-size: 13px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.importer-btn {
|
||||
align-self: flex-start;
|
||||
padding: 8px 16px;
|
||||
background: var(--accent-primary);
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: opacity 150ms ease;
|
||||
}
|
||||
|
||||
.importer-btn:hover {
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.error-text {
|
||||
color: var(--error, #ef4444);
|
||||
font-size: 13px;
|
||||
|
||||
@@ -1507,11 +1507,14 @@
|
||||
"emptyFolder": "Leerer Ordner"
|
||||
},
|
||||
"linkResolver": {
|
||||
"title": "Qobuz-Link oeffnen",
|
||||
"placeholder": "Einen Qobuz-Link einfuegen (Album, Titel, Kuenstler, Playlist)...",
|
||||
"title": "Musik-Link oeffnen",
|
||||
"placeholder": "Link von Qobuz, Spotify, Apple Music, Tidal, Deezer oder song.link einfuegen...",
|
||||
"go": "Los",
|
||||
"resolving": "Wird aufgeloest...",
|
||||
"invalidLink": "Ungueltiger oder nicht unterstuetzter Qobuz-Link."
|
||||
"invalidLink": "Ungueltiger oder nicht unterstuetzter Musik-Link.",
|
||||
"notOnQobuz": "Dieser Inhalt ist auf Qobuz nicht verfuegbar.",
|
||||
"playlistDetected": "Dies ist eine Playlist. Verwende den Playlist-Importer fuer Playlists.",
|
||||
"openPlaylistImporter": "Playlist-Importer oeffnen"
|
||||
},
|
||||
"yourMixes": {
|
||||
"title": "DailyQ",
|
||||
|
||||
@@ -1746,10 +1746,13 @@
|
||||
"emptyFolder": "Empty folder"
|
||||
},
|
||||
"linkResolver": {
|
||||
"title": "Open Qobuz Link",
|
||||
"placeholder": "Paste a Qobuz link (album, track, artist, playlist)...",
|
||||
"title": "Open Music Link",
|
||||
"placeholder": "Paste a link from Qobuz, Spotify, Apple Music, Tidal, Deezer, or song.link...",
|
||||
"go": "Go",
|
||||
"resolving": "Resolving...",
|
||||
"invalidLink": "Invalid or unsupported Qobuz link."
|
||||
"invalidLink": "Invalid or unsupported music link.",
|
||||
"notOnQobuz": "This content is not available on Qobuz.",
|
||||
"playlistDetected": "This is a playlist. Use the Playlist Importer for playlists.",
|
||||
"openPlaylistImporter": "Open Playlist Importer"
|
||||
}
|
||||
}
|
||||
@@ -1746,10 +1746,13 @@
|
||||
"emptyFolder": "Carpeta vacía"
|
||||
},
|
||||
"linkResolver": {
|
||||
"title": "Abrir enlace de Qobuz",
|
||||
"placeholder": "Pega un enlace de Qobuz (album, track, artista, playlist)...",
|
||||
"title": "Abrir enlace de música",
|
||||
"placeholder": "Pega un enlace de Qobuz, Spotify, Apple Music, Tidal, Deezer o song.link...",
|
||||
"go": "Ir",
|
||||
"resolving": "Resolviendo...",
|
||||
"invalidLink": "Enlace de Qobuz invalido o no soportado."
|
||||
"invalidLink": "Enlace inválido o no soportado.",
|
||||
"notOnQobuz": "Este contenido no está disponible en Qobuz.",
|
||||
"playlistDetected": "Esto es una playlist. Usa el Importador de Playlists.",
|
||||
"openPlaylistImporter": "Abrir Importador de Playlists"
|
||||
}
|
||||
}
|
||||
@@ -1507,11 +1507,14 @@
|
||||
"emptyFolder": "Dossier vide"
|
||||
},
|
||||
"linkResolver": {
|
||||
"title": "Ouvrir un lien Qobuz",
|
||||
"placeholder": "Collez un lien Qobuz (album, piste, artiste, playlist)...",
|
||||
"title": "Ouvrir un lien musical",
|
||||
"placeholder": "Collez un lien de Qobuz, Spotify, Apple Music, Tidal, Deezer ou song.link...",
|
||||
"go": "Aller",
|
||||
"resolving": "Resolution...",
|
||||
"invalidLink": "Lien Qobuz invalide ou non pris en charge."
|
||||
"invalidLink": "Lien musical invalide ou non pris en charge.",
|
||||
"notOnQobuz": "Ce contenu n'est pas disponible sur Qobuz.",
|
||||
"playlistDetected": "C'est une playlist. Utilisez l'importateur de playlists.",
|
||||
"openPlaylistImporter": "Ouvrir l'importateur de playlists"
|
||||
},
|
||||
"yourMixes": {
|
||||
"title": "DailyQ",
|
||||
|
||||
Reference in new issue
Block a user