Example #1
0
        private async Task ProcessMovies(EmbyMovie movieInfo, ICollection <EmbyContent> content, EmbyServers server)
        {
            // Check if it exists
            var existingMovie = await _repo.GetByEmbyId(movieInfo.Id);

            var alreadyGoingToAdd = content.Any(x => x.EmbyId == movieInfo.Id);

            if (existingMovie == null && !alreadyGoingToAdd)
            {
                _logger.LogDebug("Adding new movie {0}", movieInfo.Name);
                content.Add(new EmbyContent
                {
                    ImdbId       = movieInfo.ProviderIds.Imdb,
                    TheMovieDbId = movieInfo.ProviderIds?.Tmdb,
                    Title        = movieInfo.Name,
                    Type         = EmbyMediaType.Movie,
                    EmbyId       = movieInfo.Id,
                    Url          = EmbyHelper.GetEmbyMediaUrl(movieInfo.Id, server?.ServerId, server.ServerHostname),
                    AddedAt      = DateTime.UtcNow,
                });
            }
            else
            {
                // we have this
                _logger.LogDebug("We already have movie {0}", movieInfo.Name);
            }
        }
Example #2
0
        private async Task ProcessMovies(EmbyMovie movieInfo, ICollection <EmbyContent> content, ICollection <EmbyContent> toUpdate, EmbyServers server)
        {
            var quality = movieInfo.MediaStreams?.FirstOrDefault()?.DisplayTitle ?? string.Empty;
            var has4K   = false;

            if (quality.Contains("4K", CompareOptions.IgnoreCase))
            {
                has4K = true;
            }

            // Check if it exists
            var existingMovie = await _repo.GetByEmbyId(movieInfo.Id);

            var alreadyGoingToAdd = content.Any(x => x.EmbyId == movieInfo.Id);

            if (existingMovie == null && !alreadyGoingToAdd)
            {
                if (!movieInfo.ProviderIds.Any())
                {
                    _logger.LogWarning($"Movie {movieInfo.Name} has no relevant metadata. Skipping.");
                    return;
                }
                _logger.LogDebug($"Adding new movie {movieInfo.Name}");

                content.Add(new EmbyContent
                {
                    ImdbId       = movieInfo.ProviderIds.Imdb,
                    TheMovieDbId = movieInfo.ProviderIds?.Tmdb,
                    Title        = movieInfo.Name,
                    Type         = MediaType.Movie,
                    EmbyId       = movieInfo.Id,
                    Url          = EmbyHelper.GetEmbyMediaUrl(movieInfo.Id, server?.ServerId, server.ServerHostname),
                    AddedAt      = DateTime.UtcNow,
                    Quality      = has4K ? null : quality,
                    Has4K        = has4K
                });
            }
            else
            {
                if (!quality.Equals(existingMovie?.Quality, StringComparison.InvariantCultureIgnoreCase))
                {
                    _logger.LogDebug($"We have found another quality for Movie '{movieInfo.Name}', Quality: '{quality}'");
                    existingMovie.Quality = has4K ? null : quality;
                    existingMovie.Has4K   = has4K;

                    // Probably could refactor here
                    // If a 4k movie comes in (we don't store the quality on 4k)
                    // it will always get updated even know it's not changed
                    toUpdate.Add(existingMovie);
                }
                else
                {
                    // we have this
                    _logger.LogDebug($"We already have movie {movieInfo.Name}");
                }
            }
        }
Example #3
0
        private async Task ProcessMovies(MovieInformation movieInfo, ICollection <EmbyContent> content)
        {
            // Check if it exists
            var existingMovie = await _repo.GetByEmbyId(movieInfo.Id);

            if (existingMovie == null)
            {
                content.Add(new EmbyContent
                {
                    ImdbId       = movieInfo.ProviderIds.Imdb,
                    TheMovieDbId = movieInfo.ProviderIds?.Tmdb,
                    Title        = movieInfo.Name,
                    Type         = EmbyMediaType.Movie,
                    EmbyId       = movieInfo.Id,
                    Url          = EmbyHelper.GetEmbyMediaUrl(movieInfo.Id),
                    AddedAt      = DateTime.UtcNow,
                });
            }
        }
Example #4
0
        private async Task ProcessTv(EmbyServers server, string parentId = default)
        {
            // TV Time
            var mediaToAdd = new HashSet <EmbyContent>();
            var tv         = await Api.GetAllShows(server.ApiKey, parentId, 0, 200, server.AdministratorId, server.FullUri);

            var totalTv   = tv.TotalRecordCount;
            var 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?.ServerId, server.ServerHostname),
                                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, parentId, processed, 200, server.AdministratorId, server.FullUri);

                await _repo.AddRange(mediaToAdd);

                mediaToAdd.Clear();
            }

            if (mediaToAdd.Any())
            {
                await _repo.AddRange(mediaToAdd);
            }
        }
Example #5
0
        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);
            }
        }
Example #6
0
        public async Task <RuleResult> Execute(SearchViewModel obj)
        {
            EmbyContent item          = null;
            var         useImdb       = false;
            var         useTheMovieDb = false;
            var         useTvDb       = false;

            if (obj.ImdbId.HasValue())
            {
                item = await EmbyContentRepository.GetByImdbId(obj.ImdbId);

                if (item != null)
                {
                    useImdb = true;
                }
            }
            if (item == null)
            {
                if (obj.TheMovieDbId.HasValue())
                {
                    item = await EmbyContentRepository.GetByTheMovieDbId(obj.TheMovieDbId);

                    if (item != null)
                    {
                        useTheMovieDb = true;
                    }
                }

                if (item == null)
                {
                    if (obj.TheTvDbId.HasValue())
                    {
                        item = await EmbyContentRepository.GetByTvDbId(obj.TheTvDbId);

                        if (item != null)
                        {
                            useTvDb = true;
                        }
                    }
                }
            }

            if (item != null)
            {
                obj.Available = true;
                var s = await EmbySettings.GetSettingsAsync();

                var server = s.Servers.FirstOrDefault(x => x.ServerHostname != null);
                if ((server?.ServerHostname ?? string.Empty).HasValue())
                {
                    obj.EmbyUrl = EmbyHelper.GetEmbyMediaUrl(item.EmbyId, server?.ServerHostname, s.IsJellyfin);
                }
                else
                {
                    obj.EmbyUrl = EmbyHelper.GetEmbyMediaUrl(item.EmbyId, null, s.IsJellyfin);
                }

                if (obj.Type == RequestType.TvShow)
                {
                    var search = (SearchTvShowViewModel)obj;
                    // Let's go through the episodes now
                    if (search.SeasonRequests.Any())
                    {
                        var allEpisodes = EmbyContentRepository.GetAllEpisodes().Include(x => x.Series);
                        foreach (var season in search.SeasonRequests)
                        {
                            foreach (var episode in season.Episodes)
                            {
                                await AvailabilityRuleHelper.SingleEpisodeCheck(useImdb, allEpisodes, episode, season, item, useTheMovieDb, useTvDb);
                            }
                        }
                    }

                    AvailabilityRuleHelper.CheckForUnairedEpisodes(search);
                }
            }
            return(Success());
        }
Example #7
0
        private async Task ProcessTv(EmbyServers server, bool recentlyAdded, string parentId = default)
        {
            // TV Time
            var mediaToAdd = new HashSet <EmbyContent>();
            EmbyItemContainer <EmbySeries> tv;

            if (recentlyAdded)
            {
                var recentlyAddedAmountToTake = AmountToTake / 2;
                tv = await Api.RecentlyAddedShows(server.ApiKey, parentId, 0, recentlyAddedAmountToTake, server.AdministratorId, server.FullUri);

                if (tv.TotalRecordCount > recentlyAddedAmountToTake)
                {
                    tv.TotalRecordCount = recentlyAddedAmountToTake;
                }
            }
            else
            {
                tv = await Api.GetAllShows(server.ApiKey, parentId, 0, AmountToTake, server.AdministratorId, server.FullUri);
            }
            var totalTv   = tv.TotalRecordCount;
            var processed = 0;

            while (processed < totalTv)
            {
                foreach (var tvShow in tv.Items)
                {
                    processed++;
                    if (!tvShow.ProviderIds.Any())
                    {
                        _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         = MediaType.Series,
                            EmbyId       = tvShow.Id,
                            Url          = EmbyHelper.GetEmbyMediaUrl(tvShow.Id, server?.ServerId, server.ServerHostname),
                            AddedAt      = DateTime.UtcNow,
                        });
                    }
                    else
                    {
                        _logger.LogDebug("We already have TV Show {0}", tvShow.Name);
                    }
                }
                // Get the next batch
                if (!recentlyAdded)
                {
                    tv = await Api.GetAllShows(server.ApiKey, parentId, processed, AmountToTake, server.AdministratorId, server.FullUri);
                }
                await _repo.AddRange(mediaToAdd);

                mediaToAdd.Clear();
            }

            if (mediaToAdd.Any())
            {
                await _repo.AddRange(mediaToAdd);
            }
        }
Example #8
0
 public string TestUrl(string mediaId, string url, string serverId)
 {
     // http://192.168.68.X:8096/web/index.html#!/item?id=17980&serverId=4e7a85e6ed0b49b9a6d6d15e739a566b
     return(EmbyHelper.GetEmbyMediaUrl(mediaId, serverId, url));
 }
Example #9
0
 public string TestJellyfinUrl(string mediaId, string url)
 {
     return(EmbyHelper.GetEmbyMediaUrl(mediaId, url, true));
 }
Example #10
0
 public string TestUrl(string mediaId, string url)
 {
     return(EmbyHelper.GetEmbyMediaUrl(mediaId, url));
 }
Example #11
0
        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);
            }
        }