Exemplo n.º 1
0
        public IList<ISubtitleResult> Find(ISubtitleRequest request)
        {
            var url = _urlBuilder.BuildUrl(request.MovieName);
            var resultPage = _webpageDownloader.Download(url);

            var possibleResults = _resultExtractor.ExtractResultUrl(resultPage);

            // At the moment, if we don't have exactly one result, we give up (we'll improve that later)
            if (possibleResults.Count != 1)
                return new List<ISubtitleResult>();

            var secondResultPageUrl = "http://www.addic7ed.com/" + possibleResults[0];
            var secondResultPage = _webpageDownloader.Download(secondResultPageUrl);

            var results = _resultExtractor.ExtractSubtitleRecords(secondResultPage);

            foreach (var addictedSubtitle in results)
            {
                WebClient client = new WebClient();
                client.Headers.Add("Referer", secondResultPageUrl);

                var subtitle = client.DownloadString("http://www.addic7ed.com" + addictedSubtitle.DownloadLink);
                //var subtitle = _webpageDownloader.Download();

                using (var writer = new FileInfo(string.Format("c:\\out\\{0}.{1}.srt", request.MovieName, addictedSubtitle.Language)).CreateText())
                {
                    writer.Write(subtitle);
                }
            }

            return new List<ISubtitleResult>();
        }
Exemplo n.º 2
0
        public IList<ISubtitleResult> Find(ISubtitleRequest request)
        {
            var results = new List<ISubtitleResult>();

            var client = Osdb.Login(_settingsService.Read<string>(SettingsKeys.OpenSubtitlesApiKey));
            var movie = request.MovieLocation;

            var hash = HashHelper.ComputeMovieHash(movie.FullName);
            var hexHash = HashHelper.ToHexadecimal(hash);

            var movies = client.CheckMovieHash(hexHash).ToList();

            if (!movies.Any())
            {
                Log.Error("Couldn't find any movie matching on OpenSubtitle matching " + movie.Name);
            }
            if (movies.Count > 1)
                Log.Warn(string.Format("Found more than one movie ({0}) matching {1}", movies.Count, movie.Name));

            foreach (var movieInfo in movies)
            {
                Log.Debug("Movie found: " + movieInfo.MovieName);
            }

            var subs = client.SearchSubtitlesFromFile("", movie.FullName);
            var notFoundLanguages = new Dictionary<string, CultureInfo>(request.Languages.ToDictionary(x => _languageTranslator.Convert(x)));

            foreach (var subtitle in subs)
            {
                Log.Debug(string.Format("[{2}] {0}: {1}", subtitle.LanguageName, subtitle.MovieName, subtitle.LanguageId));

                if (subtitle.SubtitleFileName.EndsWith(".srt") && notFoundLanguages.ContainsKey(subtitle.LanguageId))
                {
                    results.Add(new OpenSubtitleResult(subtitle, notFoundLanguages[subtitle.LanguageId], client));

                    notFoundLanguages.Remove(subtitle.LanguageId);
                }
            }

            if (notFoundLanguages.Any())
            {
                Log.Debug("Didn't find all requested languages, missing: " + notFoundLanguages.Select(x => x.Value.EnglishName).Aggregate((s, s1) => s + "," + s1) + ", so requeuing");
            }

            return results;
        }