diff --git a/backend/src/main/java/org/booklore/config/BookParserConfig.java b/backend/src/main/java/org/booklore/config/BookParserConfig.java index 5ae7a4312..d1f3d55dc 100644 --- a/backend/src/main/java/org/booklore/config/BookParserConfig.java +++ b/backend/src/main/java/org/booklore/config/BookParserConfig.java @@ -21,19 +21,21 @@ public class BookParserConfig { RanobeDbParser ranobedbParser, LubimyCzytacParser lubimyczytacParser, AudibleParser audibleParser, - AppleBooksParser appleBooksParser + AppleBooksParser appleBooksParser, + OpenLibraryParser openLibraryParser ) { - return Map.of( - MetadataProvider.Amazon, amazonBookParser, - MetadataProvider.GoodReads, goodReadsParser, - MetadataProvider.Google, googleParser, - MetadataProvider.Hardcover, hardcoverParser, - MetadataProvider.Comicvine, comicvineBookParser, - MetadataProvider.Douban, doubanBookParser, - MetadataProvider.Lubimyczytac, lubimyczytacParser, - MetadataProvider.Ranobedb, ranobedbParser, - MetadataProvider.Audible, audibleParser, - MetadataProvider.AppleBooks, appleBooksParser + return Map.ofEntries( + Map.entry(MetadataProvider.OpenLibrary, openLibraryParser), + Map.entry(MetadataProvider.Amazon, amazonBookParser), + Map.entry(MetadataProvider.GoodReads, goodReadsParser), + Map.entry(MetadataProvider.Google, googleParser), + Map.entry(MetadataProvider.Hardcover, hardcoverParser), + Map.entry(MetadataProvider.Comicvine, comicvineBookParser), + Map.entry(MetadataProvider.Douban, doubanBookParser), + Map.entry(MetadataProvider.Lubimyczytac, lubimyczytacParser), + Map.entry(MetadataProvider.Ranobedb, ranobedbParser), + Map.entry(MetadataProvider.Audible, audibleParser), + Map.entry(MetadataProvider.AppleBooks, appleBooksParser) ); } } diff --git a/backend/src/main/java/org/booklore/model/MetadataClearFlags.java b/backend/src/main/java/org/booklore/model/MetadataClearFlags.java index 3610d5d82..f4c7c6f29 100644 --- a/backend/src/main/java/org/booklore/model/MetadataClearFlags.java +++ b/backend/src/main/java/org/booklore/model/MetadataClearFlags.java @@ -15,6 +15,7 @@ public class MetadataClearFlags { private boolean seriesTotal; private boolean isbn13; private boolean isbn10; + private boolean openlibraryId; private boolean asin; private boolean goodreadsId; private boolean comicvineId; diff --git a/backend/src/main/java/org/booklore/model/dto/BookMetadata.java b/backend/src/main/java/org/booklore/model/dto/BookMetadata.java index be12c2f8d..82ddc67ab 100644 --- a/backend/src/main/java/org/booklore/model/dto/BookMetadata.java +++ b/backend/src/main/java/org/booklore/model/dto/BookMetadata.java @@ -35,6 +35,7 @@ public class BookMetadata { private AudiobookMetadata audiobookMetadata; private ComicMetadata comicMetadata; + private String openlibraryId; private String asin; private Double amazonRating; private Integer amazonReviewCount; @@ -85,6 +86,7 @@ public class BookMetadata { private Boolean seriesTotalLocked; private Boolean isbn13Locked; private Boolean isbn10Locked; + private Boolean openlibraryIdLocked; private Boolean asinLocked; private Boolean goodreadsIdLocked; private Boolean comicvineIdLocked; diff --git a/backend/src/main/java/org/booklore/model/dto/EpubMetadata.java b/backend/src/main/java/org/booklore/model/dto/EpubMetadata.java index ef4ce6b4e..da35f3f31 100644 --- a/backend/src/main/java/org/booklore/model/dto/EpubMetadata.java +++ b/backend/src/main/java/org/booklore/model/dto/EpubMetadata.java @@ -39,6 +39,7 @@ public class EpubMetadata { private Double hardcoverRating; private Integer hardcoverReviewCount; private String googleId; + private String openlibraryId; private String ranobedbId; private Double ranobedbRating; private List authors; diff --git a/backend/src/main/java/org/booklore/model/dto/request/MetadataRefreshOptions.java b/backend/src/main/java/org/booklore/model/dto/request/MetadataRefreshOptions.java index 27b2f4c1b..75b768328 100644 --- a/backend/src/main/java/org/booklore/model/dto/request/MetadataRefreshOptions.java +++ b/backend/src/main/java/org/booklore/model/dto/request/MetadataRefreshOptions.java @@ -53,6 +53,7 @@ public class MetadataRefreshOptions { private FieldProvider categories; private FieldProvider cover; private FieldProvider pageCount; + private FieldProvider openlibraryId; private FieldProvider asin; private FieldProvider goodreadsId; private FieldProvider comicvineId; @@ -131,6 +132,8 @@ public class MetadataRefreshOptions { @Builder.Default @JsonSetter(nulls = Nulls.SKIP) private boolean pageCount = true; @Builder.Default @JsonSetter(nulls = Nulls.SKIP) + private boolean openlibraryId = true; + @Builder.Default @JsonSetter(nulls = Nulls.SKIP) private boolean asin = true; @Builder.Default @JsonSetter(nulls = Nulls.SKIP) private boolean goodreadsId = true; @@ -199,6 +202,7 @@ public class MetadataRefreshOptions { this.categories = true; this.cover = true; this.pageCount = true; + this.openlibraryId = true; this.asin = true; this.goodreadsId = true; this.comicvineId = true; diff --git a/backend/src/main/java/org/booklore/model/dto/settings/MetadataProviderSettings.java b/backend/src/main/java/org/booklore/model/dto/settings/MetadataProviderSettings.java index 15ac154d1..dfd1e5180 100644 --- a/backend/src/main/java/org/booklore/model/dto/settings/MetadataProviderSettings.java +++ b/backend/src/main/java/org/booklore/model/dto/settings/MetadataProviderSettings.java @@ -5,6 +5,7 @@ import lombok.Data; @Data public class MetadataProviderSettings { + private OpenLibrary openLibrary; private Amazon amazon; private Google google; private Goodreads goodReads; @@ -17,6 +18,11 @@ public class MetadataProviderSettings { private Audible audible; private AppleBooks appleBooks; + @Data + public static class OpenLibrary { + private boolean enabled; + } + @Data public static class Amazon { private boolean enabled; diff --git a/backend/src/main/java/org/booklore/model/dto/settings/MetadataProviderSpecificFields.java b/backend/src/main/java/org/booklore/model/dto/settings/MetadataProviderSpecificFields.java index 8f5a29c21..ff122320a 100644 --- a/backend/src/main/java/org/booklore/model/dto/settings/MetadataProviderSpecificFields.java +++ b/backend/src/main/java/org/booklore/model/dto/settings/MetadataProviderSpecificFields.java @@ -6,6 +6,7 @@ import lombok.NoArgsConstructor; @Data @NoArgsConstructor public class MetadataProviderSpecificFields { + private Boolean openlibraryId; private Boolean asin; private Boolean amazonRating; private Boolean amazonReviewCount; diff --git a/backend/src/main/java/org/booklore/model/dto/sidecar/SidecarIdentifiers.java b/backend/src/main/java/org/booklore/model/dto/sidecar/SidecarIdentifiers.java index 3d24dc405..cb1bc148f 100644 --- a/backend/src/main/java/org/booklore/model/dto/sidecar/SidecarIdentifiers.java +++ b/backend/src/main/java/org/booklore/model/dto/sidecar/SidecarIdentifiers.java @@ -22,4 +22,5 @@ public class SidecarIdentifiers { private String ranobedbId; private String audibleId; private String applebooksId; + private String openlibraryId; } diff --git a/backend/src/main/java/org/booklore/model/entity/BookMetadataEntity.java b/backend/src/main/java/org/booklore/model/entity/BookMetadataEntity.java index 5907a38f3..5eab4e4ad 100644 --- a/backend/src/main/java/org/booklore/model/entity/BookMetadataEntity.java +++ b/backend/src/main/java/org/booklore/model/entity/BookMetadataEntity.java @@ -96,6 +96,9 @@ public class BookMetadataEntity { @Column(name = "hardcover_review_count") private Integer hardcoverReviewCount; + @Column(name = "openlibrary_id", length = 100) + private String openlibraryId; + @Column(name = "asin", length = 10) private String asin; @@ -172,6 +175,10 @@ public class BookMetadataEntity { @Builder.Default private Boolean isbn10Locked = Boolean.FALSE; + @Column(name = "openlibrary_id_locked") + @Builder.Default + private Boolean openlibraryIdLocked = Boolean.FALSE; + @Column(name = "asin_locked") @Builder.Default private Boolean asinLocked = Boolean.FALSE; @@ -364,6 +371,7 @@ public class BookMetadataEntity { this.language = trimOrNull(this.language); this.isbn13 = trimOrNull(this.isbn13); this.isbn10 = trimOrNull(this.isbn10); + this.openlibraryId = trimOrNull(this.openlibraryId); this.asin = trimOrNull(this.asin); this.goodreadsId = trimOrNull(this.goodreadsId); this.hardcoverId = trimOrNull(this.hardcoverId); @@ -447,6 +455,7 @@ public class BookMetadataEntity { this.descriptionLocked = lock; this.isbn13Locked = lock; this.isbn10Locked = lock; + this.openlibraryIdLocked = lock; this.asinLocked = lock; this.pageCountLocked = lock; this.languageLocked = lock; @@ -498,6 +507,7 @@ public class BookMetadataEntity { && Boolean.TRUE.equals(this.descriptionLocked) && Boolean.TRUE.equals(this.isbn13Locked) && Boolean.TRUE.equals(this.isbn10Locked) + && Boolean.TRUE.equals(this.openlibraryIdLocked) && Boolean.TRUE.equals(this.asinLocked) && Boolean.TRUE.equals(this.pageCountLocked) && Boolean.TRUE.equals(this.languageLocked) diff --git a/backend/src/main/java/org/booklore/model/enums/MetadataProvider.java b/backend/src/main/java/org/booklore/model/enums/MetadataProvider.java index f8e5bfca7..7ace304a3 100644 --- a/backend/src/main/java/org/booklore/model/enums/MetadataProvider.java +++ b/backend/src/main/java/org/booklore/model/enums/MetadataProvider.java @@ -1,6 +1,7 @@ package org.booklore.model.enums; public enum MetadataProvider { + OpenLibrary, Amazon, GoodReads, Google, diff --git a/backend/src/main/java/org/booklore/service/BookRuleEvaluatorService.java b/backend/src/main/java/org/booklore/service/BookRuleEvaluatorService.java index f3fef3986..1d225bf13 100644 --- a/backend/src/main/java/org/booklore/service/BookRuleEvaluatorService.java +++ b/backend/src/main/java/org/booklore/service/BookRuleEvaluatorService.java @@ -270,7 +270,7 @@ public class BookRuleEvaluatorService { case "title", "subtitle", "description", "publisher", "language", "seriesName", "isbn13", "isbn10", "asin", "contentRating", "narrator", "goodreadsId", "hardcoverId", "googleId", "audibleId", "applebooksId", - "lubimyczytacId", "ranobedbId", "comicvineId" -> + "lubimyczytacId", "ranobedbId", "comicvineId", "openlibraryId" -> stringPresence(cb, root.get("metadata").get(metadataField)); // Numeric/date/boolean fields on BookMetadataEntity diff --git a/backend/src/main/java/org/booklore/service/SleepService.java b/backend/src/main/java/org/booklore/service/SleepService.java new file mode 100644 index 000000000..0b6ab21e0 --- /dev/null +++ b/backend/src/main/java/org/booklore/service/SleepService.java @@ -0,0 +1,16 @@ +package org.booklore.service; + +import org.springframework.stereotype.Service; + +import java.time.Duration; + +@Service +public class SleepService { + public void sleep(Duration duration) throws InterruptedException { + Thread.sleep(duration); + } + + public void sleep(long millis) throws InterruptedException { + Thread.sleep(millis); + } +} diff --git a/backend/src/main/java/org/booklore/service/appsettings/AppSettingService.java b/backend/src/main/java/org/booklore/service/appsettings/AppSettingService.java index 12472f3c6..3e17fc264 100644 --- a/backend/src/main/java/org/booklore/service/appsettings/AppSettingService.java +++ b/backend/src/main/java/org/booklore/service/appsettings/AppSettingService.java @@ -347,6 +347,9 @@ public class AppSettingService { private MetadataProviderSettings getDefaultMetadataProviderSettings() { MetadataProviderSettings defaultMetadataProviderSettings = new MetadataProviderSettings(); + MetadataProviderSettings.OpenLibrary defaultOpenLibrary = new MetadataProviderSettings.OpenLibrary(); + defaultOpenLibrary.setEnabled(false); + MetadataProviderSettings.Amazon defaultAmazon = new MetadataProviderSettings.Amazon(); defaultAmazon.setEnabled(true); defaultAmazon.setCookie(null); @@ -376,6 +379,7 @@ public class AppSettingService { defaultAppleBooks.setEnabled(false); defaultAppleBooks.setCountry("US"); + defaultMetadataProviderSettings.setOpenLibrary(defaultOpenLibrary); defaultMetadataProviderSettings.setAmazon(defaultAmazon); defaultMetadataProviderSettings.setGoogle(defaultGoogle); defaultMetadataProviderSettings.setGoodReads(defaultGoodreads); @@ -413,6 +417,7 @@ public class AppSettingService { .categories(goodreadsGoogleProvider) .cover(goodreadsGoogleProvider) .pageCount(goodreadsGoogleProvider) + .openlibraryId(nullProvider) .asin(nullProvider) .goodreadsId(nullProvider) .comicvineId(nullProvider) @@ -455,6 +460,7 @@ public class AppSettingService { .categories(true) .cover(true) .pageCount(true) + .openlibraryId(true) .asin(true) .goodreadsId(true) .comicvineId(true) @@ -608,6 +614,7 @@ public class AppSettingService { private MetadataProviderSpecificFields getDefaultMetadataProviderSpecificFields() { MetadataProviderSpecificFields fields = new MetadataProviderSpecificFields(); + fields.setOpenlibraryId(true); fields.setAsin(true); fields.setAmazonRating(true); fields.setAmazonReviewCount(true); diff --git a/backend/src/main/java/org/booklore/service/book/BookFileDetachmentService.java b/backend/src/main/java/org/booklore/service/book/BookFileDetachmentService.java index c752402ca..500e3daad 100644 --- a/backend/src/main/java/org/booklore/service/book/BookFileDetachmentService.java +++ b/backend/src/main/java/org/booklore/service/book/BookFileDetachmentService.java @@ -154,6 +154,7 @@ public class BookFileDetachmentService { copy.setRanobedbRating(source.getRanobedbRating()); copy.setAudibleRating(source.getAudibleRating()); copy.setAudibleReviewCount(source.getAudibleReviewCount()); + copy.setOpenlibraryId(source.getOpenlibraryId()); copy.setAsin(source.getAsin()); copy.setGoodreadsId(source.getGoodreadsId()); copy.setHardcoverId(source.getHardcoverId()); diff --git a/backend/src/main/java/org/booklore/service/book/BookQueryService.java b/backend/src/main/java/org/booklore/service/book/BookQueryService.java index 002c194a8..b1044779d 100644 --- a/backend/src/main/java/org/booklore/service/book/BookQueryService.java +++ b/backend/src/main/java/org/booklore/service/book/BookQueryService.java @@ -201,6 +201,7 @@ public class BookQueryService { m.setSeriesTotalLocked(null); m.setIsbn13Locked(null); m.setIsbn10Locked(null); + m.setOpenlibraryIdLocked(null); m.setAsinLocked(null); m.setGoodreadsIdLocked(null); m.setComicvineIdLocked(null); @@ -242,6 +243,7 @@ public class BookQueryService { m.setContentRatingLocked(null); // Strip external IDs + m.setOpenlibraryId(null); m.setAsin(null); m.setGoodreadsId(null); m.setComicvineId(null); @@ -338,7 +340,7 @@ public class BookQueryService { m.getTitleLocked(), m.getSubtitleLocked(), m.getPublisherLocked(), m.getPublishedDateLocked(), m.getDescriptionLocked(), m.getSeriesNameLocked(), m.getSeriesNumberLocked(), m.getSeriesTotalLocked(), m.getIsbn13Locked(), - m.getIsbn10Locked(), m.getAsinLocked(), m.getGoodreadsIdLocked(), + m.getIsbn10Locked(), m.getOpenlibraryIdLocked(), m.getAsinLocked(), m.getGoodreadsIdLocked(), m.getComicvineIdLocked(), m.getHardcoverIdLocked(), m.getHardcoverBookIdLocked(), m.getDoubanIdLocked(), m.getGoogleIdLocked(), m.getPageCountLocked(), m.getLanguageLocked(), m.getAmazonRatingLocked(), m.getAmazonReviewCountLocked(), diff --git a/backend/src/main/java/org/booklore/service/book/DuplicateDetectionService.java b/backend/src/main/java/org/booklore/service/book/DuplicateDetectionService.java index 6999ed87b..41c99ce43 100644 --- a/backend/src/main/java/org/booklore/service/book/DuplicateDetectionService.java +++ b/backend/src/main/java/org/booklore/service/book/DuplicateDetectionService.java @@ -141,6 +141,7 @@ public class DuplicateDetectionService { addIfPresent(ids, "audible:", meta.getAudibleId()); addIfPresent(ids, "comicvine:", meta.getComicvineId()); addIfPresent(ids, "applebooks:", meta.getApplebooksId()); + addIfPresent(ids, "openlibrary:", meta.getOpenlibraryId()); return ids; } diff --git a/backend/src/main/java/org/booklore/service/bookdrop/BookdropMetadataHelper.java b/backend/src/main/java/org/booklore/service/bookdrop/BookdropMetadataHelper.java index fdb8b214f..639f8e884 100644 --- a/backend/src/main/java/org/booklore/service/bookdrop/BookdropMetadataHelper.java +++ b/backend/src/main/java/org/booklore/service/bookdrop/BookdropMetadataHelper.java @@ -67,5 +67,6 @@ public class BookdropMetadataHelper { if (source.getIsbn13() != null) target.setIsbn13(source.getIsbn13()); if (source.getAsin() != null) target.setAsin(source.getAsin()); if (source.getApplebooksId() != null) target.setApplebooksId(source.getApplebooksId()); + if (source.getOpenlibraryId() != null) target.setOpenlibraryId(source.getOpenlibraryId()); } } diff --git a/backend/src/main/java/org/booklore/service/bookdrop/BookdropMetadataService.java b/backend/src/main/java/org/booklore/service/bookdrop/BookdropMetadataService.java index 68feef64b..b8ed0cb1f 100644 --- a/backend/src/main/java/org/booklore/service/bookdrop/BookdropMetadataService.java +++ b/backend/src/main/java/org/booklore/service/bookdrop/BookdropMetadataService.java @@ -121,6 +121,7 @@ public class BookdropMetadataService { m.getIsbn13(), m.getIsbn10(), m.getAsin(), m.getGoodreadsId(), m.getGoogleId(), m.getHardcoverId(), m.getHardcoverBookId(), + m.getOpenlibraryId(), m.getComicvineId(), m.getDoubanId(), m.getApplebooksId(), m.getLubimyczytacId(), m.getRanobedbId(), m.getAudibleId() ).anyMatch(id -> id != null && !id.isBlank()); @@ -156,6 +157,7 @@ public class BookdropMetadataService { // External IDs .asin(truncate(extracted.getAsin(), 10)) .audibleId(truncate(extracted.getAudibleId(), 10)) + .openlibraryId(truncate(extracted.getOpenlibraryId(), 100)) .goodreadsId(truncate(extracted.getGoodreadsId(), 100)) .hardcoverId(truncate(extracted.getHardcoverId(), 100)) .hardcoverBookId(truncate(extracted.getHardcoverBookId(), 100)) diff --git a/backend/src/main/java/org/booklore/service/fileprocessor/Azw3Processor.java b/backend/src/main/java/org/booklore/service/fileprocessor/Azw3Processor.java index 03e44552a..1d6c1485d 100644 --- a/backend/src/main/java/org/booklore/service/fileprocessor/Azw3Processor.java +++ b/backend/src/main/java/org/booklore/service/fileprocessor/Azw3Processor.java @@ -119,6 +119,7 @@ public class Azw3Processor extends AbstractFileProcessor implements BookFileProc String lang = azw3Metadata.getLanguage(); metadata.setLanguage(truncate((lang == null || "UND".equalsIgnoreCase(lang)) ? "en" : lang, 10)); + metadata.setOpenlibraryId(truncate(azw3Metadata.getOpenlibraryId(), 100)); metadata.setAsin(truncate(azw3Metadata.getAsin(), 10)); metadata.setAmazonRating(azw3Metadata.getAmazonRating()); metadata.setAmazonReviewCount(azw3Metadata.getAmazonReviewCount()); diff --git a/backend/src/main/java/org/booklore/service/fileprocessor/CbxProcessor.java b/backend/src/main/java/org/booklore/service/fileprocessor/CbxProcessor.java index 127ec8a31..3780c7e93 100644 --- a/backend/src/main/java/org/booklore/service/fileprocessor/CbxProcessor.java +++ b/backend/src/main/java/org/booklore/service/fileprocessor/CbxProcessor.java @@ -152,6 +152,7 @@ public class CbxProcessor extends AbstractFileProcessor implements BookFileProce metadata.setIsbn10(truncate(extracted.getIsbn10(), 10)); // External IDs + metadata.setOpenlibraryId(truncate(extracted.getOpenlibraryId(), 100)); metadata.setAsin(truncate(extracted.getAsin(), 10)); metadata.setGoodreadsId(truncate(extracted.getGoodreadsId(), 100)); metadata.setHardcoverId(truncate(extracted.getHardcoverId(), 100)); diff --git a/backend/src/main/java/org/booklore/service/fileprocessor/EpubProcessor.java b/backend/src/main/java/org/booklore/service/fileprocessor/EpubProcessor.java index 103d7bde0..5bd269d1d 100644 --- a/backend/src/main/java/org/booklore/service/fileprocessor/EpubProcessor.java +++ b/backend/src/main/java/org/booklore/service/fileprocessor/EpubProcessor.java @@ -128,6 +128,7 @@ public class EpubProcessor extends AbstractFileProcessor implements BookFileProc String lang = epubMetadata.getLanguage(); metadata.setLanguage(truncate((lang == null || "UND".equalsIgnoreCase(lang)) ? "en" : lang, 10)); + metadata.setOpenlibraryId(truncate(epubMetadata.getOpenlibraryId(), 100)); metadata.setAsin(truncate(epubMetadata.getAsin(), 10)); metadata.setAmazonRating(epubMetadata.getAmazonRating()); metadata.setAmazonReviewCount(epubMetadata.getAmazonReviewCount()); diff --git a/backend/src/main/java/org/booklore/service/fileprocessor/Fb2Processor.java b/backend/src/main/java/org/booklore/service/fileprocessor/Fb2Processor.java index d77876794..3d49dc25c 100644 --- a/backend/src/main/java/org/booklore/service/fileprocessor/Fb2Processor.java +++ b/backend/src/main/java/org/booklore/service/fileprocessor/Fb2Processor.java @@ -115,6 +115,7 @@ public class Fb2Processor extends AbstractFileProcessor implements BookFileProce String lang = fb2Metadata.getLanguage(); metadata.setLanguage(truncate((lang == null || "UND".equalsIgnoreCase(lang)) ? "en" : lang, 10)); + metadata.setOpenlibraryId(truncate(fb2Metadata.getOpenlibraryId(), 100)); metadata.setAsin(truncate(fb2Metadata.getAsin(), 10)); metadata.setAmazonRating(fb2Metadata.getAmazonRating()); metadata.setAmazonReviewCount(fb2Metadata.getAmazonReviewCount()); diff --git a/backend/src/main/java/org/booklore/service/fileprocessor/MobiProcessor.java b/backend/src/main/java/org/booklore/service/fileprocessor/MobiProcessor.java index e4931f70d..276096be9 100644 --- a/backend/src/main/java/org/booklore/service/fileprocessor/MobiProcessor.java +++ b/backend/src/main/java/org/booklore/service/fileprocessor/MobiProcessor.java @@ -120,6 +120,7 @@ public class MobiProcessor extends AbstractFileProcessor implements BookFileProc String lang = mobiMetadata.getLanguage(); metadata.setLanguage(truncate((lang == null || "UND".equalsIgnoreCase(lang)) ? "en" : lang, 10)); + metadata.setOpenlibraryId(truncate(mobiMetadata.getOpenlibraryId(), 100)); metadata.setAsin(truncate(mobiMetadata.getAsin(), 10)); metadata.setAmazonRating(mobiMetadata.getAmazonRating()); metadata.setAmazonReviewCount(mobiMetadata.getAmazonReviewCount()); diff --git a/backend/src/main/java/org/booklore/service/fileprocessor/PdfProcessor.java b/backend/src/main/java/org/booklore/service/fileprocessor/PdfProcessor.java index adfafcbc3..bd3b4ae20 100644 --- a/backend/src/main/java/org/booklore/service/fileprocessor/PdfProcessor.java +++ b/backend/src/main/java/org/booklore/service/fileprocessor/PdfProcessor.java @@ -137,6 +137,9 @@ public class PdfProcessor extends AbstractFileProcessor implements BookFileProce } // External IDs + if (StringUtils.isNotBlank(extracted.getOpenlibraryId())) { + bookEntity.getMetadata().setOpenlibraryId(truncate(extracted.getOpenlibraryId(), 100)); + } if (StringUtils.isNotBlank(extracted.getAsin())) { bookEntity.getMetadata().setAsin(truncate(extracted.getAsin(), 10)); } diff --git a/backend/src/main/java/org/booklore/service/kobo/CbxConversionService.java b/backend/src/main/java/org/booklore/service/kobo/CbxConversionService.java index 74a51938e..ed04e0d74 100644 --- a/backend/src/main/java/org/booklore/service/kobo/CbxConversionService.java +++ b/backend/src/main/java/org/booklore/service/kobo/CbxConversionService.java @@ -500,6 +500,9 @@ public class CbxConversionService { if (metadata.getAsin() != null && !metadata.getAsin().trim().isEmpty()) { model.put("asin", metadata.getAsin()); } + if (metadata.getOpenlibraryId() != null && !metadata.getOpenlibraryId().trim().isEmpty()) { + model.put("openlibraryId", metadata.getOpenlibraryId()); + } if (metadata.getGoodreadsId() != null && !metadata.getGoodreadsId().trim().isEmpty()) { model.put("goodreadsId", metadata.getGoodreadsId()); } diff --git a/backend/src/main/java/org/booklore/service/metadata/BookMetadataUpdater.java b/backend/src/main/java/org/booklore/service/metadata/BookMetadataUpdater.java index 8d87574d3..496756bf3 100644 --- a/backend/src/main/java/org/booklore/service/metadata/BookMetadataUpdater.java +++ b/backend/src/main/java/org/booklore/service/metadata/BookMetadataUpdater.java @@ -188,6 +188,7 @@ public class BookMetadataUpdater { handleFieldUpdate(e.getSeriesTotalLocked(), clear.isSeriesTotal(), m.getSeriesTotal(), e::setSeriesTotal, e::getSeriesTotal, replaceMode); handleFieldUpdate(e.getIsbn13Locked(), clear.isIsbn13(), m.getIsbn13(), v -> e.setIsbn13(nullIfBlank(v)), e::getIsbn13, replaceMode); handleFieldUpdate(e.getIsbn10Locked(), clear.isIsbn10(), m.getIsbn10(), v -> e.setIsbn10(nullIfBlank(v)), e::getIsbn10, replaceMode); + handleFieldUpdate(e.getOpenlibraryIdLocked(), clear.isOpenlibraryId(), m.getOpenlibraryId(), v -> e.setOpenlibraryId(nullIfBlank(v)), e::getOpenlibraryId, replaceMode); handleFieldUpdate(e.getAsinLocked(), clear.isAsin(), m.getAsin(), v -> e.setAsin(nullIfBlank(v)), e::getAsin, replaceMode); handleFieldUpdate(e.getGoodreadsIdLocked(), clear.isGoodreadsId(), m.getGoodreadsId(), v -> e.setGoodreadsId(nullIfBlank(v)), e::getGoodreadsId, replaceMode); handleFieldUpdate(e.getComicvineIdLocked(), clear.isComicvineId(), m.getComicvineId(), v -> e.setComicvineId(nullIfBlank(v)), e::getComicvineId, replaceMode); @@ -696,6 +697,7 @@ public class BookMetadataUpdater { Pair.of(m.getSeriesTotalLocked(), e::setSeriesTotalLocked), Pair.of(m.getIsbn13Locked(), e::setIsbn13Locked), Pair.of(m.getIsbn10Locked(), e::setIsbn10Locked), + Pair.of(m.getOpenlibraryIdLocked(), e::setOpenlibraryIdLocked), Pair.of(m.getAsinLocked(), e::setAsinLocked), Pair.of(m.getGoodreadsIdLocked(), e::setGoodreadsIdLocked), Pair.of(m.getComicvineIdLocked(), e::setComicvineIdLocked), diff --git a/backend/src/main/java/org/booklore/service/metadata/MetadataRefreshService.java b/backend/src/main/java/org/booklore/service/metadata/MetadataRefreshService.java index 2bc6f6426..e8924dbd0 100644 --- a/backend/src/main/java/org/booklore/service/metadata/MetadataRefreshService.java +++ b/backend/src/main/java/org/booklore/service/metadata/MetadataRefreshService.java @@ -350,6 +350,7 @@ public class MetadataRefreshService { addProviderToSet(fieldOptions.getCategories(), uniqueProviders, appSettings); addProviderToSet(fieldOptions.getCover(), uniqueProviders, appSettings); addProviderToSet(fieldOptions.getPageCount(), uniqueProviders, appSettings); + addProviderToSet(fieldOptions.getOpenlibraryId(), uniqueProviders, appSettings); addProviderToSet(fieldOptions.getAsin(), uniqueProviders, appSettings); addProviderToSet(fieldOptions.getGoodreadsId(), uniqueProviders, appSettings); addProviderToSet(fieldOptions.getComicvineId(), uniqueProviders, appSettings); @@ -394,6 +395,7 @@ public class MetadataRefreshService { var settings = appSettings.getMetadataProviderSettings(); return switch (provider) { + case OpenLibrary -> settings.getOpenLibrary() != null && settings.getOpenLibrary().isEnabled(); case Amazon -> settings.getAmazon() != null && settings.getAmazon().isEnabled(); case Google -> settings.getGoogle() != null && settings.getGoogle().isEnabled(); case GoodReads -> settings.getGoodReads() != null && settings.getGoodReads().isEnabled(); @@ -587,6 +589,14 @@ public class MetadataRefreshService { metadata.setHardcoverReviewCount(existingMetadata.getHardcoverReviewCount()); } + if (enabledFields.isOpenlibraryId()) { + if (metadataMap.containsKey(OpenLibrary)) { + metadata.setOpenlibraryId(metadataMap.get(OpenLibrary).getOpenlibraryId()); + } + } else if (isReplaceAll && existingMetadata != null) { + metadata.setOpenlibraryId(existingMetadata.getOpenlibraryId()); + } + if (enabledFields.isAsin()) { if (metadataMap.containsKey(Amazon)) { metadata.setAsin(metadataMap.get(Amazon).getAsin()); @@ -764,6 +774,7 @@ public class MetadataRefreshService { metadata.setLanguageLocked(existingMetadata.getLanguageLocked()); metadata.setCoverLocked(existingMetadata.getCoverLocked()); metadata.setAudiobookCoverLocked(existingMetadata.getAudiobookCoverLocked()); + metadata.setOpenlibraryIdLocked(existingMetadata.getOpenlibraryIdLocked()); metadata.setAsinLocked(existingMetadata.getAsinLocked()); metadata.setGoodreadsIdLocked(existingMetadata.getGoodreadsIdLocked()); metadata.setComicvineIdLocked(existingMetadata.getComicvineIdLocked()); diff --git a/backend/src/main/java/org/booklore/service/metadata/extractor/CbxMetadataExtractor.java b/backend/src/main/java/org/booklore/service/metadata/extractor/CbxMetadataExtractor.java index 01fbe9ab6..2c3fb8872 100644 --- a/backend/src/main/java/org/booklore/service/metadata/extractor/CbxMetadataExtractor.java +++ b/backend/src/main/java/org/booklore/service/metadata/extractor/CbxMetadataExtractor.java @@ -37,6 +37,7 @@ public class CbxMetadataExtractor implements FileMetadataExtractor { private static final Pattern WEB_SPLIT_PATTERN = Pattern.compile("[,;\\s]+"); // URL Patterns + private static final Pattern OPENLIBRARY_URL_PATTERN = Pattern.compile("openlibrary\\.org(/[^/]+/[^/]+)"); private static final Pattern GOODREADS_URL_PATTERN = Pattern.compile("goodreads\\.com/book/show/(\\d+)(?:-[\\w-]+)?"); private static final Pattern AMAZON_URL_PATTERN = Pattern.compile("amazon\\.com/dp/([A-Z0-9]{10})"); private static final Pattern COMICVINE_URL_PATTERN = Pattern.compile("comicvine\\.gamespot\\.com/(?:issue|volume)/(?:[^/]+/)?(\\d+-\\d+)"); @@ -308,6 +309,12 @@ public class CbxMetadataExtractor implements FileMetadataExtractor { if (url.isBlank()) continue; url = url.trim(); + Matcher olMatcher = OPENLIBRARY_URL_PATTERN.matcher(url); + if (olMatcher.find()) { + builder.openlibraryId(olMatcher.group(1)); + continue; + } + Matcher grMatcher = GOODREADS_URL_PATTERN.matcher(url); if (grMatcher.find()) { builder.goodreadsId(grMatcher.group(1)); @@ -379,6 +386,7 @@ public class CbxMetadataExtractor implements FileMetadataExtractor { case "RanobedbId" -> builder.ranobedbId(value); case "GoogleId" -> builder.googleId(value); case "GoodreadsId" -> builder.goodreadsId(value); + case "OpenlibraryId" -> builder.openlibraryId(value); case "ASIN" -> builder.asin(value); case "ComicvineId" -> builder.comicvineId(value); case "ApplebooksId" -> builder.applebooksId(value); diff --git a/backend/src/main/java/org/booklore/service/metadata/extractor/EpubMetadataExtractor.java b/backend/src/main/java/org/booklore/service/metadata/extractor/EpubMetadataExtractor.java index 84722a603..6e2dda99a 100644 --- a/backend/src/main/java/org/booklore/service/metadata/extractor/EpubMetadataExtractor.java +++ b/backend/src/main/java/org/booklore/service/metadata/extractor/EpubMetadataExtractor.java @@ -50,6 +50,7 @@ public class EpubMetadataExtractor implements FileMetadataExtractor { Map.entry("amazon", BookMetadata.BookMetadataBuilder::asin), Map.entry("asin", BookMetadata.BookMetadataBuilder::asin), Map.entry("mobi-asin", BookMetadata.BookMetadataBuilder::asin), + Map.entry("openlibrary", BookMetadata.BookMetadataBuilder::openlibraryId), Map.entry("goodreads", BookMetadata.BookMetadataBuilder::goodreadsId), Map.entry("google", BookMetadata.BookMetadataBuilder::googleId), Map.entry("hardcover", BookMetadata.BookMetadataBuilder::hardcoverId), @@ -218,6 +219,7 @@ public class EpubMetadataExtractor implements FileMetadataExtractor { switch (key) { case BookLoreMetadata.NS_PREFIX + ":asin" -> builderMeta.asin(content); + case BookLoreMetadata.NS_PREFIX + ":openlibrary_id" -> builderMeta.openlibraryId(content); case BookLoreMetadata.NS_PREFIX + ":goodreads_id" -> builderMeta.goodreadsId(content); case BookLoreMetadata.NS_PREFIX + ":comicvine_id" -> builderMeta.comicvineId(content); case BookLoreMetadata.NS_PREFIX + ":ranobedb_id" -> builderMeta.ranobedbId(content); @@ -315,6 +317,7 @@ public class EpubMetadataExtractor implements FileMetadataExtractor { if (cleanValue.length() == 13) builderMeta.isbn13(value); else if (cleanValue.length() == 10) builderMeta.isbn10(value); } + case "OPENLIBRARY" -> builderMeta.openlibraryId(value); case "GOODREADS" -> builderMeta.goodreadsId(value); case "COMICVINE" -> builderMeta.comicvineId(value); case "RANOBEDB" -> builderMeta.ranobedbId(value); diff --git a/backend/src/main/java/org/booklore/service/metadata/extractor/PdfMetadataExtractor.java b/backend/src/main/java/org/booklore/service/metadata/extractor/PdfMetadataExtractor.java index 355983a7e..c41484f23 100644 --- a/backend/src/main/java/org/booklore/service/metadata/extractor/PdfMetadataExtractor.java +++ b/backend/src/main/java/org/booklore/service/metadata/extractor/PdfMetadataExtractor.java @@ -209,6 +209,7 @@ public class PdfMetadataExtractor implements FileMetadataExtractor { findCustomField(xmp, rawXmp, "isbn10").ifPresent(val -> metadataBuilder.isbn10(cleanIsbn(val))); findCustomField(xmp, rawXmp, "googleId").ifPresent(metadataBuilder::googleId); findCustomField(xmp, rawXmp, "goodreadsId").ifPresent(metadataBuilder::goodreadsId); + findCustomField(xmp, rawXmp, "openlibraryId").ifPresent(metadataBuilder::openlibraryId); findCustomField(xmp, rawXmp, "amazonId").ifPresent(metadataBuilder::asin); findCustomField(xmp, rawXmp, "asin").ifPresent(metadataBuilder::asin); findCustomField(xmp, rawXmp, "comicvineId").ifPresent(metadataBuilder::comicvineId); @@ -233,6 +234,7 @@ public class PdfMetadataExtractor implements FileMetadataExtractor { case "isbn10" -> metadataBuilder.isbn10(cleanIsbn(value)); case "google" -> metadataBuilder.googleId(value); case "amazon", "asin", "amazonid" -> metadataBuilder.asin(value); + case "openlibrary" -> metadataBuilder.openlibraryId(value); case "goodreads" -> metadataBuilder.goodreadsId(value); case "comicvine" -> metadataBuilder.comicvineId(value); case "ranobedb" -> metadataBuilder.ranobedbId(value); diff --git a/backend/src/main/java/org/booklore/service/metadata/parser/OpenLibraryParser.java b/backend/src/main/java/org/booklore/service/metadata/parser/OpenLibraryParser.java new file mode 100644 index 000000000..542bceb02 --- /dev/null +++ b/backend/src/main/java/org/booklore/service/metadata/parser/OpenLibraryParser.java @@ -0,0 +1,569 @@ +package org.booklore.service.metadata.parser; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.booklore.model.dto.Book; +import org.booklore.model.dto.BookMetadata; +import org.booklore.model.dto.request.FetchMetadataRequest; +import org.booklore.model.enums.MetadataProvider; +import org.booklore.service.SleepService; +import org.springframework.stereotype.Service; +import org.springframework.util.MultiValueMap; +import org.springframework.web.util.UriComponentsBuilder; +import reactor.core.publisher.Flux; +import tools.jackson.core.JacksonException; +import tools.jackson.core.JsonParser; +import tools.jackson.databind.DatabindException; +import tools.jackson.databind.DeserializationContext; +import tools.jackson.databind.JsonNode; +import tools.jackson.databind.ObjectMapper; +import tools.jackson.databind.annotation.JsonDeserialize; +import tools.jackson.databind.deser.std.StdDeserializer; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.util.*; +import java.util.concurrent.atomic.AtomicLong; + +@Slf4j +@Service +@RequiredArgsConstructor +public class OpenLibraryParser implements BookParser { + // The OpenLibrary rate limit for their API is 180/minute. + // We set ours to 160/m to reduce the chance of hitting 429s + // https://github.com/internetarchive/openlibrary/blob/master/docker/nginx.conf#L99 + private static final int REQUEST_RATE_LIMIT = 160; + private static final int RATE_LIMIT_PER = 60000; + + // https://github.com/internetarchive/openlibrary/blob/master/openlibrary/plugins/openlibrary/config/edition/identifiers.yml + private static final String IDENTIFIER_GOODREADS = "goodreads"; + private static final String IDENTIFIER_GOOGLE = "google"; + private static final String IDENTIFIER_AMAZON = "amazon"; + + private static final String COVERS_BASE_URI = "https://covers.openlibrary.org/"; + private static final String COVER_PATH = "/b/id/{cover_id}-{size}.jpg"; + + private static final String BASE_URI = "https://openlibrary.org/"; + private static final String SEARCH_PATH = "/search.json"; + private static final String WORKS_PATH = "/works/{work_id}.json"; + private static final String SERIES_PATH = "/series/{series_id}.json"; + private static final String EDITIONS_PATH = "/books/{edition_id}.json"; + private static final String AUTHORS_PATH = "/authors/{author_id}.json"; + + private static final String SEARCH_FIELDS = "key,author_key,editions,editions.key"; + private static final String USER_AGENT = "Grimmory (developers@grimmory.org)"; + + // Public because it has to be for Jackson to use it. + public static class OpenLibraryTypedValueDeserializer extends StdDeserializer { + public OpenLibraryTypedValueDeserializer() { + super(OpenLibraryTypedValue.class); + } + + @Override + public OpenLibraryTypedValue deserialize(JsonParser p, DeserializationContext ctxt) throws JacksonException { + JsonNode node = p.readValueAsTree(); + + JsonNode typeNode = node.get("type"); + JsonNode valueNode = node.get("value"); + + try { + if (typeNode != null && !typeNode.isNull() && valueNode != null && !valueNode.isNull()) { + return new OpenLibraryTypedValue( + typeNode.stringValue(), + valueNode.stringValue() + ); + } + } catch (DatabindException e) { + // Do nothing + } + + try { + String value = node.stringValue(); + return new OpenLibraryTypedValue("/type/text", value); + } catch (DatabindException e) { + // Do nothing + } + + return null; + } + } + + @JsonDeserialize(using = OpenLibraryTypedValueDeserializer.class) + record OpenLibraryTypedValue( + String type, + String value + ) {} + + record OpenLibraryReference( + String key + ) {} + + record OpenLibrarySearchDocumentEditions( + Optional numFound, + Optional> docs + ) {} + + record OpenLibrarySearchDocument( + String key, + @JsonProperty("author_key") + Optional> authorKey, + Optional editions + ) {} + + record OpenLibrarySearchResult( + int numFound, + List docs + ) {} + + record OpenLibraryAuthor( + String key, + OpenLibraryReference type, + String name + ) {} + + record OpenLibraryEdition( + String key, + OpenLibraryReference type, + String title, + Optional subtitle, + Optional description, + List languages, + List authors, + List works, + Optional>> identifiers, + Optional> publishers, + @JsonProperty("publish_date") + Optional publishDate, + @JsonProperty("edition_name") + String editionName, + @JsonProperty("number_of_pages") + Optional pageCount, + @JsonProperty("isbn_10") + Optional> isbn10, + @JsonProperty("isbn_13") + Optional> isbn13, + Optional> covers + ) { + String getIdentifier(String name) { + return this.identifiers.flatMap( + i -> i.getOrDefault(name, List.of()) + .stream().findFirst() + ).orElse(null); + } + } + + record OpenLibrarySeries( + OpenLibraryReference type, + String name, + Optional description + ) {} + + record OpenLibraryWorkAuthor( + OpenLibraryReference type, + OpenLibraryReference author + ) {} + + record OpenLibraryWorkSeries( + String position, + OpenLibraryReference series + ) {} + + record OpenLibraryWork ( + String key, + OpenLibraryReference type, + String title, + Optional subtitle, + Optional description, + List authors, + Optional> series, + List subjects, + Optional> covers, + OpenLibraryTypedValue created, + @JsonProperty("last_modified") + OpenLibraryTypedValue lastModified + ) {} + + private final HttpClient httpClient; + private final ObjectMapper objectMapper; + private final SleepService sleepService; + + private long rateLimitResetTime = 0; + private long rateLimitCounter = 0; + + private URI getURI(String path) { + return getURI(path, Map.of(), Map.of()); + } + + private URI getURI(String path, Map pathParameters, Map queryParameters) { + return UriComponentsBuilder.fromUriString(BASE_URI) + .path(path) + .queryParams(MultiValueMap.fromSingleValue(queryParameters)) + .build(pathParameters); + } + + private synchronized void applyRateLimit() throws InterruptedException { + long now = System.currentTimeMillis(); + + if (rateLimitResetTime < now) { + rateLimitCounter = 0; + rateLimitResetTime = now + RATE_LIMIT_PER; + } + + if (rateLimitCounter >= REQUEST_RATE_LIMIT) { + // Slow down. + try { + sleepService.sleep(Math.max(0, rateLimitResetTime - now)); + } finally { + rateLimitResetTime = System.currentTimeMillis() + RATE_LIMIT_PER; + rateLimitCounter = 0; + } + } else { + rateLimitCounter++; + } + } + + private T sendRequest(HttpRequest request, Class tClass) throws InterruptedException { + request = HttpRequest.newBuilder(request, (n, v) -> !n.equalsIgnoreCase("User-Agent")) + .header("User-Agent", USER_AGENT) + .build(); + + log.debug("Making request: {}", request.uri().toString()); + + applyRateLimit(); + + try { + HttpResponse response = httpClient.send(request, HttpResponse.BodyHandlers.ofInputStream()); + + if (response.statusCode() < 200 || response.statusCode() > 399) { + log.error("OpenLibrary request failed with status code: {}", response.statusCode()); + throw new RuntimeException("Failed to query OpenLibrary"); + } + + log.debug("Request success with code {}", response.statusCode()); + + try (InputStream stream = response.body()) { + return objectMapper.readValue(stream, tClass); + } + } catch (IOException e) { + log.error("OpenLibrary request failed", e); + throw new RuntimeException(e); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw e; + } + } + + private String escapeSolrValue(String value) { + return value.replaceAll("[-+&|!(){}\\[\\]^\"~*?:\\\\/]", "\\\\$0"); + } + + private String getSolrQuery(List predicates, boolean isConjunction) { + predicates = predicates.stream().filter(p -> !p.isBlank()).toList(); + + if (predicates.isEmpty()) { + return ""; + } + + return "(" + String.join(isConjunction ? " AND " : " OR ", predicates) + ")"; + } + + private String getSolrAuthorTitleQuery(FetchMetadataRequest fetchMetadataRequest) { + List predicates = new ArrayList<>(); + + if (fetchMetadataRequest.getTitle() != null && !fetchMetadataRequest.getTitle().isBlank()) { + predicates.add("title:" + escapeSolrValue(fetchMetadataRequest.getTitle())); + } + + if (fetchMetadataRequest.getAuthor() != null && !fetchMetadataRequest.getAuthor().isBlank()) { + predicates.add("author_name:" + escapeSolrValue(fetchMetadataRequest.getAuthor())); + } + + return getSolrQuery(predicates, true); + } + + private String getSolrQuery(FetchMetadataRequest fetchMetadataRequest) { + List predicates = new ArrayList<>(); + + predicates.add(getSolrAuthorTitleQuery(fetchMetadataRequest)); + + if (fetchMetadataRequest.getIsbn() != null && !fetchMetadataRequest.getIsbn().isBlank()) { + predicates.add("isbn:" + escapeSolrValue(fetchMetadataRequest.getIsbn())); + } + + return getSolrQuery(predicates, false); + } + + private OpenLibrarySearchResult search(FetchMetadataRequest fetchMetadataRequest, int limit) throws InterruptedException { + String solrQuery = getSolrQuery(fetchMetadataRequest); + + if (solrQuery.isEmpty()) { + // Empty query means no results. + log.info("No search query available"); + return new OpenLibrarySearchResult(0, List.of()); + } + + URI uri = getURI( + SEARCH_PATH, + Map.of(), + Map.of( + "q", solrQuery, + "fields", SEARCH_FIELDS, + "limit", String.valueOf(limit) + ) + ); + + HttpRequest request = HttpRequest.newBuilder() + .uri(uri) + .GET() + .build(); + + return sendRequest(request, OpenLibrarySearchResult.class); + } + + private String getId(String type, String reference) { + String[] parts = reference.split("/"); + + if (parts.length != 3 || !parts[1].equalsIgnoreCase(type)) { + throw new RuntimeException("Wrong key type"); + } + + return parts[2]; + } + + private OpenLibraryAuthor getAuthor(String reference) throws InterruptedException { + String id = getId("authors", reference); + + URI uri = getURI(AUTHORS_PATH, Map.of("author_id", id), Map.of()); + + HttpRequest request = HttpRequest.newBuilder() + .uri(uri) + .GET() + .build(); + + return sendRequest(request, OpenLibraryAuthor.class); + } + + private OpenLibraryEdition getEdition(String reference) throws InterruptedException { + String id = getId("books", reference); + + URI uri = getURI(EDITIONS_PATH, Map.of("edition_id", id), Map.of()); + + HttpRequest request = HttpRequest.newBuilder() + .uri(uri) + .GET() + .build(); + + return sendRequest(request, OpenLibraryEdition.class); + } + + private OpenLibrarySeries getSeries(String reference) throws InterruptedException { + String id = getId("series", reference); + + URI uri = getURI(SERIES_PATH, Map.of("series_id", id), Map.of()); + + HttpRequest request = HttpRequest.newBuilder() + .uri(uri) + .GET() + .build(); + + return sendRequest(request, OpenLibrarySeries.class); + } + + private OpenLibraryWork getWork(String reference) throws InterruptedException { + String id = getId("works", reference); + + URI uri = getURI(WORKS_PATH, Map.of("work_id", id), Map.of()); + + HttpRequest request = HttpRequest.newBuilder() + .uri(uri) + .GET() + .build(); + + return sendRequest(request, OpenLibraryWork.class); + } + + private Optional getCoverUri( + Integer coverId, + String size + ) { + if (coverId == null || size == null) { + return Optional.empty(); + } + + return Optional.of(UriComponentsBuilder.fromUriString(COVERS_BASE_URI) + .path(COVER_PATH) + .build(Map.of("cover_id", coverId, "size", size))); + } + + private Optional getCoverUri( + OpenLibraryWork work, + OpenLibraryEdition edition, + String size + ) { + if (edition != null) { + Integer editionCoverId = edition.covers.flatMap(c -> c.stream().findFirst()).orElse(null); + if (editionCoverId != null) { + return getCoverUri( + editionCoverId, + size + ); + } + } + + Integer workCoverId = work.covers.flatMap(c -> c.stream().findFirst()).orElse(null); + if (workCoverId != null) { + return getCoverUri( + workCoverId, + size + ); + } + + return Optional.empty(); + } + + private BookMetadata toMetadata( + OpenLibraryWork work, + OpenLibrarySeries series, + OpenLibraryEdition edition, + List authors + ) { + var builder = BookMetadata.builder() + .provider(MetadataProvider.OpenLibrary) + .description(work.description.map(OpenLibraryTypedValue::value).orElse(null)) + .authors(authors.stream().map(a -> a.name).toList()) + .thumbnailUrl(getCoverUri(work, edition, "M").map(URI::toString).orElse(null)); + + if (series != null) { + builder.seriesName(series.name); + } + + if (!work.series.map(List::isEmpty).orElse(true)) { + String[] position = work.series.get().getFirst().position.split("-"); + if (position.length == 2) { + try { + Float seriesNumber = Float.valueOf(position[0]); + Integer seriesTotal = Integer.valueOf(position[1]); + + builder + .seriesNumber(seriesNumber) + .seriesTotal(seriesTotal); + } catch (NumberFormatException e) { + // Do nothing + } + } + } + + if (edition != null) { + builder + .externalUrl(getURI(edition.key).toString()) + .title(edition.title) + .subtitle(edition.subtitle.orElse(null)) + .openlibraryId(edition.key) + .publisher(edition.publishers.flatMap(p -> p.stream().findFirst()).orElse(null)) + .isbn10(edition.isbn10.flatMap(i -> i.stream().findFirst()).orElse(null)) + .isbn13(edition.isbn13.flatMap(i -> i.stream().findFirst()).orElse(null)) + .pageCount(edition.pageCount.orElse(null)) + .goodreadsId(edition.getIdentifier(IDENTIFIER_GOODREADS)) + .googleId(edition.getIdentifier(IDENTIFIER_GOOGLE)) + .asin(edition.getIdentifier(IDENTIFIER_AMAZON)); + } else { + builder + .externalUrl(getURI(work.key).toString()) + .openlibraryId(work.key) + .title(work.title) + .subtitle(work.subtitle.orElse(null)); + } + + return builder.build(); + } + + @Override + public List fetchMetadata(Book book, FetchMetadataRequest fetchMetadataRequest) { + return fetchMetadataStream(book, fetchMetadataRequest).collectList().block(); + } + + public Flux fetchMetadataStream(Book book, FetchMetadataRequest fetchMetadataRequest) { + return fetchMetadataStream(book, fetchMetadataRequest, 10); + } + + public Flux fetchMetadataStream(Book book, FetchMetadataRequest fetchMetadataRequest, int limit) { + return Flux.create(sink -> { + try { + OpenLibrarySearchResult searchResponse = search(fetchMetadataRequest, limit); + + log.debug("Found {} total results, using {}", searchResponse.numFound, searchResponse.docs.size()); + + Map seenAuthors = new HashMap<>(); + + for (OpenLibrarySearchDocument document : searchResponse.docs) { + if (sink.isCancelled()) { + return; + } + + log.debug("OpenLibrary: Fetching metadata for Work: {}", document.key); + + try { + OpenLibraryWork work = this.getWork(document.key); + + OpenLibrarySeries series = null; + + if (!work.series.map(List::isEmpty).orElse(true)) { + series = this.getSeries(work.series.get().getFirst().series.key); + } + + OpenLibraryEdition edition = null; + + var editionDocs = document.editions + .flatMap(e -> e.docs) + .orElseGet(List::of); + + if (!editionDocs.isEmpty()) { + edition = this.getEdition(editionDocs.getFirst().key); + } + + List authors = new ArrayList<>(); + for (String authorKey : document.authorKey.orElse(List.of())) { + if (seenAuthors.containsKey(authorKey)) { + authors.add(seenAuthors.get(authorKey)); + } else { + OpenLibraryAuthor author = this.getAuthor("/authors/" + authorKey); + seenAuthors.put(authorKey, author); + authors.add(author); + } + } + + BookMetadata metadata = this.toMetadata( + work, + series, + edition, + authors + ); + if (metadata != null) { + sink.next(metadata); + } + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw e; + } catch (Exception e) { + log.error("Error fetching metadata for Work: {}", document.key, e); + } + } + + sink.complete(); + } catch (Exception e) { + sink.error(e); + } + }); + } + + @Override + public BookMetadata fetchTopMetadata(Book book, FetchMetadataRequest fetchMetadataRequest) { + return fetchMetadataStream(book, fetchMetadataRequest, 1).blockFirst(); + } +} diff --git a/backend/src/main/java/org/booklore/service/metadata/sidecar/SidecarMetadataMapper.java b/backend/src/main/java/org/booklore/service/metadata/sidecar/SidecarMetadataMapper.java index c0785e65e..b90ff886f 100644 --- a/backend/src/main/java/org/booklore/service/metadata/sidecar/SidecarMetadataMapper.java +++ b/backend/src/main/java/org/booklore/service/metadata/sidecar/SidecarMetadataMapper.java @@ -100,6 +100,7 @@ public class SidecarMetadataMapper { if (m.getIdentifiers() != null) { SidecarIdentifiers ids = m.getIdentifiers(); builder.asin(ids.getAsin()) + .openlibraryId(ids.getOpenlibraryId()) .goodreadsId(ids.getGoodreadsId()) .googleId(ids.getGoogleId()) .hardcoverId(ids.getHardcoverId()) @@ -202,6 +203,7 @@ public class SidecarMetadataMapper { .ranobedbId(entity.getRanobedbId()) .audibleId(entity.getAudibleId()) .applebooksId(entity.getApplebooksId()) + .openlibraryId(entity.getOpenlibraryId()) .build(); } diff --git a/backend/src/main/java/org/booklore/service/metadata/writer/CbxMetadataWriter.java b/backend/src/main/java/org/booklore/service/metadata/writer/CbxMetadataWriter.java index 3dc170fb3..b4d901405 100644 --- a/backend/src/main/java/org/booklore/service/metadata/writer/CbxMetadataWriter.java +++ b/backend/src/main/java/org/booklore/service/metadata/writer/CbxMetadataWriter.java @@ -245,6 +245,8 @@ public class CbxMetadataWriter implements MetadataWriter { primaryUrl = "https://www.amazon.com/dp/" + metadata.getAsin(); } else if (metadata.getApplebooksId() != null && !metadata.getApplebooksId().isBlank()) { primaryUrl = "https://books.apple.com/us/book/id" + metadata.getApplebooksId(); + } else if (metadata.getOpenlibraryId() != null && !metadata.getOpenlibraryId().isBlank()) { + primaryUrl = "https://openlibrary.org/" + metadata.getOpenlibraryId().replaceAll("^/+", ""); } info.setWeb(primaryUrl); @@ -288,6 +290,7 @@ public class CbxMetadataWriter implements MetadataWriter { appendBookLoreTag(notesBuilder, "LubimyczytacId", metadata.getLubimyczytacId()); appendBookLoreTag(notesBuilder, "RanobedbId", metadata.getRanobedbId()); appendBookLoreTag(notesBuilder, "GoogleId", metadata.getGoogleId()); + appendBookLoreTag(notesBuilder, "OpenlibraryId", metadata.getOpenlibraryId()); appendBookLoreTag(notesBuilder, "GoodreadsId", metadata.getGoodreadsId()); appendBookLoreTag(notesBuilder, "ASIN", metadata.getAsin()); appendBookLoreTag(notesBuilder, "ComicvineId", metadata.getComicvineId()); diff --git a/backend/src/main/java/org/booklore/service/metadata/writer/EpubMetadataWriter.java b/backend/src/main/java/org/booklore/service/metadata/writer/EpubMetadataWriter.java index 7e44cf165..73184d440 100644 --- a/backend/src/main/java/org/booklore/service/metadata/writer/EpubMetadataWriter.java +++ b/backend/src/main/java/org/booklore/service/metadata/writer/EpubMetadataWriter.java @@ -157,6 +157,13 @@ public class EpubMetadataWriter implements MetadataWriter { } hasChanges[0] = true; }); + helper.copyOpenlibraryId(clear != null && clear.isOpenlibraryId(), val -> { + removeIdentifierByUrn(metadataElement, "openlibrary"); + if (val != null && !val.isBlank()) { + metadataElement.appendChild(createIdentifierElement(opfDoc, "openlibrary", val)); + } + hasChanges[0] = true; + }); helper.copyGoodreadsId(clear != null && clear.isGoodreadsId(), val -> { removeIdentifierByUrn(metadataElement, "goodreads"); if (val != null && !val.isBlank()) { diff --git a/backend/src/main/java/org/booklore/service/metadata/writer/MetadataCopyHelper.java b/backend/src/main/java/org/booklore/service/metadata/writer/MetadataCopyHelper.java index b20a1f86f..5fcd77502 100644 --- a/backend/src/main/java/org/booklore/service/metadata/writer/MetadataCopyHelper.java +++ b/backend/src/main/java/org/booklore/service/metadata/writer/MetadataCopyHelper.java @@ -117,6 +117,13 @@ public class MetadataCopyHelper { } } + public void copyOpenlibraryId(boolean clear, Consumer consumer) { + if (!isLocked(metadata.getOpenlibraryIdLocked())) { + if (clear) consumer.accept(null); + else if (metadata.getOpenlibraryId() != null) consumer.accept(metadata.getOpenlibraryId()); + } + } + public void copyComicvineId(boolean clear, Consumer consumer) { if (!isLocked(metadata.getComicvineIdLocked())) { if (clear) consumer.accept(null); diff --git a/backend/src/main/java/org/booklore/service/metadata/writer/PdfMetadataWriter.java b/backend/src/main/java/org/booklore/service/metadata/writer/PdfMetadataWriter.java index 8fe1784bb..fa7911676 100644 --- a/backend/src/main/java/org/booklore/service/metadata/writer/PdfMetadataWriter.java +++ b/backend/src/main/java/org/booklore/service/metadata/writer/PdfMetadataWriter.java @@ -266,6 +266,9 @@ public class PdfMetadataWriter implements MetadataWriter { helper.copyGoogleId(clear != null && clear.isGoogleId(), id -> { if (id != null && !id.isBlank()) customFields.put(prefix + "googleId", id); }); + helper.copyOpenlibraryId(clear != null && clear.isOpenlibraryId(), id -> { + if (id != null && !id.isBlank()) customFields.put(prefix + "openlibraryId", id); + }); helper.copyGoodreadsId(clear != null && clear.isGoodreadsId(), id -> { String normalized = normalizeGoodreadsId(id); if (normalized != null && !normalized.isBlank()) customFields.put(prefix + "goodreadsId", normalized); diff --git a/backend/src/main/java/org/booklore/util/MetadataChangeDetector.java b/backend/src/main/java/org/booklore/util/MetadataChangeDetector.java index 35281f0b2..c3cc54f3a 100644 --- a/backend/src/main/java/org/booklore/util/MetadataChangeDetector.java +++ b/backend/src/main/java/org/booklore/util/MetadataChangeDetector.java @@ -143,6 +143,10 @@ public class MetadataChangeDetector { BookMetadata::getIsbn10, BookMetadataEntity::getIsbn10, BookMetadata::getIsbn10Locked, BookMetadataEntity::getIsbn10Locked, MetadataClearFlags::isIsbn10, true), + new FieldDescriptor<>("openlibraryId", + BookMetadata::getOpenlibraryId, BookMetadataEntity::getOpenlibraryId, + BookMetadata::getOpenlibraryIdLocked, BookMetadataEntity::getOpenlibraryIdLocked, + MetadataClearFlags::isOpenlibraryId, true), new FieldDescriptor<>("asin", BookMetadata::getAsin, BookMetadataEntity::getAsin, BookMetadata::getAsinLocked, BookMetadataEntity::getAsinLocked, diff --git a/backend/src/main/resources/db/migration/V148__Add_openlibrary_provider.sql b/backend/src/main/resources/db/migration/V148__Add_openlibrary_provider.sql new file mode 100644 index 000000000..438b78d7d --- /dev/null +++ b/backend/src/main/resources/db/migration/V148__Add_openlibrary_provider.sql @@ -0,0 +1,4 @@ +-- Add OpenLibrary metadata columns +ALTER TABLE book_metadata + ADD COLUMN IF NOT EXISTS openlibrary_id VARCHAR(100), + ADD COLUMN IF NOT EXISTS openlibrary_id_locked BOOLEAN DEFAULT FALSE; diff --git a/backend/src/main/resources/templates/epub/xml/content.opf.ftl b/backend/src/main/resources/templates/epub/xml/content.opf.ftl index 265510a18..da1ac84a9 100644 --- a/backend/src/main/resources/templates/epub/xml/content.opf.ftl +++ b/backend/src/main/resources/templates/epub/xml/content.opf.ftl @@ -59,6 +59,10 @@ ${goodreadsId} GOODREADS + <#if openlibraryId?has_content> + ${openlibraryId} + OPENLIBRARY + <#if applebooksId?has_content> ${applebooksId} APPLEBOOKS diff --git a/backend/src/test/java/org/booklore/service/metadata/parser/OpenLibraryParserTest.java b/backend/src/test/java/org/booklore/service/metadata/parser/OpenLibraryParserTest.java new file mode 100644 index 000000000..86b2bfd5d --- /dev/null +++ b/backend/src/test/java/org/booklore/service/metadata/parser/OpenLibraryParserTest.java @@ -0,0 +1,205 @@ + +package org.booklore.service.metadata.parser; + +import org.booklore.model.dto.Book; +import org.booklore.model.dto.BookMetadata; +import org.booklore.model.dto.request.FetchMetadataRequest; +import org.booklore.service.SleepService; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import tools.jackson.databind.ObjectMapper; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.http.HttpClient; +import java.net.http.HttpResponse; +import java.nio.charset.StandardCharsets; +import java.nio.file.Paths; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.*; + +@ExtendWith(MockitoExtension.class) +public class OpenLibraryParserTest { + @Mock + private HttpClient httpClient; + + @Mock + private SleepService sleepService; + + private OpenLibraryParser parser; + + @BeforeEach + void setUp() throws IOException { + parser = new OpenLibraryParser( + httpClient, + new ObjectMapper(), + sleepService + ); + } + + private String readFixture(String fixtureName) throws IOException { + String filename = Paths.get("openlibrary", fixtureName + ".fixture").toString(); + + try (InputStream is = getClass().getClassLoader().getResourceAsStream(filename)) { + assert is != null; + + return new String(is.readAllBytes(), StandardCharsets.UTF_8); + } + } + + @SuppressWarnings("unchecked") + private HttpResponse getMockResponse(int statusCode, String response) { + HttpResponse httpResponse = (HttpResponse) mock(HttpResponse.class); + + when(httpResponse.statusCode()).thenReturn(statusCode); + + if (response != null) { + when(httpResponse.body()).thenAnswer( + (_) -> new ByteArrayInputStream(response.getBytes(StandardCharsets.UTF_8)) + ); + } + + return httpResponse; + } + + private void mockHttpClientResponse(String urlPrefix, int statusCode, String response) throws Exception { + when( + httpClient.send( + argThat(r -> r != null && r.uri().toString().startsWith(urlPrefix)), + any() + ) + ).thenAnswer((_) -> getMockResponse(statusCode, response)); + } + + @Test + void testFetchMetadata_EmptyQuery() { + // Given + Book book = Book.builder() + .title("Test Book") + .build(); + + FetchMetadataRequest request = FetchMetadataRequest.builder() + .build(); + // Empty query - no title or ISBN + + // When + List results = parser.fetchMetadata(book, request); + + // Then + assertThat(results).isNotNull(); + assertThat(results).as("Should return empty list when query is empty").isEmpty(); + } + + @Test + void testFetchMetadata_parsesBook() throws Exception { + // Given + Book book = Book.builder() + .title("A Clockwork Orange") + .build(); + + FetchMetadataRequest request = FetchMetadataRequest.builder() + .title("A Clockwork Orange") + .author("Anthony Burgess") + .build(); + + // Two expected URLs + mockHttpClientResponse("https://openlibrary.org/search.json", 200, readFixture("example-search.json")); + mockHttpClientResponse("https://openlibrary.org/works/OL261794W.json", 200, readFixture("example-work.json")); + mockHttpClientResponse("https://openlibrary.org/books/OL27284158M.json", 200, readFixture("example-edition.json")); + mockHttpClientResponse("https://openlibrary.org/authors/OL142238A.json", 200, readFixture("example-author.json")); + + // When + List results = parser.fetchMetadata(book, request); + + // Then + assertThat(results).isNotNull(); + assertThat(results).as("Should return results for real book").isNotEmpty(); + + BookMetadata result = results.getFirst(); + assertThat(result.getTitle()).isEqualTo("A Clockwork Orange"); + assertThat(result.getIsbn10()).isEqualTo("1856132668"); + assertThat(result.getIsbn13()).isEqualTo("9781856132664"); + assertThat(result.getGoodreadsId()).isEqualTo("59769676"); + assertThat(result.getAuthors()).isNotNull(); + assertThat(result.getAuthors()).hasSize(1); + assertThat(result.getAuthors().getFirst()).isEqualTo("Anthony Burgess"); + + // The description is very long, but we need to make sure we're in the right ballpark. + assertThat(result.getDescription()).startsWith("A Clockwork Orange is a dystopian satirical black comedy novel"); + assertThat(result.getDescription()).hasSize(1307); + } + + @Test + void testFetchMetadata_parsesBookWithComplexDescriptionAndSeries() throws Exception { + // Given + Book book = Book.builder() + .title("") + .build(); + + FetchMetadataRequest request = FetchMetadataRequest.builder() + .title("Lord of the Rings") + .build(); + + // Two expected URLs + mockHttpClientResponse("https://openlibrary.org/search.json", 200, readFixture("lotr-search.json")); + mockHttpClientResponse("https://openlibrary.org/works/OL27448W.json", 200, readFixture("lotr-work.json")); + mockHttpClientResponse("https://openlibrary.org/series/OL330052L.json", 200, readFixture("lotr-series.json")); + mockHttpClientResponse("https://openlibrary.org/books/OL51711484M.json", 200, readFixture("lotr-edition.json")); + mockHttpClientResponse("https://openlibrary.org/authors/OL26320A.json", 200, readFixture("lotr-author.json")); + + // When + List results = parser.fetchMetadata(book, request); + + // Then + assertThat(results).isNotNull(); + assertThat(results).as("Should return results for real book").isNotEmpty(); + + BookMetadata result = results.getFirst(); + assertThat(result.getTitle()).isEqualTo("The Lord of the Rings"); + assertThat(result.getIsbn10()).isEqualTo("0618343997"); + assertThat(result.getIsbn13()).isNull(); + assertThat(result.getGoodreadsId()).isNull(); + assertThat(result.getAuthors()).isNotNull(); + assertThat(result.getAuthors()).hasSize(1); + assertThat(result.getAuthors().getFirst()).isEqualTo("J.R.R. Tolkien"); + + assertThat(result.getSeriesName()).isEqualTo("The Lord of the Rings"); + assertThat(result.getSeriesNumber()).isEqualTo(1); + assertThat(result.getSeriesTotal()).isEqualTo(3); + + // The description is very long, but we need to make sure we're in the right ballpark. + assertThat(result.getDescription()).startsWith("Originally published from 1954 through 1956"); + assertThat(result.getDescription()).hasSize(2137); + } + + @Test + void testFetchMetadata_appliesRateLimit() throws Exception { + // Given + Book book = Book.builder() + .title("") + .build(); + + FetchMetadataRequest request = FetchMetadataRequest.builder() + .title("Lord of the Rings") + .build(); + + // Two expected URLs + mockHttpClientResponse("https://openlibrary.org/search.json", 200, readFixture("lotr-search.json")); + mockHttpClientResponse("https://openlibrary.org/works/OL27448W.json", 200, readFixture("lotr-work.json")); + mockHttpClientResponse("https://openlibrary.org/series/OL330052L.json", 200, readFixture("lotr-series.json")); + mockHttpClientResponse("https://openlibrary.org/books/OL51711484M.json", 200, readFixture("lotr-edition.json")); + mockHttpClientResponse("https://openlibrary.org/authors/OL26320A.json", 200, readFixture("lotr-author.json")); + + for (int i = 0; i < 160; i++) { + parser.fetchMetadata(book, request); + } + + verify(sleepService, times(4)).sleep(anyLong()); + } +} \ No newline at end of file diff --git a/backend/src/test/resources/openlibrary/example-author.json.fixture b/backend/src/test/resources/openlibrary/example-author.json.fixture new file mode 100644 index 000000000..c3b5926b2 --- /dev/null +++ b/backend/src/test/resources/openlibrary/example-author.json.fixture @@ -0,0 +1 @@ +{"source_records": ["amazon:0671625276", "bwb:9780486820729", "bwb:9780099778806", "bwb:9780099442592", "promise:bwb_daily_pallets_2022-07-11", "promise:bwb_daily_pallets_2022-08-30", "promise:bwb_daily_pallets_2022-10-14:KR-427-373", "promise:bwb_daily_pallets_2021-03-30", "promise:bwb_daily_pallets_2020-11-26", "promise:bwb_daily_pallets_2020-11-13", "amazon:8476698127", "amazon:8389640724", "promise:bwb_daily_pallets_2023-05-16:W3-CPM-838", "promise:bwb_daily_pallets_2023-05-22:692-ABA-806"], "bio": "John Anthony Burgess Wilson, who published under the name Anthony Burgess, was an English writer and composer.\r\n\r\nAlthough Burgess was primarily a comic writer, his dystopian satire *A Clockwork Orange* remains his best-known novel. In 1971, it was adapted into a controversial film by Stanley Kubrick, which Burgess said was chiefly responsible for the popularity of the book. Burgess produced numerous other novels, including the Enderby quartet, and Earthly Powers. He wrote librettos and screenplays, including the 1977 television mini-series Jesus of Nazareth. He worked as a literary critic for several publications, including The Observer and The Guardian, and wrote studies of classic writers, notably James Joyce. A versatile linguist, Burgess lectured in phonetics, and translated Cyrano de Bergerac, Oedipus Rex, and the opera Carmen, among others.\r\n\r\nBurgess also composed over 250 musical works; he considered himself as much a composer as an author, although he achieved considerably more success in writing.", "birth_date": "25 February 1917", "photos": [7277111, 14431059, -1], "death_date": "22 November 1993", "personal_name": "Burgess, Anthony", "links": [{"title": "VIAF", "url": "https://viaf.org/viaf/317283205", "type": {"key": "/type/link"}}, {"title": "ISNI", "url": "http://isni.org/isni/0000000456193171", "type": {"key": "/type/link"}}, {"title": "Wikidata", "url": "https://www.wikidata.org/wiki/Q217619", "type": {"key": "/type/link"}}, {"title": "The International Anthony Burgess Foundation", "url": "https://www.anthonyburgess.org/", "type": {"key": "/type/link"}}], "remote_ids": {"viaf": "71388189", "wikidata": "Q217619", "isni": "0000000121385921"}, "type": {"key": "/type/author"}, "alternate_names": ["Burgess, Anthony", "anthony-burgess", "Anthony BURGESS", "John Anthony Burgess Wilson", "ANTHONY BURGESS", "A. Burgess", "Antony Burgess", "Joseph Kell", "John Burgess Wilson", "A. BURGESS", "anthony burgess", "BURGESS,ANTHONY.", "Burgess Anthony", "\u042d\u043d\u0442\u043e\u043d\u0438 \u0411\u0451\u0440\u0434\u0436\u0435\u0441\u0441"], "name": "Anthony Burgess", "key": "/authors/OL142238A", "latest_revision": 17, "revision": 17, "created": {"type": "/type/datetime", "value": "2008-04-01T03:28:50.625462"}, "last_modified": {"type": "/type/datetime", "value": "2025-03-25T01:01:48.526462"}} \ No newline at end of file diff --git a/backend/src/test/resources/openlibrary/example-edition.json.fixture b/backend/src/test/resources/openlibrary/example-edition.json.fixture new file mode 100644 index 000000000..5a32fe332 --- /dev/null +++ b/backend/src/test/resources/openlibrary/example-edition.json.fixture @@ -0,0 +1 @@ +{"publishers": ["Penguin Classics"], "identifiers": {"amazon": ["1856132668"], "goodreads": ["59769676"]}, "source_records": ["amazon:1856132668", "promise:bwb_daily_pallets_2021-01-27"], "title": "A Clockwork Orange", "number_of_pages": 141, "covers": [12393415], "physical_format": "paperback", "full_title": "A Clockwork Orange", "publish_date": "2000", "key": "/books/OL27284158M", "authors": [{"key": "/authors/OL1607339A"}], "works": [{"key": "/works/OL261794W"}], "type": {"key": "/type/edition"}, "publish_places": ["London"], "languages": [{"key": "/languages/eng"}], "pagination": "xxiii, 140p.", "copyright_date": "1996", "edition_name": "reprint 1", "description": "Fifteen-year-old Alex doesn't just like ultra-violence - he also enjoys rape, drugs and Beethoven's Ninth. He and his gang rampage through a dystopian future, hunting for terrible thrills. But when Alex finds himself at the mercy of the state and subject to the ministrations of Dr Brodsky, the government psychologist, he discovers that fun is no longer the order of the day ...\r\n\r\nThe basis for one of the most notorious films ever made, A Clockwork Orange is both a virtuoso performance from an electrifying prose stylist and a serious exploration of the morality of free will.\r\n--back cover", "local_id": ["urn:bwbsku:KP-003-259"], "ocaid": "isbn_9781856132664", "isbn_10": ["1856132668"], "isbn_13": ["9781856132664"], "latest_revision": 14, "revision": 14, "created": {"type": "/type/datetime", "value": "2019-08-26T01:59:15.196224"}, "last_modified": {"type": "/type/datetime", "value": "2025-11-15T21:27:51.839463"}} \ No newline at end of file diff --git a/backend/src/test/resources/openlibrary/example-search.json.fixture b/backend/src/test/resources/openlibrary/example-search.json.fixture new file mode 100644 index 000000000..7f82dadd8 --- /dev/null +++ b/backend/src/test/resources/openlibrary/example-search.json.fixture @@ -0,0 +1 @@ +{"numFound":75,"start":0,"numFoundExact":true,"num_found":75,"documentation_url":"https://openlibrary.org/dev/docs/api/search","q":"title:Clockwork Orange","offset":null,"docs":[{"author_key":["OL142238A"],"key":"/works/OL261794W","editions":{"numFound":110,"start":0,"numFoundExact":true,"docs":[{"key":"/books/OL27284158M"}]}}]} \ No newline at end of file diff --git a/backend/src/test/resources/openlibrary/example-work.json.fixture b/backend/src/test/resources/openlibrary/example-work.json.fixture new file mode 100644 index 000000000..da2b5a448 --- /dev/null +++ b/backend/src/test/resources/openlibrary/example-work.json.fixture @@ -0,0 +1 @@ +{"description": "A Clockwork Orange is a dystopian satirical black comedy novel by English writer Anthony Burgess, published in 1962. It is set in a near-future society that has a youth subculture of extreme violence. The teenage protagonist, Alex, narrates his violent exploits and his experiences with state authorities intent on reforming him. The book is partially written in a Russian-influenced argot called \"Nadsat\", which takes its name from the Russian suffix that is equivalent to '-teen' in English. According to Burgess, it was a jeu d'esprit written in just three weeks.\r\n\r\nIn 2005, A Clockwork Orange was included on Time magazine's list of the 100 best English-language novels written since 1923, and it was named by Modern Library and its readers as one of the 100 best English-language novels of the 20th century. The original manuscript of the book has been kept at McMaster University's William Ready Division of Archives and Research Collections in Hamilton, Ontario, Canada since the institution purchased the documents in 1971. It is considered one of the most influential dystopian books.\r\n\r\n----------\t\t\r\nAlso contained in:\t\t\r\n\r\n[A Clockwork Orange and Honey for the Bears](https://openlibrary.org/works/OL23787405W)\r\n[A Clockwork Orange / The Wanting Seed](https://openlibrary.org/works/OL17306508W)", "first_publish_date": "1972", "title": "A Clockwork Orange", "covers": [13151224, 13950735, 13950736, 12338379, 14122257, 14122256, 11943379, 12269033, 14121728], "first_sentence": {"type": "/type/text", "value": "'WHAT'S it going to be then, eh?'"}, "excerpts": [{"excerpt": "\u2018What\u2019s it going to be then, eh?\u2019", "comment": "first sentence", "author": {"key": "/people/seabelis"}}], "key": "/works/OL261794W", "authors": [{"author": {"key": "/authors/OL142238A"}, "type": {"key": "/type/author_role"}}], "dewey_number": ["823.914"], "type": {"key": "/type/work"}, "links": [{"title": "A Clockwork Orange - The International Anthony Burgess Foundation", "url": "https://www.anthonyburgess.org/a-clockwork-orange/", "type": {"key": "/type/link"}}, {"title": "A Clockwork Orange (novel) - Wikipedia", "url": "https://en.wikipedia.org/wiki/A_Clockwork_Orange_(novel)", "type": {"key": "/type/link"}}, {"title": "The 100 best novels: No 82 \u2013 A Clockwork Orange by Anthony Burgess (1962)", "url": "https://www.theguardian.com/books/2015/apr/13/100-best-novels-clockwork-orange-anthony-burgess", "type": {"key": "/type/link"}}, {"title": "The Shock of the New \u2018A Clockwork Orange\u2019 at 50", "url": "https://www.nytimes.com/2012/09/02/books/review/a-clockwork-orange-at-50.html", "type": {"key": "/type/link"}}, {"title": "A Clockwork Orange | Summary, Analysis, & Facts | Britannica.com", "url": "https://www.britannica.com/topic/A-Clockwork-Orange-novel", "type": {"key": "/type/link"}}, {"title": "thegreatestbooks.org/items/20", "url": "https://thegreatestbooks.org/items/20", "type": {"key": "/type/link"}}], "subject_places": ["England", "Korova Milk Bar"], "subject_people": ["Ludwig van Beethoven", "Alex", "George", "Pet", "Dim", "P.R. Deltoid", "Prison Chaplain", "Billyboy", "Prison Governor", "Minister of the Interior", "Dr. Branom", "Dr. Brodsky", "F. Alexander", "Cat Woman", "Stanley Kubrick", "Anthony Burgess (1917-1993)"], "subjects": ["bible", "aversion therapy", "unintended consequences", "Beethoven's Fifth Symphony", "gang rape", "psychiatric hospitals", "maturity", "metanoia", "assault", "joyriding", "rape", "metafiction", "orgasm", "novella", "antisocial personality disorder", "classical music", "black comedy", "argot", "Nadsat", "dystopias", "satire", "literature", "Juvenile delinquents", "Science fiction", "Rehabilitation", "Fiction", "Teenage boys", "Criminals", "S\u00e1tira", "Muchachos adolescentes", "Criticism and interpretation", "Criminales", "English Authors", "Open Library Staff Picks", "Violence", "Slang language", "Gangs", "Ciencia-ficci\u00f3n", "Social conditions", "Ficci\u00f3n", "Behavior modification", "Long Now Manual for Civilization", "Juvenile delinquency", "Brainwashing", "Fiction, satire", "Fiction, dystopian", "Fiction, science fiction, general", "British and irish fiction (fictional works by one author)", "British and irish drama (dramatic works by one author)", "Kubrick, stanley, 1928-1999", "Burgess, anthony, 1917-1993", "Clockwork orange (Motion picture)", "English literature", "Juvenile delinquents in fiction", "Adventure stories", "Roman d'aventures", "D\u00e9linquance juv\u00e9nile", "Romans, nouvelles", "Jeunes d\u00e9linquants", "R\u00e9habilitation", "English Satire"], "latest_revision": 25, "revision": 25, "created": {"type": "/type/datetime", "value": "2009-10-24T07:26:31.097043"}, "last_modified": {"type": "/type/datetime", "value": "2026-01-01T17:25:03.972618"}} \ No newline at end of file diff --git a/backend/src/test/resources/openlibrary/lotr-author.json.fixture b/backend/src/test/resources/openlibrary/lotr-author.json.fixture new file mode 100644 index 000000000..6d23f4559 --- /dev/null +++ b/backend/src/test/resources/openlibrary/lotr-author.json.fixture @@ -0,0 +1 @@ +{"personal_name": "J. R. R. Tolkien", "name": "J.R.R. Tolkien", "bio": "John Ronald Reuel Tolkien (1892-1973) was a major scholar of the English language, specialising in Old and Middle English. Twice Professor of Anglo-Saxon (Old English) at the University of Oxford, he also wrote a number of stories, including most famously The Hobbit (1937) and The Lord of the Rings (1954-1955), which are set in a pre-historic era in an invented version of the world which he called by the Middle English name of Middle-earth. This was peopled by Men (and women), Elves, Dwarves, Trolls, Orcs (or Goblins) and of course Hobbits. He has regularly been condemned by the Eng. Lit. establishment, with honourable exceptions, but loved by literally millions of readers worldwide.\r\n\r\nIn the 1960s he was taken up by many members of the nascent \"counter-culture\" largely because of his concern with environmental issues. In 1997 he came top of three British polls, organised respectively by Channel 4 / Waterstone's, the Folio Society, and SFX, the UK's leading science fiction media magazine, amongst discerning readers asked to vote for the greatest book of the 20th century. \r\n\r\n([Source][1])\r\n\r\n\r\n [1]: http://www.tolkiensociety.org/tolkien/biography.html", "remote_ids": {"viaf": "95218067", "storygraph": "ab1242c9-8f9b-475c-845f-ea406db30ebc", "amazon": "B000ARC6KA", "wikidata": "Q892", "isni": "0000000121441970", "goodreads": "656983", "project_gutenberg": "42379", "musicbrainz": "97f3efea-558f-4137-9e4c-8a2fcec3c2d4", "bookbrainz": "4e8f8704-7c34-4a00-8ce5-f02bf26ca7df", "imdb": "nm0866058", "lc_naf": "n79005673", "librarything": "tolkienjrr", "librivox": "1536", "opac_sbn": "CFIV015811"}, "birth_date": "3 January 1892", "source_records": ["ia:herrabliss0000tolk", "amazon:0007557272", "amazon:0007637675", "amazon:8845927555", "bwb:9780008360108", "amazon:3867170355", "amazon:8830102717", "amazon:2266017519", "amazon:0007270615", "ia:futatsunoto0000unse", "amazon:0342851705", "ia:leseigneurdesann0000tolk_k6z7", "amazon:3423590610", "amazon:1865035955", "amazon:3608939849", "amazon:0007317255", "amazon:902254771X", "amazon:0344895459", "ia:twotowers0002tolk_r5g9", "ia:returnofkingbein0003tolk_m6s4", "amazon:226700092X", "ia:lordofrings0000tolk_j2h8", "ia:lacomunidaddelan0000tolk", "amazon:0618260293", "amazon:1705047610", "amazon:2267017415", "amazon:0007635559", "amazon:360893829X", "bwb:9781782012696", "marc:marc_uic/UIC_2022.mrc:9810667:974", "amazon:1483034577", "amazon:8845293890", "bwb:9786070791390", "promise:bwb_daily_pallets_2022-07-28", "promise:bwb_daily_pallets_2023-02-22:W8-BNK-802", "promise:bwb_daily_pallets_2020-04-30", "amazon:9022531953", "promise:bwb_daily_pallets_2022-06-06", "amazon:9600403678", "bwb:9781693418167", "amazon:8481362581", "amazon:8467909234", "amazon:2356414916", "amazon:8377856816", "amazon:2267030519", "amazon:8377856824", "promise:bwb_daily_pallets_2022-05-16", "promise:bwb_daily_pallets_2022-03-17", "amazon:5170075308", "promise:bwb_daily_pallets_2022-12-12", "ia:lesaventuresdeto0000tolk_t0n6", "promise:bwb_daily_pallets_2022-08-30:KR-117-775", "amazon:0007927045", "amazon:8412076540", "promise:bwb_daily_pallets_2022-09-07:W7-CXN-847", "amazon:0261103687", "amazon:912409546X", "bwb:9780344895463", "promise:bwb_daily_pallets_2022-08-02", "promise:bwb_daily_pallets_2022-04-01:O8-ADR-484", "amazon:8381164842", "promise:bwb_daily_pallets_2023-04-19:P8-BNX-316", "promise:bwb_daily_pallets_2023-04-11:W8-BRW-606", "promise:bwb_daily_pallets_2023-04-07:KS-199-194", "promise:bwb_daily_pallets_2023-03-31:KS-198-493", "promise:bwb_daily_pallets_2023-03-29:KS-198-041", "promise:bwb_daily_pallets_2023-05-15:KN-103-569", "marc:harvard_bibliographic_metadata/ab.bib.11.20150123.full.mrc:381341198:1041", "promise:bwb_daily_pallets_2023-06-01:KS-537-871", "promise:bwb_daily_pallets_2023-07-05:W8-BAY-330", "bwb:9780261103962", "promise:bwb_daily_pallets_2023-07-24:KS-589-214", "promise:bwb_daily_pallets_2023-08-21:W8-BVD-810", "promise:bwb_daily_pallets_2023-09-21:W8-BVW-542", "promise:bwb_daily_pallets_2023-10-10:W8-ADE-653", "amazon:505002255X", "bwb:9780008663162", "promise:bwb_daily_pallets_2023-10-19:O9-ASF-492", "marc:harvard_bibliographic_metadata/ab.bib.11.20150123.full.mrc:653596550:803", "promise:bwb_daily_pallets_2023-12-08:O9-CDZ-574", "promise:bwb_daily_pallets_2023-12-15:KT-657-103", "bwb:9780008669232", "promise:bwb_daily_pallets_2024-02-13:KT-307-140", "promise:bwb_daily_pallets_2024-03-19:KT-278-709", "promise:bwb_daily_pallets_2024-03-26:P9-DQU-862", "promise:bwb_daily_pallets_2022-04-20:KQ-937-250", "bwb:9780008705312", "marc:marc_columbia/Columbia-extract-20221130-010.mrc:238301614:1243", "bwb:9798855136401", "bwb:9781548547455", "bwb:9781530308248", "bwb:9781548547295", "ia:bwb_KQ-385-673", "ia:bwb_S0-AWJ-105", "ia:bwb_W9-DFW-842", "ia:foliosociety3vol0000unse", "ia:habbit0000jrrt", "ia:twotowersbiengse0000jrrt", "promise:bwb_daily_pallets_2021-04-01", "promise:bwb_daily_pallets_2024-12-03:KU-143-063"], "links": [{"title": "The Tolkien Society", "url": "http://www.tolkiensociety.org/index.html", "type": {"key": "/type/link"}}, {"title": "The Official Website of the JRR Tolkien Estate", "url": "http://www.tolkienestate.com/", "type": {"key": "/type/link"}}, {"title": "TheOneRing.com", "url": "http://www.theonering.com/", "type": {"key": "/type/link"}}, {"title": "Planet Tolkien", "url": "http://www.planet-tolkien.com/", "type": {"key": "/type/link"}}, {"title": "The Tolkien Library: Collecting Tolkien books", "url": "http://www.tolkienlibrary.com/", "type": {"key": "/type/link"}}, {"title": "Tolkien Gateway - The J.R.R. Tolkien encyclopedia", "url": "https://tolkiengateway.net", "type": {"key": "/type/link"}}], "death_date": "2 September 1973", "fuller_name": "John Ronald Reuel Tolkien", "alternate_names": ["Dzhon R. R. Tolkin", "J. R. R. Tolkien", "J. R. R. Tolki\u00ebn", "J. R.R. Tolkien", "John R. R. Tolkien", "John Ronald Reuel Tolkien", "Tolkien", "Yue Han Luo Na De Rui Er Tuo Er Jin"], "photos": [6155606, 6433524, 6433525, 6433526, 5731377, -1], "key": "/authors/OL26320A", "type": {"key": "/type/author"}, "latest_revision": 62, "revision": 62, "created": {"type": "/type/datetime", "value": "2008-04-01T03:28:50.625462"}, "last_modified": {"type": "/type/datetime", "value": "2026-03-28T11:01:41.560959"}} \ No newline at end of file diff --git a/backend/src/test/resources/openlibrary/lotr-edition.json.fixture b/backend/src/test/resources/openlibrary/lotr-edition.json.fixture new file mode 100644 index 000000000..69e7d96dc --- /dev/null +++ b/backend/src/test/resources/openlibrary/lotr-edition.json.fixture @@ -0,0 +1 @@ +{"works": [{"key": "/works/OL27448W"}], "title": "The Lord of the Rings", "publishers": ["Houghton Mifflin Company"], "publish_date": "2003", "key": "/books/OL51711484M", "type": {"key": "/type/edition"}, "identifiers": {}, "isbn_10": ["0618343997"], "ocaid": "lordofrings00tolk_5", "classifications": {}, "publish_places": ["Boston"], "copyright_date": "2003", "edition_name": "Movie tie-in edition (1)", "languages": [{"key": "/languages/eng"}], "physical_format": "hardcover", "pagination": "1137p.", "covers": [15131000], "latest_revision": 5, "revision": 5, "created": {"type": "/type/datetime", "value": "2024-05-17T13:51:26.585267"}, "last_modified": {"type": "/type/datetime", "value": "2025-10-10T23:14:39.486304"}} \ No newline at end of file diff --git a/backend/src/test/resources/openlibrary/lotr-search.json.fixture b/backend/src/test/resources/openlibrary/lotr-search.json.fixture new file mode 100644 index 000000000..001a3dad6 --- /dev/null +++ b/backend/src/test/resources/openlibrary/lotr-search.json.fixture @@ -0,0 +1 @@ +{"numFound":784,"start":0,"numFoundExact":true,"num_found":784,"documentation_url":"https://openlibrary.org/dev/docs/api/search","q":"title:Lord of the Rings","offset":null,"docs":[{"author_key":["OL26320A"],"key":"/works/OL27448W","editions":{"numFound":207,"start":0,"numFoundExact":true,"docs":[{"key":"/books/OL51711484M"}]}}]} \ No newline at end of file diff --git a/backend/src/test/resources/openlibrary/lotr-series.json.fixture b/backend/src/test/resources/openlibrary/lotr-series.json.fixture new file mode 100644 index 000000000..61b9cbe2c --- /dev/null +++ b/backend/src/test/resources/openlibrary/lotr-series.json.fixture @@ -0,0 +1 @@ +{"links": {"self": "/series/OL330052L", "seeds": "/series/OL330052L/seeds"}, "name": "The Lord of the Rings", "type": {"key": "/series/OL330052L"}, "description": null, "seed_count": 4, "meta": {"revision": 1, "created": "2026-03-30T18:09:40.112603", "last_modified": "2026-03-30T18:09:40.112603"}} \ No newline at end of file diff --git a/backend/src/test/resources/openlibrary/lotr-work.json.fixture b/backend/src/test/resources/openlibrary/lotr-work.json.fixture new file mode 100644 index 000000000..d326fbb06 --- /dev/null +++ b/backend/src/test/resources/openlibrary/lotr-work.json.fixture @@ -0,0 +1 @@ +{"description": {"type": "/type/text", "value": "Originally published from 1954 through 1956, J.R.R. Tolkien's richly complex series ushered in a new age of epic adventure storytelling. A philologist and illustrator who took inspiration from his work, Tolkien invented the modern heroic quest novel from the ground up, creating not just a world, but a domain, not just a lexicon, but a language, that would spawn countless imitators and lead to the inception of the epic fantasy genre. Today, THE LORD OF THE RINGS is considered \"the most influential fantasy novel ever written.\" (THE ENCYCLOPEDIA OF FANTASY)\r\n\r\nDuring his travels across Middle-earth, the hobbit Bilbo Baggins had found the Ring. But the simple band of gold was far from ordinary; it was in fact the One Ring - the greatest of the ancient Rings of Power. Sauron, the Dark Lord, had infused it with his own evil magic, and when it was lost, he was forced to flee into hiding.\r\n\r\nBut now Sauron's exile has ended and his power is spreading anew, fueled by the knowledge that his treasure has been found. He has gathered all the Great Rings to him, and will stop at nothing to reclaim the One that will complete his dominion. The only way to stop him is to cast the Ruling Ring deep into the Fire-Mountain at the heart of the land of Mordor--Sauron's dark realm.\r\n\r\nFate has placed the burden in the hands of Frodo Baggins, Bilbo's heir...and he is resolved to bear it to its end. Or his own. \r\n\r\n\r\n----------\r\n\r\n\r\n**Contains**\r\n\r\n - [The Fellowship of the Ring][1]\r\n - [The Two Towers][2]\r\n - [The Return of the King][3]\r\n - [The Lord of the Rings [2/2]](https://openlibrary.org/works/OL27306128W)\r\n - [The Lord of the Rings [1/6]](https://openlibrary.org/works/OL24170898W)\r\n - [The Lord of the Rings [1/9]](https://openlibrary.org/works/OL27305953W)\r\n - [The Lord of the Rings [2/9]](https://openlibrary.org/works/OL27305892W)\r\n - [The Lord of the Rings [3/9]](https://openlibrary.org/works/OL27306048W)\r\n\r\n\r\n\r\n [1]: https://openlibrary.org/works/OL14933414W/The_Fellowship_of_the_Ring\r\n [2]: https://openlibrary.org/works/OL27479W/The_Two_Towers\r\n [3]: https://openlibrary.org/works/OL27516W/The_Return_of_the_King"}, "links": [{"title": "Tolkien Estate | The Lord of the Rings", "url": "http://www.tolkienestate.com/en/writing/tales-of-middle-earth/the-lord-of-the-rings.html", "type": {"key": "/type/link"}}, {"title": "The Lord of the Rings - Wikipedia", "url": "https://en.wikipedia.org/wiki/The_Lord_of_the_Rings", "type": {"key": "/type/link"}}, {"title": "fantasybookreview.co.uk/JRR-Tolkien/The-Lord-Of-The-Rings", "url": "http://www.fantasybookreview.co.uk/JRR-Tolkien/The-Lord-Of-The-Rings.html", "type": {"key": "/type/link"}}, {"title": "The Lord of the Rings | Overview & Summary | Britannica.com", "url": "https://www.britannica.com/topic/The-Lord-of-the-Rings", "type": {"key": "/type/link"}}, {"title": "The Lord of the Rings - Tolkien Gateway", "url": "http://tolkiengateway.net/wiki/The_Lord_of_the_Rings", "type": {"key": "/type/link"}}], "title": "The Lord of the Rings", "covers": [14625765, 11658206, 13120659, 12524639, 12524640, 13217523, 13601172, 13344549, 10515650], "subject_places": ["Mordor", "Hornburg", "Isengard", "Cracks of Doom", "Fangorn Forest", "Middle Earth", "Tierra Media"], "first_publish_date": "September 3, 2001", "subject_people": ["Frodo Baggins", "Samwise Gamgee", "Meriadoc Brandybuck", "Peregrin Took", "Gandalf the Grey", "Aragorn", "Legolas Greenleaf", "Gimli", "Boromir", "Denethor", "Faramir", "Galadriel", "Celeborn", "Elrond", "Arwen Und\u00f3miel", "Bilbo Baggins", "Th\u00e9oden", "\u00c9omer", "\u00c9owyn", "Treebeard", "Tom Bombadil", "King Thranduil", "Silvan Elves", "Sauron", "Elves of Eregion", "the Nazg\u00fbl", "The Witch-king of Angmar", "Saruman the White", "Gr\u00edma Wormtongue", "Gollum", "Shelob", "Durin's Bane", "Mouth of Sauron"], "key": "/works/OL27448W", "authors": [{"author": {"key": "/authors/OL26320A"}, "type": {"key": "/type/author_role"}}], "excerpts": [{"pages": "494", "excerpt": "'Battle and war!' said Gandalf. 'Ride on!'", "author": {"key": "/people/mekBot"}}, {"excerpt": "This book is largely concerned with Hobbits, and from its pages a reader may discover much of their character and a little of their history.", "comment": "first sentence", "author": {"key": "/people/seabelis"}}], "subjects": ["The Lord of the Rings", "Fiction", "Ficci\u00f3n", "English Fantasy fiction", "Ficci\u00f3n fant\u00e1stica inglesa", "Fantasy fiction", "Open Library Staff Picks", "Middle Earth (Imaginary place)", "Fiction, fantasy, epic", "Middle earth (imaginary place), fiction", "Baggins, frodo (fictitious character), fiction", "Gandalf (fictitious character), fiction", "British and irish fiction (fictional works by one author)", "English literature", "Frodo Baggins (Fictitious character)", "Baggins, bilbo (fictitious character), fiction", "Fiction, fantasy, general", "English language", "Fiction, media tie-in", "Gift books", "Quests (Expeditions)", "Wizards", "Terre du Milieu (Lieu imaginaire)", "Romans, nouvelles", "Qu\u00eate", "Lord of the rings (Tolkien, J.R.R.)", "\u0424\u0438\u043b\u043e\u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043d\u0430\u0443\u043a\u0438. \u0425\u0443\u0434\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u043b\u0438\u0442\u0435\u0440\u0430\u0442\u0443\u0440\u0430 -- \u0412\u0435\u043b\u0438\u043a\u043e\u0431\u0440\u0438\u0442\u0430\u043d\u0438\u044f -- \u0410\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u0430\u044f \u043b\u0438\u0442\u0435\u0440\u0430\u0442\u0443\u0440\u0430 -- \u0441 1945 \u0433. -- \u041f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0445\u0443\u0434\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u043b\u0438\u0442\u0435\u0440\u0430\u0442\u0443\u0440\u044b -- \u0425\u0443\u0434\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u043f\u0440\u043e\u0437\u0430 -- \u0420\u043e\u043c\u0430\u043d\u044b. \u041f\u043e\u0432\u0435\u0441\u0442\u0438. \u0420\u0430\u0441\u0441\u043a\u0430\u0437\u044b -- \u0424\u0430\u043d\u0442\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0438 \u043c\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0440\u043e\u043c\u0430\u043d\u044b, \u043f\u043e\u0432\u0435\u0441\u0442\u0438, \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b. \u0420\u043e\u043c\u0430\u043d\u044b \u0443\u0436\u0430\u0441\u043e\u0432", "Baggins, frodo", "Middle earth (imaginary place)--fiction", "Fantasy fiction, english", "Pr6039.o32 l6 2005", "823/.912", "Fiction in English", "Hobbits (Fictitious characters)", "Hobbits (Personnages fictifs)", "Telephone directories"], "type": {"key": "/type/work"}, "subject_times": ["The end of the third age"], "cover_edition": {"key": "/books/OL3404981M"}, "series": [{"series": {"key": "/series/OL330052L"}, "position": "1-3"}], "latest_revision": 128, "revision": 128, "created": {"type": "/type/datetime", "value": "2009-10-13T02:46:28.838662"}, "last_modified": {"type": "/type/datetime", "value": "2026-04-09T06:22:12.405370"}} \ No newline at end of file diff --git a/frontend/src/app/features/book/components/book-browser/book-table/book-table.helpers.ts b/frontend/src/app/features/book/components/book-browser/book-table/book-table.helpers.ts index bc8f6270b..b94f5f01a 100644 --- a/frontend/src/app/features/book/components/book-browser/book-table/book-table.helpers.ts +++ b/frontend/src/app/features/book/components/book-browser/book-table/book-table.helpers.ts @@ -23,6 +23,7 @@ export const LOCK_FIELDS = [ 'seriesTotalLocked', 'isbn13Locked', 'isbn10Locked', + 'openlibraryIdLocked', 'asinLocked', 'comicvineIdLocked', 'goodreadsIdLocked', diff --git a/frontend/src/app/features/book/components/book-browser/lock-unlock-metadata-dialog/lock-unlock-metadata-dialog.component.ts b/frontend/src/app/features/book/components/book-browser/lock-unlock-metadata-dialog/lock-unlock-metadata-dialog.component.ts index 8fdf9ef96..b76b65665 100644 --- a/frontend/src/app/features/book/components/book-browser/lock-unlock-metadata-dialog/lock-unlock-metadata-dialog.component.ts +++ b/frontend/src/app/features/book/components/book-browser/lock-unlock-metadata-dialog/lock-unlock-metadata-dialog.component.ts @@ -34,7 +34,7 @@ export class LockUnlockMetadataDialogComponent implements OnInit { bookIds: Set = this.dynamicDialogConfig.data.bookIds; lockableFields: string[] = [ - 'titleLocked', 'subtitleLocked', 'publisherLocked', 'publishedDateLocked', 'descriptionLocked', + 'titleLocked', 'subtitleLocked', 'publisherLocked', 'publishedDateLocked', 'descriptionLocked', 'openlibraryIdLocked', 'isbn13Locked', 'isbn10Locked', 'asinLocked', 'pageCountLocked', 'thumbnailLocked', 'languageLocked', 'coverLocked', 'seriesNameLocked', 'seriesNumberLocked', 'seriesTotalLocked', 'authorsLocked', 'categoriesLocked', 'moodsLocked', 'tagsLocked', 'amazonRatingLocked', 'amazonReviewCountLocked', 'goodreadsRatingLocked', 'goodreadsReviewCountLocked', @@ -51,6 +51,7 @@ export class LockUnlockMetadataDialogComponent implements OnInit { descriptionLocked: 'Description', isbn13Locked: 'ISBN-13', isbn10Locked: 'ISBN-10', + openlibraryIdLocked: 'OpenLibrary ID', asinLocked: 'ASIN', pageCountLocked: 'Page Count', thumbnailLocked: 'Thumbnail', diff --git a/frontend/src/app/features/book/data/book-response.models.ts b/frontend/src/app/features/book/data/book-response.models.ts index 5d5de9725..9df57d24c 100644 --- a/frontend/src/app/features/book/data/book-response.models.ts +++ b/frontend/src/app/features/book/data/book-response.models.ts @@ -255,6 +255,7 @@ export interface BookDetailMetadata extends BookMetadataFields { lubimyczytacId?: string; ranobedbId?: string; audibleId?: string; + openlibraryId?: string; doubanRating?: number; doubanReviewCount?: number; lubimyczytacRating?: number; @@ -300,6 +301,7 @@ export interface BookDetailMetadata extends BookMetadataFields { lubimyczytacRatingLocked?: boolean; ranobedbIdLocked?: boolean; ranobedbRatingLocked?: boolean; + openlibraryIdLocked?: boolean; audibleIdLocked?: boolean; audibleRatingLocked?: boolean; audibleReviewCountLocked?: boolean; diff --git a/frontend/src/app/features/book/model/book.model.ts b/frontend/src/app/features/book/model/book.model.ts index e5bf84cc3..dbbdd677b 100644 --- a/frontend/src/app/features/book/model/book.model.ts +++ b/frontend/src/app/features/book/model/book.model.ts @@ -167,6 +167,7 @@ export interface BookMetadata { seriesTotal?: number | null; isbn13?: string; isbn10?: string; + openlibraryId?: string; asin?: string; goodreadsId?: string; comicvineId?: string; @@ -220,6 +221,7 @@ export interface BookMetadata { seriesTotalLocked?: boolean; isbn13Locked?: boolean; isbn10Locked?: boolean; + openlibraryIdLocked?: boolean; asinLocked?: boolean; comicvineIdLocked?: boolean; goodreadsIdLocked?: boolean; @@ -272,6 +274,7 @@ export interface MetadataClearFlags { seriesTotal?: boolean; isbn13?: boolean; isbn10?: boolean; + openlibraryId?: boolean; asin?: boolean; goodreadsId?: boolean; comicvineId?: boolean; diff --git a/frontend/src/app/features/magic-shelf/component/magic-shelf-component.ts b/frontend/src/app/features/magic-shelf/component/magic-shelf-component.ts index 9235b7d9f..3f221cce8 100644 --- a/frontend/src/app/features/magic-shelf/component/magic-shelf-component.ts +++ b/frontend/src/app/features/magic-shelf/component/magic-shelf-component.ts @@ -410,6 +410,7 @@ export class MagicShelfComponent implements OnInit { {label: this.t.translate('magicShelf.metadataFields.applebooksReviewCount'), value: 'applebooksReviewCount'}, ]}, { label: this.t.translate('magicShelf.metadataFieldGroups.externalIds'), items: [ + {label: this.t.translate('magicShelf.metadataFields.openlibraryId'), value: 'openlibraryId'}, {label: this.t.translate('magicShelf.metadataFields.goodreadsId'), value: 'goodreadsId'}, {label: this.t.translate('magicShelf.metadataFields.hardcoverId'), value: 'hardcoverId'}, {label: this.t.translate('magicShelf.metadataFields.googleId'), value: 'googleId'}, diff --git a/frontend/src/app/features/magic-shelf/service/book-rule-evaluator.service.ts b/frontend/src/app/features/magic-shelf/service/book-rule-evaluator.service.ts index e436fc467..55dc33aa3 100644 --- a/frontend/src/app/features/magic-shelf/service/book-rule-evaluator.service.ts +++ b/frontend/src/app/features/magic-shelf/service/book-rule-evaluator.service.ts @@ -528,6 +528,7 @@ export class BookRuleEvaluatorService { case 'seriesName': return book.metadata?.seriesName; case 'isbn13': return book.metadata?.isbn13; case 'isbn10': return book.metadata?.isbn10; + case 'openlibraryId': return book.metadata?.openlibraryId; case 'asin': return book.metadata?.asin; case 'authors': return book.metadata?.authors; case 'categories': return book.metadata?.categories; diff --git a/frontend/src/app/features/metadata/component/book-metadata-center/metadata-editor/metadata-editor.component.html b/frontend/src/app/features/metadata/component/book-metadata-center/metadata-editor/metadata-editor.component.html index 760680043..c33a97a92 100644 --- a/frontend/src/app/features/metadata/component/book-metadata-center/metadata-editor/metadata-editor.component.html +++ b/frontend/src/app/features/metadata/component/book-metadata-center/metadata-editor/metadata-editor.component.html @@ -664,6 +664,20 @@ @if (providerSectionExpanded) {