add audiobook chapters tab and move audiobook details inline (#3133)

This commit is contained in:
ACX
2026-02-28 23:12:31 -07:00
committed by GitHub
parent 6705ba4074
commit 7993bfe7a0
8 changed files with 335 additions and 298 deletions
@@ -1,5 +1,5 @@
<ng-container *transloco="let t; prefix: 'metadata.tabs'">
<p-tabs lazy class="custom-p-tabs" [value]="defaultTabValue" scrollable>
<p-tabs lazy class="custom-p-tabs" [value]="defaultTabValue" scrollable (valueChange)="onTabChange($event)">
<p-tablist>
@if (bookInSeries.length > 1) {
<p-tab value="series">
@@ -14,6 +14,11 @@
<i class="pi pi-images"></i> {{ t('covers') }}
</p-tab>
}
@if (hasAudiobookFormat()) {
<p-tab value="chapters">
<i class="pi pi-headphones"></i> {{ t('chapters') }}
</p-tab>
}
<p-tab value="files">
<i class="pi pi-folder-open"></i> {{ t('files') }}
</p-tab>
@@ -108,6 +113,90 @@
<app-book-reviews [bookId]="book.id"></app-book-reviews>
</ng-template>
</p-tabpanel>
<p-tabpanel value="chapters">
<ng-template #content>
<div class="chapters-tab-content">
@if (chaptersLoading) {
<div class="chapters-loading">
<i class="pi pi-spin pi-spinner"></i>
</div>
} @else if (audiobookInfo) {
<div class="chapters-tech-info">
<span class="tech-info-item">
<i class="pi pi-clock"></i> {{ formatDuration(audiobookInfo.durationMs) }}
</span>
@if (audiobookInfo.codec) {
<span class="tech-info-item">{{ audiobookInfo.codec.toUpperCase() }}</span>
}
@if (audiobookInfo.bitrate) {
<span class="tech-info-item">{{ audiobookInfo.bitrate }} kbps</span>
}
@if (audiobookInfo.sampleRate) {
<span class="tech-info-item">{{ formatSampleRate(audiobookInfo.sampleRate) }}</span>
}
@if (audiobookInfo.channels) {
<span class="tech-info-item">{{ getChannelLabel(audiobookInfo.channels) }}</span>
}
</div>
@if (audiobookInfo.folderBased && audiobookInfo.tracks?.length) {
<div class="chapters-table-wrapper">
<table class="chapters-table">
<thead>
<tr>
<th class="chapter-num">#</th>
<th class="chapter-title">{{ t('chapterTitle') }}</th>
<th class="chapter-file">{{ t('fileName') }}</th>
<th class="chapter-time">{{ t('startTime') }}</th>
<th class="chapter-time">{{ t('duration') }}</th>
</tr>
</thead>
<tbody>
@for (track of audiobookInfo.tracks; track track.index) {
<tr>
<td class="chapter-num">{{ track.index + 1 }}</td>
<td class="chapter-title">{{ track.title }}</td>
<td class="chapter-file">{{ track.fileName }}</td>
<td class="chapter-time">{{ formatDuration(track.cumulativeStartMs) }}</td>
<td class="chapter-time">{{ formatDuration(track.durationMs) }}</td>
</tr>
}
</tbody>
</table>
</div>
} @else if (audiobookInfo.chapters?.length) {
<div class="chapters-table-wrapper">
<table class="chapters-table">
<thead>
<tr>
<th class="chapter-num">#</th>
<th class="chapter-title">{{ t('chapterTitle') }}</th>
<th class="chapter-time">{{ t('startTime') }}</th>
<th class="chapter-time">{{ t('endTime') }}</th>
<th class="chapter-time">{{ t('duration') }}</th>
</tr>
</thead>
<tbody>
@for (chapter of audiobookInfo.chapters; track chapter.index) {
<tr>
<td class="chapter-num">{{ chapter.index + 1 }}</td>
<td class="chapter-title">{{ chapter.title }}</td>
<td class="chapter-time">{{ formatDuration(chapter.startTimeMs) }}</td>
<td class="chapter-time">{{ formatDuration(chapter.endTimeMs) }}</td>
<td class="chapter-time">{{ formatDuration(chapter.durationMs) }}</td>
</tr>
}
</tbody>
</table>
</div>
} @else {
<div class="chapters-empty">
<i class="pi pi-info-circle"></i> {{ t('noChapters') }}
</div>
}
}
</div>
</ng-template>
</p-tabpanel>
<p-tabpanel value="files">
<ng-template #content>
<div class="files-tab-content">
@@ -215,6 +215,144 @@
opacity: 0.8;
}
// Chapters tab styles
.chapters-tab-content {
padding: 0.5rem 0;
}
.chapters-loading {
display: flex;
justify-content: center;
padding: 2rem;
font-size: 1.5rem;
color: var(--text-color-secondary);
}
.chapters-tech-info {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.5rem;
margin-bottom: 1rem;
font-size: 0.8rem;
color: var(--text-color-secondary);
.tech-info-item {
display: flex;
align-items: center;
gap: 0.25rem;
padding: 0.25rem 0.625rem;
background: var(--highlight-background);
border: 1px solid var(--border-color);
border-radius: 9999px;
white-space: nowrap;
i {
font-size: 0.75rem;
color: var(--primary-color);
}
}
}
.chapters-table-wrapper {
overflow-x: auto;
border: 1px solid var(--border-color);
border-radius: 0.5rem;
}
.chapters-table {
width: 100%;
border-collapse: collapse;
font-size: 0.875rem;
th, td {
padding: 0.625rem 0.75rem;
text-align: left;
}
thead tr {
background: var(--highlight-background);
border-bottom: 1px solid var(--border-color);
}
th {
font-weight: 600;
color: var(--text-color-secondary);
font-size: 0.8rem;
text-transform: uppercase;
letter-spacing: 0.025em;
}
tbody tr {
border-bottom: 1px solid var(--border-color);
transition: background 0.15s ease;
&:last-child {
border-bottom: none;
}
&:hover {
background: var(--highlight-background);
}
}
td {
color: var(--text-color);
}
.chapter-num {
width: 3rem;
text-align: center;
color: var(--text-color-secondary);
}
.chapter-title {
min-width: 10rem;
}
.chapter-file {
min-width: 8rem;
color: var(--text-color-secondary);
font-size: 0.8rem;
}
.chapter-time {
width: 6rem;
font-family: monospace;
font-size: 0.8rem;
color: var(--text-color-secondary);
white-space: nowrap;
}
}
.chapters-empty {
display: flex;
align-items: center;
gap: 0.5rem;
padding: 2rem;
justify-content: center;
color: var(--text-color-secondary);
font-size: 0.9rem;
}
@media (max-width: 576px) {
.chapters-table {
font-size: 0.8rem;
th, td {
padding: 0.5rem;
}
.chapter-file {
display: none;
}
.chapter-time {
width: auto;
}
}
}
// Covers tab styles
.covers-tab-content {
padding: 1rem 0;
@@ -12,7 +12,9 @@ import {Tooltip} from 'primeng/tooltip';
import {Image} from 'primeng/image';
import {UrlHelperService} from '../../../../../../shared/service/url-helper.service';
import {BookMetadataManageService} from '../../../../../book/service/book-metadata-manage.service';
import {TranslocoDirective} from '@jsverse/transloco';
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
import {AudiobookService} from '../../../../../readers/audiobook-player/audiobook.service';
import {AudiobookInfo} from '../../../../../readers/audiobook-player/audiobook.model';
export interface ReadEvent {
bookId: number;
@@ -83,6 +85,11 @@ export class MetadataTabsComponent {
protected urlHelper = inject(UrlHelperService);
private bookMetadataManageService = inject(BookMetadataManageService);
private audiobookService = inject(AudiobookService);
private t = inject(TranslocoService);
audiobookInfo: AudiobookInfo | null = null;
chaptersLoading = false;
@Output() readBook = new EventEmitter<ReadEvent>();
@Output() downloadBook = new EventEmitter<DownloadEvent>();
@@ -192,4 +199,53 @@ export class MetadataTabsComponent {
supportsDualCovers(): boolean {
return this.bookMetadataManageService.supportsDualCovers(this.book);
}
onTabChange(value: string | number | undefined): void {
if (value === 'chapters') {
this.loadChapters();
}
}
hasAudiobookFormat(): boolean {
const allFiles = [this.book.primaryFile, ...(this.book.alternativeFormats || [])].filter(f => f?.bookType);
return allFiles.some(f => f!.bookType === 'AUDIOBOOK');
}
loadChapters(): void {
if (this.audiobookInfo || this.chaptersLoading) return;
this.chaptersLoading = true;
this.audiobookService.getAudiobookInfo(this.book.id).subscribe({
next: info => {
this.audiobookInfo = info;
this.chaptersLoading = false;
},
error: () => {
this.chaptersLoading = false;
}
});
}
formatDuration(ms: number): string {
const totalSeconds = Math.floor(ms / 1000);
const hours = Math.floor(totalSeconds / 3600);
const minutes = Math.floor((totalSeconds % 3600) / 60);
const seconds = totalSeconds % 60;
const pad = (n: number) => n.toString().padStart(2, '0');
return hours > 0 ? `${pad(hours)}:${pad(minutes)}:${pad(seconds)}` : `${pad(minutes)}:${pad(seconds)}`;
}
formatSampleRate(sampleRate: number): string {
return `${(sampleRate / 1000).toFixed(1)} kHz`;
}
getChannelLabel(channels: number): string {
switch (channels) {
case 1:
return this.t.translate('metadata.viewer.channelMono');
case 2:
return this.t.translate('metadata.viewer.channelStereo');
default:
return this.t.translate('metadata.viewer.channelMultiple', { count: channels });
}
}
}
@@ -560,6 +560,36 @@
}
</div>
@if (isAudiobook(book) && hasAudiobookMetadata(book)) {
@let audio = book.metadata!.audiobookMetadata!;
@if (book.metadata?.narrator) {
<div class="metadata-item">
<span class="metadata-key">{{ t('audiobookNarrator') }}</span>
<a class="metadata-value metadata-link" (click)="goToNarrator(book.metadata!.narrator!)">
{{ book.metadata?.narrator }}
</a>
</div>
}
@if (audio.durationSeconds) {
<div class="metadata-item">
<span class="metadata-key">{{ t('audiobookDuration') }}</span>
<span class="metadata-value">{{ formatDuration(audio.durationSeconds) }}</span>
</div>
}
@if (audio.chapterCount) {
<div class="metadata-item">
<span class="metadata-key">{{ t('audiobookChapters') }}</span>
<span class="metadata-value">{{ audio.chapterCount }}</span>
</div>
}
@if (book.metadata?.abridged != null) {
<div class="metadata-item">
<span class="metadata-key">{{ t('audiobookAbridged') }}</span>
<span class="metadata-value">{{ book.metadata?.abridged ? t('abridged') : t('unabridged') }}</span>
</div>
}
}
@if (hasDigitalFile(book)) {
<div class="metadata-item">
<span class="metadata-key">{{ t('fileSizeLabel') }}</span>
@@ -908,99 +938,6 @@
</div>
}
@if (isAudiobook(book) && hasAudiobookMetadata(book)) {
<div class="audiobook-metadata-section">
<div class="section-header clickable" (click)="isAudiobookSectionExpanded = !isAudiobookSectionExpanded">
<div class="section-header-left">
<i class="pi pi-headphones"></i>
<span>{{ t('audiobookDetailsTitle') }}</span>
</div>
<i class="pi section-toggle-icon" [ngClass]="isAudiobookSectionExpanded ? 'pi-chevron-up' : 'pi-chevron-down'"></i>
</div>
<div class="audiobook-metadata-content" [ngClass]="{'collapsed': !isAudiobookSectionExpanded}">
@let audio = book.metadata!.audiobookMetadata!;
<div class="audiobook-info-grid">
@if (audio.durationSeconds) {
<div class="audiobook-info-item">
<span class="audiobook-info-label">{{ t('audiobookDuration') }}</span>
<span class="audiobook-info-value">{{ formatDuration(audio.durationSeconds) }}</span>
</div>
}
@if (book.metadata?.narrator) {
<div class="audiobook-info-item">
<span class="audiobook-info-label">{{ t('audiobookNarrator') }}</span>
<a class="audiobook-info-value audiobook-link" (click)="goToNarrator(book.metadata!.narrator!)">
{{ book.metadata?.narrator }}
</a>
</div>
}
@if (audio.chapterCount) {
<div class="audiobook-info-item">
<span class="audiobook-info-label">{{ t('audiobookChapters') }}</span>
<span class="audiobook-info-value">{{ audio.chapterCount }}</span>
</div>
}
@if (audio.bitrate) {
<div class="audiobook-info-item">
<span class="audiobook-info-label">{{ t('audiobookBitrate') }}</span>
<span class="audiobook-info-value">{{ audio.bitrate }} kbps</span>
</div>
}
@if (audio.sampleRate) {
<div class="audiobook-info-item">
<span class="audiobook-info-label">{{ t('audiobookSampleRate') }}</span>
<span class="audiobook-info-value">{{ formatSampleRate(audio.sampleRate) }}</span>
</div>
}
@if (audio.channels) {
<div class="audiobook-info-item">
<span class="audiobook-info-label">{{ t('audiobookChannels') }}</span>
<span class="audiobook-info-value">{{ getChannelLabel(audio.channels) }}</span>
</div>
}
@if (audio.codec) {
<div class="audiobook-info-item">
<span class="audiobook-info-label">{{ t('audiobookCodec') }}</span>
<span class="audiobook-info-value">{{ audio.codec.toUpperCase() }}</span>
</div>
}
</div>
@if (book.metadata?.abridged != null) {
<div class="audiobook-properties">
<span class="audiobook-property-badge" [ngClass]="book.metadata?.abridged ? 'abridged' : 'unabridged'">
<i class="pi" [ngClass]="book.metadata?.abridged ? 'pi-minus-circle' : 'pi-check-circle'"></i>
{{ book.metadata?.abridged ? t('abridged') : t('unabridged') }}
</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>
}
<app-metadata-tabs
[book]="book"
[bookInSeries]="bookInSeries"
@@ -1002,189 +1002,6 @@
}
// Audiobook Metadata Section Styles
.audiobook-metadata-section {
background: var(--card-background);
border: 1px solid var(--border-color);
border-radius: 0.75rem;
overflow: hidden;
transition: box-shadow 0.3s ease;
&:hover {
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
}
.audiobook-metadata-content {
padding: 0.875rem;
display: flex;
flex-direction: column;
gap: 1rem;
max-height: 2000px;
overflow: hidden;
transition: max-height 0.3s ease, padding 0.3s ease, opacity 0.3s ease;
opacity: 1;
&.collapsed {
max-height: 0;
padding: 0 0.875rem;
opacity: 0;
}
}
.audiobook-info-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
gap: 0.75rem;
}
.audiobook-info-item {
display: flex;
flex-direction: column;
gap: 0.125rem;
}
.audiobook-info-label {
font-size: 0.75rem;
font-weight: 600;
color: var(--text-color-secondary);
text-transform: uppercase;
letter-spacing: 0.5px;
}
.audiobook-info-value {
font-size: 0.95rem;
color: var(--text-color);
font-weight: 500;
}
.audiobook-link {
color: cornflowerblue;
cursor: pointer;
transition: color 0.2s ease;
&:hover {
color: dodgerblue;
text-decoration: underline;
}
}
.audiobook-properties {
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
padding-top: 0.5rem;
border-top: 1px solid var(--border-color);
}
.audiobook-property-badge {
display: inline-flex;
align-items: center;
gap: 0.25rem;
padding: 0.25rem 0.625rem;
border-radius: 9999px;
font-size: 0.8rem;
font-weight: 600;
i {
font-size: 0.75rem;
}
&.unabridged {
background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
color: white;
}
&.abridged {
background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
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;
}
.detach-dialog-content {
display: flex;
flex-direction: column;
@@ -80,8 +80,6 @@ export class MetadataViewerComponent implements OnInit, OnChanges, AfterViewChec
isExpanded = false;
isOverflowing = false;
isComicSectionExpanded = true;
isAudiobookSectionExpanded = true;
isChapterListExpanded = false;
showFilePath = false;
isAutoFetching = false;
private metadataCenterViewMode: 'route' | 'dialog' = 'route';
@@ -1415,18 +1413,6 @@ 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`;
+10 -3
View File
@@ -222,7 +222,15 @@
"deleteTooltip": "Delete",
"detachTooltip": "Detach",
"downloadAllTooltip": "Download all files as a ZIP archive",
"physicalBookHint": "You can upload a digital copy or add metadata manually."
"physicalBookHint": "You can upload a digital copy or add metadata manually.",
"chapters": "Chapters",
"chapterTitle": "Title",
"startTime": "Start",
"endTime": "End",
"duration": "Duration",
"totalDuration": "Total Duration",
"noChapters": "No chapter information available.",
"fileName": "File"
},
"viewer": {
"metadataLocked": "This book metadata is locked.",
@@ -279,7 +287,6 @@
"blackAndWhite": "B&W",
"rightToLeft": "RTL",
"notesLabel": "Notes",
"audiobookDetailsTitle": "Audiobook Details",
"audiobookDuration": "Duration",
"audiobookNarrator": "Narrator",
"audiobookChapters": "Chapters",
@@ -287,7 +294,7 @@
"audiobookSampleRate": "Sample Rate",
"audiobookChannels": "Channels",
"audiobookCodec": "Codec",
"audiobookChapterList": "Chapter List",
"audiobookAbridged": "Abridged",
"abridged": "Abridged",
"unabridged": "Unabridged",
"readBtn": "Read",
+10 -3
View File
@@ -222,7 +222,15 @@
"deleteTooltip": "Eliminar",
"detachTooltip": "Separar",
"downloadAllTooltip": "Descargar todos los archivos como archivo ZIP",
"physicalBookHint": "Puede subir una copia digital o agregar metadatos manualmente."
"physicalBookHint": "Puede subir una copia digital o agregar metadatos manualmente.",
"chapters": "Capítulos",
"chapterTitle": "Título",
"startTime": "Inicio",
"endTime": "Fin",
"duration": "Duración",
"totalDuration": "Duración total",
"noChapters": "No hay información de capítulos disponible.",
"fileName": "Archivo"
},
"viewer": {
"metadataLocked": "Los metadatos de este libro están bloqueados.",
@@ -279,7 +287,6 @@
"blackAndWhite": "B/N",
"rightToLeft": "DaI",
"notesLabel": "Notas",
"audiobookDetailsTitle": "Detalles del audiolibro",
"audiobookDuration": "Duración",
"audiobookNarrator": "Narrador",
"audiobookChapters": "Capítulos",
@@ -287,7 +294,7 @@
"audiobookSampleRate": "Frecuencia de muestreo",
"audiobookChannels": "Canales",
"audiobookCodec": "Códec",
"audiobookChapterList": "Lista de capítulos",
"audiobookAbridged": "Abreviado",
"abridged": "Abreviado",
"unabridged": "Íntegro",
"readBtn": "Leer",