Exemple #1
0
func FetchMetadataForSeries(queue *Queue, series *Series) error {
	log.Printf("Fetching metadata for series: %q", series.Title)

	ss, err := tvdbconn.GetSeries(series.Title, "")
	if err != nil {
		log.Printf("Error querying TVDB for %s: %v", series.Title, err)
		return err
	}

	if len(ss) < 1 {
		log.Printf("No Series found for name: %s", series.Title)
		return nil
	}

	// Now that we have basic info, get hte extended info.
	s, err := tvdbconn.GetSeriesById(ss[0].Id, "")
	if err != nil {
		log.Printf("Error querying TVDB for %s: %v", series.Title, err)
		return err
	}

	// Use the top matching series for now
	series.Title = s.SeriesName
	series.Overview = s.Overview
	series.SeriesId = int64(s.Id)
	series.Language = s.Language
	series.ImdbId = s.ImdbId
	series.Banner = tvdbconn.GetImageUrl(s.Banner)
	series.FanArt = tvdbconn.GetImageUrl(s.FanArt)
	series.Poster = tvdbconn.GetImageUrl(s.Poster)

	log.Printf("Writing series: %+v", series)

	// Persist the series
	err = database.SaveSeries(series)
	if err != nil {
		return err
	}

	eps, err := database.ListEpisodesForSeries(series.SeriesId)
	if err != nil && err != sql.ErrNoRows {
		log.Printf("Failed to fetch episodes for season: %v", err)
	}

	if eps != nil {
		for _, ep := range eps {
			ep.TvdbSeriesId = series.SeriesId
			err = database.SaveEpisode(ep)
			if err != nil {
				return err
			}

			queue.Add(&FetchMetadataTask{Episode: ep})
		}
	}

	return nil
}
Exemple #2
0
func SeriesEpisodeList(w http.ResponseWriter, r *http.Request) (interface{}, error) {
	idstr := getPathParam(r, "id")
	id, err := strconv.ParseInt(idstr, 10, 64)
	if err != nil {
		return nil, err
	}

	return database.ListEpisodesForSeries(id)
}