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;
|
||||
|
||||
+1
@@ -42,6 +42,7 @@ export class BookdropFileMetadataPickerComponent {
|
||||
|
||||
metadataFieldsTop = [
|
||||
{label: 'Title', controlName: 'title', fetchedKey: 'title'},
|
||||
{label: 'Subtitle', controlName: 'subtitle', fetchedKey: 'subtitle'},
|
||||
{label: 'Publisher', controlName: 'publisher', fetchedKey: 'publisher'},
|
||||
{label: 'Published', controlName: 'publishedDate', fetchedKey: 'publishedDate'}
|
||||
];
|
||||
|
||||
+1
@@ -42,6 +42,7 @@ export class MetadataPickerComponent implements OnInit {
|
||||
|
||||
metadataFieldsTop = [
|
||||
{label: 'Title', controlName: 'title', lockedKey: 'titleLocked', fetchedKey: 'title'},
|
||||
{label: 'Subtitle', controlName: 'subtitle', lockedKey: 'subtitleLocked', fetchedKey: 'subtitle'},
|
||||
{label: 'Publisher', controlName: 'publisher', lockedKey: 'publisherLocked', fetchedKey: 'publisher'},
|
||||
{label: 'Published', controlName: 'publishedDate', lockedKey: 'publishedDateLocked', fetchedKey: 'publishedDate'}
|
||||
];
|
||||
|
||||
+2
-2
@@ -69,7 +69,7 @@
|
||||
<div class="flex flex-col items-center md:items-start gap-1">
|
||||
<div class="flex items-center gap-2 justify-center md:justify-start flex-wrap text-center md:text-left">
|
||||
<h2 class="text-2xl md:text-3xl font-extrabold leading-tight">
|
||||
{{ book?.metadata!.title }}
|
||||
{{ book?.metadata?.title }}@if (book?.metadata?.subtitle) {: {{ book.metadata?.subtitle }}}
|
||||
</h2>
|
||||
<i
|
||||
class="pi align-middle"
|
||||
@@ -548,7 +548,7 @@
|
||||
[horizontal]="true">
|
||||
@for (book of recommendedBooks; track book.book.id) {
|
||||
<div class="dashboard-scroller-card">
|
||||
<app-book-card-lite-component [book]="book.book" ></app-book-card-lite-component>
|
||||
<app-book-card-lite-component [book]="book.book"></app-book-card-lite-component>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user