Exemple #1
0
func Search(show *store.Show) ([]Torrent, error) {
	// torrents holds the torrents to complete a serie
	var torrents []Torrent

	// TODO perhaps mashing season and episode jobs together is a bad idea
	queryJobs := createQueryJobs(show)
	for _, queryJob := range queryJobs {
		torrent, err := executeJob(queryJob)
		if err != nil {
			continue
		}

		torrent.AssociatedMedia = queryJob.media
		queryJob.snippet.Score = torrent.seeds
		// *ouch* this type switch is ugly
		switch queryJob.media.(type) {
		case *store.Season:
			show.StoreSeasonSnippet(queryJob.snippet)
		case *store.Episode:
			show.StoreEpisodeSnippet(queryJob.snippet)
		default:
			panic("unknown media type")
		}
		torrents = append(torrents, *torrent)
	}

	return torrents, nil
}
Exemple #2
0
func TestStoreEpisodeSnippet(t *testing.T) {
	show := store.Show{}
	snippet := store.Snippet{Score: 123, TitleSnippet: "abc", FormatSnippet: "sxs"}
	show.StoreEpisodeSnippet(snippet)

	assert.Equal(t, snippet, show.QuerySnippets.ForEpisode[0])
}