public void ProvideSubtitleForVideo(Video video)
    {
        try
        {

            var message = string.Format("Finding subtitle for {0}", video.Name);
            InformUser(message);

            var dataSource = DataSourceFactory.CreateDataSource();
            var blackListingProvider = new BlackListingProvider(video, dataSource);
            var subtitleSelector = new SubtitleSelector(blackListingProvider);

            var languageProvider = new LanguageProvider();
            var languages = languageProvider.CreateLanguageCollectionFromString(Plugin.PluginOptions.Instance.Languages);
            var finder = new RemoteSubtitleFinder(video, subtitleSelector);
            var subtitle = finder.FindSubtitle(languages, blackListingProvider);

            if (subtitle == null)
            {
                var failureMessage = string.Format("Downloading subtitle failed. No subtitle found for {0}", video.Name);
                InformUser(failureMessage);
                return;
            }

            var filePath = Path.Combine(ApplicationPaths.AppCachePath, Path.GetRandomFileName() + ".zip");

            var subtitleDownloader = new SubtitleDownloader();
            subtitleDownloader.GetSubtitleToPath(subtitle, filePath);

            var subtitleExtractorFactory = new SubtitleExtractorFactory();
            var subtitleExtractor = subtitleExtractorFactory.CreateSubtitleExtractorByVideo(video);

            try
            {
                subtitleExtractor.ExtractSubtitleFile(filePath);
            }
            catch (InvalidSubtitleFileException)
            {
                blackListingProvider.BlackList(subtitle);
                throw new Exception("Invalid subtitle file, blacklisting: " + subtitle.UrlToFile);
            }

            dataSource.SetCurrentSubtitle(video, subtitle);
            var successMessage = string.Format("Subtitle downloaded for {0} - {1}", video.Name, subtitle.Langugage);
            InformUser(successMessage);

        }
        catch (Exception ex)
        {
            var reportedError =
                string.Format("Error when getting subtitle for video: {0}.", video.Name);

            InformUser(reportedError);

            Logger.ReportException(reportedError, ex);
        }
    }
    private static void HandleBlackListing(Video video)
    {
        var dataSource = DataSourceFactory.CreateDataSource();
        var subtitle = dataSource.GetCurrentSubtitle(video);

        var blackListingProvider = new BlackListingProvider(video);
        blackListingProvider.BlackList(subtitle);

        HandleDownloadSubtitle(video);
    }
Exemplo n.º 3
0
        public Subtitle FindSubtitle(List <string> preferredLanguages, BlackListingProvider blackListingProvider)
        {
            var subtitleCollection = GetSubtitlesFromAllSources(preferredLanguages);

            if (subtitleCollection.IsNullOrEmpty())
            {
                return(null);
            }

            var bestSubtitle = SelectBestSubtitle(subtitleCollection, preferredLanguages, blackListingProvider);

            return(bestSubtitle);
        }
Exemplo n.º 4
0
 public SubtitleSelector(BlackListingProvider blackListingProvider)
 {
     this.blackListingProvider = blackListingProvider;
 }
Exemplo n.º 5
0
 private Subtitle SelectBestSubtitle(List <Subtitle> subtitleCollection, List <string> preferredLanguages, BlackListingProvider blackListingProvider)
 {
     return(selector.SelectBestSubtitle(subtitleCollection, preferredLanguages));
 }
 public SubtitleSelector(BlackListingProvider blackListingProvider)
 {
     this.blackListingProvider = blackListingProvider;
 }