Documentation
¶
Index ¶
- Variables
- func CleanupEmptyDirectory(dirPath string, ignoredPatterns ...string) (bool, error)
- func CleanupEmptyParentDirectories(startPath, stopAt string, ignoredPatterns ...string) error
- func ComputeNewCoverFilename(oldCoverFilename, newFilePath string) string
- func CoverExistsWithBaseName(dir, baseName string) string
- func ExtractSeriesFromTitle(title string, fileType string) (seriesName string, volumeNumber *float64, ok bool)
- func GenerateOrganizedFileName(opts OrganizedNameOptions, originalFilepath string) string
- func GenerateOrganizedFolderName(opts OrganizedNameOptions) string
- func GenerateUniqueFilepathIfExists(path string) string
- func IsOrganizedName(name string) bool
- func MimeTypeFromExtension(ext string) string
- func MoveFile(src, dst string) error
- func MoveFileWithAssociatedFiles(originalFilePath, newFilePath string) (int, error)
- func NormalizeImage(data []byte, mimeType string) ([]byte, string, error)
- func NormalizeVolumeInTitle(title string, fileType string) (string, bool)
- func RenameOrganizedFile(currentPath string, opts OrganizedNameOptions) (string, error)
- func RenameOrganizedFileForSupplement(currentPath string, opts OrganizedNameOptions) (string, error)deprecated
- func RenameOrganizedFileOnly(currentPath string, opts OrganizedNameOptions) (string, error)
- func RenameOrganizedFolder(currentFolderPath string, opts OrganizedNameOptions) (string, error)
- func SplitNames(s string) []string
- type OrganizeFileResult
- type OrganizedNameOptions
Constants ¶
This section is empty.
Variables ¶
var CoverImageExtensions = []string{".jpg", ".jpeg", ".png", ".webp", ".gif", ".bmp"}
CoverImageExtensions contains all supported image extensions for cover files.
Functions ¶
func CleanupEmptyDirectory ¶
CleanupEmptyDirectory removes a directory if it's empty or only contains ignored files. ignoredPatterns can include glob patterns like ".*" (dotfiles), ".DS_Store", "Thumbs.db", etc. Returns true if the directory was removed, false if it wasn't empty or didn't exist.
func CleanupEmptyParentDirectories ¶
CleanupEmptyParentDirectories removes empty parent directories starting from startPath up to (but not including) stopAt. ignoredPatterns are passed to CleanupEmptyDirectory.
func ComputeNewCoverFilename ¶ added in v0.0.8
ComputeNewCoverFilename computes the new cover filename after a file has been renamed. It preserves the cover's extension while updating the base filename to match the new file path. Returns just the filename (e.g., "book.epub.cover.jpg"), not a full path. Returns empty string if oldCoverFilename is empty.
func CoverExistsWithBaseName ¶
CoverExistsWithBaseName checks if any cover file exists with the given base name, regardless of image extension. This allows users to provide custom covers that won't be overwritten even if the book would extract a different format.
Parameters:
- dir: the directory to check
- baseName: the cover base name without extension (e.g., "mybook.epub.cover")
Returns the path to the existing cover file if found, or empty string if no cover exists.
func ExtractSeriesFromTitle ¶
func ExtractSeriesFromTitle(title string, fileType string) (seriesName string, volumeNumber *float64, ok bool)
ExtractSeriesFromTitle extracts series name and volume number from a normalized title. Only applies to CBZ files with volume indicators in the "v{number}" format. Returns the base title (series name), volume number, and whether extraction succeeded.
func GenerateOrganizedFileName ¶
func GenerateOrganizedFileName(opts OrganizedNameOptions, originalFilepath string) string
GenerateOrganizedFileName creates a standardized filename: Title.ext. For M4B files, includes narrator in braces: Title {Narrator}.m4b. Author names are NOT included since files are already inside author-prefixed folders.
func GenerateOrganizedFolderName ¶
func GenerateOrganizedFolderName(opts OrganizedNameOptions) string
GenerateOrganizedFolderName creates a standardized folder name: [Author] Title #Volume.
func GenerateUniqueFilepathIfExists ¶ added in v0.0.8
GenerateUniqueFilepathIfExists returns a unique filepath if the path exists, otherwise returns the original.
func IsOrganizedName ¶
IsOrganizedName checks if a filename/foldername follows the organized naming pattern.
func MimeTypeFromExtension ¶
MimeTypeFromExtension returns the MIME type for a given file extension. Returns empty string if the extension is not recognized.
func MoveFile ¶ added in v0.0.8
MoveFile safely moves a file from source to destination. Returns error if move fails.
func MoveFileWithAssociatedFiles ¶ added in v0.0.8
MoveFileWithAssociatedFiles moves a file and its associated files (covers, file sidecar). This does NOT move book sidecars - only file-specific associated files. Returns the number of associated files moved.
func NormalizeImage ¶
NormalizeImage decodes and re-encodes an image to strip problematic metadata (like gAMA chunks without sRGB in PNG) that cause color rendering issues in browsers. Returns the normalized image data and the new MIME type. If the input is a JPEG, it stays as JPEG to preserve quality. Otherwise, it becomes PNG.
func NormalizeVolumeInTitle ¶
NormalizeVolumeInTitle normalizes volume indicators in titles to the standard v{number} format. Only applies to CBZ files. Returns the normalized title and whether a volume was found.
func RenameOrganizedFile ¶
func RenameOrganizedFile(currentPath string, opts OrganizedNameOptions) (string, error)
RenameOrganizedFile renames an already organized file with new metadata. Also renames associated cover images, file sidecar, AND the book sidecar. Use this for BOOK-level changes (title, author changes) that should update the book sidecar. For FILE-level changes (file name, narrator), use RenameOrganizedFileOnly.
func RenameOrganizedFileForSupplement
deprecated
func RenameOrganizedFileForSupplement(currentPath string, opts OrganizedNameOptions) (string, error)
RenameOrganizedFileForSupplement is an alias for RenameOrganizedFileOnly for backwards compatibility.
Deprecated: Use RenameOrganizedFileOnly instead.
func RenameOrganizedFileOnly ¶
func RenameOrganizedFileOnly(currentPath string, opts OrganizedNameOptions) (string, error)
RenameOrganizedFileOnly renames a file with new metadata, but does NOT rename the book sidecar. Renames the file and its associated cover images and file-specific sidecar. Use this for FILE-level changes (file name, narrator) that should not affect the book sidecar. The book sidecar should only be renamed when book-level metadata (title, author) changes.
func RenameOrganizedFolder ¶
func RenameOrganizedFolder(currentFolderPath string, opts OrganizedNameOptions) (string, error)
RenameOrganizedFolder renames a folder containing organized files.
func SplitNames ¶
SplitNames splits a string of names by common delimiters (comma and semicolon), trims whitespace from each name, and returns non-empty names. This is used for parsing author and narrator lists from metadata.
Types ¶
type OrganizeFileResult ¶
type OrganizeFileResult struct {
OriginalPath string
NewPath string
FolderCreated bool
Moved bool
CoversMoved int
CoversError error
}
OrganizeFileResult contains the results of organizing a file.
func OrganizeRootLevelFile ¶
func OrganizeRootLevelFile(originalPath string, opts OrganizedNameOptions) (*OrganizeFileResult, error)
OrganizeRootLevelFile creates a folder and moves a root-level file into it.
type OrganizedNameOptions ¶
type OrganizedNameOptions struct {
AuthorNames []string // Author names as strings for file naming
NarratorNames []string // Narrator names for M4B file naming
Title string
SeriesNumber *float64
FileType string // for determining volume number formatting
}
OrganizedNameOptions contains the data needed to generate organized file/folder names.