41 lines
773 B
Go
41 lines
773 B
Go
package main
|
|
|
|
import (
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"git.milar.in/milarin/anilist"
|
|
"git.milar.in/nyaanime/model"
|
|
)
|
|
|
|
type AnimePathPatternData struct {
|
|
Title anilist.MediaTitle
|
|
Episode int
|
|
Ext string
|
|
}
|
|
|
|
func GetAnimeEpFilepath(animeEp model.AnimeEpisode, ext string) string {
|
|
tmplData := AnimePathPatternData{
|
|
Title: animeEp.Anime.Title,
|
|
Episode: animeEp.Episode,
|
|
Ext: ext,
|
|
}
|
|
|
|
b := new(strings.Builder)
|
|
if err := AnimeEpFilepathPattern.Execute(b, tmplData); err != nil {
|
|
panic(err)
|
|
}
|
|
return b.String()
|
|
}
|
|
|
|
func AnimeEpExistsLocally(animeEp model.AnimeEpisode) bool {
|
|
animeEpPath := filepath.Join(AnimePath, GetAnimeEpFilepath(animeEp, "*"))
|
|
|
|
files, err := filepath.Glob(animeEpPath)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
return len(files) > 0
|
|
}
|