コード例 #1
0
ファイル: cmd_rename.go プロジェクト: BurntSushi/goim
func tvEpisodes(db *imdb.DB, tv *imdb.Tvshow) (episodeMap, error) {
	episodes := make(episodeMap, 30)
	epsearch := search.New(db)
	epsearch.Entity(imdb.EntityEpisode)
	epsearch.Tvshow(search.New(db).Atom(tv.Id))
	epsearch.Seasons(1, -1).Episodes(1, -1)
	epsearch.Limit(-1)

	results, err := epsearch.Results()
	if err != nil {
		return nil, err
	}
	if len(results) == 0 {
		return nil, ef("Could not find any episodes for %s", tv)
	}
	for _, r := range results {
		ent, err := r.GetEntity(db)
		if err != nil {
			return nil, err
		}
		ep := ent.(*imdb.Episode)
		episodes[episodeKey{ep.Season, ep.EpisodeNum}] = ep
	}
	return episodes, nil
}
コード例 #2
0
ファイル: cmd_rename.go プロジェクト: BurntSushi/goim
func guessEpisode(
	c *command,
	db *imdb.DB,
	fname string,
) (*imdb.Episode, error) {
	fname = path.Base(fname)
	s, e, start, _, err := episodeNumbers(fname, flagRenameRegexEpisode)
	if err != nil {
		return nil, ef("Could not find episode numbers: %s", err)
	}

	// A guess at where the TV show name is in the file name.
	title := strings.TrimSpace(fname[0:start])

	tvsub, err := search.Query(db, title)
	if err != nil {
		return nil, err
	}
	tvsub.Entity(imdb.EntityTvshow)
	tvsub.Votes(flagVotes, -1)

	esearch := search.New(db)
	esearch.Tvshow(tvsub)
	esearch.Entity(imdb.EntityEpisode)
	esearch.Seasons(s, s).Episodes(e, e)
	esearch.Chooser(c.chooser)

	results, err := esearch.Results()
	if err != nil {
		return nil, err
	}
	if len(results) == 0 {
		return nil, ef("Could not find episode.")
	}
	m, err := esearch.Pick(results)
	if err != nil {
		return nil, err
	}
	if m == nil {
		return nil, ef("No episode results to pick from.")
	}
	if m.Entity != imdb.EntityEpisode {
		return nil, ef("Expected episode but got %s", m.Entity)
	}
	ent, err := m.GetEntity(db)
	if err != nil {
		return nil, err
	}
	return ent.(*imdb.Episode), nil
}