private async Task StartEmbyMovies(EmbySettings settings) { var allMovies = _embyRepo.GetAll().Where(x => x.Type == EmbyMediaType.Movie && (!x.TheMovieDbId.HasValue() || !x.ImdbId.HasValue())); foreach (var movie in allMovies) { movie.ImdbId.HasValue(); movie.TheMovieDbId.HasValue(); // Movies don't really use TheTvDb // Check if it even has 1 ID if (!movie.HasImdb && !movie.HasTheMovieDb) { // Ok this sucks, // The only think I can think that has happened is that we scanned Emby before Emby has got the metadata // So let's recheck emby to see if they have got the metadata now // // Yeah your right that does suck - Future Jamie _log.LogInformation($"Movie {movie.Title} does not have a ImdbId or TheMovieDbId, so rechecking emby"); foreach (var server in settings.Servers) { _log.LogInformation($"Checking server {server.Name} for upto date metadata"); var movieInfo = await _embyApi.GetMovieInformation(movie.EmbyId, server.ApiKey, server.AdministratorId, server.FullUri); if (movieInfo.ProviderIds?.Imdb.HasValue() ?? false) { movie.ImdbId = movieInfo.ProviderIds.Imdb; } if (movieInfo.ProviderIds?.Tmdb.HasValue() ?? false) { movie.TheMovieDbId = movieInfo.ProviderIds.Tmdb; } } } if (!movie.HasImdb) { var imdbId = await GetImdbId(movie.HasTheMovieDb, false, movie.Title, movie.TheMovieDbId, string.Empty); movie.ImdbId = imdbId; _embyRepo.UpdateWithoutSave(movie); } if (!movie.HasTheMovieDb) { var id = await GetTheMovieDbId(false, movie.HasImdb, string.Empty, movie.ImdbId, movie.Title, true); movie.TheMovieDbId = id; _embyRepo.UpdateWithoutSave(movie); } await _embyRepo.SaveChangesAsync(); } }
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); } }