Example #1
0
 private Series Adapt(TheTvDbSeries theTvDbSeries, TheTvDbSeriesImageResults theTvDbSeriesImages)
 {
     Adapt(theTvDbSeries, out Series series);
     Adapt(theTvDbSeries, theTvDbSeriesImages, out SeriesImageUrls seriesMetadata);
     series.ImageUrls = seriesMetadata;
     return(series);
 }
Example #2
0
        public async Task <List <Series> > GetSeriesListAsync(int startId, int endId, HashSet <Genre> gl, HashSet <Network> nl)
        {
            List <Series> l  = new List <Series>();
            int           id = startId;

            try {
                for (; id <= endId; id++)
                {
                    using (HttpResponseMessage resp = TvDbClient.GetAsync("/series/" + id).Result) {
                        if (!resp.IsSuccessStatusCode)
                        {
                            Debug.WriteLine("No pude recuperar serie nº" + id + ". Boomer :(");
                            continue;
                        }

                        string jsonString = await resp.Content.ReadAsStringAsync();

                        TheTvDbSeries TvDbS = JsonConvert.DeserializeObject <TheTvDbSeries>(jsonString);
                        Series        s     = TvDbS.ToSeries(gl, nl);

                        if (String.IsNullOrWhiteSpace(s.seriesName))
                        {
                            continue;
                        }

                        s.actorList = await GetActorRolesBySeriesIdAsync(id);

                        foreach (ActorRole ar in s.actorList)
                        {
                            ar.series = s;
                        }

                        IMDbSeries IMDbS = await GetIMDbSeriesAsync(s.imbdId);

                        if (IMDbS != null)
                        {
                            s.posterUrl = IMDbS.Poster;
                        }

                        s.seasonList = await GetSeasonListSeriesIdAsync(id);

                        foreach (Season se in s.seasonList)
                        {
                            se.series = s;
                        }

                        l.Add(s);
                    }
                }
            } catch (Exception e) {
                MessageBox.Show(e.Message, "Excepción procesando la serie nº" + id + ".");
            }

            return(l);
        }
Example #3
0
 private void Adapt(TheTvDbSeries input, out Series output)
 {
     output = new Series
     {
         Name        = input.SeriesName,
         Id          = input.Id.ToString(),
         ImdbId      = input.ImdbId,
         ReleaseDate = input.AirDate,
         Genres      = input.Genre,
         Networks    = new [] { input.Network },
         Status      = input.Status,
         Description = input?.Overview,
         Year        = input?.AirDate?.Year,
         // TODO: FIX ImageUrls = {PosterImageUrls = input.ImageUrls.PosterImageUrls}
     };
 }
Example #4
0
        private void Adapt(TheTvDbSeries theTvDbSeries, TheTvDbSeriesImageResults images, out SeriesImageUrls output)
        {
            output = new SeriesImageUrls();
            if (images == null)
            {
                return;
            }

            output.PosterImageUrls = images.Poster?.Data?.Take(MaxImageResults)
                                     .Select(x => _configurationValues.ArtworkBaseUrl + "/" + x.FileName)
                                     .ToArray();
            output.BackgroundImageUrls = images.FanArt?.Data?.Take(MaxImageResults)
                                         .Select(x => _configurationValues.ArtworkBaseUrl + "/" + x.FileName)
                                         .ToArray();
            output.BannerImageUrls =
                ((!string.IsNullOrWhiteSpace(theTvDbSeries.Banner) ? new [] { theTvDbSeries.Banner } : new string[0])
                 .Concat(images.Series?.Data?.Select(x => x.FileName) ?? new string[0]))
                .Distinct(StringComparer.OrdinalIgnoreCase)
                .Take(MaxImageResults)
                .Select(x => _configurationValues.ArtworkBaseUrl + "/" + x)
                .ToArray();
        }
        public void UpdateSeries(uint seriesId, TheTvDbSeries series)
        {
            if (series == null)
            {
                if (_series.Any(p => p.SeriesId == seriesId))
                {
                    // Remove the series from the cache
                    _series.Remove(_series.First(p => p.SeriesId == seriesId));
                }
                else
                {
                    throw new TheTvDbCacheUpdateException("Series ID to remove was not found in the cache.");
                }
            }
            else
            {
                if (seriesId == series.SeriesId)
                {
                    if (_series.Any(p => p.SeriesId == seriesId))
                    {
                        // the series is already in the cache, so edit the existing entry
                        _series.First(p => p.SeriesId == seriesId).UpdateFrom(series);
                    }
                    else
                    {
                        // the series is not in the cache, add it
                        _series.Add(series);
                    }
                }
                else
                {
                    throw new TheTvDbCacheUpdateException("Series IDs do not match");
                }
            }

            IsSaved = false;
        }
        /// <summary>
        /// Parse series metadata as xml element and returns null if xml is not valid (series has no id) 
        /// </summary>
        /// <param name="seriesXml">Series metadata as xml element</param>
        /// <param name="isSearchElement"></param>
        /// <returns>Returns the successfully parsed series</returns>
        public TheTvDbSeries Parse(XElement seriesXml, bool isSearchElement = false)
        {
            if (seriesXml == null) throw new ArgumentNullException(nameof(seriesXml));

            // If series has no id throw ParseException
            var id = seriesXml.ElementAsUInt("id");
            if (!id.HasValue) throw new TheTvDbParseException("Error while parsing a series xml element. Id is missing.");

            var series = new TheTvDbSeries(id.Value)
            {
                ImdbId = seriesXml.ElementAsString("IMDB_ID"),
                SeriesName = seriesXml.ElementAsString("SeriesName", true),
                Language = seriesXml.ElementAsString(isSearchElement ? "language" : "Language").ToTheTvDbLanguage(),
                Network = seriesXml.ElementAsString("Network"),
                Description = seriesXml.ElementAsString("Overview", true),
                Rating = seriesXml.ElementAsDouble("Rating"),
                RatingCount = seriesXml.ElementAsInt("RatingCount"),
                Runtime = seriesXml.ElementAsInt("Runtime"),
                BannerRemotePath = seriesXml.ElementAsString("banner"),
                FanartRemotePath = seriesXml.ElementAsString("fanart"),
                LastUpdated = seriesXml.ElementFromEpochToDateTime("lastupdated"),
                PosterRemotePath = seriesXml.ElementAsString("poster"),
                Zap2ItId = seriesXml.ElementAsString("zap2it_id"),
                FirstAired = seriesXml.ElementAsDateTime("FirstAired"),
                AirTime = seriesXml.ElementAsTimeSpan("Airs_Time"),
                AirDay = seriesXml.ElementAsEnum<TheTvDbFrequency>("Airs_DayOfWeek"),
                Status = seriesXml.ElementAsEnum<TheTvDbStatus>("Status"),
                ContentRating = seriesXml.ElementAsString("ContentRating").ToTheTvDbContentRating(),
                Genres = seriesXml.ElementAsString("Genre").SplitByPipe()
            };

            if (series.FirstAired.HasValue)
            {
                series.SeriesName = series.SeriesName.Replace(string.Format(" ({0})", series.FirstAired.Value.Year), "");
            }

            return series;
        }