utils

package
v0.0.0-...-f5c6aee Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package utils provides utility functions for file operations and audio file handling

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyRegex

func ApplyRegex(input string, regex *regexp.Regexp, format string) (string, error)

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 GetAllFilesByName

func GetAllFilesByName(basepath string, name string) ([]string, error)

func GetFilesByExtensions

func GetFilesByExtensions(fullpath string, extensions []string) ([]string, error)

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

func GetValidDirPathFromArgs(args []string, index int) (string, error)

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

func GetValidFilePathFromArgs(args []string, index int) (string, error)

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

func GetValidFullpathFromArgs(args []string, index int) (string, error)

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

func NaturalCompare(a, b string) int

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 ReplaceDirAndExt

func ReplaceDirAndExt(file string, dir string, ext string) string

func SanitizePathComponent

func SanitizePathComponent(s string) string

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"

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL