Co-authored-by: blitzar3k <263961889+blitzar3k@users.noreply.github.com>
This commit is contained in:
@@ -33,6 +33,9 @@ public class MetadataClearFlags {
|
||||
private boolean lubimyczytacRating;
|
||||
private boolean ranobedbId;
|
||||
private boolean ranobedbRating;
|
||||
private boolean audibleId;
|
||||
private boolean audibleRating;
|
||||
private boolean audibleReviewCount;
|
||||
private boolean authors;
|
||||
private boolean categories;
|
||||
private boolean moods;
|
||||
|
||||
@@ -204,6 +204,9 @@ public class BookMetadataUpdater {
|
||||
handleFieldUpdate(e.getLubimyczytacRatingLocked(), clear.isLubimyczytacRating(), m.getLubimyczytacRating(), v -> e.setLubimyczytacRating(v), () -> e.getLubimyczytacRating(), replaceMode);
|
||||
handleFieldUpdate(e.getRanobedbIdLocked(), clear.isRanobedbId(), m.getRanobedbId(), v -> e.setRanobedbId(nullIfBlank(v)), e::getRanobedbId, replaceMode);
|
||||
handleFieldUpdate(e.getRanobedbRatingLocked(), clear.isRanobedbRating(), m.getRanobedbRating(), e::setRanobedbRating, e::getRanobedbRating, replaceMode);
|
||||
handleFieldUpdate(e.getAudibleIdLocked(), clear.isAudibleId(), m.getAudibleId(), v -> e.setAudibleId(nullIfBlank(v)), e::getAudibleId, replaceMode);
|
||||
handleFieldUpdate(e.getAudibleRatingLocked(), clear.isAudibleRating(), m.getAudibleRating(), e::setAudibleRating, e::getAudibleRating, replaceMode);
|
||||
handleFieldUpdate(e.getAudibleReviewCountLocked(), clear.isAudibleReviewCount(), m.getAudibleReviewCount(), e::setAudibleReviewCount, e::getAudibleReviewCount, replaceMode);
|
||||
handleFieldUpdate(e.getAgeRatingLocked(), clear.isAgeRating(), m.getAgeRating(), e::setAgeRating, e::getAgeRating, replaceMode);
|
||||
handleFieldUpdate(e.getContentRatingLocked(), clear.isContentRating(), m.getContentRating(), v -> e.setContentRating(nullIfBlank(v)), e::getContentRating, replaceMode);
|
||||
}
|
||||
|
||||
@@ -125,6 +125,7 @@ public class AudibleParser implements BookParser, DetailedMetadataProvider {
|
||||
String narrator = extractPreviewNarrator(container);
|
||||
|
||||
BookMetadata.BookMetadataBuilder builder = BookMetadata.builder()
|
||||
.asin(asin)
|
||||
.audibleId(asin)
|
||||
.title(title)
|
||||
.thumbnailUrl(thumbnailUrl)
|
||||
@@ -416,6 +417,7 @@ public class AudibleParser implements BookParser, DetailedMetadataProvider {
|
||||
|
||||
return BookMetadata.builder()
|
||||
.provider(MetadataProvider.Audible)
|
||||
.asin(audibleId)
|
||||
.audibleId(audibleId)
|
||||
.title(title)
|
||||
.subtitle(subtitle)
|
||||
|
||||
@@ -197,6 +197,18 @@ public class MetadataChangeDetector {
|
||||
BookMetadata::getRanobedbRating, BookMetadataEntity::getRanobedbRating,
|
||||
BookMetadata::getRanobedbRatingLocked, BookMetadataEntity::getRanobedbRatingLocked,
|
||||
MetadataClearFlags::isRanobedbRating, false),
|
||||
new FieldDescriptor<>("audibleId",
|
||||
BookMetadata::getAudibleId, BookMetadataEntity::getAudibleId,
|
||||
BookMetadata::getAudibleIdLocked, BookMetadataEntity::getAudibleIdLocked,
|
||||
MetadataClearFlags::isAudibleId, false),
|
||||
new FieldDescriptor<>("audibleRating",
|
||||
BookMetadata::getAudibleRating, BookMetadataEntity::getAudibleRating,
|
||||
BookMetadata::getAudibleRatingLocked, BookMetadataEntity::getAudibleRatingLocked,
|
||||
MetadataClearFlags::isAudibleRating, false),
|
||||
new FieldDescriptor<>("audibleReviewCount",
|
||||
BookMetadata::getAudibleReviewCount, BookMetadataEntity::getAudibleReviewCount,
|
||||
BookMetadata::getAudibleReviewCountLocked, BookMetadataEntity::getAudibleReviewCountLocked,
|
||||
MetadataClearFlags::isAudibleReviewCount, false),
|
||||
new FieldDescriptor<>("narrator",
|
||||
BookMetadata::getNarrator, BookMetadataEntity::getNarrator,
|
||||
BookMetadata::getNarratorLocked, BookMetadataEntity::getNarratorLocked,
|
||||
|
||||
@@ -515,6 +515,46 @@ class BookMetadataUpdaterTest {
|
||||
"Title should be replaced when using REPLACE_ALL mode");
|
||||
}
|
||||
|
||||
@Test
|
||||
void setBookMetadata_shouldUpdateAudibleFields() {
|
||||
BookEntity bookEntity = new BookEntity();
|
||||
bookEntity.setId(1L);
|
||||
BookMetadataEntity metadataEntity = new BookMetadataEntity();
|
||||
metadataEntity.setBook(bookEntity);
|
||||
bookEntity.setMetadata(metadataEntity);
|
||||
|
||||
BookFileEntity primaryFile = new BookFileEntity();
|
||||
primaryFile.setBook(bookEntity);
|
||||
primaryFile.setBookType(BookFileType.EPUB);
|
||||
primaryFile.setBookFormat(true);
|
||||
primaryFile.setFileSubPath("sub");
|
||||
primaryFile.setFileName("file.epub");
|
||||
bookEntity.setBookFiles(List.of(primaryFile));
|
||||
|
||||
BookMetadata newMetadata = new BookMetadata();
|
||||
newMetadata.setAsin("B0EXAMPLE1");
|
||||
newMetadata.setAudibleId("B0EXAMPLE1");
|
||||
newMetadata.setAudibleRating(4.5);
|
||||
newMetadata.setAudibleReviewCount(1200);
|
||||
|
||||
MetadataUpdateWrapper wrapper = MetadataUpdateWrapper.builder()
|
||||
.metadata(newMetadata)
|
||||
.build();
|
||||
|
||||
MetadataUpdateContext context = MetadataUpdateContext.builder()
|
||||
.bookEntity(bookEntity)
|
||||
.metadataUpdateWrapper(wrapper)
|
||||
.replaceMode(MetadataReplaceMode.REPLACE_ALL)
|
||||
.build();
|
||||
|
||||
bookMetadataUpdater.setBookMetadata(context);
|
||||
|
||||
assertEquals("B0EXAMPLE1", bookEntity.getMetadata().getAsin());
|
||||
assertEquals("B0EXAMPLE1", bookEntity.getMetadata().getAudibleId());
|
||||
assertEquals(4.5, bookEntity.getMetadata().getAudibleRating());
|
||||
assertEquals(1200, bookEntity.getMetadata().getAudibleReviewCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
void setBookMetadata_withReplaceMissingMode_shouldNotReplaceExistingTitle() {
|
||||
// This test verifies the old behavior that was causing the bug
|
||||
|
||||
@@ -205,7 +205,10 @@ public class MetadataChangeDetectorTest {
|
||||
Arguments.of("goodreadsRating", (Consumer<BookMetadata>) m -> m.setGoodreadsRating(4.3)),
|
||||
Arguments.of("goodreadsReviewCount", (Consumer<BookMetadata>) m -> m.setGoodreadsReviewCount(30000)),
|
||||
Arguments.of("hardcoverRating", (Consumer<BookMetadata>) m -> m.setHardcoverRating(4.2)),
|
||||
Arguments.of("hardcoverReviewCount", (Consumer<BookMetadata>) m -> m.setHardcoverReviewCount(750))
|
||||
Arguments.of("hardcoverReviewCount", (Consumer<BookMetadata>) m -> m.setHardcoverReviewCount(750)),
|
||||
Arguments.of("audibleId", (Consumer<BookMetadata>) m -> m.setAudibleId("B098765432")),
|
||||
Arguments.of("audibleRating", (Consumer<BookMetadata>) m -> m.setAudibleRating(4.6)),
|
||||
Arguments.of("audibleReviewCount", (Consumer<BookMetadata>) m -> m.setAudibleReviewCount(3000))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -551,6 +554,8 @@ public class MetadataChangeDetectorTest {
|
||||
newMeta.setAmazonReviewCount(2000);
|
||||
newMeta.setGoodreadsReviewCount(35000);
|
||||
newMeta.setHardcoverReviewCount(800);
|
||||
newMeta.setAudibleRating(4.6);
|
||||
newMeta.setAudibleReviewCount(3000);
|
||||
boolean result = MetadataChangeDetector.hasValueChangesForFileWrite(newMeta, existingMeta, clearFlags);
|
||||
assertFalse(result, "Rating and review count fields should not trigger file write");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user