示例#1
0
        /// <summary>
        /// Adds the external subtitles.
        /// </summary>
        /// <param name="video">The video.</param>
        /// <param name="currentStreams">The current streams.</param>
        /// <param name="options">The options.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Task.</returns>
        private async Task AddExternalSubtitles(Video video,
                                                List <MediaStream> currentStreams,
                                                MetadataRefreshOptions options,
                                                CancellationToken cancellationToken)
        {
            var subtitleResolver = new SubtitleResolver(_localization, _fileSystem);

            var startIndex = currentStreams.Count == 0 ? 0 : (currentStreams.Select(i => i.Index).Max() + 1);
            var externalSubtitleStreams = subtitleResolver.GetExternalSubtitleStreams(video, startIndex, options.DirectoryService, false).ToList();

            var enableSubtitleDownloading = options.MetadataRefreshMode == MetadataRefreshMode.Default ||
                                            options.MetadataRefreshMode == MetadataRefreshMode.FullRefresh;

            var subtitleOptions = GetOptions();

            if (enableSubtitleDownloading && (subtitleOptions.DownloadEpisodeSubtitles &&
                                              video is Episode) ||
                (subtitleOptions.DownloadMovieSubtitles &&
                 video is Movie))
            {
                var downloadedLanguages = await new SubtitleDownloader(_logger,
                                                                       _subtitleManager)
                                          .DownloadSubtitles(video,
                                                             currentStreams.Concat(externalSubtitleStreams).ToList(),
                                                             subtitleOptions.SkipIfEmbeddedSubtitlesPresent,
                                                             subtitleOptions.SkipIfAudioTrackMatches,
                                                             subtitleOptions.RequirePerfectMatch,
                                                             subtitleOptions.DownloadLanguages,
                                                             cancellationToken).ConfigureAwait(false);

                // Rescan
                if (downloadedLanguages.Count > 0)
                {
                    externalSubtitleStreams = subtitleResolver.GetExternalSubtitleStreams(video, startIndex, options.DirectoryService, true).ToList();
                }
            }

            video.SubtitleFiles = externalSubtitleStreams.Select(i => i.Path).OrderBy(i => i).ToList();

            currentStreams.AddRange(externalSubtitleStreams);
        }
示例#2
0
        /// <summary>
        /// Adds the external subtitles.
        /// </summary>
        /// <param name="video">The video.</param>
        /// <param name="currentStreams">The current streams.</param>
        /// <param name="options">The options.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Task.</returns>
        private async Task AddExternalSubtitles(Video video,
                                                List <MediaStream> currentStreams,
                                                MetadataRefreshOptions options,
                                                CancellationToken cancellationToken)
        {
            var subtitleResolver = new SubtitleResolver(_localization);

            var externalSubtitleStreams = subtitleResolver.GetExternalSubtitleStreams(video, currentStreams.Count, options.DirectoryService, false).ToList();

            var enableSubtitleDownloading = options.MetadataRefreshMode == MetadataRefreshMode.EnsureMetadata ||
                                            options.MetadataRefreshMode == MetadataRefreshMode.FullRefresh;

            if (enableSubtitleDownloading && (_config.Configuration.SubtitleOptions.DownloadEpisodeSubtitles &&
                                              video is Episode) ||
                (_config.Configuration.SubtitleOptions.DownloadMovieSubtitles &&
                 video is Movie))
            {
                var downloadedLanguages = await new SubtitleDownloader(_logger,
                                                                       _subtitleManager)
                                          .DownloadSubtitles(video,
                                                             currentStreams,
                                                             externalSubtitleStreams,
                                                             _config.Configuration.SubtitleOptions.SkipIfGraphicalSubtitlesPresent,
                                                             _config.Configuration.SubtitleOptions.SkipIfAudioTrackMatches,
                                                             _config.Configuration.SubtitleOptions.DownloadLanguages,
                                                             cancellationToken).ConfigureAwait(false);

                // Rescan
                if (downloadedLanguages.Count > 0)
                {
                    externalSubtitleStreams = subtitleResolver.GetExternalSubtitleStreams(video, currentStreams.Count, options.DirectoryService, true).ToList();
                }
            }

            video.SubtitleFiles = externalSubtitleStreams.Select(i => i.Path).OrderBy(i => i).ToList();

            currentStreams.AddRange(externalSubtitleStreams);
        }
示例#3
0
        /// <summary>
        /// Adds the external subtitles.
        /// </summary>
        /// <param name="video">The video.</param>
        /// <param name="currentStreams">The current streams.</param>
        /// <param name="options">The refreshOptions.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Task.</returns>
        private async Task AddExternalSubtitles(Video video,
                                                List <MediaStream> currentStreams,
                                                MetadataRefreshOptions options,
                                                CancellationToken cancellationToken)
        {
            var subtitleResolver = new SubtitleResolver(_localization, _fileSystem);

            var startIndex = currentStreams.Count == 0 ? 0 : (currentStreams.Select(i => i.Index).Max() + 1);
            var externalSubtitleStreams = subtitleResolver.GetExternalSubtitleStreams(video, startIndex, options.DirectoryService, false);

            var enableSubtitleDownloading = options.MetadataRefreshMode == MetadataRefreshMode.Default ||
                                            options.MetadataRefreshMode == MetadataRefreshMode.FullRefresh;

            var subtitleOptions = GetOptions();

            var libraryOptions = _libraryManager.GetLibraryOptions(video);

            string[] subtitleDownloadLanguages;
            bool     SkipIfEmbeddedSubtitlesPresent;
            bool     SkipIfAudioTrackMatches;
            bool     RequirePerfectMatch;
            bool     enabled;

            if (libraryOptions.SubtitleDownloadLanguages == null)
            {
                subtitleDownloadLanguages      = subtitleOptions.DownloadLanguages;
                SkipIfEmbeddedSubtitlesPresent = subtitleOptions.SkipIfEmbeddedSubtitlesPresent;
                SkipIfAudioTrackMatches        = subtitleOptions.SkipIfAudioTrackMatches;
                RequirePerfectMatch            = subtitleOptions.RequirePerfectMatch;
                enabled = (subtitleOptions.DownloadEpisodeSubtitles &&
                           video is Episode) ||
                          (subtitleOptions.DownloadMovieSubtitles &&
                           video is Movie);
            }
            else
            {
                subtitleDownloadLanguages      = libraryOptions.SubtitleDownloadLanguages;
                SkipIfEmbeddedSubtitlesPresent = libraryOptions.SkipSubtitlesIfEmbeddedSubtitlesPresent;
                SkipIfAudioTrackMatches        = libraryOptions.SkipSubtitlesIfAudioTrackMatches;
                RequirePerfectMatch            = libraryOptions.RequirePerfectSubtitleMatch;
                enabled = true;
            }

            if (enableSubtitleDownloading && enabled)
            {
                var downloadedLanguages = await new SubtitleDownloader(_logger,
                                                                       _subtitleManager)
                                          .DownloadSubtitles(video,
                                                             currentStreams.Concat(externalSubtitleStreams).ToList(),
                                                             SkipIfEmbeddedSubtitlesPresent,
                                                             SkipIfAudioTrackMatches,
                                                             RequirePerfectMatch,
                                                             subtitleDownloadLanguages,
                                                             libraryOptions.DisabledSubtitleFetchers,
                                                             libraryOptions.SubtitleFetcherOrder,
                                                             cancellationToken).ConfigureAwait(false);

                // Rescan
                if (downloadedLanguages.Count > 0)
                {
                    externalSubtitleStreams = subtitleResolver.GetExternalSubtitleStreams(video, startIndex, options.DirectoryService, true);
                }
            }

            video.SubtitleFiles = externalSubtitleStreams.Select(i => i.Path).ToArray();

            currentStreams.AddRange(externalSubtitleStreams);
        }