Exemplo n.º 1
0
 public async Task AddRange(IEnumerable <T> content, bool save = true)
 {
     _db.AddRange(content);
     if (save)
     {
         await _ctx.SaveChangesAsync();
     }
 }
Exemplo n.º 2
0
        public async Task Start()
        {
            try
            {
                var settings = await _settings.GetSettingsAsync();

                if (!settings.Enabled)
                {
                    return;
                }
                var series = await _api.GetSeries(settings.ApiKey, settings.FullUri);

                if (series != null)
                {
                    var sonarrSeries = series as ImmutableHashSet <SonarrSeries> ?? series.ToImmutableHashSet();
                    var ids          = sonarrSeries.Select(x => x.tvdbId);

                    await _ctx.Database.ExecuteSqlCommandAsync("DELETE FROM SonarrCache");

                    var entites = ids.Select(id => new SonarrCache {
                        TvDbId = id
                    }).ToImmutableHashSet();

                    await _ctx.SonarrCache.AddRangeAsync(entites);

                    entites.Clear();

                    await _ctx.Database.ExecuteSqlCommandAsync("DELETE FROM SonarrEpisodeCache");

                    foreach (var s in sonarrSeries)
                    {
                        if (!s.monitored)
                        {
                            continue;
                        }
                        _log.LogDebug("Syncing series: {0}", s.title);
                        var episodes = await _api.GetEpisodes(s.id, settings.ApiKey, settings.FullUri);

                        var monitoredEpisodes = episodes.Where(x => x.monitored || x.hasFile);

                        // Add to DB
                        _log.LogDebug("We have the episodes, adding to db transaction");
                        await _ctx.SonarrEpisodeCache.AddRangeAsync(monitoredEpisodes.Select(episode => new SonarrEpisodeCache
                        {
                            EpisodeNumber = episode.episodeNumber,
                            SeasonNumber  = episode.seasonNumber,
                            TvDbId        = s.tvdbId,
                            HasFile       = episode.hasFile
                        }));

                        _log.LogDebug("Commiting the transaction");
                        await _ctx.SaveChangesAsync();
                    }
                }
            }
            catch (Exception e)
            {
                _log.LogError(LoggingEvents.SonarrCacher, e, "Exception when trying to cache Sonarr");
            }
        }
Exemplo n.º 3
0
        public async Task Start()
        {
            try
            {
                var settings = await _settings.GetSettingsAsync();

                if (!settings.Enabled)
                {
                    return;
                }

                var shows = await _api.GetShows(settings.ApiKey, settings.FullUri);

                if (shows != null)
                {
                    var srShows = shows.data.Values;
                    var ids     = srShows.Select(x => x.tvdbid);

                    await _ctx.Database.ExecuteSqlCommandAsync("DELETE FROM SickRageCache");

                    var entites = ids.Select(id => new SickRageCache {
                        TvDbId = id
                    }).ToList();

                    await _ctx.SickRageCache.AddRangeAsync(entites);

                    var episodesToAdd = new List <SickRageEpisodeCache>();
                    await _ctx.Database.ExecuteSqlCommandAsync("DELETE FROM SickRageEpisodeCache");

                    foreach (var s in srShows)
                    {
                        var seasons = await _api.GetSeasonList(s.tvdbid, settings.ApiKey, settings.FullUri);

                        foreach (var season in seasons.data)
                        {
                            var episodes =
                                await _api.GetEpisodesForSeason(s.tvdbid, season, settings.ApiKey, settings.FullUri);

                            var monitoredEpisodes = episodes.data.Where(x => x.Value.status.Equals(SickRageStatus.Wanted));

                            episodesToAdd.AddRange(monitoredEpisodes.Select(episode => new SickRageEpisodeCache
                            {
                                EpisodeNumber = episode.Key,
                                SeasonNumber  = season,
                                TvDbId        = s.tvdbid
                            }));
                        }
                    }

                    await _ctx.SickRageEpisodeCache.AddRangeAsync(episodesToAdd);

                    await _ctx.SaveChangesAsync();
                }
            }
            catch (Exception e)
            {
                _log.LogError(LoggingEvents.SickRageCacher, e, "Exception when trying to cache SickRage");
            }
        }
Exemplo n.º 4
0
        public async Task CacheContent()
        {
            await SemaphoreSlim.WaitAsync();

            try
            {
                var settings = await RadarrSettings.GetSettingsAsync();

                if (settings.Enabled)
                {
                    try
                    {
                        var movies = await RadarrApi.GetMovies(settings.ApiKey, settings.FullUri);

                        if (movies != null)
                        {
                            // Let's remove the old cached data
                            await _ctx.Database.ExecuteSqlCommandAsync("DELETE FROM RadarrCache");

                            var movieIds = new List <RadarrCache>();
                            foreach (var m in movies)
                            {
                                if (m.tmdbId > 0)
                                {
                                    movieIds.Add(new RadarrCache
                                    {
                                        TheMovieDbId = m.tmdbId,
                                        HasFile      = m.hasFile
                                    });
                                }
                                else
                                {
                                    Logger.LogError("TMDBId is not > 0 for movie {0}", m.title);
                                }
                            }
                            await _ctx.RadarrCache.AddRangeAsync(movieIds);

                            await _ctx.SaveChangesAsync();
                        }
                    }
                    catch (System.Exception ex)
                    {
                        Logger.LogError(LoggingEvents.Cacher, ex, "Failed caching queued items from Radarr");
                    }
                }
            }
            catch (Exception)
            {
                Logger.LogInformation(LoggingEvents.RadarrCacher, "Radarr is not setup, cannot cache episodes");
            }
            finally
            {
                SemaphoreSlim.Release();
            }
        }
Exemplo n.º 5
0
        public async Task Start()
        {
            var settings = await _settings.GetSettingsAsync();

            if (!settings.Enabled)
            {
                return;
            }

            try
            {
                _log.LogInformation(LoggingEvents.CouchPotatoCacher, "Getting all active movies from CP");
                var movies = await _api.GetMovies(settings.FullUri, settings.ApiKey, new[] { "active" });

                if (movies != null)
                {
                    // Let's remove the old cached data
                    await _ctx.Database.ExecuteSqlCommandAsync("DELETE FROM CouchPotatoCache");

                    // Save
                    var movieIds = new List <CouchPotatoCache>();
                    foreach (var m in movies.movies)
                    {
                        if (m.info == null)
                        {
                            _log.LogInformation("Movie {0} does nto have a tmdbid", m.title);
                            continue;
                        }
                        if (m.info.tmdb_id > 0)
                        {
                            movieIds.Add(new CouchPotatoCache {
                                TheMovieDbId = m.info.tmdb_id
                            });
                        }
                        else
                        {
                            _log.LogError("TMDBId is not > 0 for movie {0}", m.title);
                        }
                    }
                    await _ctx.CouchPotatoCache.AddRangeAsync(movieIds);

                    await _ctx.SaveChangesAsync();
                }
            }
            catch (Exception e)
            {
                _log.LogError(LoggingEvents.CouchPotatoCacher, e, "error when trying to get movies from CP");
                throw;
            }
        }
Exemplo n.º 6
0
 public async Task AddRange(IEnumerable <T> content)
 {
     _db.AddRange(content);
     await _ctx.SaveChangesAsync();
 }