コード例 #1
0
ファイル: TvShowService.cs プロジェクト: saltz/Din
 public TvShowService(DinContext context, ITvShowClient tvShowClient, ITMDBClientConfig config, IMapper mapper) : base(context, mapper)
 {
     _tvShowClient = tvShowClient;
     _tmdbKey      = config.Key;
 }
コード例 #2
0
        private async Task UpdateStatusTvShowObjects(DinContext context, ITvShowClient tvShowClient)
        {
            try
            {
                var content = await context.AddedContent
                              .Where(c => c.Type.Equals(ContentType.TvShow) && !c.Status.Equals(ContentStatus.Done))
                              .ToListAsync();

                var now = DateTime.Now;

                _logger.LogInformation($"Updating: {content.Count} tvshows");

                foreach (var c in content)
                {
                    var show = await tvShowClient.GetTvShowByIdAsync(c.SystemId);

                    var pilotSeason = show.Seasons.FirstOrDefault(s => s.SeasonsNumber.Equals(0));

                    if (pilotSeason != null)
                    {
                        show.Seasons.Remove(pilotSeason);
                    }

                    var seasonsDone      = 0;
                    var seasonPercentage = new List <double>();

                    foreach (var s in show.Seasons)
                    {
                        if (s.Statistics.EpisodeCount.Equals(s.Statistics.TotalEpisodeCount))
                        {
                            seasonsDone++;
                            continue;
                        }

                        seasonPercentage.Add(Convert.ToDouble(s.Statistics.EpisodeCount) /
                                             (Convert.ToDouble(s.Statistics.TotalEpisodeCount) / 100));
                    }

                    if (seasonsDone.Equals(show.Seasons.Count))
                    {
                        c.Status = ContentStatus.Done;
                        continue;
                    }

                    var showPercentage = Math.Round((seasonPercentage.Sum() / seasonPercentage.Count) / 100, 2);

                    if (showPercentage > 0.0)
                    {
                        c.Status     = ContentStatus.Downloading;
                        c.Percentage = showPercentage;
                    }

                    if (now >= c.DateAdded.AddDays(2) && showPercentage > 0.0)
                    {
                        c.Status     = ContentStatus.Stuck;
                        c.Percentage = showPercentage;
                        continue;
                    }

                    if (now >= c.DateAdded.AddDays(5))
                    {
                        c.Status = ContentStatus.NotAvailable;
                    }
                }
            }
            catch (Exception e)
            {
                _logger.LogInformation($"Updating tvshows encounterd error: {e.Message}");
            }
        }