示例#1
0
        private async Task ProcessMovies(JellyfinMovie movieInfo, ICollection <JellyfinContent> content, JellyfinServers server)
        {
            // Check if it exists
            var existingMovie = await _repo.GetByJellyfinId(movieInfo.Id);

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

            if (existingMovie == null && !alreadyGoingToAdd)
            {
                _logger.LogDebug("Adding new movie {0}", movieInfo.Name);
                content.Add(new JellyfinContent
                {
                    ImdbId       = movieInfo.ProviderIds.Imdb,
                    TheMovieDbId = movieInfo.ProviderIds?.Tmdb,
                    Title        = movieInfo.Name,
                    Type         = JellyfinMediaType.Movie,
                    JellyfinId   = movieInfo.Id,
                    Url          = JellyfinHelper.GetJellyfinMediaUrl(movieInfo.Id, server?.ServerId, server.ServerHostname),
                    AddedAt      = DateTime.UtcNow,
                });
            }
            else
            {
                // we have this
                _logger.LogDebug("We already have movie {0}", movieInfo.Name);
            }
        }
示例#2
0
        private async Task ProcessMovies(JellyfinMovie movieInfo, ICollection <JellyfinContent> content, ICollection <JellyfinContent> toUpdate, JellyfinServers 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.GetByJellyfinId(movieInfo.Id);

            var alreadyGoingToAdd = content.Any(x => x.JellyfinId == 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 JellyfinContent
                {
                    ImdbId       = movieInfo.ProviderIds.Imdb,
                    TheMovieDbId = movieInfo.ProviderIds?.Tmdb,
                    Title        = movieInfo.Name,
                    Type         = MediaType.Movie,
                    JellyfinId   = movieInfo.Id,
                    Url          = JellyfinHelper.GetJellyfinMediaUrl(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}");
                }
            }
        }
示例#3
0
        private async Task ProcessTv(JellyfinServers server, string parentId = default)
        {
            // TV Time
            var mediaToAdd = new HashSet <JellyfinContent>();
            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.GetByJellyfinId(tvShow.Id);

                        if (existingTv == null)
                        {
                            _logger.LogDebug("Adding new TV Show {0}", tvShow.Name);
                            mediaToAdd.Add(new JellyfinContent
                            {
                                TvDbId       = tvShow.ProviderIds?.Tvdb,
                                ImdbId       = tvShow.ProviderIds?.Imdb,
                                TheMovieDbId = tvShow.ProviderIds?.Tmdb,
                                Title        = tvShow.Name,
                                Type         = JellyfinMediaType.Series,
                                JellyfinId   = tvShow.Id,
                                Url          = JellyfinHelper.GetJellyfinMediaUrl(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);
            }
        }
示例#4
0
        public async Task <RuleResult> Execute(SearchViewModel obj)
        {
            JellyfinContent item          = null;
            var             useImdb       = false;
            var             useTheMovieDb = false;
            var             useTvDb       = false;
            var             useId         = false;

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

                if (item != null)
                {
                    useImdb = true;
                }
            }
            if (item == null)
            {
                if (obj.Id > 0)
                {
                    item = await JellyfinContentRepository.GetByTheMovieDbId(obj.Id.ToString());

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

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

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

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

            if (item != null)
            {
                if (useId)
                {
                    obj.TheMovieDbId = obj.Id.ToString();
                    useTheMovieDb    = true;
                }
                obj.Available = true;
                var s = await JellyfinSettings.GetSettingsAsync();

                if (s.Enable)
                {
                    var server = s.Servers.FirstOrDefault(x => x.ServerHostname != null);
                    if ((server?.ServerHostname ?? string.Empty).HasValue())
                    {
                        obj.JellyfinUrl = JellyfinHelper.GetJellyfinMediaUrl(item.JellyfinId, server?.ServerId, server?.ServerHostname);
                    }
                    else
                    {
                        var firstServer = s.Servers?.FirstOrDefault();
                        obj.JellyfinUrl = JellyfinHelper.GetJellyfinMediaUrl(item.JellyfinId, firstServer.ServerId, firstServer.FullUri);
                    }
                }

                if (obj.Type == RequestType.TvShow)
                {
                    var search = (SearchTvShowViewModel)obj;
                    // Let's go through the episodes now
                    if (search.SeasonRequests.Any())
                    {
                        var allEpisodes = JellyfinContentRepository.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());
        }
示例#5
0
        private async Task StartServerCache(JellyfinServers server, JellyfinSettings settings)
        {
            if (!ValidateSettings(server))
            {
                return;
            }

            //await _repo.ExecuteSql("DELETE FROM JellyfinEpisode");
            //await _repo.ExecuteSql("DELETE FROM JellyfinContent");

            var movies = await Api.GetAllMovies(server.ApiKey, 0, 200, server.AdministratorId, server.FullUri);

            var totalCount = movies.TotalRecordCount;
            var processed  = 1;

            var mediaToAdd = new HashSet <JellyfinContent>();

            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.GetByJellyfinId(tvShow.Id);

                        if (existingTv == null)
                        {
                            _logger.LogDebug("Adding new TV Show {0}", tvShow.Name);
                            mediaToAdd.Add(new JellyfinContent
                            {
                                TvDbId       = tvShow.ProviderIds?.Tvdb,
                                ImdbId       = tvShow.ProviderIds?.Imdb,
                                TheMovieDbId = tvShow.ProviderIds?.Tmdb,
                                Title        = tvShow.Name,
                                Type         = JellyfinMediaType.Series,
                                JellyfinId   = tvShow.Id,
                                Url          = JellyfinHelper.GetJellyfinMediaUrl(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, processed, 200, server.AdministratorId, server.FullUri);

                await _repo.AddRange(mediaToAdd);

                mediaToAdd.Clear();
            }

            if (mediaToAdd.Any())
            {
                await _repo.AddRange(mediaToAdd);
            }
        }
示例#6
0
 public string TestUrl(string mediaId, string url, string serverId)
 {
     // http://192.168.68.X:8097/web/index.html#!/details?id=7ffe222498445d5ebfddb31bc4fa9a6d&serverId=50cce67f0baa425093d189b3017331fb
     return(JellyfinHelper.GetJellyfinMediaUrl(mediaId, serverId, url));
 }