示例#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 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();

            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);
                }
            }

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

            currentStreams.AddRange(externalSubtitleStreams);
        }
示例#2
0
        public FFProbeProvider(ILogger logger, IMediaSourceManager mediaSourceManager, IChannelManager channelManager, IIsoManager isoManager, IMediaEncoder mediaEncoder, IItemRepository itemRepo, IBlurayExaminer blurayExaminer, ILocalizationManager localization, IApplicationPaths appPaths, IJsonSerializer json, IEncodingManager encodingManager, IFileSystem fileSystem, IServerConfigurationManager config, ISubtitleManager subtitleManager, IChapterManager chapterManager, ILibraryManager libraryManager)
        {
            _logger             = logger;
            _isoManager         = isoManager;
            _mediaEncoder       = mediaEncoder;
            _itemRepo           = itemRepo;
            _blurayExaminer     = blurayExaminer;
            _localization       = localization;
            _appPaths           = appPaths;
            _json               = json;
            _encodingManager    = encodingManager;
            _fileSystem         = fileSystem;
            _config             = config;
            _subtitleManager    = subtitleManager;
            _chapterManager     = chapterManager;
            _libraryManager     = libraryManager;
            _channelManager     = channelManager;
            _mediaSourceManager = mediaSourceManager;

            _subtitleResolver = new SubtitleResolver(BaseItem.LocalizationManager, fileSystem);
        }
示例#3
0
        public bool HasChanged(IHasMetadata item, IDirectoryService directoryService, DateTime date)
        {
            if (item.DateModified > date)
            {
                return(true);
            }

            if (item.SupportsLocalMetadata)
            {
                var video = item as Video;

                if (video != null && !video.IsPlaceHolder)
                {
                    return(!video.SubtitleFiles
                           .SequenceEqual(SubtitleResolver.GetSubtitleFiles(video, directoryService, _fileSystem, false)
                                          .Select(i => i.FullName)
                                          .OrderBy(i => i), StringComparer.OrdinalIgnoreCase));
                }
            }

            return(false);
        }
示例#4
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);
        }
示例#5
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);

            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);
        }