Пример #1
0
func main() {
	store, err := store.Open(config.Config().StateDir)
	if err != nil {
		fmt.Println("Error opening state")
		os.Exit(1)
	}
	defer store.Close()

	for _, v := range store.Shows() {
		fmt.Printf("Show: %s\n", v.Title)
		fmt.Printf("Pending seasons: ")
		for _, season := range v.PendingSeasons() {
			fmt.Printf("%d, ", season.Season)
		}
		fmt.Println("")
		fmt.Println("Pending episodes:")
		for _, episode := range v.PendingEpisodes() {
			fmt.Printf(
				"%02dx%02d - %s\n",
				episode.Season(),
				episode.Episode,
				episode.Title,
			)
		}
		fmt.Println("")
	}
}
Пример #2
0
func updateMedia() {
	store, err := store.Open(config.Config().StateDir)
	if err != nil {
		fmt.Println("We've failed to open the data store.")
		log.WithFields(log.Fields{
			"err": err,
		}).Error("We've failed to open the data store.")
		return
	}
	defer store.Close()

	ui.Update(store)
}
Пример #3
0
func TestCreateDuplicateShow(t *testing.T) {
	testDir := "test_state_dir"
	os.MkdirAll(path.Join(testDir, "shows"), 0755)
	defer func() {
		os.RemoveAll(testDir)
	}()

	s, _ := store.Open(testDir)

	show := store.Show{Title: "my show"}
	s.CreateShow(&show)
	err := s.CreateShow(&show)
	if err == nil {
		t.Error("Expected not to be able to store same shows.")
	}
}
Пример #4
0
func TestClose(t *testing.T) {
	testDir := "test_state_dir"
	os.MkdirAll(path.Join(testDir, "shows"), 0755)
	defer func() {
		os.RemoveAll(testDir)
	}()

	s, _ := store.Open(testDir)
	show := store.Show{Title: "my show"}
	s.CreateShow(&show)

	s.Close()
	if _, err := os.Stat(path.Join(testDir, "shows", "my_show.json")); os.IsNotExist(err) {
		t.Error("Expected show to be stored as file.")
	}
}
Пример #5
0
func TestReadShows(t *testing.T) {
	testDir := "test_state_dir"
	os.MkdirAll(path.Join(testDir, "shows"), 0755)
	defer func() {
		os.RemoveAll(testDir)
	}()

	os.Link(path.Join("testdata", "my_show.json"), path.Join(testDir, "shows", "my_show.json"))

	s, _ := store.Open(testDir)
	if len(s.Shows()) != 1 {
		t.Error("Expected to have read 1 show, got:", len(s.Shows()))
	}
	if _, ok := s.Shows()["my show"]; !ok {
		t.Error("Expected to find 'my show'.")
	}
}
Пример #6
0
func handleShow(show *sources.Show) error {
	store, err := store.Open(config.Config().StateDir)
	if err != nil {
		fmt.Println("We've failed to open the data store.")
		log.WithFields(log.Fields{
			"err": err,
		}).Error("We've failed to open the data store.")
		return err
	}
	defer store.Close()

	// Fetch the seasons/episodes associated with the found show.
	persistedShow := store.NewShow(show.Source, show.ID, show.URL, show.Title)
	err = ui.Lookup(persistedShow)
	if err != nil {
		fmt.Println("We've encountered a problem looking up seasons for the show.")
		log.WithFields(log.Fields{
			"err": err,
		}).Error("We've encountered a problem looking up seasons for the show.")
		return err
	}

	if len(persistedShow.Episodes()) == 0 {
		fmt.Println("No episodes could be found for show.")
		log.WithFields(log.Fields{
			"show": persistedShow.Title,
		}).Info("No episodes could be found for show.")
		return nil
	}

	err = store.CreateShow(persistedShow)
	if err != nil {
		fmt.Println("Show already exists. Remove it or search for something else. If you want to update it do: getme -u")
		log.WithFields(log.Fields{
			"err":  err,
			"show": persistedShow.Title,
		}).Fatal("Show already exists.")
	}

	if !noDownload {
		downloadTorrents(persistedShow)
	}

	return nil
}