utils

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanText

func CleanText(text string) string

CleanText removes extra whitespace and trims a string

func Contains

func Contains(slice []string, item string) bool

Contains checks if a slice contains a string (case-insensitive)

func DefaultInt

func DefaultInt(values ...int) int

DefaultInt returns the first non-zero int

func DefaultString

func DefaultString(values ...string) string

DefaultString returns the first non-empty string

func ExtractYear

func ExtractYear(text string) int

ExtractYear extracts a 4-digit year from a string Returns 0 if no year is found

func LevenshteinDistance

func LevenshteinDistance(s1, s2 string) int

LevenshteinDistance calculates the Levenshtein distance between two strings It returns the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one string into the other

func NormalizeTitle

func NormalizeTitle(title string) string

NormalizeTitle normalizes a title for comparison Removes special characters, converts to lowercase, removes season/part patterns

func ParseFloat

func ParseFloat(s string) float64

ParseFloat safely parses a string to float64, returning 0.0 on error

func ParseInt

func ParseInt(s string) int

ParseInt safely parses a string to int, returning 0 on error

func RemoveDuplicates

func RemoveDuplicates(slice []string) []string

RemoveDuplicates removes duplicate strings from a slice while preserving order

func SimilarityScore

func SimilarityScore(title1, title2 string) float64

SimilarityScore calculates a similarity score between two titles (0.0 to 1.0) 1.0 means perfect match, 0.0 means completely different

func SplitGenres

func SplitGenres(genres string) []string

SplitGenres splits a genre string by common delimiters

func TruncateString

func TruncateString(s string, maxLen int) string

TruncateString truncates a string to maxLen characters If truncated, appends "..." to the end

Types

type MatchResult

type MatchResult struct {
	Media   providers.Media
	Score   float64
	IsExact bool
}

MatchResult represents a search result with its similarity score

func FindBestMatch

func FindBestMatch(query string, results []providers.Media, minScore float64) *MatchResult

FindBestMatch finds the single best matching media item Returns nil if no match meets the minimum score threshold

func FindBestMatches

func FindBestMatches(query string, results []providers.Media, minScore float64) []MatchResult

FindBestMatches finds the best matching media items from a list based on title similarity Returns sorted list of matches with similarity scores minScore is the minimum similarity threshold (0.0 to 1.0)

Jump to

Keyboard shortcuts

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