private async Task StartServerCache(EmbyServers server, EmbySettings settings) { if (!ValidateSettings(server)) { return; } //await _repo.ExecuteSql("DELETE FROM EmbyEpisode"); //await _repo.ExecuteSql("DELETE FROM EmbyContent"); var movies = await _api.GetAllMovies(server.ApiKey, 0, 200, server.AdministratorId, server.FullUri); var totalCount = movies.TotalRecordCount; var processed = 1; var mediaToAdd = new HashSet <EmbyContent>(); while (processed < totalCount) { foreach (var movie in movies.Items) { if (movie.Type.Equals("boxset", StringComparison.InvariantCultureIgnoreCase)) { var movieInfo = await _api.GetCollection(movie.Id, server.ApiKey, server.AdministratorId, server.FullUri); foreach (var item in movieInfo.Items) { await ProcessMovies(item, mediaToAdd, server); } processed++; } else { processed++; // Regular movie await ProcessMovies(movie, mediaToAdd, server); } } // Get the next batch movies = await _api.GetAllMovies(server.ApiKey, processed, 200, server.AdministratorId, server.FullUri); await _repo.AddRange(mediaToAdd); mediaToAdd.Clear(); } // TV Time var tv = await _api.GetAllShows(server.ApiKey, 0, 200, server.AdministratorId, server.FullUri); var totalTv = tv.TotalRecordCount; processed = 1; while (processed < totalTv) { foreach (var tvShow in tv.Items) { try { processed++; if (string.IsNullOrEmpty(tvShow.ProviderIds?.Tvdb)) { _logger.LogInformation("Provider Id on tv {0} is null", tvShow.Name); continue; } var existingTv = await _repo.GetByEmbyId(tvShow.Id); if (existingTv == null) { _logger.LogDebug("Adding new TV Show {0}", tvShow.Name); mediaToAdd.Add(new EmbyContent { TvDbId = tvShow.ProviderIds?.Tvdb, ImdbId = tvShow.ProviderIds?.Imdb, TheMovieDbId = tvShow.ProviderIds?.Tmdb, Title = tvShow.Name, Type = EmbyMediaType.Series, EmbyId = tvShow.Id, Url = EmbyHelper.GetEmbyMediaUrl(tvShow.Id, server.ServerHostname, settings.IsJellyfin), AddedAt = DateTime.UtcNow }); } else { _logger.LogDebug("We already have TV Show {0}", tvShow.Name); } } catch (Exception) { throw; } } // Get the next batch tv = await _api.GetAllShows(server.ApiKey, processed, 200, server.AdministratorId, server.FullUri); await _repo.AddRange(mediaToAdd); mediaToAdd.Clear(); } if (mediaToAdd.Any()) { await _repo.AddRange(mediaToAdd); } }
private async Task StartServerCache(EmbyServers server) { if (!ValidateSettings(server)) { return; } await _repo.ExecuteSql("DELETE FROM EmbyEpisode"); await _repo.ExecuteSql("DELETE FROM EmbyContent"); var movies = await _api.GetAllMovies(server.ApiKey, server.AdministratorId, server.FullUri); var mediaToAdd = new HashSet <EmbyContent>(); foreach (var movie in movies.Items) { if (movie.Type.Equals("boxset", StringComparison.CurrentCultureIgnoreCase)) { var movieInfo = await _api.GetCollection(movie.Id, server.ApiKey, server.AdministratorId, server.FullUri); foreach (var item in movieInfo.Items) { var info = await _api.GetMovieInformation(item.Id, server.ApiKey, server.AdministratorId, server.FullUri); await ProcessMovies(info, mediaToAdd); } } else { // Regular movie var movieInfo = await _api.GetMovieInformation(movie.Id, server.ApiKey, server.AdministratorId, server.FullUri); await ProcessMovies(movieInfo, mediaToAdd); } } // TV Time var tv = await _api.GetAllShows(server.ApiKey, server.AdministratorId, server.FullUri); foreach (var tvShow in tv.Items) { var tvInfo = await _api.GetSeriesInformation(tvShow.Id, server.ApiKey, server.AdministratorId, server.FullUri); if (string.IsNullOrEmpty(tvInfo.ProviderIds?.Tvdb)) { Log.Error("Provider Id on tv {0} is null", tvShow.Name); continue; } var existingTv = await _repo.GetByEmbyId(tvShow.Id); if (existingTv == null) { mediaToAdd.Add(new EmbyContent { TvDbId = tvInfo.ProviderIds?.Tvdb, ImdbId = tvInfo.ProviderIds?.Imdb, TheMovieDbId = tvInfo.ProviderIds?.Tmdb, Title = tvInfo.Name, Type = EmbyMediaType.Series, EmbyId = tvShow.Id, Url = EmbyHelper.GetEmbyMediaUrl(tvShow.Id), AddedAt = DateTime.UtcNow }); } } if (mediaToAdd.Any()) { await _repo.AddRange(mediaToAdd); } }