Add ISBN to Metadata Search

This commit is contained in:
aditya.chandel
2025-08-28 23:35:24 -06:00
committed by Aditya Chandel
parent 12b7aaa8e9
commit 4abf5eccaa
9 changed files with 257 additions and 134 deletions
@@ -38,7 +38,12 @@ public class GoogleBooksApiResponse {
@Data @Data
public static class ImageLinks { public static class ImageLinks {
private String smallThumbnail;
private String thumbnail; private String thumbnail;
private String small;
private String medium;
private String large;
private String extraLarge;
} }
} }
} }
@@ -32,7 +32,7 @@ import java.util.stream.Collectors;
@AllArgsConstructor @AllArgsConstructor
public class AmazonBookParser implements BookParser { public class AmazonBookParser implements BookParser {
private static final int COUNT_DETAILED_METADATA_TO_GET = 5; private static final int COUNT_DETAILED_METADATA_TO_GET = 3;
private static final String BASE_BOOK_URL = "https://www.amazon.com/dp/"; private static final String BASE_BOOK_URL = "https://www.amazon.com/dp/";
private final AppSettingService appSettingService; private final AppSettingService appSettingService;
@@ -76,7 +76,6 @@ public class AmazonBookParser implements BookParser {
} }
private LinkedList<String> getAmazonBookIds(Book book, FetchMetadataRequest request) { private LinkedList<String> getAmazonBookIds(Book book, FetchMetadataRequest request) {
log.info("Amazon: Querying metadata for ISBN: {}, Title: {}, Author: {}, FileName: {}", request.getIsbn(), request.getTitle(), request.getAuthor(), book.getFileName());
String queryUrl = buildQueryUrl(request, book); String queryUrl = buildQueryUrl(request, book);
if (queryUrl == null) { if (queryUrl == null) {
log.error("Query URL is null, cannot proceed."); log.error("Query URL is null, cannot proceed.");
@@ -194,6 +193,16 @@ public class AmazonBookParser implements BookParser {
} }
private String buildQueryUrl(FetchMetadataRequest fetchMetadataRequest, Book book) { private String buildQueryUrl(FetchMetadataRequest fetchMetadataRequest, Book book) {
// 1. Prefer ISBN if present
if (fetchMetadataRequest.getIsbn() != null && !fetchMetadataRequest.getIsbn().isEmpty()) {
String url = "https://www.amazon."
+ appSettingService.getAppSettings().getMetadataProviderSettings().getAmazon().getDomain()
+ "/s?k=" + fetchMetadataRequest.getIsbn();
log.info("Amazon Query URL (ISBN): {}", url);
return url;
}
// 2. Otherwise, fall back to title + author + filename
StringBuilder searchTerm = new StringBuilder(); StringBuilder searchTerm = new StringBuilder();
String title = fetchMetadataRequest.getTitle(); String title = fetchMetadataRequest.getTitle();
@@ -231,8 +240,10 @@ public class AmazonBookParser implements BookParser {
} }
String encodedSearchTerm = searchTerm.toString().replace(" ", "+"); String encodedSearchTerm = searchTerm.toString().replace(" ", "+");
String url = "https://www.amazon." + appSettingService.getAppSettings().getMetadataProviderSettings().getAmazon().getDomain() + "/s?k=" + encodedSearchTerm; String url = "https://www.amazon."
log.info("Query URL: {}", url); + appSettingService.getAppSettings().getMetadataProviderSettings().getAmazon().getDomain()
+ "/s?k=" + encodedSearchTerm;
log.info("Amazon Query URL: {}", url);
return url; return url;
} }
@@ -37,7 +37,8 @@ public class GoodReadsParser implements BookParser {
private static final String BASE_SEARCH_URL = "https://www.goodreads.com/search?q="; private static final String BASE_SEARCH_URL = "https://www.goodreads.com/search?q=";
private static final String BASE_BOOK_URL = "https://www.goodreads.com/book/show/"; private static final String BASE_BOOK_URL = "https://www.goodreads.com/book/show/";
private static final int COUNT_DETAILED_METADATA_TO_GET = 5; private static final String BASE_ISBN_URL = "https://www.goodreads.com/book/isbn/";
private static final int COUNT_DETAILED_METADATA_TO_GET = 3;
private final AppSettingService appSettingService; private final AppSettingService appSettingService;
@Override @Override
@@ -52,6 +53,25 @@ public class GoodReadsParser implements BookParser {
@Override @Override
public List<BookMetadata> fetchMetadata(Book book, FetchMetadataRequest fetchMetadataRequest) { public List<BookMetadata> fetchMetadata(Book book, FetchMetadataRequest fetchMetadataRequest) {
String isbn = 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);
}
}
}
}
List<BookMetadata> previews = fetchMetadataPreviews(book, fetchMetadataRequest).stream() List<BookMetadata> previews = fetchMetadataPreviews(book, fetchMetadataRequest).stream()
.limit(COUNT_DETAILED_METADATA_TO_GET) .limit(COUNT_DETAILED_METADATA_TO_GET)
.toList(); .toList();
@@ -387,36 +407,54 @@ public class GoodReadsParser implements BookParser {
public String generateSearchUrl(String searchTerm) { public String generateSearchUrl(String searchTerm) {
String encodedSearchTerm = URLEncoder.encode(searchTerm, StandardCharsets.UTF_8); String encodedSearchTerm = URLEncoder.encode(searchTerm, StandardCharsets.UTF_8);
return BASE_SEARCH_URL + encodedSearchTerm; String url = BASE_SEARCH_URL + encodedSearchTerm;
log.info("Goodreads Query URL: {}", url);
return url;
} }
public List<BookMetadata> fetchMetadataPreviews(Book book, FetchMetadataRequest request) { public List<BookMetadata> fetchMetadataPreviews(Book book, FetchMetadataRequest request) {
String searchTerm = getSearchTerm(book, request); String searchTerm = getSearchTerm(book, request);
if (searchTerm != null) {
log.info("GoodReads: Fetching metadata previews for: {}", searchTerm); if (searchTerm == null || searchTerm.isEmpty()) {
log.info("GoodReads: No metadata previews found (no ISBN, title, or filename).");
return Collections.emptyList();
}
try { try {
String searchUrl = generateSearchUrl(searchTerm); String searchUrl = generateSearchUrl(searchTerm);
Elements previewBooks = fetchDoc(searchUrl).select("table.tableList").first().select("tr[itemtype=http://schema.org/Book]"); Elements previewBooks = fetchDoc(searchUrl)
.select("table.tableList")
.first()
.select("tr[itemtype=http://schema.org/Book]");
List<BookMetadata> metadataPreviews = new ArrayList<>(); List<BookMetadata> metadataPreviews = new ArrayList<>();
FuzzyScore fuzzyScore = new FuzzyScore(Locale.ENGLISH); FuzzyScore fuzzyScore = new FuzzyScore(Locale.ENGLISH);
String queryAuthor = request.getAuthor(); String queryAuthor = request.getAuthor();
for (Element previewBook : previewBooks) { for (Element previewBook : previewBooks) {
Set<String> authors = extractAuthorsPreview(previewBook); Set<String> authors = extractAuthorsPreview(previewBook);
// Author fuzzy match if author provided
if (queryAuthor != null && !queryAuthor.isBlank()) { if (queryAuthor != null && !queryAuthor.isBlank()) {
List<String> queryAuthorTokens = List.of(queryAuthor.toLowerCase().split("\\s+")); List<String> queryAuthorTokens = List.of(queryAuthor.toLowerCase().split("\\s+"));
boolean matches = authors.stream().flatMap(a -> Arrays.stream(a.toLowerCase().split("\\s+"))).anyMatch(actual -> { boolean matches = authors.stream()
.flatMap(a -> Arrays.stream(a.toLowerCase().split("\\s+")))
.anyMatch(actual -> {
for (String query : queryAuthorTokens) { for (String query : queryAuthorTokens) {
int score = fuzzyScore.fuzzyScore(actual, query); int score = fuzzyScore.fuzzyScore(actual, query);
int maxScore = Math.max(fuzzyScore.fuzzyScore(query, query), fuzzyScore.fuzzyScore(actual, actual)); int maxScore = Math.max(fuzzyScore.fuzzyScore(query, query),
fuzzyScore.fuzzyScore(actual, actual));
double similarity = maxScore > 0 ? (double) score / maxScore : 0; double similarity = maxScore > 0 ? (double) score / maxScore : 0;
if (similarity >= 0.5) return true; if (similarity >= 0.5) return true;
} }
return false; return false;
}); });
if (!matches) { if (!matches) {
continue; continue;
} }
} }
BookMetadata previewMetadata = BookMetadata.builder() BookMetadata previewMetadata = BookMetadata.builder()
.goodreadsId(String.valueOf(extractGoodReadsIdPreview(previewBook))) .goodreadsId(String.valueOf(extractGoodReadsIdPreview(previewBook)))
.title(extractTitlePreview(previewBook)) .title(extractTitlePreview(previewBook))
@@ -424,16 +462,15 @@ public class GoodReadsParser implements BookParser {
.build(); .build();
metadataPreviews.add(previewMetadata); metadataPreviews.add(previewMetadata);
} }
Thread.sleep(Duration.ofSeconds(1)); Thread.sleep(Duration.ofSeconds(1));
return metadataPreviews; return metadataPreviews;
} catch (Exception e) { } catch (Exception e) {
log.error("Error fetching metadata previews: {}", e.getMessage()); log.error("Error fetching metadata previews: {}", e.getMessage());
return Collections.emptyList(); return Collections.emptyList();
} }
} }
log.info("GoodReads: No metadata previews found for title '{}'!", request.getTitle());
return Collections.emptyList();
}
private String getSearchTerm(Book book, FetchMetadataRequest request) { private String getSearchTerm(Book book, FetchMetadataRequest request) {
return (request.getTitle() != null && !request.getTitle().isEmpty()) return (request.getTitle() != null && !request.getTitle().isEmpty())
@@ -41,18 +41,55 @@ public class GoogleParser implements BookParser {
@Override @Override
public List<BookMetadata> fetchMetadata(Book book, FetchMetadataRequest fetchMetadataRequest) { public List<BookMetadata> fetchMetadata(Book book, FetchMetadataRequest fetchMetadataRequest) {
// 1. If ISBN exists, prioritize it
if (fetchMetadataRequest.getIsbn() != null && !fetchMetadataRequest.getIsbn().isBlank()) {
return getMetadataListByIsbn(fetchMetadataRequest.getIsbn());
}
// 2. Otherwise fallback to existing title/author search
String searchTerm = getSearchTerm(book, fetchMetadataRequest); String searchTerm = getSearchTerm(book, fetchMetadataRequest);
return searchTerm != null ? getMetadataListByTerm(searchTerm) : List.of(); return searchTerm != null ? getMetadataListByTerm(searchTerm) : List.of();
} }
private List<BookMetadata> getMetadataListByIsbn(String isbn) {
try {
URI uri = UriComponentsBuilder.fromUriString(GOOGLE_BOOKS_API_URL)
.queryParam("q", "isbn:" + isbn.replace("-", ""))
.build()
.toUri();
log.info("Google Books API URL (ISBN): {}", uri);
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(uri)
.GET()
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() == 200) {
return parseGoogleBooksApiResponse(response.body());
} else {
log.error("Failed to fetch metadata from Google Books API with ISBN. Status: {}, Response: {}",
response.statusCode(), response.body());
return List.of();
}
} catch (IOException | InterruptedException e) {
log.error("Error occurred while fetching metadata from Google Books API with ISBN", e);
return List.of();
}
}
public List<BookMetadata> getMetadataListByTerm(String term) { public List<BookMetadata> getMetadataListByTerm(String term) {
log.info("Google Books: Fetching metadata for: {}", term);
try { try {
URI uri = UriComponentsBuilder.fromUriString(GOOGLE_BOOKS_API_URL) URI uri = UriComponentsBuilder.fromUriString(GOOGLE_BOOKS_API_URL)
.queryParam("q", term) .queryParam("q", term)
.build() .build()
.toUri(); .toUri();
log.info("Google Books API URLx: {}", uri);
HttpClient client = HttpClient.newHttpClient(); HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder() HttpRequest request = HttpRequest.newBuilder()
.uri(uri) .uri(uri)
@@ -87,6 +124,17 @@ public class GoogleParser implements BookParser {
GoogleBooksApiResponse.Item.VolumeInfo volumeInfo = item.getVolumeInfo(); GoogleBooksApiResponse.Item.VolumeInfo volumeInfo = item.getVolumeInfo();
Map<String, String> isbns = extractISBNs(volumeInfo.getIndustryIdentifiers()); Map<String, String> isbns = extractISBNs(volumeInfo.getIndustryIdentifiers());
String highResCover = Optional.ofNullable(volumeInfo.getImageLinks())
.map(links -> {
if (links.getExtraLarge() != null) return links.getExtraLarge();
if (links.getLarge() != null) return links.getLarge();
if (links.getMedium() != null) return links.getMedium();
if (links.getSmall() != null) return links.getSmall();
if (links.getThumbnail() != null) return links.getThumbnail();
return links.getSmallThumbnail();
})
.orElse(null);
return BookMetadata.builder() return BookMetadata.builder()
.provider(MetadataProvider.Google) .provider(MetadataProvider.Google)
.googleId(item.getId()) .googleId(item.getId())
@@ -100,9 +148,7 @@ public class GoogleParser implements BookParser {
.isbn13(isbns.get("ISBN_13")) .isbn13(isbns.get("ISBN_13"))
.isbn10(isbns.get("ISBN_10")) .isbn10(isbns.get("ISBN_10"))
.pageCount(volumeInfo.getPageCount()) .pageCount(volumeInfo.getPageCount())
.thumbnailUrl(Optional.ofNullable(volumeInfo.getImageLinks()) .thumbnailUrl(highResCover)
.map(GoogleBooksApiResponse.Item.ImageLinks::getThumbnail)
.orElse(null))
.language(volumeInfo.getLanguage()) .language(volumeInfo.getLanguage())
.build(); .build();
} }
@@ -10,6 +10,7 @@ import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.apache.commons.text.similarity.FuzzyScore; import org.apache.commons.text.similarity.FuzzyScore;
import java.util.Locale; import java.util.Locale;
import java.math.BigDecimal; import java.math.BigDecimal;
@@ -26,11 +27,20 @@ public class HardcoverParser implements BookParser {
@Override @Override
public List<BookMetadata> fetchMetadata(Book book, FetchMetadataRequest fetchMetadataRequest) { public List<BookMetadata> fetchMetadata(Book book, FetchMetadataRequest fetchMetadataRequest) {
log.info("Hardcover: Fetching metadata for book {}", fetchMetadataRequest.getTitle());
List<GraphQLResponse.Hit> hits = hardcoverBookSearchService.searchBooks(fetchMetadataRequest.getTitle()); boolean searchByIsbn = fetchMetadataRequest.getIsbn() != null && !fetchMetadataRequest.getIsbn().isBlank();
List<GraphQLResponse.Hit> hits;
if (searchByIsbn) {
log.info("Hardcover: Fetching metadata using ISBN {}", fetchMetadataRequest.getIsbn());
hits = hardcoverBookSearchService.searchBooks(fetchMetadataRequest.getIsbn());
} else {
log.info("Hardcover: Fetching metadata using title '{}'", fetchMetadataRequest.getTitle());
hits = hardcoverBookSearchService.searchBooks(fetchMetadataRequest.getTitle());
}
if (hits == null || hits.isEmpty()) { if (hits == null || hits.isEmpty()) {
log.info("Hardcover: No results found for title '{}'", fetchMetadataRequest.getTitle()); log.info("Hardcover: No results found for {}", searchByIsbn ? "ISBN " + fetchMetadataRequest.getIsbn() : "title " + fetchMetadataRequest.getTitle());
return List.of(); return List.of();
} }
@@ -39,11 +49,13 @@ public class HardcoverParser implements BookParser {
return hits.stream() return hits.stream()
.filter(hit -> { .filter(hit -> {
if (searchAuthor.isBlank()) return true; if (searchByIsbn || searchAuthor.isBlank()) return true;
List<String> actualAuthorTokens = hit.getDocument().getAuthorNames().stream() List<String> actualAuthorTokens = hit.getDocument().getAuthorNames().stream()
.flatMap(name -> List.of(name.toLowerCase().split("\\s+")).stream()) .flatMap(name -> List.of(name.toLowerCase().split("\\s+")).stream())
.toList(); .toList();
List<String> searchAuthorTokens = List.of(searchAuthor.toLowerCase().split("\\s+")); List<String> searchAuthorTokens = List.of(searchAuthor.toLowerCase().split("\\s+"));
for (String actual : actualAuthorTokens) { for (String actual : actualAuthorTokens) {
for (String query : searchAuthorTokens) { for (String query : searchAuthorTokens) {
int score = fuzzyScore.fuzzyScore(actual, query); int score = fuzzyScore.fuzzyScore(actual, query);
@@ -71,14 +83,12 @@ public class HardcoverParser implements BookParser {
try { try {
metadata.setSeriesNumber(Float.parseFloat(String.valueOf(doc.getFeaturedSeries().getPosition()))); metadata.setSeriesNumber(Float.parseFloat(String.valueOf(doc.getFeaturedSeries().getPosition())));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
} }
} }
} }
if (doc.getRating() != null) { if (doc.getRating() != null) {
BigDecimal roundedRating = BigDecimal.valueOf(doc.getRating()).setScale(2, RoundingMode.HALF_UP); metadata.setHardcoverRating(BigDecimal.valueOf(doc.getRating()).setScale(2, RoundingMode.HALF_UP).doubleValue());
metadata.setHardcoverRating(roundedRating.doubleValue());
} }
metadata.setHardcoverReviewCount(doc.getRatingsCount()); metadata.setHardcoverReviewCount(doc.getRatingsCount());
metadata.setPageCount(doc.getPages()); metadata.setPageCount(doc.getPages());
@@ -86,21 +96,15 @@ public class HardcoverParser implements BookParser {
metadata.setCategories(doc.getGenres()); metadata.setCategories(doc.getGenres());
if (doc.getIsbns() != null) { if (doc.getIsbns() != null) {
metadata.setIsbn10(doc.getIsbns().stream() metadata.setIsbn10(doc.getIsbns().stream().filter(isbn -> isbn.length() == 10).findFirst().orElse(null));
.filter(isbn -> isbn.length() == 10) metadata.setIsbn13(doc.getIsbns().stream().filter(isbn -> isbn.length() == 13).findFirst().orElse(null));
.findFirst()
.orElse(null));
metadata.setIsbn13(doc.getIsbns().stream()
.filter(isbn -> isbn.length() == 13)
.findFirst()
.orElse(null));
} }
metadata.setThumbnailUrl(doc.getImage() != null ? doc.getImage().getUrl() : null); metadata.setThumbnailUrl(doc.getImage() != null ? doc.getImage().getUrl() : null);
metadata.setProvider(MetadataProvider.Hardcover); metadata.setProvider(MetadataProvider.Hardcover);
return metadata; return metadata;
}).toList(); })
.toList();
} }
@Override @Override
@@ -9,9 +9,9 @@
} @else { } @else {
<form class="flex flex-col w-full h-full pt-2 min-w-full md:min-w-[60rem] pr-0 md:pr-2 pl-0 md:pl-2" [formGroup]="form" (ngSubmit)="onSubmit()"> <form class="flex flex-col w-full h-full pt-2 min-w-full md:min-w-[60rem] pr-0 md:pr-2 pl-0 md:pl-2" [formGroup]="form" (ngSubmit)="onSubmit()">
<div class="flex flex-col space-y-3">
<div class="grid grid-cols-1 md:flex md:flex-row w-full gap-2 md:gap-4 md:items-end"> <div class="grid grid-cols-1 md:flex md:flex-row w-full gap-2 md:gap-4 md:items-end">
<div class="flex flex-col gap-1 w-full max-w-full md:w-1/3">
<div class="flex flex-col gap-1 w-full max-w-full md:w-3/12">
<label for="provider">Providers</label> <label for="provider">Providers</label>
<p-multiselect <p-multiselect
id="provider" id="provider"
@@ -24,12 +24,17 @@
</p-multiselect> </p-multiselect>
</div> </div>
<div class="flex flex-col gap-1 w-full max-w-full md:w-5/12"> <div class="flex flex-col gap-1 w-full max-w-full md:w-56">
<label for="isbn">ISBN</label>
<input pInputText formControlName="isbn" id="isbn" class="w-full" placeholder="ISBN-10 or ISBN-13"/>
</div>
<div class="flex flex-col gap-1 w-full max-w-full md:w-1/3">
<label for="title">Title</label> <label for="title">Title</label>
<input pInputText formControlName="title" id="title" class="w-full"/> <input pInputText formControlName="title" id="title" class="w-full"/>
</div> </div>
<div class="flex flex-col gap-1 w-full max-w-full md:w-4/12"> <div class="flex flex-col gap-1 w-full max-w-full md:w-1/3">
<label for="author">Author</label> <label for="author">Author</label>
<input pInputText formControlName="author" id="author" class="w-full"/> <input pInputText formControlName="author" id="author" class="w-full"/>
</div> </div>
@@ -46,7 +51,13 @@
</p-button> </p-button>
</div> </div>
</div> </div>
</div>
<div class="text-sm text-gray-400 flex items-start gap-2">
<i class="pi pi-info-circle text-sky-600 mt-0.5"></i>
<span>
When an ISBN is provided, the search will use only the ISBN. If no ISBN is given, the search will fall back to Title and Author.
</span>
</div>
</div> </div>
@if (loading) { @if (loading) {
@@ -80,8 +91,12 @@
<div class="flex flex-col md:flex-row gap-2 md:gap-4 justify-between"> <div class="flex flex-col md:flex-row gap-2 md:gap-4 justify-between">
<p class="font-bold">{{ truncateText(metadata['title']!, 90) }}</p> <p class="font-bold">{{ truncateText(metadata['title']!, 90) }}</p>
<div class="flex flex-wrap gap-2 text-sm"> <div class="flex flex-wrap gap-2 text-sm">
@if (metadata['isbn10'] || metadata['asin']) { @if (metadata['isbn10']) {
<p>ISBN: {{ metadata['isbn10'] || metadata['asin'] }}</p> <p>ISBN10: {{ metadata['isbn10']}}</p>
<span class="hidden md:inline">|</span>
}
@if (metadata['isbn13']) {
<p>ISBN13: {{ metadata['isbn13']}}</p>
<span class="hidden md:inline">|</span> <span class="hidden md:inline">|</span>
} }
<p>Published: {{ metadata['publishedDate'] }}</p> <p>Published: {{ metadata['publishedDate'] }}</p>
@@ -60,7 +60,8 @@ export class MetadataSearcherComponent implements OnInit, OnDestroy {
this.form = this.formBuilder.group({ this.form = this.formBuilder.group({
provider: null, provider: null,
title: [''], title: [''],
author: [''] author: [''],
isbn: ['']
}); });
} }
@@ -105,7 +106,8 @@ export class MetadataSearcherComponent implements OnInit, OnDestroy {
this.form.patchValue({ this.form.patchValue({
provider: this.providers, provider: this.providers,
title: book.metadata?.title ?? '', title: book.metadata?.title ?? '',
author: book.metadata?.authors?.[0] ?? '' author: book.metadata?.authors?.[0] ?? '',
isbn: book.metadata?.isbn10 ?? book.metadata?.isbn13 ?? ''
}); });
} }
@@ -118,7 +120,8 @@ export class MetadataSearcherComponent implements OnInit, OnDestroy {
get isSearchEnabled(): boolean { get isSearchEnabled(): boolean {
const providerSelected = !!this.form.get('provider')?.value; const providerSelected = !!this.form.get('provider')?.value;
const title = this.form.get('title')?.value; const title = this.form.get('title')?.value;
return providerSelected && title; const isbn = this.form.get('isbn')?.value;
return providerSelected && (title || isbn);
} }
onSubmit(): void { onSubmit(): void {
@@ -131,7 +134,8 @@ export class MetadataSearcherComponent implements OnInit, OnDestroy {
bookId: this.bookId, bookId: this.bookId,
providers: providerKeys, providers: providerKeys,
title: this.form.get('title')?.value, title: this.form.get('title')?.value,
author: this.form.get('author')?.value author: this.form.get('author')?.value,
isbn: this.form.get('isbn')?.value
}; };
this.loading = true; this.loading = true;
@@ -2,5 +2,6 @@ export interface FetchMetadataRequest {
bookId: number, bookId: number,
providers: string[], providers: string[],
title: string, title: string,
author: string author: string,
isbn: string
} }