50 lines
979 B
Go
50 lines
979 B
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"git.milar.in/milarin/anilist"
|
|
"git.milar.in/nyaanime/logic"
|
|
"git.milar.in/nyaanime/model"
|
|
)
|
|
|
|
type AnimePathPatternData struct {
|
|
Title anilist.MediaTitle
|
|
Episode int
|
|
Ext string
|
|
}
|
|
|
|
func AnimeEpExistsLocally(animeEp model.AnimeEpisode) bool {
|
|
animeEpPath := logic.GetAnimeEpFilepath(animeEp, "*")
|
|
|
|
files, err := filepath.Glob(animeEpPath)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
return len(files) > 0
|
|
}
|
|
|
|
func IsCurrentlyDownloading(animeEp model.AnimeEpisode) bool {
|
|
animeEpPath := logic.GetAnimeEpFilepath(animeEp, "lock")
|
|
_, err := os.Stat(animeEpPath)
|
|
return !errors.Is(err, os.ErrNotExist)
|
|
}
|
|
|
|
func SetCurrentlyDownloading(animeEp model.AnimeEpisode) error {
|
|
animeEpPath := logic.GetAnimeEpFilepath(animeEp, "lock")
|
|
|
|
dir := filepath.Dir(animeEpPath)
|
|
if err := os.MkdirAll(dir, 0755); err != nil {
|
|
return err
|
|
}
|
|
|
|
file, err := os.Create(animeEpPath)
|
|
if err != nil {
|
|
defer file.Close()
|
|
}
|
|
return err
|
|
}
|