feat: use info from dir if longer than filename
This commit is contained in:
parent
b680f59f9d
commit
812f53ac16
44
media.go
44
media.go
@ -22,41 +22,51 @@ func newMediaElement(p string) *mediaElement {
|
||||
episodeMatch := regexp.MustCompile(`[.\- ]?(S\d\dE\d\d)[.\- ]?`)
|
||||
yearMatch := regexp.MustCompile(`[.\- ]?(\d{4})[.\- ]?`)
|
||||
|
||||
text := filepath.Base(p)
|
||||
ext := filepath.Ext(text)
|
||||
text = strings.TrimSuffix(text, ext)
|
||||
text = strings.ReplaceAll(text, ".", " ")
|
||||
text = strings.ReplaceAll(text, "-", " ")
|
||||
name := filepath.Base(p)
|
||||
ext := filepath.Ext(name)
|
||||
name = strings.TrimSuffix(name, ext)
|
||||
|
||||
parentDir := filepath.Dir(p)
|
||||
// use parent directory if it starts similarly and is longer
|
||||
dir := filepath.Base(parentDir)
|
||||
if len(dir) >= len(name) && dir[0:3] == name[0:3] {
|
||||
parentDir = filepath.Dir(parentDir)
|
||||
name = dir
|
||||
fmt.Println(dir)
|
||||
}
|
||||
|
||||
name = strings.ReplaceAll(name, ".", " ")
|
||||
name = strings.ReplaceAll(name, "-", " ")
|
||||
|
||||
element := &mediaElement{
|
||||
Directory: filepath.Dir(p),
|
||||
Directory: parentDir,
|
||||
Extension: ext,
|
||||
}
|
||||
|
||||
title := ""
|
||||
// get first group of regex match from episodeMatch
|
||||
match := episodeMatch.FindStringSubmatch(text)
|
||||
match := episodeMatch.FindStringSubmatch(name)
|
||||
if len(match) > 0 {
|
||||
element.Episode = match[1]
|
||||
indexOfEpisode := strings.Index(text, match[0])
|
||||
text = strings.Replace(text, match[0], "", -1)
|
||||
title = text[indexOfEpisode:]
|
||||
text = text[:indexOfEpisode]
|
||||
indexOfEpisode := strings.Index(name, match[0])
|
||||
name = strings.Replace(name, match[0], "", -1)
|
||||
title = name[indexOfEpisode:]
|
||||
name = name[:indexOfEpisode]
|
||||
}
|
||||
|
||||
match = yearMatch.FindStringSubmatch(text)
|
||||
match = yearMatch.FindStringSubmatch(name)
|
||||
if len(match) > 0 {
|
||||
year, err := strconv.Atoi(match[1])
|
||||
if err == nil {
|
||||
element.Year = year
|
||||
}
|
||||
indexOfYear := strings.Index(text, match[0])
|
||||
text = strings.Replace(text, match[0], "", -1)
|
||||
title = text[indexOfYear:]
|
||||
text = text[:indexOfYear]
|
||||
indexOfYear := strings.Index(name, match[0])
|
||||
name = strings.Replace(name, match[0], "", -1)
|
||||
title = name[indexOfYear:]
|
||||
name = name[:indexOfYear]
|
||||
}
|
||||
|
||||
element.Name = strings.TrimSpace(text)
|
||||
element.Name = strings.TrimSpace(name)
|
||||
words := strings.Split(title, " ")
|
||||
titleWords := []string{}
|
||||
for i := len(words) - 1; i >= 0; i-- {
|
||||
|
Loading…
x
Reference in New Issue
Block a user