feat: add button to fetch metadata from book file in metadata editor (#2739)

This commit is contained in:
ACX
2026-02-13 21:04:00 -07:00
committed by GitHub
parent 5076522f35
commit 77b4deb942
7 changed files with 83 additions and 3 deletions
@@ -120,6 +120,14 @@ public class BookController {
return ResponseEntity.ok(bookMetadataService.getComicInfoMetadata(bookId));
}
@Operation(summary = "Get file metadata", description = "Extract embedded metadata from the book file.")
@ApiResponse(responseCode = "200", description = "File metadata returned successfully")
@GetMapping("/{bookId}/file-metadata")
public ResponseEntity<?> getFileMetadata(
@Parameter(description = "ID of the book") @PathVariable long bookId) {
return ResponseEntity.ok(bookMetadataService.getFileMetadata(bookId));
}
@Operation(summary = "Get book content", description = "Retrieve the binary content of a book for reading. Supports HTTP Range requests for partial content streaming.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "Full book content returned"),
@@ -23,6 +23,7 @@ import org.booklore.repository.BookRepository;
import org.booklore.service.NotificationService;
import org.booklore.service.book.BookQueryService;
import org.booklore.service.metadata.extractor.CbxMetadataExtractor;
import org.booklore.service.metadata.extractor.MetadataExtractorFactory;
import org.booklore.service.metadata.parser.BookParser;
import org.booklore.service.metadata.parser.DetailedMetadataProvider;
import org.booklore.util.FileUtils;
@@ -58,6 +59,7 @@ public class BookMetadataService {
private final BookQueryService bookQueryService;
private final Map<MetadataProvider, BookParser> parserMap;
private final CbxMetadataExtractor cbxMetadataExtractor;
private final MetadataExtractorFactory metadataExtractorFactory;
private final MetadataClearFlagsMapper metadataClearFlagsMapper;
private final PlatformTransactionManager transactionManager;
@@ -147,6 +149,16 @@ public class BookMetadataService {
return cbxMetadataExtractor.extractMetadata(new File(FileUtils.getBookFullPath(bookEntity)));
}
public BookMetadata getFileMetadata(long bookId) {
log.info("Extracting file metadata for book ID: {}", bookId);
BookEntity bookEntity = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
var primaryFile = bookEntity.getPrimaryBookFile();
if (primaryFile == null) {
throw ApiError.GENERIC_BAD_REQUEST.createException("Book has no file to extract metadata from");
}
return metadataExtractorFactory.extractMetadata(primaryFile.getBookType(), new File(FileUtils.getBookFullPath(bookEntity)));
}
@Transactional
public void bulkUpdateMetadata(BulkMetadataUpdateRequest request, boolean mergeCategories, boolean mergeMoods, boolean mergeTags) {
MetadataClearFlags clearFlags = metadataClearFlagsMapper.toClearFlags(request);