wip
This commit is contained in:
27
internal/classifier/classifier.go
Normal file
27
internal/classifier/classifier.go
Normal 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
|
||||||
|
}
|
||||||
0
internal/classifier/misc.go
Normal file
0
internal/classifier/misc.go
Normal file
28
internal/classifier/movie.go
Normal file
28
internal/classifier/movie.go
Normal 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
21
internal/classifier/tv.go
Normal 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
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
type StructureConfig struct {
|
||||||
|
MoviesDir string `yaml:"movies_dir"`
|
||||||
|
TVDir string `yaml:"tv_dir"`
|
||||||
|
MiscDir string `yaml:"misc_dir"`
|
||||||
|
UnknownDir string `yaml:"unknown_dir"`
|
||||||
|
AutoCreate bool `yaml:"auto_create"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type WatchConfig struct {
|
||||||
|
Dirs []string `yaml:"dirs"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
Watch WatchConfig `yaml:"watch"`
|
||||||
|
Structure StructureConfig `yaml:"structure"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func LoadConfig(path string) (*Config, error) {
|
||||||
|
data, err := os.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var cfg Config
|
||||||
|
if err := yaml.Unmarshal(data, &cfg); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &cfg, nil
|
||||||
|
}
|
||||||
|
|||||||
0
internal/mover/mover.go
Normal file
0
internal/mover/mover.go
Normal file
0
internal/util/file.go
Normal file
0
internal/util/file.go
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package watcher
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"github.com/fsnotify/fsnotify"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FileHandler func(path string)
|
||||||
|
|
||||||
|
func WatchDirs(dirs []string, handler FileHandler) error {
|
||||||
|
watcher, err := fsnotify.NewWatcher()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer watcher.Close()
|
||||||
|
|
||||||
|
for _, d := range dirs {
|
||||||
|
if err := watcher.Add(d); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case event := <-watcher.Events:
|
||||||
|
if event.Op&(fsnotify.Create|fsnotify.Write) != 0 {
|
||||||
|
handler(event.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
case err := <-watcher.Errors:
|
||||||
|
log.Printf("Watcher error: %v\n", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user