Automatically detect and set book subtitle from title field (#1146)
This commit is contained in:
+1
-1
@@ -70,7 +70,7 @@ public class MonitoredFileOperationService {
|
||||
if (!sourceDir.equals(targetDir) && Files.exists(targetDir) && monitoringRegistrationService.isPathMonitored(targetDir)) {
|
||||
monitoringRegistrationService.unregisterSpecificPath(targetDir);
|
||||
unregisteredPaths.add(targetDir);
|
||||
log.info("Temporarily unregistered target directory to prevent monitoring conflicts: {}", targetDir);
|
||||
log.debug("Temporarily unregistered target directory to prevent monitoring conflicts: {}", targetDir);
|
||||
}
|
||||
|
||||
log.debug("Protected {} directory paths from monitoring during file operation", unregisteredPaths.size());
|
||||
|
||||
+1
-1
@@ -404,7 +404,7 @@ public class MetadataRefreshService {
|
||||
protected void setOtherUnspecifiedMetadata(Map<MetadataProvider, BookMetadata> metadataMap, BookMetadata metadataCombined, MetadataProvider provider) {
|
||||
if (metadataMap.containsKey(provider)) {
|
||||
BookMetadata metadata = metadataMap.get(provider);
|
||||
metadataCombined.setSubtitle(metadata.getSubtitle() != null ? metadata.getSubtitle() : metadata.getTitle());
|
||||
metadataCombined.setSubtitle(metadata.getSubtitle() != null ? metadata.getSubtitle() : metadataCombined.getSubtitle());
|
||||
metadataCombined.setPublisher(metadata.getPublisher() != null ? metadata.getPublisher() : metadataCombined.getPublisher());
|
||||
metadataCombined.setPublishedDate(metadata.getPublishedDate() != null ? metadata.getPublishedDate() : metadataCombined.getPublishedDate());
|
||||
metadataCombined.setIsbn10(metadata.getIsbn10() != null ? metadata.getIsbn10() : metadataCombined.getIsbn10());
|
||||
|
||||
+10
-4
@@ -250,17 +250,23 @@ public class AmazonBookParser implements BookParser {
|
||||
private String getTitle(Document doc) {
|
||||
Element titleElement = doc.getElementById("productTitle");
|
||||
if (titleElement != null) {
|
||||
return titleElement.text();
|
||||
String fullTitle = titleElement.text();
|
||||
return fullTitle.split(":", 2)[0].trim();
|
||||
}
|
||||
log.warn("Failed to parse title: Element not found.");
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getSubtitle(Document doc) {
|
||||
Element subtitleElement = doc.getElementById("productSubtitle");
|
||||
if (subtitleElement != null) {
|
||||
return subtitleElement.text();
|
||||
Element titleElement = doc.getElementById("productTitle");
|
||||
if (titleElement != null) {
|
||||
String fullTitle = titleElement.text();
|
||||
String[] parts = fullTitle.split(":", 2);
|
||||
if (parts.length > 1) {
|
||||
return parts[1].trim();
|
||||
}
|
||||
}
|
||||
|
||||
log.warn("Failed to parse subtitle: Element not found.");
|
||||
return null;
|
||||
}
|
||||
|
||||
+14
-3
@@ -224,7 +224,8 @@ public class GoodReadsParser implements BookParser {
|
||||
private void extractBookDetails(JSONObject apolloStateJson, LinkedHashSet<String> keySet, BookMetadata.BookMetadataBuilder builder) {
|
||||
JSONObject bookJson = getValidBookJson(apolloStateJson, keySet, "Book:kca:");
|
||||
if (bookJson != null) {
|
||||
builder.title(handleStringNull(bookJson.optString("title")))
|
||||
builder.title(handleStringNull(extractTitleFromFull(bookJson.optString("title"))))
|
||||
.subtitle(handleStringNull(extractSubtitleFromFull(bookJson.optString("title"))))
|
||||
.description(handleStringNull(bookJson.optString("description")))
|
||||
.thumbnailUrl(handleStringNull(bookJson.optString("imageUrl")))
|
||||
.categories(extractGenres(bookJson));
|
||||
@@ -263,12 +264,22 @@ public class GoodReadsParser implements BookParser {
|
||||
builder.goodreadsRating(parseDouble(statsJson.optString("averageRating")))
|
||||
.goodreadsReviewCount(parseInteger(statsJson.optString("ratingsCount")));
|
||||
}
|
||||
|
||||
JSONObject detailsJson = workJson.optJSONObject("details");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String extractTitleFromFull(String fullTitle) {
|
||||
if (fullTitle == null) return null;
|
||||
String[] parts = fullTitle.split(":", 2);
|
||||
return parts[0].trim();
|
||||
}
|
||||
|
||||
private String extractSubtitleFromFull(String fullTitle) {
|
||||
if (fullTitle == null) return null;
|
||||
String[] parts = fullTitle.split(":", 2);
|
||||
return parts.length > 1 ? parts[1].trim() : null;
|
||||
}
|
||||
|
||||
private Double parseDouble(String value) {
|
||||
try {
|
||||
return value != null ? Double.parseDouble(value) : null;
|
||||
|
||||
Reference in New Issue
Block a user