當前位置: 首頁>>代碼示例>>Golang>>正文


Golang store.Show類代碼示例

本文整理匯總了Golang中github.com/haarts/getme/store.Show的典型用法代碼示例。如果您正苦於以下問題:Golang Show類的具體用法?Golang Show怎麽用?Golang Show使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Show類的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Search

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
}
開發者ID:gitter-badger,項目名稱:getme,代碼行數:28,代碼來源:torrents.go

示例2: selectEpisodeSnippet

func selectEpisodeSnippet(show *store.Show) store.Snippet {
	if len(show.QuerySnippets.ForEpisode) == 0 || isExplore() {
		// select random snippet
		var snippets []store.Snippet
		for k, _ := range episodeQueryAlternatives {
			for _, morpher := range titleMorphers {
				snippets = append(
					snippets,
					store.Snippet{
						Score:         0,
						TitleSnippet:  morpher(show.Title),
						FormatSnippet: k,
					},
				)
			}
		}
		snippet := snippets[rand.Intn(len(snippets))]
		log.WithFields(
			log.Fields{
				"title_snippet":  snippet.TitleSnippet,
				"format_snippet": snippet.FormatSnippet,
			}).Debug("Random snippet")
		return snippet
	}

	// select the current best
	return show.BestEpisodeSnippet()
}
開發者ID:gitter-badger,項目名稱:getme,代碼行數:28,代碼來源:snippets.go

示例3: TestStoreEpisodeSnippet

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])
}
開發者ID:gitter-badger,項目名稱:getme,代碼行數:7,代碼來源:show_test.go

示例4: SearchTorrents

// SearchTorrents provides some feedback to the user and searches for torrents
// for the pending items.
func SearchTorrents(show *store.Show) ([]torrents.Torrent, error) {
	fmt.Printf(
		"Searching for %d torrents",
		len(show.PendingSeasons())+len(show.PendingEpisodes()),
	)

	c := startProgressBar()
	defer stopProgressBar(c)

	return torrents.Search(show)
}
開發者ID:gitter-badger,項目名稱:getme,代碼行數:13,代碼來源:ui.go

示例5: TestEpisodes

func TestEpisodes(t *testing.T) {
	season1 := &store.Season{Episodes: []*store.Episode{
		{Episode: 1},
		{Episode: 2}}}
	season2 := &store.Season{Episodes: []*store.Episode{
		{Episode: 1},
		{Episode: 2}}}
	s := store.Show{Seasons: []*store.Season{season1, season2}}

	if len(s.Episodes()) != 4 {
		t.Error("Expected to have 4 episodes, got: ", len(s.Episodes()))
	}
}
開發者ID:gitter-badger,項目名稱:getme,代碼行數:13,代碼來源:show_test.go

示例6: DisplayPendingEpisodes

// DisplayPendingEpisodes shows, on stdout, the episodes pending for a
// particular show.
func DisplayPendingEpisodes(show *store.Show) {
	xs := show.PendingSeasons()
	for _, x := range xs {
		fmt.Printf("Pending: %s season %d\n", show.Title, x.Season)
	}
	ys := show.PendingEpisodes()
	if len(ys) > 10 {
		fmt.Println("<snip>")
		ys = ys[len(ys)-10:]
	}
	for _, y := range ys {
		fmt.Printf("Pending: %s season %d episode %d\n", show.Title, y.Season(), y.Episode)
	}
}
開發者ID:gitter-badger,項目名稱:getme,代碼行數:16,代碼來源:ui.go

示例7: queriesForEpisodes

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
}
開發者ID:gitter-badger,項目名稱:getme,代碼行數:18,代碼來源:torrents.go

示例8: queriesForSeasons

func queriesForSeasons(show *store.Show) []queryJob {
	queries := []queryJob{}
	for _, season := range show.PendingSeasons() {
		// ignore Season 0, which are specials and are rarely found and/or
		// interesting.
		if season.Season == 0 {
			continue
		}

		snippet := selectSeasonSnippet(show)

		query := seasonQueryAlternatives[snippet.FormatSnippet](snippet.TitleSnippet, season)
		queries = append(queries, queryJob{
			snippet: snippet,
			query:   query,
			media:   season,
			season:  season.Season,
		})
	}
	return queries
}
開發者ID:gitter-badger,項目名稱:getme,代碼行數:21,代碼來源:torrents.go

示例9: selectSeasonSnippet

func selectSeasonSnippet(show *store.Show) store.Snippet {
	if len(show.QuerySnippets.ForSeason) == 0 || isExplore() {
		// select random snippet
		var snippets []store.Snippet
		for k, _ := range seasonQueryAlternatives {
			for _, morpher := range titleMorphers {
				snippets = append(
					snippets,
					store.Snippet{
						Score:         0,
						TitleSnippet:  morpher(show.Title),
						FormatSnippet: k,
					},
				)
			}
		}
		return snippets[rand.Intn(len(snippets))]
	}

	// select the current best
	return show.BestSeasonSnippet()
}
開發者ID:gitter-badger,項目名稱:getme,代碼行數:22,代碼來源:snippets.go

示例10: addSeason

func addSeason(show *store.Show, season Season) {
	newSeason := store.Season{
		Season: season.Season,
	}
	for _, episode := range season.Episodes {
		newEpisode := store.Episode{
			Episode: episode.Episode,
			AirDate: episode.AirDate,
			Title:   episode.Title,
			Pending: true,
		}
		newSeason.Episodes = append(newSeason.Episodes, &newEpisode)
	}

	show.Seasons = append(show.Seasons, &newSeason)
}
開發者ID:gitter-badger,項目名稱:getme,代碼行數:16,代碼來源:sources.go

示例11: TestDisplayTitle

func TestDisplayTitle(t *testing.T) {
	s := store.Show{Title: "bar"}
	if s.DisplayTitle() != s.Title {
		t.Error("Expected DisplayTitle to return the Title, got: ", s.DisplayTitle())
	}
}
開發者ID:gitter-badger,項目名稱:getme,代碼行數:6,代碼來源:show_test.go

示例12: TestPendingItems

func TestPendingItems(t *testing.T) {
	show := store.Show{}
	episodes := []*store.Episode{
		{Pending: true},
		{Pending: true},
		{Pending: true},
	}
	season1 := store.Season{Season: 1, Episodes: episodes}
	show.Seasons = append(show.Seasons, &season1)
	if len(show.PendingSeasons()) != 0 {
		t.Error("All episodes are pending but it's from the last seasons thus no seasons should be returned, got:", len(show.PendingSeasons()))
	}
	if len(show.PendingEpisodes()) != 3 {
		t.Error("All episodes are pending, got:", len(show.PendingEpisodes()))
	}

	episodes = []*store.Episode{
		{Pending: true},
		{Pending: true},
	}
	season2 := store.Season{Season: 2, Episodes: episodes}
	show.Seasons = append(show.Seasons, &season2)
	if len(show.PendingSeasons()) != 1 {
		t.Error("Expected 2 items representing the episodes of the last season and 1 item representing the first season.")
	}
	if len(show.PendingEpisodes()) != 2 {
		t.Error("Expected 2 items representing the episodes of the last season and 1 item representing the first season.")
	}
}
開發者ID:gitter-badger,項目名稱:getme,代碼行數:29,代碼來源:show_test.go


注:本文中的github.com/haarts/getme/store.Show類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。