This commit is contained in:
Javis Sullivan
2025-12-07 20:11:10 -05:00
parent 81e1e23066
commit 0e0fe0e37c
9 changed files with 147 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
package classifier
import (
"path/filepath"
"regexp"
"strings"
)
var movieYear = regexp.MustCompile(`(?i)(19|20)\d{2}`)
func classifyMovie(filename string) (bool, string, int) {
base := strings.TrimSuffix(filepath.Base(filename), filepath.Ext(filename))
// Find year
yearMatch := movieYear.FindString(base)
if yearMatch == "" {
return false, "", 0
}
year := parseInt(yearMatch)
// Extract title (everything before year)
title := strings.TrimSpace(strings.Replace(base, yearMatch, "", 1))
title = cleanupTitle(title)
return true, title, year
}

View File

View File

@@ -0,0 +1,28 @@
package classifier
import (
"path/filepath"
"regexp"
"strings"
)
var movieYear = regexp.MustCompile(`(?i)(19|20)\d{2}`)
func classifyMovie(filename string) (bool, string, int) {
base := strings.TrimSuffix(filepath.Base(filename), filepath.Ext(filename))
// Find year
yearMatch := movieYear.FindString(base)
if yearMatch == "" {
return false, "", 0
}
year := parseInt(yearMatch)
// Extract title (everything before year)
title := strings.TrimSpace(strings.Replace(base, yearMatch, "", 1))
title = cleanupTitle(title)
return true, title, year
}

21
internal/classifier/tv.go Normal file
View File

@@ -0,0 +1,21 @@
package classifier
var tvPattern = regexp.MustCompile(`(?i)(S?)(\d{1,2})(E|x)(\d{1,2})`)
func classifyTV(filename string) (bool, string, int, int) {
base := strings.TrimSuffix(filepath.Base(filename), filepath.Ext(filename))
match := tvPattern.FindStringSubmatch(base)
if len(match) < 5 {
return false, "", 0, 0
}
season := parseInt(match[2])
episode := parseInt(match[4])
// Remove S01E02 or similar from the string
cleaned := tvPattern.ReplaceAllString(base, "")
title := cleanupTitle(cleaned)
return true, title, season, episode
}