Documentation
¶
Overview ¶
Package utils provides utility functions for file operations and audio file handling
Index ¶
- func ApplyRegex(input string, regex *regexp.Regexp, format string) (string, error)
- func GetAllFilesByName(basepath string, name string) ([]string, error)
- func GetFilesByExtensions(fullpath string, extensions []string) ([]string, error)
- func GetValidDirPathFromArgs(args []string, index int) (string, error)
- func GetValidFilePathFromArgs(args []string, index int) (string, error)
- func GetValidFullpathFromArgs(args []string, index int) (string, error)
- func NaturalCompare(a, b string) int
- func ReplaceDirAndExt(file string, dir string, ext string) string
- func SanitizePathComponent(s string) string
- type Diff
- type OSAudioFileProvider
- type TagWithValue
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyRegex ¶
ApplyRegex applies a regular expression pattern to an input string and formats the captured groups using the provided format string. The format string should contain %s placeholders that match the number of capture groups in the regex pattern.
Parameters:
- input: The input string to apply the regex pattern to
- regex: A compiled regular expression pattern with capture groups
- format: A format string containing %s placeholders for each capture group
Returns:
- string: The formatted result using captured groups, or the original input if there's an error
- error: An error if the input doesn't match the pattern or if the number of capture groups doesn't match the format string placeholders
func GetFilesByExtensions ¶
GetFilesByExtensions walks through a directory tree and returns all files with any of the specified extensions. It returns an error if there are any issues accessing the filesystem during the walk.
func GetValidDirPathFromArgs ¶
GetValidDirPathFromArgs retrieves and validates a directory path from command line arguments. It returns an error if the path at the given index doesn't exist or is not a directory.
func GetValidFilePathFromArgs ¶
GetValidFilePathFromArgs retrieves and validates a file path from command line arguments. It returns an error if the path at the given index doesn't exist or is a directory.
func GetValidFullpathFromArgs ¶
GetValidFullpathFromArgs retrieves a path from command line arguments and converts it to an absolute path. It returns an error if the index is out of bounds or the path conversion fails.
func NaturalCompare ¶
NaturalCompare compares two strings using natural sort order (numbers are compared numerically). For example: "file2.txt" < "file10.txt" (unlike lexicographic where "file10.txt" < "file2.txt")
func SanitizePathComponent ¶
SanitizePathComponent replaces unallowed symbols with _ from a path component
Types ¶
type Diff ¶
type Diff struct {
// Tag represents the metadata tag name that was modified
Tag string
// Before contains the original value before modification
Before string
// After contains the new value after modification
After string
}
Diff represents a difference between two metadata values
func UpdateMetadataTags ¶
func UpdateMetadataTags( metadata string, tags []string, regex *regexp.Regexp, format string, ) (string, []Diff)
UpdateMetadataTags updates the metadata fields provided in the tags slice, replacing their values based on the provided regular expression and format.
The function looks for the current value of each tag in the metadata. If the current value matches the provided regular expression, it constructs a new value using the format string and the capture groups from the regex.
Parameters:
- metadata: The full metadata string where fields are located.
- tags: A list of tags on which the substitution is applied.
- regex: A regex with capture groups
- format: A format string for constructing the new tag value, with placeholders for the capture groups from the regex. (in go syntax)
Returns: The updated metadata and diffs for each change.
type OSAudioFileProvider ¶
type OSAudioFileProvider struct{}
OSAudioFileProvider implements audio file discovery functionality using the OS filesystem
func (*OSAudioFileProvider) AudioFiles ¶
func (p *OSAudioFileProvider) AudioFiles(fullPath string) ([]string, error)
AudioFiles returns a list of audio files found at the given path
type TagWithValue ¶
type TagWithValue struct {
Tag string // The metadata tag name
Value string // The value associated with the tag
}
TagWithValue represents a metadata tag and its associated value
func GetMetadataTagValues ¶
func GetMetadataTagValues(metadata string, tags []string) []TagWithValue
GetMetadataTagValues returns metadata tag values from a string Deprecated: Use Project#GetMetadataTags instead
func (TagWithValue) Prefix ¶
func (t TagWithValue) Prefix() string
Prefix returns the tag name with an equals sign appended
func (TagWithValue) String ¶
func (t TagWithValue) String() string
String returns the tag and value formatted as "tag=value"