From 4ac1d31bc6019501699262da9ff19b0ebdb052ea Mon Sep 17 00:00:00 2001 From: brios <127139797+balazs-szucs@users.noreply.github.com> Date: Tue, 24 Mar 2026 10:39:14 +0100 Subject: [PATCH] fix(metadata): fix metadata fetching relying for filename "first" instead of better fields like ISBN in Goodreads/Bookdrop (#85) * chore(deps): bump actions/setup-node from 6.2.0 to 6.3.0 (#1) Dependabot couldn't find the original pull request head commit, ea510f40fc1855aa17a782e05b0d30547e84955e. Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump docker/setup-buildx-action from 3.12.0 to 4.0.0 (#2) Dependabot couldn't find the original pull request head commit, faed6bf8a712c5fc793fa628157de25d97888131. Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump docker/build-push-action from 6.19.2 to 7.0.0 (#3) Dependabot couldn't find the original pull request head commit, f110823720b6dd773df014ba288a126d8837fe28. Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump docker/login-action from 3.7.0 to 4.0.0 (#6) Dependabot couldn't find the original pull request head commit, 9a8d7a1daf5afff06bb35e36607c3da9aa730e21. Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix(metadata): fix metadata fetching relying for filename "first" instead of better fields like ISBN in Goodreads/Bookdrop * perf(ci): speed up image builds and centralize cache writes - Image builds: - pin frontend and backend Docker build stages to the build platform so multi-arch packaging can reuse architecture-independent work - add an Angular build cache mount and move dynamic version metadata to the end of the runtime stage so static layers stay reusable across tags - reduce image workflow checkout depth and keep preview builds on `linux/amd64` only to avoid unnecessary QEMU and history overhead - Cache policy: - make CI packaging smoke builds consume the shared image cache without writing new BuildKit cache state - make normal preview builds consume shared GHA and registry caches without mutating the canonical cache - keep nightly and stable release builds as the workflows that refresh the shared image cache in both GHA and registry backends - Preview override: - add a `refresh_shared_cache` input to the preview workflow for an explicit no-cache rebuild that repopulates the shared cache when maintainers need to bust and refresh it - keep the default preview behavior optimized for fast disposable builds rather than cache churn - Validation: - keep workflow YAML parsing clean after the cache-policy changes - keep `git diff --check` clean for the touched Docker and workflow files * docs: Add a note about how to make a release * chore: remove unncesary comments --------- Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: James Cox --- .../bookdrop/BookdropMetadataService.java | 31 +++++++++- .../metadata/parser/GoodReadsParser.java | 56 +++++++++++++++---- 2 files changed, 74 insertions(+), 13 deletions(-) diff --git a/booklore-api/src/main/java/org/booklore/service/bookdrop/BookdropMetadataService.java b/booklore-api/src/main/java/org/booklore/service/bookdrop/BookdropMetadataService.java index 3bc7e78c7..c9835f67b 100644 --- a/booklore-api/src/main/java/org/booklore/service/bookdrop/BookdropMetadataService.java +++ b/booklore-api/src/main/java/org/booklore/service/bookdrop/BookdropMetadataService.java @@ -4,7 +4,6 @@ import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.booklore.exception.ApiError; import org.booklore.model.dto.Book; -import org.booklore.model.dto.BookFile; import org.booklore.model.dto.BookMetadata; import org.booklore.model.dto.request.MetadataRefreshOptions; import org.booklore.model.dto.settings.AppSettings; @@ -29,6 +28,7 @@ import java.time.Instant; import java.util.List; import java.util.Map; import java.util.concurrent.ThreadLocalRandom; +import java.util.stream.Stream; import static org.booklore.model.entity.BookdropFileEntity.Status.PENDING_REVIEW; @@ -71,9 +71,15 @@ public class BookdropMetadataService { BookMetadata initial = objectMapper.readValue(entity.getOriginalMetadata(), BookMetadata.class); + if (!hasSearchableMetadata(initial, entity)) { + log.info("Skipping online metadata fetch for '{}' — no reliable search data (title derived from filename, no ISBN or ASIN).", entity.getFileName()); + entity.setStatus(PENDING_REVIEW); + entity.setUpdatedAt(Instant.now()); + return bookdropFileRepository.save(entity); + } + List providers = metadataRefreshService.prepareProviders(refreshOptions); Book book = Book.builder() - .primaryFile(BookFile.builder().fileName(entity.getFileName()).build()) .metadata(initial) .build(); @@ -96,6 +102,27 @@ public class BookdropMetadataService { return bookdropFileRepository.save(entity); } + private boolean hasSearchableMetadata(BookMetadata metadata, BookdropFileEntity entity) { + if (hasAnyKnownIdentifier(metadata)) { + return true; + } + String title = metadata.getTitle(); + String filenameFallback = FilenameUtils.getBaseName(entity.getFileName()); + return title != null && !title.isBlank() + && !title.strip().equalsIgnoreCase(filenameFallback.strip()); + } + + private boolean hasAnyKnownIdentifier(BookMetadata m) { + // Keep in sync with identifier fields in BookMetadata when new providers are added. + return Stream.of( + m.getIsbn13(), m.getIsbn10(), m.getAsin(), + m.getGoodreadsId(), m.getGoogleId(), + m.getHardcoverId(), m.getHardcoverBookId(), + m.getComicvineId(), m.getDoubanId(), + m.getLubimyczytacId(), m.getRanobedbId(), m.getAudibleId() + ).anyMatch(id -> id != null && !id.isBlank()); + } + private BookdropFileEntity getOrThrow(Long id) { return bookdropFileRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("Bookdrop file not found: " + id)); } diff --git a/booklore-api/src/main/java/org/booklore/service/metadata/parser/GoodReadsParser.java b/booklore-api/src/main/java/org/booklore/service/metadata/parser/GoodReadsParser.java index f24c532ff..97aba9f99 100644 --- a/booklore-api/src/main/java/org/booklore/service/metadata/parser/GoodReadsParser.java +++ b/booklore-api/src/main/java/org/booklore/service/metadata/parser/GoodReadsParser.java @@ -20,6 +20,8 @@ import org.springframework.boot.configurationprocessor.json.JSONObject; import org.springframework.stereotype.Service; import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.time.Duration; @@ -66,6 +68,24 @@ public class GoodReadsParser implements BookParser, DetailedMetadataProvider { } } + String isbn = ParserUtils.cleanIsbn(fetchMetadataRequest.getIsbn()); + if (isbn != null && !isbn.isBlank()) { + log.info("GoodReads: Trying ISBN lookup: {}", isbn); + try { + Document doc = fetchDoc(BASE_ISBN_URL + isbn); + String goodreadsId = extractGoodreadsIdFromOgUrl(doc); + if (goodreadsId != null) { + BookMetadata metadata = parseBookDetails(doc, goodreadsId); + if (metadata != null) { + return metadata; + } + } + log.info("GoodReads: ISBN lookup returned no results, falling back to title search"); + } catch (Exception e) { + log.warn("GoodReads: ISBN lookup failed: {}, falling back to title search", e.getMessage()); + } + } + Optional preview = fetchMetadataPreviews(book, fetchMetadataRequest).stream().findFirst(); if (preview.isEmpty()) { return null; @@ -92,23 +112,37 @@ public class GoodReadsParser implements BookParser, DetailedMetadataProvider { } } + private String extractGoodreadsIdFromOgUrl(Document doc) { + String ogUrl = Optional.ofNullable(doc.selectFirst("meta[property=og:url]")) + .map(e -> e.attr("content")) + .orElse(null); + if (ogUrl == null || ogUrl.isBlank()) { + return null; + } + try { + String path = new URI(ogUrl).getPath(); + if (path == null || path.isBlank()) { + return null; + } + String id = path.substring(path.lastIndexOf('/') + 1); + return id.isBlank() ? null : id; + } catch (URISyntaxException e) { + log.warn("GoodReads: Could not parse og:url '{}': {}", ogUrl, e.getMessage()); + return null; + } + } + @Override public List fetchMetadata(Book book, FetchMetadataRequest fetchMetadataRequest) { String isbn = ParserUtils.cleanIsbn(fetchMetadataRequest.getIsbn()); if (isbn != null && !isbn.isBlank()) { log.info("Goodreads Query URL (ISBN): {}{}", BASE_ISBN_URL, isbn); Document doc = fetchDoc(BASE_ISBN_URL + isbn); - String ogUrl = Optional.ofNullable(doc.selectFirst("meta[property=og:url]")) - .map(e -> e.attr("content")) - .orElse(null); - - if (ogUrl != null && !ogUrl.isBlank()) { - String goodreadsId = ogUrl.substring(ogUrl.lastIndexOf('/') + 1); - if (!goodreadsId.isBlank()) { - BookMetadata metadata = parseBookDetails(doc, goodreadsId); - if (metadata != null) { - return List.of(metadata); - } + String goodreadsId = extractGoodreadsIdFromOgUrl(doc); + if (goodreadsId != null) { + BookMetadata metadata = parseBookDetails(doc, goodreadsId); + if (metadata != null) { + return List.of(metadata); } } }