Exemple #1
0
func CreateEpisodeFromPath(path string) (*Episode, error) {
	episode := new(Episode)

	if !util.PathExists(path) {
		return episode, errors.New("Supplied episode does not exist")
	}

	basename := filepath.Base(path)
	if !IsInterestingDirEntry(basename) {
		return episode, errors.New("Supplied episode has no series information")
	}

	episode.Path = path
	episode.Episodefile = path
	if util.IsDirectory(path) {
		episodefile, err := FindBiggestVideoFile(path)

		if err != nil {
			return episode, err
		}
		episode.Episodefile = episodefile
	}

	if !HasVideoFileEnding(episode.Episodefile) {
		return episode, errors.New("No videofile available")
	}

	information := ExtractEpisodeInformation(basename)
	episode.Season, _ = strconv.Atoi(information["season"])
	episode.Episode, _ = strconv.Atoi(information["episode"])

	episode.Series = CleanEpisodeInformation(information["series"])
	episode.Extension = GlobalPath.Ext(episode.Episodefile)

	name := information["episodename"]
	if util.IsFile(path) {
		name = name[:len(name)-len(episode.Extension)]
	}
	episode.Name = CleanEpisodeInformation(name)

	episode.ExtractLanguage()

	return episode, nil
}
Exemple #2
0
func (self *Episode) CanBeRenamed() bool {
	return self.HasValidEpisodeName() && util.IsFile(self.Episodefile)
}