示例#1
0
        public async Task <ActionResult <Page <Season> > > GetSeasons(Identifier identifier,
                                                                      [FromQuery] string sortBy,
                                                                      [FromQuery] Dictionary <string, string> where,
                                                                      [FromQuery] int limit   = 20,
                                                                      [FromQuery] int?afterID = null)
        {
            try
            {
                ICollection <Season> resources = await _libraryManager.GetAll(
                    ApiHelper.ParseWhere(where, identifier.Matcher <Season>(x => x.ShowID, x => x.Show.Slug)),
                    new Sort <Season>(sortBy),
                    new Pagination(limit, afterID)
                    );

                if (!resources.Any() && await _libraryManager.GetOrDefault(identifier.IsSame <Show>()) == null)
                {
                    return(NotFound());
                }
                return(Page(resources, limit));
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(new RequestError(ex.Message)));
            }
        }
示例#2
0
        /// <summary>
        /// Retrieve the relative path of an episode or subtitle.
        /// </summary>
        /// <param name="path">The full path of the episode</param>
        /// <returns>The path relative to the library root.</returns>
        private async Task <string> _GetRelativePath(string path)
        {
            string libraryPath = (await _libraryManager.GetAll <Library>())
                                 .SelectMany(x => x.Paths)
                                 .Where(path.StartsWith)
                                 .OrderByDescending(x => x.Length)
                                 .FirstOrDefault();

            return(path[(libraryPath?.Length ?? 0)..]);
示例#3
0
        /// <inheritdoc />
        public async Task Run(TaskParameters arguments, IProgress <float> progress, CancellationToken cancellationToken)
        {
            string argument = arguments["slug"].As <string>();
            ICollection <Library> libraries = argument == null
                                ? await _libraryManager.GetAll <Library>()
                                : new[] { await _libraryManager.GetOrDefault <Library>(argument) };

            if (argument != null && libraries.First() == null)
            {
                throw new ArgumentException($"No library found with the name {argument}");
            }

            foreach (Library library in libraries)
            {
                await _libraryManager.Load(library, x => x.Providers);
            }

            progress.Report(0);
            float percent = 0;

            ICollection <Episode> episodes = await _libraryManager.GetAll <Episode>();

            ICollection <Track> tracks = await _libraryManager.GetAll <Track>();

            foreach (Library library in libraries)
            {
                IProgress <float> reporter = new Progress <float>(x =>
                {
                    // ReSharper disable once AccessToModifiedClosure
                    progress.Report(percent + (x / libraries.Count));
                });
                await _Scan(library, episodes, tracks, reporter, cancellationToken);

                percent += 100f / libraries.Count;

                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }
            }

            progress.Report(100);
        }
示例#4
0
        /// <inheritdoc />
        public async Task Run(TaskParameters arguments, IProgress <float> progress, CancellationToken cancellationToken)
        {
            int count    = 0;
            int delCount = await _libraryManager.GetCount <Show>() + await _libraryManager.GetCount <Episode>();

            progress.Report(0);

            foreach (Show show in await _libraryManager.GetAll <Show>())
            {
                progress.Report(count / delCount * 100);
                count++;

                if (await _fileSystem.Exists(show.Path))
                {
                    continue;
                }
                _logger.LogWarning("Show {Name}'s folder has been deleted (was {Path}), removing it from kyoo",
                                   show.Title, show.Path);
                await _libraryManager.Delete(show);
            }

            foreach (Episode episode in await _libraryManager.GetAll <Episode>())
            {
                progress.Report(count / delCount * 100);
                count++;

                if (await _fileSystem.Exists(episode.Path))
                {
                    continue;
                }
                _logger.LogWarning("Episode {Slug}'s file has been deleted (was {Path}), removing it from kyoo",
                                   episode.Slug, episode.Path);
                await _libraryManager.Delete(episode);
            }

            progress.Report(100);
        }