Ejemplo n.º 1
0
        public TvReleaseIdentity ParseEpisodeInfo(string fileName)
        {
            foreach (var pattern in _patterns)
            {
                var match = Regex.Match(fileName, pattern, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
                if (!match.Success)
                    continue;

                var seriesName = match.Groups["SeriesName"].Value.Replace('.', ' ').Replace('_', ' ').Trim();
                var season = int.Parse(match.Groups["Season"].Value);
                var episode = int.Parse(match.Groups["Episode"].Value);
                var endEpisode = ExtractEndEpisode(match.Groups["EndEpisode"], episode);
                var releaseGroup = match.Groups["ReleaseGroup"].Value;
                var extraInfo = GetTags(match.Groups["ExtraInfo"]);

                var releaseIdentity = new TvReleaseIdentity
                {
                    SeriesName = seriesName,
                    Season = season,
                    Episode = episode,
                    EndEpisode = endEpisode,
                    ReleaseGroup = releaseGroup
                };
                foreach (var tag in extraInfo)
                {
                    releaseIdentity.Tags.Add(tag);
                }

                return releaseIdentity;
            }
            return new TvReleaseIdentity();
        }
        public void ApplyEnhancements(string filePath, TvReleaseIdentity identity)
        {
            Type[] enhancementRequests = GetDistinctEnhancementRequestsFromDownloaders();
            var enhancements = GetEnhancements(filePath, identity, enhancementRequests);

            identity.Enhancements.AddRange(enhancements);
        }
Ejemplo n.º 3
0
 private static bool CheckIfShowIsIgnored(IEnumerable<string> ignoredShows, 
     TvReleaseIdentity tvReleaseIdentity)
 {
     return ignoredShows.Any(s => string.Equals(s.RemoveNonAlphaNumericChars(),
         tvReleaseIdentity.SeriesName.RemoveNonAlphaNumericChars(),
         StringComparison.OrdinalIgnoreCase));
 }
Ejemplo n.º 4
0
 public IEnumerable<Subtitle> FilterOutSubtitlesNotMatching(IEnumerable<Subtitle> subtitles, TvReleaseIdentity identity)
 {
     return from subtitle in subtitles
         let subtitleInfo = _episodeParser.ExtractReleaseIdentity(subtitle)
         where subtitleInfo.IsEquivalent(identity)
         select subtitle;
 }
 private IOrderedEnumerable<DownloaderMatch> FindMatchingSubtitlesOrderedByRanking(string targetSubtitleFile, TvReleaseIdentity tvReleaseIdentity, IEnumerable<Language> languages)
 {
     var languageArray = languages.ToArray();
     var compatibleDownloaders = GetDownloadersForLanguages(languageArray);
     EnhanceIdentity(compatibleDownloaders, tvReleaseIdentity, targetSubtitleFile);
     var searchResults = SearchDownloaders(compatibleDownloaders, languageArray, tvReleaseIdentity);
     return OrderByRanking(searchResults, languageArray, tvReleaseIdentity);
 }
        public IEnhancement Enhance(string filePath, TvReleaseIdentity identity)
        {
            var fileHash = Hasher.ComputeHash(filePath);
            if (string.IsNullOrEmpty(fileHash))
                return null;

            return new SubDbFileHashEnhancement {FileHash = fileHash};
        }
 private static IEnumerable<DownloaderMatch> SearchDownloaders(IEnumerable<IEpisodeSubtitleDownloader> compatibleDownloaders, Language[] languageArray, TvReleaseIdentity tvReleaseIdentity)
 {
     var searchResults = compatibleDownloaders
         .AsParallel()
         .SelectMany(downloader => downloader.SearchSubtitle(tvReleaseIdentity, languageArray)
             .Select(match => new DownloaderMatch(downloader, match)))
         .AsSequential().ToArray();
     return FilterOutLanguagesNotInRequest(searchResults, languageArray);
 }
        public IEnhancement Enhance(string filePath, TvReleaseIdentity identity)
        {
            var byteSize = new FileInfo(filePath).Length;
            var fileHash = Hasher.ComputeHash(filePath);
            if (string.IsNullOrEmpty(fileHash))
                return null;

            return new OpenSubtitlesFileHashEnhancement
            {
                FileByteSize = byteSize,
                FileHash = fileHash
            };
        }
        public IEnumerable<Subtitle> SearchSubtitle(TvReleaseIdentity tvReleaseIdentity, IEnumerable<Language> languages)
        {
            var languageArray = languages.ToArray();
            var query = CreateSearchQuery(tvReleaseIdentity, languageArray);
            Subtitle[] searchResult;
            try
            {
                _logger.Debug("SubtitleDownloaderWrapper", "Searching with downloader {0}", Name);
                var watch = Stopwatch.StartNew();
                searchResult = _downloader.SearchSubtitles(query).ToArray();
                watch.Stop();
                _logger.Debug("SubtitleDownloaderWrapper", "Done searching with downloader {0} in {1} ms - found {2} candidate(s)", Name, watch.ElapsedMilliseconds, searchResult.Length);
            }
            catch (Exception ex)
            {
                _logger.Verbose("SubtitleDownloaderWrapper", "Downloader search for downloader {0} failed with message: {1}", Name, ex.Message);
                return Enumerable.Empty<Subtitle>();
            }

            return FilterOutSubtitlesNotMatching(tvReleaseIdentity, searchResult);
        }
 private void EnhanceIdentity(IEnumerable<IEpisodeSubtitleDownloader> compatibleDownloaders, TvReleaseIdentity tvReleaseIdentity, string filePath)
 {
     var applicator = new EnhancementApplicator(compatibleDownloaders, _enhancementProvider);
     applicator.ApplyEnhancements(filePath, tvReleaseIdentity);
 }
Ejemplo n.º 11
0
 private bool DownloadSubtitle(string fileName, TvReleaseIdentity tvReleaseIdentity, 
     IEnumerable<Language> languagesToDownload)
 {
     return _subtitleService.DownloadSubtitle(fileName , tvReleaseIdentity, languagesToDownload);
 }
Ejemplo n.º 12
0
 public int GetRankingScore(Subtitle subtitle, Language[] languages, TvReleaseIdentity identity)
 {
     int baseScore = 100 - FindPreferenceIndexOfLanguage(languages, subtitle.Language);
     return baseScore;
 }
 private IOrderedEnumerable<DownloaderMatch> OrderByRanking(IEnumerable<DownloaderMatch> searchResults, Language[] languageArray, TvReleaseIdentity identity)
 {
     return searchResults.OrderByDescending(s => _subtitleRanker.GetRankingScore(s.Subtitle, languageArray, identity));
 }
 private IEnumerable<IEnhancement> GetEnhancements(string filePath, TvReleaseIdentity identity, Type[] enhancementTypes)
 {
     return enhancementTypes.Select(
         enhancementType => _enhancementProvider.GetEnhancement(enhancementType, filePath, identity))
         .Where(enhancement => enhancement != null);
 }
 public bool DownloadSubtitle(string targetSubtitleFile, TvReleaseIdentity tvReleaseIdentity, IEnumerable<Language> languages)
 {
     var matches = FindMatchingSubtitlesOrderedByRanking(targetSubtitleFile, tvReleaseIdentity, languages).ToArray();
        return DownloadFirstAvailableSubtitle(targetSubtitleFile, matches);
 }
 private static SearchQuery CreateSearchQuery(TvReleaseIdentity tvReleaseIdentity, Language[] languageArray)
 {
     var query = new SearchQuery(tvReleaseIdentity.SeriesName, tvReleaseIdentity.Season, tvReleaseIdentity.Episode,
         tvReleaseIdentity.ReleaseGroup) { Languages = languageArray };
     query.Enhancements.AddRange(tvReleaseIdentity.Enhancements);
     return query;
 }
 private IEnumerable<Subtitle> FilterOutSubtitlesNotMatching(TvReleaseIdentity tvReleaseIdentity, IEnumerable<Subtitle> searchResult)
 {
     var subtitleMatcher = new SubtitleMatcher(_nameParser);
     return subtitleMatcher.FilterOutSubtitlesNotMatching(searchResult, tvReleaseIdentity);
 }
Ejemplo n.º 18
0
 public IEnhancement Enhance(string filePath, TvReleaseIdentity identity)
 {
     var series = _searcher.FindSeriesExact(identity.SeriesName);
     return series.SeriesId != null ? new TvDbEnhancement(series.SeriesId.Value) : null;
 }