Exemple #1
0
    /// <inheritdoc />
    public Task ExecuteAsync(IProgress <double> progress, CancellationToken cancellationToken)
    {
        var query = new InternalItemsQuery
        {
            MediaTypes       = new[] { MediaType.Video },
            IsVirtualItem    = false,
            IncludeItemTypes = _itemTypes,
            DtoOptions       = new DtoOptions(true),
            SourceTypes      = new[] { SourceType.Library },
            Recursive        = true,
            Limit            = Pagesize
        };

        var numberOfVideos = _libraryManager.GetCount(query);

        var startIndex  = 0;
        var numComplete = 0;

        while (startIndex < numberOfVideos)
        {
            query.StartIndex = startIndex;

            var videos           = _libraryManager.GetItemList(query);
            var currentPageCount = videos.Count;
            // TODO parallelize with Parallel.ForEach?
            for (var i = 0; i < currentPageCount; i++)
            {
                var video = videos[i];
                // Only local files supported
                if (video.IsFileProtocol && File.Exists(video.Path))
                {
                    for (var j = 0; j < _keyframeExtractors.Length; j++)
                    {
                        var extractor = _keyframeExtractors[j];
                        // The cache decorator will make sure to save them in the data dir
                        if (extractor.TryExtractKeyframes(video.Path, out _))
                        {
                            break;
                        }
                    }
                }

                // Update progress
                numComplete++;
                double percent = (double)numComplete / numberOfVideos;
                progress.Report(100 * percent);
            }

            startIndex += Pagesize;
        }

        progress.Report(100);
        return(Task.CompletedTask);
    }
        protected int GetOwnedCount(Type type)
        {
            var query = new InternalItemsQuery(User)
            {
                IncludeItemTypes = new[] { type.Name },
                Limit            = 0,
                Recursive        = true,
                IsVirtualItem    = false
            };

            return(LibraryManager.GetCount(query));
        }
Exemple #3
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);
        }