Audiobook enhancement (#2611)
* Audiobook enhancement * Fix choppy virtual scroller with mixed audiobook/ebook cards by using uniform heights * Fix audiobook cover regeneration for combined books and improve error messages * Fix cover extraction when attaching audiobook files during rescan * Set audiobookCoverUpdatedOn for cache busting when generating cover * Add support for regenerating covers from specific book files * Fix Continue Reading/Listening scrollers to filter by actual progress instead of primary file type * Show ebook cover and open ebook reader in Continue Reading scroller for combined books * Prevent read status from being downgraded when saving audiobook progress * Fix BookCoverServiceTest to match updated regenerateCover method signature --------- Co-authored-by: acx10 <acx10@users.noreply.github.com>
This commit is contained in:
@@ -207,15 +207,14 @@ export class BookBrowserComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
return this.coverScalePreferenceService.gridColumnMinWidth;
|
||||
}
|
||||
|
||||
getCardHeight(book: Book): number {
|
||||
getCardHeight(_book: Book): number {
|
||||
// Use uniform height for all book types to ensure smooth virtual scrolling.
|
||||
// Mixed heights cause choppy/jumpy scrolling because the virtual scroller
|
||||
// cannot accurately estimate positions when item heights vary.
|
||||
if (this.isMobile) {
|
||||
const isAudiobook = book.primaryFile?.bookType === 'AUDIOBOOK';
|
||||
if (isAudiobook) {
|
||||
return this.mobileCardSize.width + this.MOBILE_TITLE_BAR_HEIGHT;
|
||||
}
|
||||
return this.mobileCardSize.height;
|
||||
}
|
||||
return this.coverScalePreferenceService.getCardHeight(book);
|
||||
return this.coverScalePreferenceService.getCardHeight(_book);
|
||||
}
|
||||
|
||||
get viewIcon(): string {
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@
|
||||
}
|
||||
|
||||
@if (!_isSeriesViewActive && hasDigitalFile()) {
|
||||
<p-button [rounded]="true" icon="pi pi-book" class="read-btn" (click)="readBook(book)"></p-button>
|
||||
<p-button [rounded]="true" [icon]="_isAudiobook ? 'pi pi-play' : 'pi pi-book'" class="read-btn" (click)="readBook(book)"></p-button>
|
||||
}
|
||||
|
||||
@if (isCheckboxEnabled) {
|
||||
|
||||
+6
-1
@@ -3,6 +3,9 @@
|
||||
border-radius: 8px 8px 8px 8px;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
&.selected {
|
||||
border: 2px solid var(--primary-color);
|
||||
@@ -22,7 +25,9 @@
|
||||
}
|
||||
|
||||
.cover-container.audiobook-cover {
|
||||
aspect-ratio: 1/1;
|
||||
// Use same aspect-ratio as ebooks for uniform virtual scroller row heights.
|
||||
// The square audiobook cover image will be centered via object-fit: contain.
|
||||
aspect-ratio: 5/7;
|
||||
background-color: var(--surface-ground);
|
||||
}
|
||||
|
||||
|
||||
+35
-9
@@ -1,6 +1,6 @@
|
||||
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, inject, Input, OnChanges, OnDestroy, OnInit, Output, SimpleChanges, ViewChild} from '@angular/core';
|
||||
import {TooltipModule} from "primeng/tooltip";
|
||||
import {AdditionalFile, Book, ReadStatus} from '../../../model/book.model';
|
||||
import {AdditionalFile, Book, BookType, ReadStatus} from '../../../model/book.model';
|
||||
import {Button} from 'primeng/button';
|
||||
import {MenuModule} from 'primeng/menu';
|
||||
import {ConfirmationService, MenuItem, MessageService} from 'primeng/api';
|
||||
@@ -49,6 +49,7 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
|
||||
@Input() seriesViewEnabled: boolean = false;
|
||||
@Input() isSeriesCollapsed: boolean = false;
|
||||
@Input() overlayPreferenceService?: BookCardOverlayPreferenceService;
|
||||
@Input() forceEbookMode: boolean = false;
|
||||
|
||||
@ViewChild('checkboxElem') checkboxElem!: ElementRef<HTMLInputElement>;
|
||||
|
||||
@@ -128,9 +129,9 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
if (changes['book']) {
|
||||
if (changes['book'] || changes['forceEbookMode']) {
|
||||
this.computeAllMemoizedValues();
|
||||
if (!changes['book'].firstChange && this.menuInitialized) {
|
||||
if (changes['book'] && !changes['book'].firstChange && this.menuInitialized) {
|
||||
this.additionalFilesLoaded = false;
|
||||
this.initMenu();
|
||||
}
|
||||
@@ -158,7 +159,10 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
|
||||
this._displayTitle = (this.isSeriesCollapsed && this.book.metadata?.seriesName)
|
||||
? this.book.metadata?.seriesName
|
||||
: this.book.metadata?.title;
|
||||
this._coverImageUrl = this.urlHelper.getThumbnailUrl(this.book.id, this.book.metadata?.coverUpdatedOn);
|
||||
this._isAudiobook = this.book.primaryFile?.bookType === 'AUDIOBOOK' && !this.forceEbookMode;
|
||||
this._coverImageUrl = this._isAudiobook
|
||||
? this.urlHelper.getAudiobookThumbnailUrl(this.book.id, this.book.metadata?.audiobookCoverUpdatedOn)
|
||||
: this.urlHelper.getThumbnailUrl(this.book.id, this.book.metadata?.coverUpdatedOn);
|
||||
|
||||
this._readStatusIcon = this.readStatusHelper.getReadStatusIcon(this.book.readStatus);
|
||||
this._readStatusClass = this.readStatusHelper.getReadStatusClass(this.book.readStatus);
|
||||
@@ -167,7 +171,6 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
|
||||
|
||||
this._seriesCountTooltip = 'Series collapsed: ' + this.book.seriesCount + ' books';
|
||||
this._titleTooltip = 'Title: ' + this._displayTitle;
|
||||
this._isAudiobook = this.book.primaryFile?.bookType === 'AUDIOBOOK';
|
||||
}
|
||||
|
||||
get hasProgress(): boolean {
|
||||
@@ -200,9 +203,26 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
|
||||
}
|
||||
|
||||
readBook(book: Book): void {
|
||||
if (this.forceEbookMode && book.primaryFile?.bookType === 'AUDIOBOOK') {
|
||||
const ebookType = this.getEbookType(book);
|
||||
if (ebookType) {
|
||||
this.bookService.readBook(book.id, undefined, ebookType);
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.bookService.readBook(book.id);
|
||||
}
|
||||
|
||||
private getEbookType(book: Book): BookType | undefined {
|
||||
if (book.epubProgress) return 'EPUB';
|
||||
if (book.pdfProgress) return 'PDF';
|
||||
if (book.cbxProgress) return 'CBX';
|
||||
const alternativeFormat = book.alternativeFormats?.find(f =>
|
||||
f.bookType && ['EPUB', 'PDF', 'CBX', 'FB2', 'MOBI', 'AZW3'].includes(f.bookType)
|
||||
);
|
||||
return alternativeFormat?.bookType;
|
||||
}
|
||||
|
||||
onMenuShow(): void {
|
||||
this.menuToggled.emit(true);
|
||||
}
|
||||
@@ -425,10 +445,10 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
|
||||
summary: 'Success',
|
||||
detail: 'Cover regeneration started'
|
||||
}),
|
||||
error: () => this.messageService.add({
|
||||
error: (err) => this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: 'Failed to regenerate cover'
|
||||
detail: err?.error?.message || 'Failed to regenerate cover'
|
||||
})
|
||||
});
|
||||
}
|
||||
@@ -443,10 +463,10 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
|
||||
summary: 'Success',
|
||||
detail: 'Cover generated successfully'
|
||||
}),
|
||||
error: () => this.messageService.add({
|
||||
error: (err) => this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: 'Failed to generate cover'
|
||||
detail: err?.error?.message || 'Failed to generate cover'
|
||||
})
|
||||
});
|
||||
}
|
||||
@@ -740,6 +760,12 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
|
||||
if (!this.book?.primaryFile) {
|
||||
return 'PHYSICAL';
|
||||
}
|
||||
if (this.forceEbookMode && this.book.primaryFile?.bookType === 'AUDIOBOOK') {
|
||||
const ebookType = this.getEbookType(this.book);
|
||||
if (ebookType) {
|
||||
return ebookType;
|
||||
}
|
||||
}
|
||||
const ext = this.book?.primaryFile?.extension;
|
||||
if (ext) {
|
||||
return ext.toUpperCase();
|
||||
|
||||
+2
-1
@@ -124,12 +124,13 @@ export class BookDialogHelperService {
|
||||
});
|
||||
}
|
||||
|
||||
openCoverSearchDialog(bookId: number): DynamicDialogRef | null {
|
||||
openCoverSearchDialog(bookId: number, coverType?: 'ebook' | 'audiobook'): DynamicDialogRef | null {
|
||||
return this.openDialog(CoverSearchComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.FULL} ${DialogStyle.MINIMAL}`,
|
||||
data: {
|
||||
bookId: bookId,
|
||||
coverType: coverType,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
+4
-5
@@ -52,11 +52,10 @@ export class CoverScalePreferenceService {
|
||||
return `${this.currentCardSize.width}px`;
|
||||
}
|
||||
|
||||
getCardHeight(book: Book): number {
|
||||
const isAudiobook = book.primaryFile?.bookType === 'AUDIOBOOK';
|
||||
if (isAudiobook) {
|
||||
return Math.round((this.BASE_WIDTH + this.TITLE_BAR_HEIGHT) * this.scaleFactor);
|
||||
}
|
||||
getCardHeight(_book: Book): number {
|
||||
// Use uniform height for all book types to ensure smooth virtual scrolling.
|
||||
// Mixed heights cause choppy/jumpy scrolling because the virtual scroller
|
||||
// cannot accurately estimate positions when item heights vary.
|
||||
return this.currentCardSize.height;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
<div class="book-cover-wrapper" (mouseenter)="isHovered = true" (mouseleave)="isHovered = false">
|
||||
<div class="book-cover-wrapper" [class.audiobook-only]="isAudiobookOnly()" (mouseenter)="isHovered = true" (mouseleave)="isHovered = false">
|
||||
<img
|
||||
[src]="urlHelper.getThumbnailUrl(book.id, book.metadata?.coverUpdatedOn)"
|
||||
[src]="getThumbnailUrl()"
|
||||
class="book-cover"
|
||||
alt="Cover of {{ book.metadata?.title }}"
|
||||
loading="lazy"/>
|
||||
|
||||
+7
@@ -10,6 +10,13 @@
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
&.audiobook-only {
|
||||
.book-cover {
|
||||
aspect-ratio: 1 / 1;
|
||||
object-fit: cover;
|
||||
}
|
||||
}
|
||||
|
||||
.info-btn {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
|
||||
+13
@@ -35,6 +35,19 @@ export class BookCardLiteComponent implements OnInit, OnDestroy {
|
||||
private metadataCenterViewMode: 'route' | 'dialog' = 'route';
|
||||
isHovered: boolean = false;
|
||||
|
||||
isAudiobookOnly(): boolean {
|
||||
const primaryIsAudiobook = this.book.primaryFile?.bookType === 'AUDIOBOOK';
|
||||
const hasEbookAlternative = this.book.alternativeFormats?.some(f => f.bookType !== 'AUDIOBOOK') ?? false;
|
||||
return primaryIsAudiobook && !hasEbookAlternative;
|
||||
}
|
||||
|
||||
getThumbnailUrl(): string {
|
||||
if (this.isAudiobookOnly()) {
|
||||
return this.urlHelper.getAudiobookThumbnailUrl(this.book.id, this.book.metadata?.audiobookCoverUpdatedOn);
|
||||
}
|
||||
return this.urlHelper.getThumbnailUrl(this.book.id, this.book.metadata?.coverUpdatedOn);
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.userService.userState$
|
||||
.pipe(
|
||||
|
||||
@@ -97,6 +97,19 @@ export interface BookFileProgress {
|
||||
progressPercent: number;
|
||||
}
|
||||
|
||||
export interface AudiobookMetadata {
|
||||
narrator?: string;
|
||||
abridged?: boolean | null;
|
||||
durationSeconds?: number;
|
||||
bitrate?: number;
|
||||
sampleRate?: number;
|
||||
channels?: number;
|
||||
codec?: string;
|
||||
chapterCount?: number;
|
||||
narratorLocked?: boolean;
|
||||
abridgedLocked?: boolean;
|
||||
}
|
||||
|
||||
export interface BookMetadata {
|
||||
bookId: number;
|
||||
title?: string;
|
||||
@@ -129,7 +142,16 @@ export interface BookMetadata {
|
||||
ranobedbId?: string;
|
||||
ranobedbRating?: number | null;
|
||||
hardcoverRating?: number | null;
|
||||
audibleId?: string;
|
||||
audibleRating?: number | null;
|
||||
audibleReviewCount?: number | null;
|
||||
narrator?: string;
|
||||
abridged?: boolean | null;
|
||||
narratorLocked?: boolean;
|
||||
abridgedLocked?: boolean;
|
||||
audiobookMetadata?: AudiobookMetadata;
|
||||
coverUpdatedOn?: string;
|
||||
audiobookCoverUpdatedOn?: string;
|
||||
authors?: string[];
|
||||
categories?: string[];
|
||||
moods?: string[];
|
||||
@@ -166,12 +188,16 @@ export interface BookMetadata {
|
||||
lubimyczytacRatingLocked?: boolean;
|
||||
ranobedbIdLocked?: boolean;
|
||||
ranobedbRatingLocked?: boolean;
|
||||
audibleIdLocked?: boolean;
|
||||
audibleRatingLocked?: boolean;
|
||||
audibleReviewCountLocked?: boolean;
|
||||
coverUpdatedOnLocked?: boolean;
|
||||
authorsLocked?: boolean;
|
||||
categoriesLocked?: boolean;
|
||||
moodsLocked?: boolean;
|
||||
tagsLocked?: boolean;
|
||||
coverLocked?: boolean;
|
||||
audiobookCoverLocked?: boolean;
|
||||
reviewsLocked?: boolean;
|
||||
|
||||
[key: string]: unknown;
|
||||
@@ -206,11 +232,17 @@ export interface MetadataClearFlags {
|
||||
lubimyczytacRating?: boolean;
|
||||
ranobedbId?: boolean;
|
||||
ranobedbRating?: boolean;
|
||||
audibleId?: boolean;
|
||||
audibleRating?: boolean;
|
||||
audibleReviewCount?: boolean;
|
||||
narrator?: boolean;
|
||||
abridged?: boolean;
|
||||
authors?: boolean;
|
||||
categories?: boolean;
|
||||
moods?: boolean;
|
||||
tags?: boolean;
|
||||
cover?: boolean;
|
||||
audiobookCover?: boolean;
|
||||
}
|
||||
|
||||
export interface MetadataUpdateWrapper {
|
||||
|
||||
@@ -11,6 +11,7 @@ export interface Library {
|
||||
sort?: SortOption;
|
||||
paths: LibraryPath[];
|
||||
formatPriority?: BookType[];
|
||||
allowedFormats?: BookType[];
|
||||
}
|
||||
|
||||
export interface LibraryPath {
|
||||
|
||||
@@ -310,7 +310,7 @@ export class BookService {
|
||||
break;
|
||||
|
||||
case 'AUDIOBOOK':
|
||||
baseUrl = 'audiobook-reader';
|
||||
baseUrl = 'audiobook-player';
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -700,6 +700,35 @@ export class BookService {
|
||||
return this.http.post<void>(`${this.url}/bulk-regenerate-covers`, {bookIds});
|
||||
}
|
||||
|
||||
uploadAudiobookCoverFromUrl(bookId: number, url: string): Observable<BookMetadata> {
|
||||
return this.http.post<BookMetadata>(`${this.url}/${bookId}/metadata/audiobook-cover/from-url`, {url});
|
||||
}
|
||||
|
||||
uploadAudiobookCoverFromFile(bookId: number, file: File): Observable<void> {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
return this.http.post<void>(`${this.url}/${bookId}/metadata/audiobook-cover/upload`, formData);
|
||||
}
|
||||
|
||||
getUploadAudiobookCoverUrl(bookId: number): string {
|
||||
return this.url + '/' + bookId + "/metadata/audiobook-cover/upload";
|
||||
}
|
||||
|
||||
regenerateAudiobookCover(bookId: number): Observable<void> {
|
||||
return this.http.post<void>(`${this.url}/${bookId}/regenerate-audiobook-cover`, {});
|
||||
}
|
||||
|
||||
generateCustomAudiobookCover(bookId: number): Observable<void> {
|
||||
return this.http.post<void>(`${this.url}/${bookId}/generate-custom-audiobook-cover`, {});
|
||||
}
|
||||
|
||||
supportsDualCovers(book: Book): boolean {
|
||||
const allFiles = [book.primaryFile, ...(book.alternativeFormats || [])].filter(f => f?.bookType);
|
||||
const hasAudiobook = allFiles.some(f => f!.bookType === 'AUDIOBOOK');
|
||||
const hasEbook = allFiles.some(f => f!.bookType !== 'AUDIOBOOK');
|
||||
return hasAudiobook && hasEbook;
|
||||
}
|
||||
|
||||
bulkUploadCover(bookIds: number[], file: File): Observable<void> {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
|
||||
@@ -165,4 +165,8 @@ export class LibraryService {
|
||||
setLargeLibraryLoading(isLoading: boolean, expectedCount: number): void {
|
||||
this.largeLibraryLoadingSubject.next({ isLoading, expectedCount });
|
||||
}
|
||||
|
||||
getBookCountsByFormat(libraryId: number): Observable<Record<string, number>> {
|
||||
return this.http.get<Record<string, number>>(`${this.url}/${libraryId}/format-counts`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user