Esempio n. 1
0
func TestSortByAirDate(t *testing.T) {
	episodes := []*store.Episode{
		{AirDate: time.Now().Add(-5 * time.Hour), Title: "oldest"},
		{AirDate: time.Now().Add(-1 * time.Hour), Title: "youngest"},
		{AirDate: time.Now().Add(-3 * time.Hour), Title: "middle aged"},
	}

	sort.Sort(store.ByAirDate(episodes))
	if episodes[0].Title != "youngest" {
		t.Error("Expected the younget episode on top, got:", episodes)
	}
}
Esempio n. 2
0
func queriesForEpisodes(show *store.Show) []queryJob {
	episodes := show.PendingEpisodes()
	sort.Sort(store.ByAirDate(episodes))
	min := math.Min(float64(len(episodes)), float64(batchSize))

	queries := []queryJob{}
	for _, episode := range episodes[0:int(min)] {
		snippet := selectEpisodeSnippet(show)

		query := episodeQueryAlternatives[snippet.FormatSnippet](snippet.TitleSnippet, episode)
		queries = append(queries, queryJob{
			snippet: snippet,
			query:   query,
			media:   episode,
		})
	}
	return queries
}