Exemplo n.º 1
0
func populateSampleEpisodes(t *testing.T, name string, count int) (*Series, *Season, []*Episode) {
	series := NewSeries(name)
	if err := database.SaveSeries(series); err != nil {
		t.Errorf("unexpected error: %v", err)
	}

	season, err := NewSeason(series.Id, 1)
	if err != nil {
		t.Errorf("unexpected error: %v", err)
	}

	if err := database.SaveSeason(season); err != nil {
		t.Errorf("unexpected error: %v", err)
	}

	episodes := make([]*Episode, count)
	for i := 0; i < count; i++ {
		e := &Episode{
			Title:        fmt.Sprintf("Episode %d", i),
			SeasonId:     season.Id,
			SeasonNumber: uint64(season.SeasonNumber),
			SeriesId:     series.Id,
		}
		if err := database.SaveEpisode(e); err != nil {
			t.Errorf("unexpected error: %v", err)
		}
		episodes[i] = e
	}

	return series, season, episodes
}
Exemplo n.º 2
0
func populateSampleSeries(t *testing.T, count int) {
	for pos := 0; pos < count; pos++ {
		s := &Series{Title: fmt.Sprintf("Series %d", pos)}
		if err := database.SaveSeries(s); err != nil {
			t.Errorf("unexpected error: %v", err)
		}
	}
}
Exemplo n.º 3
0
func FetchMetadataForSeries(queue *Queue, series *Series) error {
	log.Printf("Fetching metadata for series: %q", series.Title)

	ss, err := tvdbconn.GetSeries(series.Title, "")
	if err != nil {
		log.Printf("Error querying TVDB for %s: %v", series.Title, err)
		return err
	}

	if len(ss) < 1 {
		log.Printf("No Series found for name: %s", series.Title)
		return nil
	}

	// Now that we have basic info, get hte extended info.
	s, err := tvdbconn.GetSeriesById(ss[0].Id, "")
	if err != nil {
		log.Printf("Error querying TVDB for %s: %v", series.Title, err)
		return err
	}

	// Use the top matching series for now
	series.Title = s.SeriesName
	series.Overview = s.Overview
	series.SeriesId = int64(s.Id)
	series.Language = s.Language
	series.ImdbId = s.ImdbId
	series.Banner = tvdbconn.GetImageUrl(s.Banner)
	series.FanArt = tvdbconn.GetImageUrl(s.FanArt)
	series.Poster = tvdbconn.GetImageUrl(s.Poster)

	log.Printf("Writing series: %+v", series)

	// Persist the series
	err = database.SaveSeries(series)
	if err != nil {
		return err
	}

	eps, err := database.ListEpisodesForSeries(series.SeriesId)
	if err != nil && err != sql.ErrNoRows {
		log.Printf("Failed to fetch episodes for season: %v", err)
	}

	if eps != nil {
		for _, ep := range eps {
			ep.TvdbSeriesId = series.SeriesId
			err = database.SaveEpisode(ep)
			if err != nil {
				return err
			}

			queue.Add(&FetchMetadataTask{Episode: ep})
		}
	}

	return nil
}
Exemplo n.º 4
0
// PUT /api/series
// Creates a new series
func SeriesCreate(w http.ResponseWriter, r *http.Request) (interface{}, error) {
	var s Series
	err := json.NewDecoder(r.Body).Decode(&s)
	if err != nil {
		return nil, err
	}

	if s.Id != 0 {
		return nil, badRequest{errors.New("Series already has an Id")}
	}

	err = database.SaveSeries(&s)
	if err != nil {
		return nil, err
	}

	return s, nil
}
Exemplo n.º 5
0
// Creates test seasons all belonging to a single series
func (s *SeasonTestSuite) createSeasons(c *C, count int) (*Series, []*Season) {
	series := NewSeries("test series")
	if err := database.SaveSeries(series); err != nil {
		c.Errorf("unexpected error: %v", err)
	}

	seasons := make([]*Season, count)
	for i := 0; i < count; i++ {
		s, err := NewSeason(series.Id, uint64(i+1))
		if err != nil {
			c.Errorf("unexpected error: %v", err)
		}
		if err = database.SaveSeason(s); err != nil {
			c.Errorf("unexpected error: %v", err)
		}
		seasons[i] = s
	}

	return series, seasons
}
Exemplo n.º 6
0
func processEpisode(path string, meta *guessit.GuessResult, queue *Queue) error {
	episode, _ := database.GetEpisodeByFilename(path)
	var fetchMetadataTask *FetchMetadataTask
	if episode == nil || episode.Filename == "" {
		s, err := database.GetSeriesByTitle(meta.Series)
		if err != nil {
			// Create and save a placeholder series
			s = &Series{
				Title: meta.Series,
			}
			err = database.SaveSeries(s)
			if err != nil {
				return err
			}

			// Queue a metadata refresh of the series data
			fetchMetadataTask = &FetchMetadataTask{Series: s}
		}

		episode = &Episode{
			Filename:      path,
			Title:         meta.Title,
			EpisodeNumber: uint64(meta.EpisodeNumber),
			SeasonNumber:  uint64(meta.Season),
			SeriesId:      s.Id,
			TvdbSeriesId:  s.SeriesId,
		}
		err = database.SaveEpisode(episode)
		if err != nil {
			log.Println("Error saving movie")
		}
	}

	if fetchMetadataTask != nil {
		queue.Add(fetchMetadataTask)
	} else {
		queue.Add(&FetchMetadataTask{Episode: episode})
	}

	return nil
}