58 lines
1.1 KiB
Go
58 lines
1.1 KiB
Go
|
package tv
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"path"
|
||
|
|
||
|
"github.com/ollien/gobbler/categorize/location"
|
||
|
)
|
||
|
|
||
|
type Location struct {
|
||
|
showTitle string
|
||
|
seasons []int
|
||
|
}
|
||
|
|
||
|
func NewLocation(showTitle string, seasons []int) Location {
|
||
|
seasonsCopy := make([]int, len(seasons))
|
||
|
copy(seasonsCopy, seasons)
|
||
|
|
||
|
return Location{
|
||
|
showTitle: showTitle,
|
||
|
seasons: seasonsCopy,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (loc Location) MediaTitle() string {
|
||
|
return loc.showTitle
|
||
|
}
|
||
|
|
||
|
func (loc Location) Seasons() []int {
|
||
|
ret := make([]int, len(loc.seasons))
|
||
|
copy(ret, loc.seasons)
|
||
|
|
||
|
return ret
|
||
|
}
|
||
|
|
||
|
func (loc Location) MediaType() location.MediaType {
|
||
|
return location.MediaTypeTV
|
||
|
}
|
||
|
|
||
|
func (loc Location) Path() (string, error) {
|
||
|
if !loc.IsFullyResolved() {
|
||
|
return "", location.ErrUnresolvedLocation
|
||
|
}
|
||
|
|
||
|
return makeSeasonPath(loc.showTitle, loc.seasons[0]), nil
|
||
|
}
|
||
|
|
||
|
func (loc Location) IsFullyResolved() bool {
|
||
|
return len(loc.seasons) == 1
|
||
|
}
|
||
|
|
||
|
// makeSeasonPath makes the final path for a season-categorized TV show
|
||
|
func makeSeasonPath(showFolder string, seasonNumber int) string {
|
||
|
seasonFolderName := fmt.Sprintf("Season-%d", seasonNumber)
|
||
|
|
||
|
return path.Join(showFolder, seasonFolderName)
|
||
|
}
|