2019-02-09 12:30:49 +00:00
|
|
|
package paths
|
|
|
|
|
|
|
|
import (
|
2020-07-07 00:35:43 +00:00
|
|
|
"path/filepath"
|
|
|
|
|
2021-09-20 23:34:25 +00:00
|
|
|
"github.com/stashapp/stash/pkg/logger"
|
2020-04-24 02:52:21 +00:00
|
|
|
"github.com/stashapp/stash/pkg/utils"
|
2019-02-09 12:30:49 +00:00
|
|
|
)
|
|
|
|
|
2020-09-15 07:28:53 +00:00
|
|
|
type JSONPaths struct {
|
2020-04-24 02:52:21 +00:00
|
|
|
Metadata string
|
|
|
|
|
2019-02-09 12:30:49 +00:00
|
|
|
MappingsFile string
|
|
|
|
ScrapedFile string
|
|
|
|
|
|
|
|
Performers string
|
|
|
|
Scenes string
|
2020-10-12 23:12:46 +00:00
|
|
|
Images string
|
2019-02-09 12:30:49 +00:00
|
|
|
Galleries string
|
|
|
|
Studios string
|
2020-07-07 00:35:43 +00:00
|
|
|
Tags string
|
2020-03-10 03:28:15 +00:00
|
|
|
Movies string
|
2019-02-09 12:30:49 +00:00
|
|
|
}
|
|
|
|
|
2020-09-15 07:28:53 +00:00
|
|
|
func newJSONPaths(baseDir string) *JSONPaths {
|
|
|
|
jp := JSONPaths{}
|
|
|
|
jp.Metadata = baseDir
|
|
|
|
jp.MappingsFile = filepath.Join(baseDir, "mappings.json")
|
|
|
|
jp.ScrapedFile = filepath.Join(baseDir, "scraped.json")
|
|
|
|
jp.Performers = filepath.Join(baseDir, "performers")
|
|
|
|
jp.Scenes = filepath.Join(baseDir, "scenes")
|
2020-10-12 23:12:46 +00:00
|
|
|
jp.Images = filepath.Join(baseDir, "images")
|
2020-09-15 07:28:53 +00:00
|
|
|
jp.Galleries = filepath.Join(baseDir, "galleries")
|
|
|
|
jp.Studios = filepath.Join(baseDir, "studios")
|
|
|
|
jp.Movies = filepath.Join(baseDir, "movies")
|
|
|
|
jp.Tags = filepath.Join(baseDir, "tags")
|
2019-02-09 12:30:49 +00:00
|
|
|
return &jp
|
|
|
|
}
|
|
|
|
|
2020-09-15 07:28:53 +00:00
|
|
|
func GetJSONPaths(baseDir string) *JSONPaths {
|
|
|
|
jp := newJSONPaths(baseDir)
|
2020-04-24 02:52:21 +00:00
|
|
|
return jp
|
|
|
|
}
|
|
|
|
|
2020-09-15 07:28:53 +00:00
|
|
|
func EnsureJSONDirs(baseDir string) {
|
|
|
|
jsonPaths := GetJSONPaths(baseDir)
|
2021-09-20 23:34:25 +00:00
|
|
|
if err := utils.EnsureDir(jsonPaths.Metadata); err != nil {
|
|
|
|
logger.Warnf("couldn't create directories for Metadata: %v", err)
|
|
|
|
}
|
|
|
|
if err := utils.EnsureDir(jsonPaths.Scenes); err != nil {
|
|
|
|
logger.Warnf("couldn't create directories for Scenes: %v", err)
|
|
|
|
}
|
|
|
|
if err := utils.EnsureDir(jsonPaths.Images); err != nil {
|
|
|
|
logger.Warnf("couldn't create directories for Images: %v", err)
|
|
|
|
}
|
|
|
|
if err := utils.EnsureDir(jsonPaths.Galleries); err != nil {
|
|
|
|
logger.Warnf("couldn't create directories for Galleries: %v", err)
|
|
|
|
}
|
|
|
|
if err := utils.EnsureDir(jsonPaths.Performers); err != nil {
|
|
|
|
logger.Warnf("couldn't create directories for Performers: %v", err)
|
|
|
|
}
|
|
|
|
if err := utils.EnsureDir(jsonPaths.Studios); err != nil {
|
|
|
|
logger.Warnf("couldn't create directories for Studios: %v", err)
|
|
|
|
}
|
|
|
|
if err := utils.EnsureDir(jsonPaths.Movies); err != nil {
|
|
|
|
logger.Warnf("couldn't create directories for Movies: %v", err)
|
|
|
|
}
|
|
|
|
if err := utils.EnsureDir(jsonPaths.Tags); err != nil {
|
|
|
|
logger.Warnf("couldn't create directories for Tags: %v", err)
|
|
|
|
}
|
2020-04-24 02:52:21 +00:00
|
|
|
}
|
|
|
|
|
2020-09-15 07:28:53 +00:00
|
|
|
func (jp *JSONPaths) PerformerJSONPath(checksum string) string {
|
2019-02-14 22:53:32 +00:00
|
|
|
return filepath.Join(jp.Performers, checksum+".json")
|
2019-02-09 12:30:49 +00:00
|
|
|
}
|
|
|
|
|
2020-09-15 07:28:53 +00:00
|
|
|
func (jp *JSONPaths) SceneJSONPath(checksum string) string {
|
2019-02-14 22:53:32 +00:00
|
|
|
return filepath.Join(jp.Scenes, checksum+".json")
|
2019-02-09 12:30:49 +00:00
|
|
|
}
|
|
|
|
|
2020-10-12 23:12:46 +00:00
|
|
|
func (jp *JSONPaths) ImageJSONPath(checksum string) string {
|
|
|
|
return filepath.Join(jp.Images, checksum+".json")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (jp *JSONPaths) GalleryJSONPath(checksum string) string {
|
|
|
|
return filepath.Join(jp.Galleries, checksum+".json")
|
|
|
|
}
|
|
|
|
|
2020-09-15 07:28:53 +00:00
|
|
|
func (jp *JSONPaths) StudioJSONPath(checksum string) string {
|
2019-02-14 22:53:32 +00:00
|
|
|
return filepath.Join(jp.Studios, checksum+".json")
|
2019-02-09 12:30:49 +00:00
|
|
|
}
|
2020-03-10 03:28:15 +00:00
|
|
|
|
2020-09-15 07:28:53 +00:00
|
|
|
func (jp *JSONPaths) TagJSONPath(checksum string) string {
|
2020-07-07 00:35:43 +00:00
|
|
|
return filepath.Join(jp.Tags, checksum+".json")
|
|
|
|
}
|
|
|
|
|
2020-09-15 07:28:53 +00:00
|
|
|
func (jp *JSONPaths) MovieJSONPath(checksum string) string {
|
2020-03-10 03:28:15 +00:00
|
|
|
return filepath.Join(jp.Movies, checksum+".json")
|
|
|
|
}
|