AnimeEpFilepathPattern improved

This commit is contained in:
milarin 2023-01-15 22:32:01 +01:00
parent 8ed3e407ee
commit bda72cc7db
3 changed files with 9 additions and 9 deletions

View File

@ -4,14 +4,21 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"git.milar.in/milarin/anilist"
"git.milar.in/nyaanime/model" "git.milar.in/nyaanime/model"
) )
type AnimePathPatternData struct {
Anime *anilist.Media
Episode int
Ext string
}
func GetAnimeEpFilepath(animeEp model.AnimeEpisode, ext string) string { func GetAnimeEpFilepath(animeEp model.AnimeEpisode, ext string) string {
ext = strings.TrimPrefix(ext, ".") ext = strings.TrimPrefix(ext, ".")
tmplData := AnimePathPatternData{ tmplData := AnimePathPatternData{
Title: animeEp.Anime.Title, Anime: animeEp.Anime,
Episode: animeEp.Episode, Episode: animeEp.Episode,
Ext: ext, Ext: ext,
} }

View File

@ -21,7 +21,7 @@ var (
AnimeEpFilepathPattern = envvars.Object( AnimeEpFilepathPattern = envvars.Object(
"EPISODE_FILEPATH_PATTERN", "EPISODE_FILEPATH_PATTERN",
template.Must(template.New("anime-episode-filepath-pattern").Parse(`{{.Title.UserPreferred}}/{{.Title.UserPreferred}} Episode {{.Episode}}.{{.Ext}}`)), template.Must(template.New("anime-episode-filepath-pattern").Parse(`{{.Anime.Title.UserPreferred}}/{{.Anime.Title.UserPreferred}} Episode {{.Episode}}.{{.Ext}}`)),
template.New("anime-episode-filepath-pattern").Parse, template.New("anime-episode-filepath-pattern").Parse,
) )

View File

@ -3,18 +3,11 @@ package logic
import ( import (
"path/filepath" "path/filepath"
"git.milar.in/milarin/anilist"
"git.milar.in/milarin/slices" "git.milar.in/milarin/slices"
"git.milar.in/nyaanime/model" "git.milar.in/nyaanime/model"
"git.milar.in/nyaanime/parsers" "git.milar.in/nyaanime/parsers"
) )
type AnimePathPatternData struct {
Title anilist.MediaTitle
Episode int
Ext string
}
func GetAnimeEpProps(animeEp model.AnimeEpisode) (*FilePriority, bool) { func GetAnimeEpProps(animeEp model.AnimeEpisode) (*FilePriority, bool) {
animeEpPath := GetAnimeEpFilepath(animeEp, "*") animeEpPath := GetAnimeEpFilepath(animeEp, "*")
files, err := filepath.Glob(animeEpPath) files, err := filepath.Glob(animeEpPath)