Esempio n. 1
0
func FetchMetadataForEpisode(e *Episode) error {
	log.Printf("Fetching metadata for episode: %q", e.Title)

	if e.TvdbSeriesId == 0 {
		s, err := database.GetSeries(e.SeriesId)
		if err != nil {
			return err
		}
		e.TvdbSeriesId = s.SeriesId
		log.Printf("Adding series id to episode: %d", e.TvdbSeriesId)
	}

	b, err := tvdbconn.GetEpisodeBySeasonEp(int(e.TvdbSeriesId), int(e.SeasonNumber), int(e.EpisodeNumber), "en")
	if err != nil {
		log.Printf("Error querying TheTVDB for %s: %v", e.Title, err)
		return err
	}

	singleEpisode, err := tvdb.ParseSingleEpisode(b)
	if err != nil {
		log.Printf("Error parsing single episode: %v", err)
		return err
	}

	episode := singleEpisode.Episode
	e.Title = episode.EpisodeName
	e.Overview = episode.Overview
	e.ImdbId = episode.ImdbId
	e.Director = episode.Director
	e.Writer = episode.Writer
	e.SeasonId = int64(episode.SeasonId)
	e.GuestStars = episode.GuestStars
	e.AbsoluteNumber = episode.AbsoluteNumber

	// IMDB info
	title, err := imdb.NewTitle(http.DefaultClient, e.ImdbId)
	if err != nil {
		log.Printf("Failed to get extended info from imdb: %v", err)
	} else {
		e.Poster = title.Poster.ContentURL
	}

	err = database.SaveEpisode(e)
	if err != nil {
		return err
	}

	return nil
}
Esempio n. 2
0
func title(c appengine.Context, id string) ([]byte, error) {
	client := &http.Client{
		Transport: &urlfetch.Transport{
			Context:  c,
			Deadline: 15 * time.Second,
		},
	}
	t, err := imdb.NewTitle(client, id)
	if err != nil {
		return nil, err
	}
	b, err := json.MarshalIndent(t, "", "  ")
	if err != nil {
		return nil, err
	}
	return b, err
}