T-012: Bibliothek komplett — Cover-Raster, Suche (Titel/Autor/Sprecher), Sortierung (5 Optionen), Status-Chips (lokal/fertig), Fortschrittsbalken
This commit is contained in:
@ -22,7 +22,7 @@ Abnahme M0: Ein gekauftes Buch läuft lokal mit Kapiteln.
|
|||||||
|----|-------|--------|
|
|----|-------|--------|
|
||||||
| T-010 | Tauri-Projekt aufsetzen (Rust-Backend, Svelte-Frontend) | fertig |
|
| T-010 | Tauri-Projekt aufsetzen (Rust-Backend, Svelte-Frontend) | fertig |
|
||||||
| T-011 | Login-Flow in der App (Auth-Datei sicher unter ~/.config speichern) | fertig |
|
| T-011 | Login-Flow in der App (Auth-Datei sicher unter ~/.config speichern) | fertig |
|
||||||
| T-012 | Bibliotheksansicht mit Covern, Suche, Sortierung | offen |
|
| T-012 | Bibliotheksansicht mit Covern, Suche, Sortierung | fertig |
|
||||||
| T-013 | Download-Manager (Queue, Fortschritt, Abbruch) | offen |
|
| T-013 | Download-Manager (Queue, Fortschritt, Abbruch) | offen |
|
||||||
| T-014 | Entschlüsseln nach dem Download, Ablage als .m4b mit Kapiteln und Cover | offen |
|
| T-014 | Entschlüsseln nach dem Download, Ablage als .m4b mit Kapiteln und Cover | offen |
|
||||||
|
|
||||||
|
|||||||
@ -30,6 +30,11 @@ pub struct Book {
|
|||||||
pub percent_complete: f64,
|
pub percent_complete: f64,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub is_finished: bool,
|
pub is_finished: bool,
|
||||||
|
#[serde(default)]
|
||||||
|
pub date_added: String,
|
||||||
|
/// lokal vorhanden (book.m4b im Datenverzeichnis) — vom Backend gesetzt
|
||||||
|
#[serde(default, skip_deserializing)]
|
||||||
|
pub local: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Zugriffsschicht auf Audible — hinter diesem Trait kapseln, damit
|
/// Zugriffsschicht auf Audible — hinter diesem Trait kapseln, damit
|
||||||
@ -95,6 +100,18 @@ fn default_auth_dir() -> PathBuf {
|
|||||||
.unwrap_or_else(|| PathBuf::from("."))
|
.unwrap_or_else(|| PathBuf::from("."))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Lokale Bücherablage (spec): ~/.local/share/hoerwerk/books/<ASIN>/book.m4b,
|
||||||
|
/// per HOERWERK_BOOKS_DIR überschreibbar.
|
||||||
|
fn books_dir() -> PathBuf {
|
||||||
|
env::var("HOERWERK_BOOKS_DIR")
|
||||||
|
.map(PathBuf::from)
|
||||||
|
.unwrap_or_else(|_| {
|
||||||
|
home_dir()
|
||||||
|
.map(|h| h.join(".local/share/hoerwerk/books"))
|
||||||
|
.unwrap_or_else(|| PathBuf::from("books"))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
impl AudibleClient for CliAudibleClient {
|
impl AudibleClient for CliAudibleClient {
|
||||||
fn auth_status(&self) -> Result<AuthStatus, String> {
|
fn auth_status(&self) -> Result<AuthStatus, String> {
|
||||||
let mut profiles = Vec::new();
|
let mut profiles = Vec::new();
|
||||||
@ -167,7 +184,12 @@ impl AudibleClient for CliAudibleClient {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
let _ = fs::remove_file(&out);
|
let _ = fs::remove_file(&out);
|
||||||
parse_library(&content)
|
let mut books = parse_library(&content)?;
|
||||||
|
let dir = books_dir();
|
||||||
|
for b in &mut books {
|
||||||
|
b.local = dir.join(&b.asin).join("book.m4b").is_file();
|
||||||
|
}
|
||||||
|
Ok(books)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,12 +304,14 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_library_nimmt_pfelder() {
|
fn parse_library_nimmt_pfelder() {
|
||||||
let json = r#"[{"asin":"B08L4WJMDM","title":"Elfe 2"}]"#;
|
let json = r#"[{"asin":"B08L4WJMDM","title":"Elfe 2","date_added":"2020-01-01"}]"#;
|
||||||
let books = parse_library(json).unwrap();
|
let books = parse_library(json).unwrap();
|
||||||
assert_eq!(books.len(), 1);
|
assert_eq!(books.len(), 1);
|
||||||
assert_eq!(books[0].asin, "B08L4WJMDM");
|
assert_eq!(books[0].asin, "B08L4WJMDM");
|
||||||
assert_eq!(books[0].runtime_length_min, 0);
|
assert_eq!(books[0].runtime_length_min, 0);
|
||||||
assert!(!books[0].is_finished);
|
assert!(!books[0].is_finished);
|
||||||
|
assert!(!books[0].local);
|
||||||
|
assert_eq!(books[0].date_added, "2020-01-01");
|
||||||
assert!(parse_library("kaputt").is_err());
|
assert!(parse_library("kaputt").is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
105
src/App.svelte
105
src/App.svelte
@ -2,6 +2,7 @@
|
|||||||
import { authStatus, startLogin, getLibrary, type Book } from './lib/audible'
|
import { authStatus, startLogin, getLibrary, type Book } from './lib/audible'
|
||||||
|
|
||||||
type View = 'loading' | 'login' | 'library'
|
type View = 'loading' | 'login' | 'library'
|
||||||
|
type SortKey = 'added' | 'title' | 'author' | 'runtime' | 'percent'
|
||||||
|
|
||||||
let view = $state<View>('loading')
|
let view = $state<View>('loading')
|
||||||
let loadingMsg = $state<string>('Prüfe Anmeldung…')
|
let loadingMsg = $state<string>('Prüfe Anmeldung…')
|
||||||
@ -12,6 +13,40 @@
|
|||||||
let checking = $state(false)
|
let checking = $state(false)
|
||||||
let pollTimer = $state<ReturnType<typeof setInterval> | null>(null)
|
let pollTimer = $state<ReturnType<typeof setInterval> | null>(null)
|
||||||
|
|
||||||
|
let query = $state('')
|
||||||
|
let sortBy = $state<SortKey>('added')
|
||||||
|
|
||||||
|
const filtered = $derived.by(() => {
|
||||||
|
const q = query.trim().toLowerCase()
|
||||||
|
const hits = books.filter((b) => {
|
||||||
|
if (!q) return true
|
||||||
|
return (
|
||||||
|
b.title.toLowerCase().includes(q) ||
|
||||||
|
b.authors.toLowerCase().includes(q) ||
|
||||||
|
b.narrators.toLowerCase().includes(q)
|
||||||
|
)
|
||||||
|
})
|
||||||
|
const cmp: Record<SortKey, (a: Book, b: Book) => number> = {
|
||||||
|
added: (a, b) => b.date_added.localeCompare(a.date_added),
|
||||||
|
title: (a, b) => a.title.localeCompare(b.title, 'de'),
|
||||||
|
author: (a, b) => a.authors.localeCompare(b.authors, 'de') || a.title.localeCompare(b.title, 'de'),
|
||||||
|
runtime: (a, b) => b.runtime_length_min - a.runtime_length_min,
|
||||||
|
percent: (a, b) => b.percent_complete - a.percent_complete,
|
||||||
|
}
|
||||||
|
return [...hits].sort(cmp[sortBy])
|
||||||
|
})
|
||||||
|
|
||||||
|
function fmtRuntime(min: number): string {
|
||||||
|
if (!min || min <= 0) return ''
|
||||||
|
const h = Math.floor(min / 60)
|
||||||
|
const m = min % 60
|
||||||
|
return m ? `${h} h ${m} min` : `${h} h`
|
||||||
|
}
|
||||||
|
|
||||||
|
function hideBrokenCover(e: Event): void {
|
||||||
|
;(e.currentTarget as HTMLElement).style.display = 'none'
|
||||||
|
}
|
||||||
|
|
||||||
function clearPoll() {
|
function clearPoll() {
|
||||||
if (pollTimer !== null) {
|
if (pollTimer !== null) {
|
||||||
clearInterval(pollTimer)
|
clearInterval(pollTimer)
|
||||||
@ -108,29 +143,61 @@
|
|||||||
<main>
|
<main>
|
||||||
<header class="bar">
|
<header class="bar">
|
||||||
<h1>Hörwerk</h1>
|
<h1>Hörwerk</h1>
|
||||||
<span class="muted">{books.length} Titel</span>
|
<span class="muted small">{filtered.length} / {books.length} Titel</span>
|
||||||
<button class="ghost" onclick={() => checkAuth()} disabled={checking}>Aushang prüfen</button>
|
<input
|
||||||
|
class="search"
|
||||||
|
type="search"
|
||||||
|
placeholder="Suche Titel, Autor, Sprecher…"
|
||||||
|
bind:value={query}
|
||||||
|
/>
|
||||||
|
<select bind:value={sortBy}>
|
||||||
|
<option value="added">Zuletzt hinzugefügt</option>
|
||||||
|
<option value="title">Titel A–Z</option>
|
||||||
|
<option value="author">Autor</option>
|
||||||
|
<option value="runtime">Laufzeit</option>
|
||||||
|
<option value="percent">Fortschritt</option>
|
||||||
|
</select>
|
||||||
|
<button class="ghost" onclick={() => checkAuth()} disabled={checking}>
|
||||||
|
{checking ? '…' : 'Auffrischen'}
|
||||||
|
</button>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
{#if error}
|
{#if error}
|
||||||
<p class="error">{error}</p>
|
<div class="statespace">
|
||||||
|
<p class="error">{error}</p>
|
||||||
|
<button class="ghost" onclick={() => checkAuth()} disabled={checking}>Nochmal versuchen</button>
|
||||||
|
</div>
|
||||||
|
{:else if filtered.length === 0}
|
||||||
|
<div class="statespace">
|
||||||
|
<p class="muted">{query ? 'Kein Treffer für „' + query + '“' : 'Bibliothek leer.'}</p>
|
||||||
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
<table>
|
<div class="grid">
|
||||||
<thead>
|
{#each filtered as b (b.asin)}
|
||||||
<tr><th>Titel</th><th>Autor</th><th>Sprecher</th><th class="num">Min</th></tr>
|
<article class="card">
|
||||||
</thead>
|
<div class="cover">
|
||||||
<tbody>
|
<img
|
||||||
{#each books as b (b.asin)}
|
src={b.cover_url}
|
||||||
<tr>
|
alt="Cover von {b.title}"
|
||||||
<td>{b.title}</td>
|
loading="lazy"
|
||||||
<td>{b.authors}</td>
|
onerror={hideBrokenCover}
|
||||||
<td>{b.narrators}</td>
|
/>
|
||||||
<td class="num">{b.runtime_length_min}</td>
|
</div>
|
||||||
</tr>
|
<div class="meta">
|
||||||
{/each}
|
<div class="t">{b.title}</div>
|
||||||
</tbody>
|
<div class="muted small">{b.authors}</div>
|
||||||
</table>
|
<div class="chips">
|
||||||
<p class="muted footnote">Bibliotheksansicht minimal (T-012: Cover, Suche, Sortierung, Status).</p>
|
{#if b.local}<span class="chip ok" title="book.m4b liegt lokal vor">lokal</span>{/if}
|
||||||
|
{#if b.is_finished}<span class="chip done">fertig</span>{/if}
|
||||||
|
{#if b.runtime_length_min > 0}<span class="chip">{fmtRuntime(b.runtime_length_min)}</span>{/if}
|
||||||
|
</div>
|
||||||
|
{#if b.percent_complete > 0}
|
||||||
|
<div class="progress"><div class="fill" style={`width:${b.percent_complete}%`}></div></div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</main>
|
</main>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
154
src/app.css
154
src/app.css
@ -6,6 +6,7 @@
|
|||||||
--fg-muted: #9aa0a8;
|
--fg-muted: #9aa0a8;
|
||||||
--accent: #c2762f;
|
--accent: #c2762f;
|
||||||
--error: #d4645c;
|
--error: #d4645c;
|
||||||
|
--ok: #6fa06b;
|
||||||
--border: #2a2e36;
|
--border: #2a2e36;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,6 +31,7 @@ h1 {
|
|||||||
font-size: 1.4rem;
|
font-size: 1.4rem;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.muted {
|
.muted {
|
||||||
@ -37,19 +39,40 @@ h1 {
|
|||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.small {
|
||||||
|
font-size: 0.86rem;
|
||||||
|
}
|
||||||
|
|
||||||
.bar {
|
.bar {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 1rem;
|
gap: 0.7rem;
|
||||||
padding: 0.8rem 1.2rem;
|
padding: 0.8rem 1.2rem;
|
||||||
border-bottom: 1px solid var(--border);
|
border-bottom: 1px solid var(--border);
|
||||||
position: sticky;
|
position: sticky;
|
||||||
top: 0;
|
top: 0;
|
||||||
background: var(--bg);
|
background: var(--bg);
|
||||||
|
z-index: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.bar .muted {
|
.bar .muted {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input,
|
||||||
|
.bar input,
|
||||||
|
.bar select {
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 0.4rem 0.7rem;
|
||||||
|
background: var(--bg-card);
|
||||||
|
color: var(--fg);
|
||||||
|
font-size: 0.92rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bar input.search {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
|
min-width: 12rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
button {
|
button {
|
||||||
@ -59,6 +82,8 @@ button {
|
|||||||
background: var(--bg-card);
|
background: var(--bg-card);
|
||||||
color: var(--fg);
|
color: var(--fg);
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
font-size: 0.92rem;
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
button:hover:enabled {
|
button:hover:enabled {
|
||||||
@ -81,29 +106,6 @@ button.ghost {
|
|||||||
background: transparent;
|
background: transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
table {
|
|
||||||
width: calc(100% - 2.4rem);
|
|
||||||
margin: 1rem 1.2rem;
|
|
||||||
border-collapse: collapse;
|
|
||||||
}
|
|
||||||
|
|
||||||
th,
|
|
||||||
td {
|
|
||||||
border-bottom: 1px solid var(--border);
|
|
||||||
padding: 0.4rem 0.6rem;
|
|
||||||
text-align: left;
|
|
||||||
}
|
|
||||||
|
|
||||||
th.num,
|
|
||||||
td.num {
|
|
||||||
text-align: right;
|
|
||||||
}
|
|
||||||
|
|
||||||
.footnote {
|
|
||||||
margin: 0.6rem 1.2rem 2rem;
|
|
||||||
font-size: 0.85rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.info {
|
.info {
|
||||||
color: #7fa9d4;
|
color: #7fa9d4;
|
||||||
}
|
}
|
||||||
@ -111,3 +113,107 @@ td.num {
|
|||||||
.error {
|
.error {
|
||||||
color: var(--error);
|
color: var(--error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Bibliotheksraster */
|
||||||
|
|
||||||
|
.grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
|
||||||
|
gap: 1rem;
|
||||||
|
padding: 1rem 1.2rem 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card {
|
||||||
|
background: var(--bg-card);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 8px;
|
||||||
|
overflow: hidden;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cover {
|
||||||
|
aspect-ratio: 1 / 1;
|
||||||
|
width: 100%;
|
||||||
|
background: linear-gradient(160deg, #262a31, #1b1e24);
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cover img {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
.meta {
|
||||||
|
padding: 0.55rem 0.65rem 0.7rem;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.3rem;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.meta .t {
|
||||||
|
font-size: 0.92rem;
|
||||||
|
font-weight: 600;
|
||||||
|
line-height: 1.25;
|
||||||
|
display: -webkit-box;
|
||||||
|
-webkit-line-clamp: 3;
|
||||||
|
-webkit-box-orient: vertical;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chips {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.3rem;
|
||||||
|
margin-top: auto;
|
||||||
|
padding-top: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chip {
|
||||||
|
font-size: 0.72rem;
|
||||||
|
padding: 0.1rem 0.45rem;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 99px;
|
||||||
|
color: var(--fg-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.chip.ok {
|
||||||
|
color: var(--ok);
|
||||||
|
border-color: var(--ok);
|
||||||
|
}
|
||||||
|
|
||||||
|
.chip.done {
|
||||||
|
color: var(--accent);
|
||||||
|
border-color: var(--accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress {
|
||||||
|
height: 3px;
|
||||||
|
border-radius: 2px;
|
||||||
|
background: var(--border);
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress .fill {
|
||||||
|
height: 100%;
|
||||||
|
background: var(--accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.statespace {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.8rem;
|
||||||
|
align-items: flex-start;
|
||||||
|
padding: 2.4rem 1.2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
code {
|
||||||
|
background: var(--bg-card);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 4px;
|
||||||
|
padding: 0.05rem 0.3rem;
|
||||||
|
}
|
||||||
|
|||||||
@ -15,6 +15,8 @@ export interface Book {
|
|||||||
cover_url: string
|
cover_url: string
|
||||||
percent_complete: number
|
percent_complete: number
|
||||||
is_finished: boolean
|
is_finished: boolean
|
||||||
|
date_added: string
|
||||||
|
local: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export const authStatus = () => invoke<AuthStatus>('auth_status')
|
export const authStatus = () => invoke<AuthStatus>('auth_status')
|
||||||
|
|||||||
Reference in New Issue
Block a user