26 lines
622 B
Go
26 lines
622 B
Go
|
|
package tmdb
|
||
|
|
|
||
|
|
import (
|
||
|
|
"regexp"
|
||
|
|
"strconv"
|
||
|
|
"strings"
|
||
|
|
)
|
||
|
|
|
||
|
|
var yearRegex = regexp.MustCompile(`\b(19|20)\d{2}\b`)
|
||
|
|
|
||
|
|
// ExtractTitleAndYear parses a torrent release name and returns the clean title and year.
|
||
|
|
// Example: "The.Housemaid.2025.FRENCH.1080p" → ("The Housemaid", 2025)
|
||
|
|
func ExtractTitleAndYear(releaseName string) (string, int) {
|
||
|
|
s := strings.ReplaceAll(releaseName, ".", " ")
|
||
|
|
s = strings.ReplaceAll(s, "_", " ")
|
||
|
|
|
||
|
|
loc := yearRegex.FindStringIndex(s)
|
||
|
|
if loc == nil {
|
||
|
|
return strings.TrimSpace(s), 0
|
||
|
|
}
|
||
|
|
|
||
|
|
year, _ := strconv.Atoi(s[loc[0]:loc[1]])
|
||
|
|
title := strings.TrimSpace(s[:loc[0]])
|
||
|
|
return title, year
|
||
|
|
}
|