Asin metadata support (#346)
--------- Co-authored-by: Aditya Chandel <8075870+adityachandelgit@users.noreply.github.com>
This commit is contained in:
committed by
aditya.chandel
co-authored by
Aditya Chandel
parent
3921d42014
commit
a7b665e0ba
@@ -26,6 +26,7 @@ public class BookMetadata {
|
||||
private Integer seriesTotal;
|
||||
private String isbn13;
|
||||
private String isbn10;
|
||||
private String asin;
|
||||
private Integer pageCount;
|
||||
private String language;
|
||||
private Double rating;
|
||||
@@ -54,6 +55,7 @@ public class BookMetadata {
|
||||
private Boolean seriesTotalLocked;
|
||||
private Boolean isbn13Locked;
|
||||
private Boolean isbn10Locked;
|
||||
private Boolean asinLocked;
|
||||
private Boolean pageCountLocked;
|
||||
private Boolean languageLocked;
|
||||
private Boolean ratingLocked;
|
||||
|
||||
+1
@@ -14,4 +14,5 @@ public class FetchMetadataRequest {
|
||||
private String isbn;
|
||||
private String title;
|
||||
private String author;
|
||||
private String asin;
|
||||
}
|
||||
|
||||
+9
@@ -51,6 +51,9 @@ public class BookMetadataEntity {
|
||||
@Column(name = "isbn_10", length = 10)
|
||||
private String isbn10;
|
||||
|
||||
@Column(name = "asin", length = 10)
|
||||
private String asin;
|
||||
|
||||
@Column(name = "page_count")
|
||||
private Integer pageCount;
|
||||
|
||||
@@ -104,6 +107,9 @@ public class BookMetadataEntity {
|
||||
@Column(name = "isbn_10_locked")
|
||||
private Boolean isbn10Locked = Boolean.FALSE;
|
||||
|
||||
@Column(name = "asin_locked")
|
||||
private Boolean asinLocked = Boolean.FALSE;
|
||||
|
||||
@Column(name = "page_count_locked")
|
||||
private Boolean pageCountLocked = Boolean.FALSE;
|
||||
|
||||
@@ -181,6 +187,7 @@ public class BookMetadataEntity {
|
||||
this.descriptionLocked = lock;
|
||||
this.isbn13Locked = lock;
|
||||
this.isbn10Locked = lock;
|
||||
this.asinLocked = lock;
|
||||
this.pageCountLocked = lock;
|
||||
this.thumbnailLocked = lock;
|
||||
this.languageLocked = lock;
|
||||
@@ -206,6 +213,7 @@ public class BookMetadataEntity {
|
||||
|| Boolean.TRUE.equals(this.descriptionLocked)
|
||||
|| Boolean.TRUE.equals(this.isbn13Locked)
|
||||
|| Boolean.TRUE.equals(this.isbn10Locked)
|
||||
|| Boolean.TRUE.equals(this.asinLocked)
|
||||
|| Boolean.TRUE.equals(this.pageCountLocked)
|
||||
|| Boolean.TRUE.equals(this.thumbnailLocked)
|
||||
|| Boolean.TRUE.equals(this.languageLocked)
|
||||
@@ -231,6 +239,7 @@ public class BookMetadataEntity {
|
||||
&& Boolean.TRUE.equals(this.descriptionLocked)
|
||||
&& Boolean.TRUE.equals(this.isbn13Locked)
|
||||
&& Boolean.TRUE.equals(this.isbn10Locked)
|
||||
&& Boolean.TRUE.equals(this.asinLocked)
|
||||
&& Boolean.TRUE.equals(this.pageCountLocked)
|
||||
&& Boolean.TRUE.equals(this.thumbnailLocked)
|
||||
&& Boolean.TRUE.equals(this.languageLocked)
|
||||
|
||||
@@ -200,6 +200,7 @@ public class BookMetadataService {
|
||||
metadataCombined.setPublishedDate(metadata.getPublishedDate() != null ? metadata.getPublishedDate() : metadataCombined.getPublishedDate());
|
||||
metadataCombined.setIsbn10(metadata.getIsbn10() != null ? metadata.getIsbn10() : metadataCombined.getIsbn10());
|
||||
metadataCombined.setIsbn13(metadata.getIsbn13() != null ? metadata.getIsbn13() : metadataCombined.getIsbn13());
|
||||
metadataCombined.setAsin(metadata.getAsin() != null ? metadata.getAsin() : metadataCombined.getAsin());
|
||||
metadataCombined.setPageCount(metadata.getPageCount() != null ? metadata.getPageCount() : metadataCombined.getPageCount());
|
||||
metadataCombined.setLanguage(metadata.getLanguage() != null ? metadata.getLanguage() : metadataCombined.getLanguage());
|
||||
metadataCombined.setRating(metadata.getRating() != null ? metadata.getRating() : metadataCombined.getRating());
|
||||
@@ -334,6 +335,7 @@ public class BookMetadataService {
|
||||
private FetchMetadataRequest buildFetchMetadataRequestFromBook(Book book) {
|
||||
return FetchMetadataRequest.builder()
|
||||
.isbn(book.getMetadata().getIsbn10())
|
||||
.asin(book.getMetadata().getAsin())
|
||||
.author(String.join(", ", book.getMetadata().getAuthors()))
|
||||
.title(book.getMetadata().getTitle())
|
||||
.bookId(book.getId())
|
||||
@@ -375,6 +377,9 @@ public class BookMetadataService {
|
||||
case "isbn13":
|
||||
existingMetadata.setIsbn13Locked(isLocked);
|
||||
break;
|
||||
case "asin":
|
||||
existingMetadata.setAsinLocked(isLocked);
|
||||
break;
|
||||
case "description":
|
||||
existingMetadata.setDescriptionLocked(isLocked);
|
||||
break;
|
||||
|
||||
+6
-1
@@ -71,7 +71,9 @@ public class BookMetadataUpdater {
|
||||
if ((metadata.getIsbn13Locked() == null || !metadata.getIsbn13Locked()) && newMetadata.getIsbn13() != null) {
|
||||
metadata.setIsbn13(newMetadata.getIsbn13().isBlank() ? null : newMetadata.getIsbn13());
|
||||
}
|
||||
|
||||
if ((metadata.getAsinLocked() == null || !metadata.getAsinLocked()) && newMetadata.getAsin() != null) {
|
||||
metadata.setAsin(newMetadata.getAsin().isBlank() ? null : newMetadata.getAsin());
|
||||
}
|
||||
if ((metadata.getDescriptionLocked() == null || !metadata.getDescriptionLocked()) && newMetadata.getDescription() != null) {
|
||||
metadata.setDescription(newMetadata.getDescription().isBlank() ? null : newMetadata.getDescription());
|
||||
}
|
||||
@@ -216,6 +218,9 @@ public class BookMetadataUpdater {
|
||||
if (newMetadata.getIsbn10Locked() != null) {
|
||||
metadata.setIsbn10Locked(newMetadata.getIsbn10Locked());
|
||||
}
|
||||
if (newMetadata.getAsinLocked() != null) {
|
||||
metadata.setAsinLocked(newMetadata.getAsinLocked());
|
||||
}
|
||||
if (newMetadata.getPageCountLocked() != null) {
|
||||
metadata.setPageCountLocked(newMetadata.getPageCountLocked());
|
||||
}
|
||||
|
||||
+27
-2
@@ -11,6 +11,7 @@ import java.time.LocalDate;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -153,12 +154,36 @@ public class EpubProcessor implements FileProcessor {
|
||||
|
||||
List<String> identifiers = epubMetadata.getIdentifiers().stream()
|
||||
.map(Identifier::getValue)
|
||||
.filter(Objects::nonNull)
|
||||
.map(String::trim)
|
||||
.map(id -> id.contains(":") ? id.substring(id.indexOf(":") + 1) : id) // strip prefix
|
||||
.map(id -> id.replace("-", "")) // remove dashes
|
||||
.toList();
|
||||
|
||||
|
||||
if (!identifiers.isEmpty()) {
|
||||
String isbn13 = identifiers.stream().filter(id -> id.length() == 13).findFirst().orElse(null);
|
||||
String isbn10 = identifiers.stream().filter(id -> id.length() == 10).findFirst().orElse(null);
|
||||
// Checking for ISBN 13 (strict 13-digit numeric)
|
||||
String isbn13 = identifiers.stream()
|
||||
.filter(id -> id.length() == 13 && id.matches("\\d{13}"))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
// Checking for ISBN 10 (strict 10-digit format or ends in X)
|
||||
String isbn10 = identifiers.stream()
|
||||
.filter(id -> id.length() == 10 && id.matches("\\d{9}[\\dXx]"))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
// Checking for ASIN (alphanumeric 10 chars, must not be ISBN-10)
|
||||
String asin = identifiers.stream()
|
||||
.filter(id -> id.length() == 10 && id.matches("^[A-Z0-9]{10}$"))
|
||||
.filter(id -> !id.equalsIgnoreCase(isbn10))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
bookMetadata.setIsbn13(truncate(isbn13, 64));
|
||||
bookMetadata.setIsbn10(truncate(isbn10, 64));
|
||||
bookMetadata.setAsin(truncate(asin, 20));
|
||||
}
|
||||
|
||||
bookMetadata.setLanguage(truncate(
|
||||
|
||||
+1
@@ -126,6 +126,7 @@ public class AmazonBookParser implements BookParser {
|
||||
.seriesTotal(getSeriesTotal(doc))
|
||||
.isbn13(getIsbn13(doc))
|
||||
.isbn10(getIsbn10(doc))
|
||||
.asin(amazonBookId)
|
||||
.publisher(getPublisher(doc))
|
||||
.publishedDate(getPublicationDate(doc))
|
||||
.language(getLanguage(doc))
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE book_metadata ADD COLUMN asin VARCHAR(20);
|
||||
ALTER TABLE book_metadata ADD COLUMN asin_locked BOOLEAN DEFAULT FALSE;
|
||||
+8
@@ -183,6 +183,14 @@
|
||||
<p-button *ngIf="metadata['isbn13Locked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('isbn13')" severity="warn"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1 w-1/4">
|
||||
<label for="asin">ASIN</label>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<input pInputText id="asin" formControlName="asin" class="w-full"/>
|
||||
<p-button *ngIf="!metadata['asinLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('asin')" severity="success"></p-button>
|
||||
<p-button *ngIf="metadata['asinLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('asin')" severity="warn"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1 w-1/4">
|
||||
<label for="reviewCount">Rating Count (Legacy)</label>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
|
||||
+14
-2
@@ -69,6 +69,7 @@ export class MetadataEditorComponent implements OnInit {
|
||||
publishedDate: new FormControl(''),
|
||||
isbn10: new FormControl(''),
|
||||
isbn13: new FormControl(''),
|
||||
asin: new FormControl(''),
|
||||
description: new FormControl(''),
|
||||
pageCount: new FormControl(''),
|
||||
language: new FormControl(''),
|
||||
@@ -90,6 +91,7 @@ export class MetadataEditorComponent implements OnInit {
|
||||
publishedDateLocked: new FormControl(false),
|
||||
isbn10Locked: new FormControl(false),
|
||||
isbn13Locked: new FormControl(false),
|
||||
asinLocked: new FormControl(false),
|
||||
descriptionLocked: new FormControl(false),
|
||||
pageCountLocked: new FormControl(false),
|
||||
languageLocked: new FormControl(false),
|
||||
@@ -125,6 +127,7 @@ export class MetadataEditorComponent implements OnInit {
|
||||
publishedDate: metadata.publishedDate || null,
|
||||
isbn10: metadata.isbn10 || null,
|
||||
isbn13: metadata.isbn13 || null,
|
||||
asin: metadata.asin || null,
|
||||
description: metadata.description || null,
|
||||
pageCount: metadata.pageCount || null,
|
||||
language: metadata.language || null,
|
||||
@@ -146,6 +149,7 @@ export class MetadataEditorComponent implements OnInit {
|
||||
publishedDateLocked: metadata.publishedDateLocked || false,
|
||||
isbn10Locked: metadata.isbn10Locked || false,
|
||||
isbn13Locked: metadata.isbn13Locked || false,
|
||||
asinLocked: metadata.asinLocked || false,
|
||||
descriptionLocked: metadata.descriptionLocked || false,
|
||||
pageCountLocked: metadata.pageCountLocked || false,
|
||||
languageLocked: metadata.languageLocked || false,
|
||||
@@ -171,6 +175,7 @@ export class MetadataEditorComponent implements OnInit {
|
||||
{ key: 'languageLocked', control: 'language' },
|
||||
{ key: 'isbn10Locked', control: 'isbn10' },
|
||||
{ key: 'isbn13Locked', control: 'isbn13' },
|
||||
{ key: 'asinLocked', control: 'asin'},
|
||||
{ key: 'amazonReviewCountLocked', control: 'amazonReviewCount' },
|
||||
{ key: 'amazonRatingLocked', control: 'amazonRating' },
|
||||
{ key: 'goodreadsReviewCountLocked', control: 'goodreadsReviewCount' },
|
||||
@@ -210,8 +215,13 @@ export class MetadataEditorComponent implements OnInit {
|
||||
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book metadata updated'});
|
||||
this.metadataCenterService.emitMetadata(response);
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update book metadata'});
|
||||
error: (err) => {
|
||||
console.error('Update metadata failed:', err);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: err?.error?.message || 'Failed to update book metadata'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -276,6 +286,7 @@ export class MetadataEditorComponent implements OnInit {
|
||||
publishedDate: this.metadataForm.get('publishedDate')?.value,
|
||||
isbn10: this.metadataForm.get('isbn10')?.value,
|
||||
isbn13: this.metadataForm.get('isbn13')?.value,
|
||||
asin: this.metadataForm.get('asin')?.value,
|
||||
description: this.metadataForm.get('description')?.value,
|
||||
pageCount: this.metadataForm.get('pageCount')?.value,
|
||||
rating: this.metadataForm.get('rating')?.value,
|
||||
@@ -297,6 +308,7 @@ export class MetadataEditorComponent implements OnInit {
|
||||
publishedDateLocked: this.metadataForm.get('publishedDateLocked')?.value,
|
||||
isbn10Locked: this.metadataForm.get('isbn10Locked')?.value,
|
||||
isbn13Locked: this.metadataForm.get('isbn13Locked')?.value,
|
||||
asinLocked: this.metadataForm.get('asinLocked')?.value,
|
||||
descriptionLocked: this.metadataForm.get('descriptionLocked')?.value,
|
||||
pageCountLocked: this.metadataForm.get('pageCountLocked')?.value,
|
||||
languageLocked: this.metadataForm.get('languageLocked')?.value,
|
||||
|
||||
+8
@@ -54,6 +54,7 @@ export class MetadataPickerComponent implements OnInit {
|
||||
{label: 'Book #', controlName: 'seriesNumber', lockedKey: 'seriesNumberLocked', fetchedKey: 'seriesNumber'},
|
||||
{label: 'Total Books', controlName: 'seriesTotal', lockedKey: 'seriesTotalLocked', fetchedKey: 'seriesTotal'},
|
||||
{label: 'ISBN-13', controlName: 'isbn13', lockedKey: 'isbn13Locked', fetchedKey: 'isbn13'},
|
||||
{label: 'ASIN', controlName: 'asin', lockedKey: 'asinLocked', fetchedKey: 'asin'},
|
||||
{label: 'Amazon Reviews', controlName: 'amazonReviewCount', lockedKey: 'amazonReviewCountLocked', fetchedKey: 'amazonReviewCount'},
|
||||
{label: 'Amazon Rating', controlName: 'amazonRating', lockedKey: 'amazonRatingLocked', fetchedKey: 'amazonRating'},
|
||||
{label: 'Goodreads Reviews', controlName: 'goodreadsReviewCount', lockedKey: 'goodreadsReviewCountLocked', fetchedKey: 'goodreadsReviewCount'},
|
||||
@@ -87,6 +88,7 @@ export class MetadataPickerComponent implements OnInit {
|
||||
publishedDate: new FormControl(''),
|
||||
isbn10: new FormControl(''),
|
||||
isbn13: new FormControl(''),
|
||||
asin: new FormControl(''),
|
||||
description: new FormControl(''),
|
||||
pageCount: new FormControl(''),
|
||||
language: new FormControl(''),
|
||||
@@ -107,6 +109,7 @@ export class MetadataPickerComponent implements OnInit {
|
||||
publishedDateLocked: new FormControl(false),
|
||||
isbn10Locked: new FormControl(false),
|
||||
isbn13Locked: new FormControl(false),
|
||||
asinLocked: new FormControl(false),
|
||||
descriptionLocked: new FormControl(false),
|
||||
pageCountLocked: new FormControl(false),
|
||||
languageLocked: new FormControl(false),
|
||||
@@ -136,6 +139,7 @@ export class MetadataPickerComponent implements OnInit {
|
||||
publishedDate: metadata.publishedDate || null,
|
||||
isbn10: metadata.isbn10 || null,
|
||||
isbn13: metadata.isbn13 || null,
|
||||
asin: metadata.asin || null,
|
||||
description: metadata.description || null,
|
||||
pageCount: metadata.pageCount || null,
|
||||
language: metadata.language || null,
|
||||
@@ -156,6 +160,7 @@ export class MetadataPickerComponent implements OnInit {
|
||||
publishedDateLocked: metadata.publishedDateLocked || false,
|
||||
isbn10Locked: metadata.isbn10Locked || false,
|
||||
isbn13Locked: metadata.isbn13Locked || false,
|
||||
asinLocked: metadata.asinLocked || false,
|
||||
descriptionLocked: metadata.descriptionLocked || false,
|
||||
pageCountLocked: metadata.pageCountLocked || false,
|
||||
languageLocked: metadata.languageLocked || false,
|
||||
@@ -178,6 +183,7 @@ export class MetadataPickerComponent implements OnInit {
|
||||
if (metadata.languageLocked) this.metadataForm.get('language')?.disable();
|
||||
if (metadata.isbn10Locked) this.metadataForm.get('isbn10')?.disable();
|
||||
if (metadata.isbn13Locked) this.metadataForm.get('isbn13')?.disable();
|
||||
if (metadata.asinLocked) this.metadataForm.get('asin')?.disable();
|
||||
if (metadata.amazonReviewCountLocked) this.metadataForm.get('amazonReviewCount')?.disable();
|
||||
if (metadata.amazonRatingLocked) this.metadataForm.get('amazonRating')?.disable();
|
||||
if (metadata.goodreadsReviewCountLocked) this.metadataForm.get('goodreadsReviewCount')?.disable();
|
||||
@@ -220,6 +226,7 @@ export class MetadataPickerComponent implements OnInit {
|
||||
publishedDate: this.metadataForm.get('publishedDate')?.value || this.copiedFields['publishedDate'] ? this.getValueOrCopied('publishedDate') : '',
|
||||
isbn10: this.metadataForm.get('isbn10')?.value || this.copiedFields['isbn10'] ? this.getValueOrCopied('isbn10') : '',
|
||||
isbn13: this.metadataForm.get('isbn13')?.value || this.copiedFields['isbn13'] ? this.getValueOrCopied('isbn13') : '',
|
||||
asin: this.metadataForm.get('asin')?.value || this.copiedFields['asin'] ? this.getValueOrCopied('asin') : '',
|
||||
description: this.metadataForm.get('description')?.value || this.copiedFields['description'] ? this.getValueOrCopied('description') : '',
|
||||
pageCount: this.metadataForm.get('pageCount')?.value || this.copiedFields['pageCount'] ? this.getPageCountOrCopied() : null,
|
||||
language: this.metadataForm.get('language')?.value || this.copiedFields['language'] ? this.getValueOrCopied('language') : '',
|
||||
@@ -240,6 +247,7 @@ export class MetadataPickerComponent implements OnInit {
|
||||
publishedDateLocked: this.metadataForm.get('publishedDateLocked')?.value,
|
||||
isbn10Locked: this.metadataForm.get('isbn10Locked')?.value,
|
||||
isbn13Locked: this.metadataForm.get('isbn13Locked')?.value,
|
||||
asinLocked: this.metadataForm.get('asin')?.value,
|
||||
descriptionLocked: this.metadataForm.get('descriptionLocked')?.value,
|
||||
pageCountLocked: this.metadataForm.get('pageCountLocked')?.value,
|
||||
languageLocked: this.metadataForm.get('languageLocked')?.value,
|
||||
|
||||
+1
@@ -86,6 +86,7 @@
|
||||
<p class="whitespace-nowrap"><span class="font-bold">Language:</span> {{ metadata.language || '-' }}</p>
|
||||
<p class="whitespace-nowrap"><span class="font-bold">ISBN 10:</span> {{ metadata.isbn10 || '-' }}</p>
|
||||
<p class="whitespace-nowrap"><span class="font-bold">ISBN 13:</span> {{ metadata.isbn13 || '-' }}</p>
|
||||
<p class="whitespace-nowrap"><span class="font-bold">ASIN:</span> {{ metadata.asin || '-' }}</p>
|
||||
<p class="whitespace-nowrap"><span class="font-bold">Page Count:</span> {{ metadata.pageCount || '-' }}</p>
|
||||
<p class="whitespace-nowrap"><span class="font-bold">File Size:</span> {{ getFileSizeInMB() }}</p>
|
||||
<p class="whitespace-nowrap"><span class="font-bold">Progress:</span> {{ getProgressPercent() !== null ? getProgressPercent() + '%' : '-' }}</p>
|
||||
|
||||
Reference in New Issue
Block a user