Esempio n. 1
0
func (s *MySuite) TestEnvironment(c *C) {
	c.Assert(util.PathExists(s.dir), Equals, true)
	c.Assert(util.PathExists(s.FileWithPath("royal")), Equals, true)
	c.Assert(util.PathExists(s.FileWithPath("crmi_dir")), Equals, true)
	c.Assert(util.PathExists(
		path.Join(s.FileWithPath("crmi_dir"), "episode.mkv")), Equals, true)
}
Esempio n. 2
0
func (s *MySuite) TestEpisodeRenamingFromDir(c *C) {
	episode, _ := CreateEpisodeFromPath(s.FileWithPath("crmi_dir"))
	c.Assert(episode.CanBeRenamed(), Equals, true)
	episode.Rename(s.dir)
	c.Assert(util.PathExists(path.Join(s.dir, episode.CleanedFileName())),
		Equals, true)
	c.Assert(util.PathExists(s.FileWithPath("crmi_dir")), Equals, false)
}
Esempio n. 3
0
func (s *MySuite) TestConfigParsingWhenNoConfigExists(c *C) {
	standard := Config{}
	config := GetConfig(s.config_file, standard)

	c.Assert(config, DeepEquals, standard)
	c.Assert(util.PathExists(s.config_file), Equals, true)
}
Esempio n. 4
0
func GetConfig(config_file string, standard Config) Config {

	if !util.PathExists(config_file) {
		config_dir := path.Dir(config_file)

		dir_err := os.MkdirAll(config_dir, 0755)
		if dir_err != nil {
			panic(dir_err)
		}

		writeMarshaledDataToFile(config_file, standard)
	}

	content, read_err := ioutil.ReadFile(config_file)
	if read_err != nil {
		panic(read_err)
	}

	unmarshal_err := json.Unmarshal(content, &standard)
	if unmarshal_err != nil {
		panic(unmarshal_err)
	}

	writeMarshaledDataToFile(config_file, standard)

	return standard
}
Esempio n. 5
0
func (s *MySuite) TestConfigParsingWithChanges(c *C) {
	// create config which seems to be changed by the user
	old := Config{IndexFile: "/not/existing/file.json"}
	_ = GetConfig(s.config_file, old)
	c.Assert(util.PathExists(s.config_file), Equals, true)

	standard := Config{IndexFile: "/other/non/existing/file"}
	config := GetConfig(s.config_file, standard)
	c.Assert(config.IndexFile, Equals, "/not/existing/file.json")
}
Esempio n. 6
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
}
Esempio n. 7
0
func (s *MySuite) TestWriteIndexToFile(c *C) {
	episode := renamer.Episode{Series: "Shameless US", Season: 1, Episode: 9,
		Name: "Testepisode", Extension: ".mkv", Language: "de"}

	c.Assert(s.index.IsEpisodeInIndex(episode), Equals, false)

	// add episode
	added, err := s.index.AddEpisode(&episode)
	c.Assert(err, IsNil)
	c.Assert(added, Equals, true)
	c.Assert(s.index.IsEpisodeInIndex(episode), Equals, true)

	// dump it
	dest := path.Join(s.dir, "seriesindex_dump.xml")
	s.index.WriteToFile(dest)
	c.Assert(util.PathExists(dest), Equals, true)

	// parse it back and make assertions
	index, err := ParseSeriesIndex(dest)
	c.Assert(err, IsNil)
	c.Assert(index.IsEpisodeInIndex(episode), Equals, true)
}
Esempio n. 8
0
func (s *MySuite) TestEnvironment(c *C) {
	c.Assert(util.PathExists(s.dir), Equals, true)
}