fix(metadata): missing lubimyczytac fields and fetch retry (#2179)
* fix(metadata): fix LubimyczytacId and LubimyczytacRating not appearing with metadata refresh * fix(metadata): remove searching by ISBN on lubimyczytac.pl (not supported) * fix(metadata): add retries for lubimyczytac.pl --------- Co-authored-by: ACX <8075870+acx10@users.noreply.github.com>
This commit is contained in:
+12
@@ -334,12 +334,14 @@ public class MetadataRefreshService {
|
||||
addProviderToSet(fieldOptions.getComicvineId(), uniqueProviders, appSettings);
|
||||
addProviderToSet(fieldOptions.getHardcoverId(), uniqueProviders, appSettings);
|
||||
addProviderToSet(fieldOptions.getGoogleId(), uniqueProviders, appSettings);
|
||||
addProviderToSet(fieldOptions.getLubimyczytacId(), uniqueProviders, appSettings);
|
||||
addProviderToSet(fieldOptions.getAmazonRating(), uniqueProviders, appSettings);
|
||||
addProviderToSet(fieldOptions.getAmazonReviewCount(), uniqueProviders, appSettings);
|
||||
addProviderToSet(fieldOptions.getGoodreadsRating(), uniqueProviders, appSettings);
|
||||
addProviderToSet(fieldOptions.getGoodreadsReviewCount(), uniqueProviders, appSettings);
|
||||
addProviderToSet(fieldOptions.getHardcoverRating(), uniqueProviders, appSettings);
|
||||
addProviderToSet(fieldOptions.getHardcoverReviewCount(), uniqueProviders, appSettings);
|
||||
addProviderToSet(fieldOptions.getLubimyczytacRating(), uniqueProviders, appSettings);
|
||||
addProviderToSet(fieldOptions.getRanobedbId(), uniqueProviders, appSettings);
|
||||
addProviderToSet(fieldOptions.getRanobedbRating(), uniqueProviders, appSettings);
|
||||
addProviderToSet(fieldOptions.getMoods(), uniqueProviders, appSettings);
|
||||
@@ -372,6 +374,7 @@ public class MetadataRefreshService {
|
||||
case Comicvine -> settings.getComicvine() != null && settings.getComicvine().isEnabled();
|
||||
case Ranobedb -> settings.getRanobedb() != null && settings.getRanobedb().isEnabled();
|
||||
case Douban -> settings.getDouban() != null && settings.getDouban().isEnabled();
|
||||
case Lubimyczytac -> settings.getLubimyczytac() != null && settings.getLubimyczytac().isEnabled();
|
||||
default -> true;
|
||||
};
|
||||
}
|
||||
@@ -510,6 +513,15 @@ public class MetadataRefreshService {
|
||||
metadata.setComicvineId(metadataMap.get(Comicvine).getComicvineId());
|
||||
}
|
||||
}
|
||||
if (enabledFields.isLubimyczytacId()) {
|
||||
if (metadataMap.containsKey(Lubimyczytac)) {
|
||||
metadata.setLubimyczytacId(metadataMap.get(Lubimyczytac).getLubimyczytacId());
|
||||
}
|
||||
}
|
||||
if (enabledFields.isLubimyczytacRating()) {
|
||||
if (metadataMap.containsKey(Lubimyczytac)) {
|
||||
metadata.setLubimyczytacRating(metadataMap.get(Lubimyczytac).getLubimyczytacRating());
|
||||
}
|
||||
if (enabledFields.isRanobedbId()) {
|
||||
if (metadataMap.containsKey(Ranobedb)) {
|
||||
metadata.setRanobedbId(metadataMap.get(Ranobedb).getRanobedbId());
|
||||
|
||||
+54
-23
@@ -24,6 +24,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Collections;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -36,6 +37,7 @@ public class LubimyCzytacParser implements BookParser {
|
||||
private static final String SEARCH_URL = BASE_URL + "/szukaj/ksiazki";
|
||||
private static final String USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36";
|
||||
private static final int CONNECTION_TIMEOUT_MS = 10000;
|
||||
private static final int MAX_RETRIES = 3;
|
||||
private static final int MAX_RESULTS = 10;
|
||||
private static final double RATING_SCALE_DIVISOR = 2.0; // Convert 10-point scale to 5-point scale
|
||||
private static final Pattern SERIES_NUMBER_PATTERN = Pattern.compile("\\(tom\\s+(\\d+)\\)");
|
||||
@@ -115,11 +117,6 @@ public class LubimyCzytacParser implements BookParser {
|
||||
}
|
||||
|
||||
private String buildSearchQuery(FetchMetadataRequest request) {
|
||||
String isbn = request.getIsbn();
|
||||
if (isbn != null && !isbn.isEmpty()) {
|
||||
return isbn;
|
||||
}
|
||||
|
||||
String title = request.getTitle();
|
||||
if (title != null && !title.isEmpty()) {
|
||||
return title.trim();
|
||||
@@ -141,17 +138,46 @@ public class LubimyCzytacParser implements BookParser {
|
||||
}
|
||||
|
||||
private List<String> searchBooks(String query, String author) {
|
||||
List<String> bookUrls = new ArrayList<>();
|
||||
|
||||
try {
|
||||
String searchUrl = buildSearchUrl(query, author);
|
||||
log.info("Searching LubimyCzytac: {}", searchUrl);
|
||||
|
||||
Document doc = Jsoup.connect(searchUrl)
|
||||
Document doc = fetchWithRetry(searchUrl);
|
||||
if (doc == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return extractBookUrls(doc);
|
||||
}
|
||||
|
||||
private Document fetchWithRetry(String url) {
|
||||
for (int attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
||||
try {
|
||||
return Jsoup.connect(url)
|
||||
.userAgent(USER_AGENT)
|
||||
.timeout(CONNECTION_TIMEOUT_MS)
|
||||
.get();
|
||||
|
||||
} catch (IOException e) {
|
||||
if (!isConnectivityError(e)) {
|
||||
log.error("Error connecting to LubimyCzytac", e);
|
||||
return null;
|
||||
} else {
|
||||
log.warn("Attempt {}/{} failed to connect to {}. Retrying...", attempt, MAX_RETRIES, url);
|
||||
try {
|
||||
Thread.sleep(1000 * attempt);
|
||||
} catch (InterruptedException ie) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.error("Error connecting to LubimyCzytac. All {} retry attempts failed", MAX_RETRIES);
|
||||
return null;
|
||||
}
|
||||
|
||||
private static List<String> extractBookUrls(Document doc) {
|
||||
List<String> bookUrls = new ArrayList<>();
|
||||
Elements results = doc.select(".authorAllBooks__single");
|
||||
log.info("Found {} search results", results.size());
|
||||
|
||||
@@ -166,21 +192,18 @@ public class LubimyCzytacParser implements BookParser {
|
||||
}
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
log.error("Error searching LubimyCzytac", e);
|
||||
}
|
||||
|
||||
return bookUrls;
|
||||
}
|
||||
|
||||
private BookMetadata parseBookDetails(String url) {
|
||||
try {
|
||||
log.info("Parsing book details from: {}", url);
|
||||
|
||||
Document doc = Jsoup.connect(url)
|
||||
.userAgent(USER_AGENT)
|
||||
.timeout(CONNECTION_TIMEOUT_MS)
|
||||
.get();
|
||||
Document doc = fetchWithRetry(url);
|
||||
|
||||
if (doc == null) {
|
||||
log.error("Error parsing book details from: {}", url);
|
||||
return null;
|
||||
}
|
||||
|
||||
BookMetadata metadata = new BookMetadata();
|
||||
metadata.setProvider(MetadataProvider.Lubimyczytac);
|
||||
@@ -276,11 +299,6 @@ public class LubimyCzytacParser implements BookParser {
|
||||
}
|
||||
|
||||
return metadata;
|
||||
|
||||
} catch (IOException e) {
|
||||
log.error("Error parsing book details from: {}", url, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private String extractIdFromUrl(String url) {
|
||||
@@ -432,4 +450,17 @@ public class LubimyCzytacParser implements BookParser {
|
||||
log.warn("Failed to parse JSON-LD structure", e);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isConnectivityError(Exception e) {
|
||||
Throwable cause = e;
|
||||
while (cause != null) {
|
||||
if (e instanceof java.net.ConnectException ||
|
||||
e instanceof java.nio.channels.UnresolvedAddressException ||
|
||||
e instanceof java.net.SocketTimeoutException) {
|
||||
return true;
|
||||
}
|
||||
cause = cause.getCause();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user