2022-08-22 14:14:14 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-08-23 11:48:26 +02:00
|
|
|
"errors"
|
2022-08-22 14:14:14 +02:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
2023-01-13 13:38:51 +01:00
|
|
|
"git.milar.in/nyaanime/logic"
|
2022-08-22 14:14:14 +02:00
|
|
|
"git.milar.in/nyaanime/model"
|
|
|
|
)
|
|
|
|
|
2022-08-23 13:24:03 +02:00
|
|
|
func IsCurrentlyDownloading(animeEp model.AnimeEpisode) bool {
|
2023-01-13 13:38:51 +01:00
|
|
|
animeEpPath := logic.GetAnimeEpFilepath(animeEp, "lock")
|
2022-08-23 11:48:26 +02:00
|
|
|
_, err := os.Stat(animeEpPath)
|
|
|
|
return !errors.Is(err, os.ErrNotExist)
|
|
|
|
}
|
2022-08-22 14:14:14 +02:00
|
|
|
|
2022-08-23 13:24:03 +02:00
|
|
|
func SetCurrentlyDownloading(animeEp model.AnimeEpisode) error {
|
2023-01-13 13:38:51 +01:00
|
|
|
animeEpPath := logic.GetAnimeEpFilepath(animeEp, "lock")
|
2022-08-25 23:25:48 +02:00
|
|
|
|
|
|
|
dir := filepath.Dir(animeEpPath)
|
|
|
|
if err := os.MkdirAll(dir, 0755); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-08-23 11:48:26 +02:00
|
|
|
file, err := os.Create(animeEpPath)
|
|
|
|
if err != nil {
|
|
|
|
defer file.Close()
|
2022-08-22 14:14:14 +02:00
|
|
|
}
|
2022-08-23 11:48:26 +02:00
|
|
|
return err
|
2022-08-22 14:14:14 +02:00
|
|
|
}
|