Fix additional file uploader bugs and move formats to metadata header (#2816)
This commit is contained in:
@@ -20,7 +20,7 @@ public enum ApiError {
|
||||
INVALID_VIEWER_SETTING(HttpStatus.BAD_REQUEST, "Invalid viewer setting for the book"),
|
||||
FILE_READ_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "Error reading files from path: %s"),
|
||||
IMAGE_NOT_FOUND(HttpStatus.NOT_FOUND, "Image not found or not readable"),
|
||||
INVALID_FILE_FORMAT(HttpStatus.BAD_REQUEST, "Invalid file format, only pdf and epub are supported"),
|
||||
INVALID_FILE_FORMAT(HttpStatus.BAD_REQUEST, "Invalid file format: %s"),
|
||||
LIBRARY_NOT_FOUND(HttpStatus.NOT_FOUND, "Library not found with ID: %d"),
|
||||
FILE_TOO_LARGE(HttpStatus.BAD_REQUEST, "File size exceeds the limit: %d MB"),
|
||||
CACHE_TOO_LARGE(HttpStatus.BAD_REQUEST, "Book archive is too large to cache with current settings"),
|
||||
|
||||
@@ -128,9 +128,7 @@ public class BookFileEntity {
|
||||
.filter(java.nio.file.Files::isRegularFile)
|
||||
.filter(p -> {
|
||||
String name = p.getFileName().toString().toLowerCase();
|
||||
return name.endsWith(".mp3") || name.endsWith(".m4a") || name.endsWith(".m4b")
|
||||
|| name.endsWith(".flac") || name.endsWith(".ogg") || name.endsWith(".opus")
|
||||
|| name.endsWith(".aac");
|
||||
return name.endsWith(".mp3") || name.endsWith(".m4a") || name.endsWith(".m4b");
|
||||
})
|
||||
.sorted()
|
||||
.findFirst()
|
||||
|
||||
@@ -20,11 +20,7 @@ public enum BookFileExtension {
|
||||
FB2("fb2", BookFileType.FB2),
|
||||
M4B("m4b", BookFileType.AUDIOBOOK),
|
||||
M4A("m4a", BookFileType.AUDIOBOOK),
|
||||
MP3("mp3", BookFileType.AUDIOBOOK),
|
||||
AAC("aac", BookFileType.AUDIOBOOK),
|
||||
FLAC("flac", BookFileType.AUDIOBOOK),
|
||||
OPUS("opus", BookFileType.AUDIOBOOK),
|
||||
OGG("ogg", BookFileType.AUDIOBOOK);
|
||||
MP3("mp3", BookFileType.AUDIOBOOK);
|
||||
|
||||
private final String extension;
|
||||
private final BookFileType type;
|
||||
|
||||
@@ -15,7 +15,7 @@ public enum BookFileType {
|
||||
FB2(Set.of("fb2")),
|
||||
MOBI(Set.of("mobi")),
|
||||
AZW3(Set.of("azw3", "azw")),
|
||||
AUDIOBOOK(Set.of("m4b", "m4a", "mp3", "aac", "flac", "opus", "ogg"));
|
||||
AUDIOBOOK(Set.of("m4b", "m4a", "mp3"));
|
||||
|
||||
private final Set<String> extensions;
|
||||
|
||||
|
||||
+2
-22
@@ -1,7 +1,6 @@
|
||||
package org.booklore.repository;
|
||||
|
||||
import org.booklore.model.entity.BookFileEntity;
|
||||
import org.booklore.model.enums.BookFileType;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
@@ -18,31 +17,12 @@ public interface BookAdditionalFileRepository extends JpaRepository<BookFileEnti
|
||||
|
||||
List<BookFileEntity> findByBookIdAndIsBookFormat(Long bookId, boolean isBookFormat);
|
||||
|
||||
List<BookFileEntity> findByBookIdAndBookType(Long bookId, BookFileType bookType);
|
||||
|
||||
/**
|
||||
* Finds a {@link BookFileEntity} by its alternative format current hash.
|
||||
* <p>
|
||||
* This method queries against the {@code alt_format_current_hash} virtual column, which is indexed
|
||||
* and only contains values for files where the {@code additional_file_type} is 'ALTERNATIVE_FORMAT'.
|
||||
* This implicitly filters by the file type and provides an efficient lookup.
|
||||
*
|
||||
* @param altFormatCurrentHash The current hash of the file, which is only considered for alternative format files.
|
||||
* @return an {@link Optional} containing the found entity, or an empty {@link Optional} if no match is found.
|
||||
*/
|
||||
Optional<BookFileEntity> findByAltFormatCurrentHash(String altFormatCurrentHash);
|
||||
|
||||
@Query("SELECT bf FROM BookFileEntity bf WHERE bf.book.libraryPath.id = :libraryPathId AND bf.fileSubPath = :fileSubPath AND bf.fileName = :fileName")
|
||||
Optional<BookFileEntity> findByLibraryPath_IdAndFileSubPathAndFileName(@Param("libraryPathId") Long libraryPathId,
|
||||
@Param("fileSubPath") String fileSubPath,
|
||||
@Param("fileName") String fileName);
|
||||
|
||||
List<BookFileEntity> findByIsBookFormat(boolean isBookFormat);
|
||||
|
||||
List<BookFileEntity> findByBookType(BookFileType bookType);
|
||||
|
||||
@Query("SELECT COUNT(bf) FROM BookFileEntity bf WHERE bf.book.id = :bookId AND bf.isBookFormat = :isBookFormat")
|
||||
long countByBookIdAndIsBookFormat(@Param("bookId") Long bookId, @Param("isBookFormat") boolean isBookFormat);
|
||||
@Param("fileSubPath") String fileSubPath,
|
||||
@Param("fileName") String fileName);
|
||||
|
||||
@Query("SELECT bf FROM BookFileEntity bf WHERE bf.book.library.id = :libraryId")
|
||||
List<BookFileEntity> findByLibraryId(@Param("libraryId") Long libraryId);
|
||||
|
||||
@@ -85,8 +85,6 @@ public class FileFingerprint {
|
||||
private static boolean isAudioFile(String fileName) {
|
||||
if (fileName == null) return false;
|
||||
String lower = fileName.toLowerCase();
|
||||
return lower.endsWith(".mp3") || lower.endsWith(".m4a") || lower.endsWith(".m4b")
|
||||
|| lower.endsWith(".flac") || lower.endsWith(".ogg") || lower.endsWith(".opus")
|
||||
|| lower.endsWith(".aac");
|
||||
return lower.endsWith(".mp3") || lower.endsWith(".m4a") || lower.endsWith(".m4b");
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -40,7 +40,7 @@ public class MetadataExtractorFactory {
|
||||
case FB2 -> fb2MetadataExtractor.extractMetadata(file);
|
||||
case MOBI -> mobiMetadataExtractor.extractMetadata(file);
|
||||
case AZW3, AZW -> azw3MetadataExtractor.extractMetadata(file);
|
||||
case M4B, M4A, MP3, AAC, FLAC, OPUS, OGG -> audiobookMetadataExtractor.extractMetadata(file);
|
||||
case M4B, M4A, MP3 -> audiobookMetadataExtractor.extractMetadata(file);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class MetadataExtractorFactory {
|
||||
case FB2 -> fb2MetadataExtractor.extractCover(file);
|
||||
case MOBI -> mobiMetadataExtractor.extractCover(file);
|
||||
case AZW3, AZW -> azw3MetadataExtractor.extractCover(file);
|
||||
case M4B, M4A, MP3, AAC, FLAC, OPUS, OGG -> audiobookMetadataExtractor.extractCover(file);
|
||||
case M4B, M4A, MP3 -> audiobookMetadataExtractor.extractCover(file);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -691,11 +691,7 @@ public class OpdsFeedService {
|
||||
}
|
||||
case AUDIOBOOK -> {
|
||||
String lower = bookFile.getFileName().toLowerCase();
|
||||
if (lower.endsWith(".m4b") || lower.endsWith(".m4a")) yield "audio/mp4";
|
||||
if (lower.endsWith(".mp3")) yield "audio/mpeg";
|
||||
if (lower.endsWith(".flac")) yield "audio/flac";
|
||||
if (lower.endsWith(".ogg") || lower.endsWith(".opus")) yield "audio/ogg";
|
||||
if (lower.endsWith(".aac")) yield "audio/aac";
|
||||
yield "audio/mp4";
|
||||
}
|
||||
};
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.util.stream.Stream;
|
||||
public class AudioFileUtilityService {
|
||||
|
||||
private static final Set<String> AUDIO_EXTENSIONS = Set.of(
|
||||
".mp3", ".m4a", ".m4b", ".aac", ".flac", ".ogg", ".opus"
|
||||
".mp3", ".m4a", ".m4b"
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -55,14 +55,6 @@ public class AudioFileUtilityService {
|
||||
return "audio/mp4";
|
||||
} else if (fileName.endsWith(".mp3")) {
|
||||
return "audio/mpeg";
|
||||
} else if (fileName.endsWith(".aac")) {
|
||||
return "audio/aac";
|
||||
} else if (fileName.endsWith(".flac")) {
|
||||
return "audio/flac";
|
||||
} else if (fileName.endsWith(".ogg")) {
|
||||
return "audio/ogg";
|
||||
} else if (fileName.endsWith(".opus")) {
|
||||
return "audio/opus";
|
||||
}
|
||||
return "application/octet-stream";
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public class BookFileGroupingUtils {
|
||||
// Known book file extensions - only strip these, not arbitrary dots in folder names
|
||||
private static final Set<String> KNOWN_EXTENSIONS = Set.of(
|
||||
"pdf", "epub", "cbz", "cbr", "cb7", "mobi", "azw3", "azw", "fb2",
|
||||
"m4b", "m4a", "mp3", "aac", "flac", "opus", "ogg"
|
||||
"m4b", "m4a", "mp3"
|
||||
);
|
||||
|
||||
public String extractGroupingKey(String fileName) {
|
||||
|
||||
@@ -125,9 +125,7 @@ public class FileUtils {
|
||||
public boolean isAudioFile(String fileName) {
|
||||
if (fileName == null) return false;
|
||||
String lower = fileName.toLowerCase();
|
||||
return lower.endsWith(".mp3") || lower.endsWith(".m4a") || lower.endsWith(".m4b")
|
||||
|| lower.endsWith(".flac") || lower.endsWith(".ogg") || lower.endsWith(".opus")
|
||||
|| lower.endsWith(".aac");
|
||||
return lower.endsWith(".mp3") || lower.endsWith(".m4a") || lower.endsWith(".m4b");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user