2023-01-13 10:39:59 +01:00
|
|
|
package logic
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
|
2023-01-15 22:32:01 +01:00
|
|
|
"git.milar.in/milarin/anilist"
|
2023-01-13 10:39:59 +01:00
|
|
|
"git.milar.in/nyaanime/model"
|
|
|
|
)
|
|
|
|
|
2023-01-15 22:32:01 +01:00
|
|
|
type AnimePathPatternData struct {
|
|
|
|
Anime *anilist.Media
|
|
|
|
Episode int
|
|
|
|
Ext string
|
|
|
|
}
|
|
|
|
|
2023-01-13 10:39:59 +01:00
|
|
|
func GetAnimeEpFilepath(animeEp model.AnimeEpisode, ext string) string {
|
2023-01-13 11:27:09 +01:00
|
|
|
ext = strings.TrimPrefix(ext, ".")
|
|
|
|
|
2023-01-13 10:39:59 +01:00
|
|
|
tmplData := AnimePathPatternData{
|
2023-01-15 22:32:01 +01:00
|
|
|
Anime: animeEp.Anime,
|
2023-01-13 10:39:59 +01:00
|
|
|
Episode: animeEp.Episode,
|
|
|
|
Ext: ext,
|
|
|
|
}
|
|
|
|
|
|
|
|
b := new(strings.Builder)
|
|
|
|
if err := AnimeEpFilepathPattern.Execute(b, tmplData); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return filepath.Join(AnimePath, b.String())
|
|
|
|
}
|