Fix audiobook chapter extraction for M4B/M4A formats (#2976)
* Fix audiobook chapter extraction for M4B/M4A formats * Add unit tests for ffprobe service, chapter backfill, and audiobook rescan * Add collapsible chapter list to audiobook details section
This commit is contained in:
@@ -97,6 +97,14 @@ export interface BookFileProgress {
|
||||
progressPercent: number;
|
||||
}
|
||||
|
||||
export interface AudiobookChapterInfo {
|
||||
index?: number;
|
||||
title?: string;
|
||||
startTimeMs?: number;
|
||||
endTimeMs?: number;
|
||||
durationMs?: number;
|
||||
}
|
||||
|
||||
export interface AudiobookMetadata {
|
||||
narrator?: string;
|
||||
abridged?: boolean | null;
|
||||
@@ -106,6 +114,7 @@ export interface AudiobookMetadata {
|
||||
channels?: number;
|
||||
codec?: string;
|
||||
chapterCount?: number;
|
||||
chapters?: AudiobookChapterInfo[];
|
||||
narratorLocked?: boolean;
|
||||
abridgedLocked?: boolean;
|
||||
}
|
||||
|
||||
+21
@@ -978,6 +978,27 @@
|
||||
</span>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (audio.chapters?.length) {
|
||||
<div class="audiobook-chapters-section">
|
||||
<div class="audiobook-chapters-header clickable" (click)="isChapterListExpanded = !isChapterListExpanded">
|
||||
<span class="audiobook-chapters-toggle-label">
|
||||
<i class="pi pi-list"></i>
|
||||
{{ t('audiobookChapterList') }}
|
||||
</span>
|
||||
<i class="pi section-toggle-icon" [ngClass]="isChapterListExpanded ? 'pi-chevron-up' : 'pi-chevron-down'"></i>
|
||||
</div>
|
||||
<div class="audiobook-chapters-list" [ngClass]="{'collapsed': !isChapterListExpanded}">
|
||||
@for (chapter of audio.chapters; track chapter.index) {
|
||||
<div class="audiobook-chapter-row">
|
||||
<span class="audiobook-chapter-index">{{ chapter.index! + 1 }}</span>
|
||||
<span class="audiobook-chapter-title">{{ chapter.title }}</span>
|
||||
<span class="audiobook-chapter-duration">{{ formatDurationMs(chapter.durationMs!) }}</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
+86
-1
@@ -1019,7 +1019,7 @@
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
max-height: 500px;
|
||||
max-height: 2000px;
|
||||
overflow: hidden;
|
||||
transition: max-height 0.3s ease, padding 0.3s ease, opacity 0.3s ease;
|
||||
opacity: 1;
|
||||
@@ -1099,3 +1099,88 @@
|
||||
color: white;
|
||||
}
|
||||
}
|
||||
|
||||
.audiobook-chapters-section {
|
||||
border-top: 1px solid var(--border-color);
|
||||
padding-top: 0.75rem;
|
||||
}
|
||||
|
||||
.audiobook-chapters-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
padding: 0.375rem 0;
|
||||
|
||||
&:hover .audiobook-chapters-toggle-label {
|
||||
color: var(--primary-hover-color);
|
||||
}
|
||||
}
|
||||
|
||||
.audiobook-chapters-toggle-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
font-size: 0.85rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-color);
|
||||
transition: color 0.2s ease;
|
||||
|
||||
i {
|
||||
font-size: 0.9rem;
|
||||
color: var(--primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.audiobook-chapters-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0;
|
||||
max-height: 500px;
|
||||
overflow-y: auto;
|
||||
transition: max-height 0.3s ease, opacity 0.3s ease;
|
||||
opacity: 1;
|
||||
|
||||
&.collapsed {
|
||||
max-height: 0;
|
||||
opacity: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
}
|
||||
|
||||
.audiobook-chapter-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
padding: 0.5rem 0.25rem;
|
||||
border-bottom: 1px solid var(--surface-border);
|
||||
font-size: 0.875rem;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
}
|
||||
|
||||
.audiobook-chapter-index {
|
||||
flex: 0 0 1.75rem;
|
||||
text-align: center;
|
||||
font-weight: 600;
|
||||
color: var(--text-color-secondary);
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
.audiobook-chapter-title {
|
||||
flex: 1;
|
||||
color: var(--text-color);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.audiobook-chapter-duration {
|
||||
flex-shrink: 0;
|
||||
color: var(--text-color-secondary);
|
||||
font-size: 0.8rem;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
+13
@@ -78,6 +78,7 @@ export class MetadataViewerComponent implements OnInit, OnChanges, AfterViewChec
|
||||
isOverflowing = false;
|
||||
isComicSectionExpanded = true;
|
||||
isAudiobookSectionExpanded = true;
|
||||
isChapterListExpanded = false;
|
||||
showFilePath = false;
|
||||
isAutoFetching = false;
|
||||
private metadataCenterViewMode: 'route' | 'dialog' = 'route';
|
||||
@@ -1372,6 +1373,18 @@ export class MetadataViewerComponent implements OnInit, OnChanges, AfterViewChec
|
||||
return `${minutes}m`;
|
||||
}
|
||||
|
||||
formatDurationMs(ms: number): string {
|
||||
if (!ms) return '-';
|
||||
const totalSeconds = Math.floor(ms / 1000);
|
||||
const hours = Math.floor(totalSeconds / 3600);
|
||||
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
||||
const seconds = totalSeconds % 60;
|
||||
if (hours > 0) {
|
||||
return `${hours}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
|
||||
}
|
||||
return `${minutes}:${seconds.toString().padStart(2, '0')}`;
|
||||
}
|
||||
|
||||
formatSampleRate(sampleRate: number): string {
|
||||
if (!sampleRate) return '-';
|
||||
return `${(sampleRate / 1000).toFixed(1)} kHz`;
|
||||
|
||||
@@ -388,9 +388,12 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
|
||||
private updateMediaSessionMetadata(): void {
|
||||
if (!('mediaSession' in navigator)) return;
|
||||
|
||||
const chapters = this.audiobookInfo.chapters;
|
||||
const chapterTitle = chapters && chapters.length > 1 ? this.getCurrentChapter()?.title : null;
|
||||
|
||||
const title = this.audiobookInfo.folderBased
|
||||
? this.currentTrack?.title
|
||||
: this.getCurrentChapter()?.title || this.audiobookInfo.title;
|
||||
: chapterTitle || this.audiobookInfo.title;
|
||||
|
||||
navigator.mediaSession.metadata = new MediaMetadata({
|
||||
title: title || this.t.translate('readerAudiobook.untitled'),
|
||||
|
||||
Reference in New Issue
Block a user