Beispiel #1
0
        public override async Task <IEnumerable <MovieDto> > GetMoviesByNameAsync(string name)
        {
            var  pageIndex  = 0;
            bool keepSearch = true;

            var moviesSearchResult = new List <MovieDto>();

            var tokenizedName = name.Split(' ');

            while (keepSearch)
            {
                pageIndex++;

                var doc = await HttpRequester.GetHtmlDocumentAsync(htmlUrlProvider.GetMovieSearchByNameUrl(name, pageIndex));

                var movieDtos = GetYtsHtmlMovieLiteDtos(doc.DocumentNode);

                if (movieDtos.Any())
                {
                    moviesSearchResult.AddRange(movieDtos.Where(m => m.Title.ToLower().ContainsWords(tokenizedName)));
                }
                else
                {
                    keepSearch = false;
                }
            }

            return(moviesSearchResult);
        }
Beispiel #2
0
        public override async Task <MovieDto> GetMovieDetailsAsync(string movieId)
        {
            var doc = await HttpRequester.GetHtmlDocumentAsync(htmlUrlProvider.GetMovieDetailsUrl(movieId));

            var movieTorrents     = doc.DocumentNode.SelectSingleNode("//p/em[contains(text(), 'Available in')]").ParentNode;
            var movieTorrentsHtml = new HtmlAgilityPack.HtmlDocument();

            movieTorrentsHtml.LoadHtml(movieTorrents.InnerHtml);

            return(new MovieDto()
            {
                Id = movieId,
                Title = doc.DocumentNode.SelectSingleNode("//div[@id='movie-info']//h1")?.InnerText,
                Year = doc.DocumentNode.SelectSingleNode("//div[@id='movie-info']//h2")?.InnerText,
                Duration = doc.DocumentNode.SelectSingleNode("//span[@title='Runtime']")?.ParentNode?.InnerText.Trim(),
                Genres = doc.DocumentNode.SelectNodes("//div[@id='movie-info']//h2")?.Last().InnerText.Replace("&nbsp;", string.Empty).Replace("/", ", "),
                ImdbCode = doc.DocumentNode.SelectSingleNode("//div[@id='movie-info']//a[@title='IMDb Rating']")?.Attributes["href"].Value.Split('/').SingleOrDefault(t => t.StartsWith("tt")),
                BackgroundImageUrl = htmlUrlProvider.GetImageUrl(doc.DocumentNode.SelectSingleNode("//a[contains(@class, 'screenshot-group')]").Attributes["href"].Value),
                CoverImageUrl = htmlUrlProvider.GetImageUrl(doc.DocumentNode.SelectSingleNode("//div[@id='movie-poster']//img")?.Attributes["src"].Value),
                Rating = doc.DocumentNode.SelectSingleNode("//div[@class='rating-row']/a[@title='IMDb Rating']").ParentNode.InnerText.Trim().Split('\n').First(),
                Synopsis = doc.DocumentNode.SelectSingleNode("//div[@id='synopsis']//p")?.InnerText,
                Director = doc.DocumentNode.SelectSingleNode("//div[@class='directors']//a[@class='name-cast']")?.InnerText,
                Cast = doc.DocumentNode.SelectNodes("//div[@class='actors']//a[@class='name-cast']")?.Select(n => n.InnerText).Aggregate((a, b) => a + ", " + b),
                YoutubeTrailerUrl = doc.DocumentNode.SelectSingleNode("//*[@id='playTrailer']")?.Attributes["href"].Value,
                Torrents = movieTorrentsHtml.DocumentNode.SelectNodes("//a[contains(@title, 'torrent') or contains(@title, 'Torrent')]")
                           .Select(n => new MovieTorrent()
                {
                    DownloadUrl = htmlUrlProvider.GetTorrentUrl(n.Attributes["href"].Value),
                    Quality = n.InnerText
                }).ToArray()
            });
        }
Beispiel #3
0
        private MovieDto GetYtsHtmlMovieLiteDto(string movieHtml, bool withSynopsis = false, bool withBackgroundImage = false)
        {
            var doc = new HtmlAgilityPack.HtmlDocument();

            doc.LoadHtml(movieHtml);

            var movieId = htmlUrlProvider.GetMovieId(doc.DocumentNode.SelectSingleNode("/*[contains(@class, 'browse-movie-link')]")?.Attributes["href"].Value);

            string synopsis        = "";
            string backgroundImage = "";

            if (withSynopsis || withBackgroundImage)
            {
                var detailsDoc = HttpRequester.GetHtmlDocumentAsync(htmlUrlProvider.GetMovieDetailsUrl(movieId)).Result;
                synopsis        = withSynopsis ? detailsDoc.DocumentNode.SelectNodes("//div[@id='synopsis']//p")?.First().InnerText : string.Empty;
                backgroundImage = withBackgroundImage ? htmlUrlProvider.GetImageUrl(detailsDoc.DocumentNode.SelectSingleNode("//a[contains(@class, 'screenshot-group')]").Attributes["href"].Value) : string.Empty;
            }

            // XPATH : '/a[...]' = search a at fist level of doc, //img[...] search img recursivily in doc
            return(new MovieDto()
            {
                CoverImageUrl = htmlUrlProvider.GetImageUrl(doc.DocumentNode.SelectSingleNode("//img[contains(@class, 'img-responsive')]")?.Attributes["src"].Value),
                Id = movieId,
                Synopsis = synopsis,
                BackgroundImageUrl = backgroundImage,
                Title = doc.DocumentNode.SelectSingleNode("//*[contains(@class, 'browse-movie-title')]")?.InnerText,
                Year = doc.DocumentNode.SelectSingleNode("//*[contains(@class, 'browse-movie-year')]")?.InnerText,
                Rating = doc.DocumentNode.SelectSingleNode("//*[contains(@class, 'rating')]")?.InnerText.Replace("/ 10", "").Trim()
            });
        }
Beispiel #4
0
        public async override Task <IEnumerable <MovieTorrent> > GetMovieTorrentsAsync(string title, int year, bool exactTitle)
        {
            var imdbMoviesInfo = await ImdbRequester.GetImdbMoviesInfoAsync(title);

            var imdbMovieInfo = imdbMoviesInfo?.SingleOrDefault(m => m.OriginalTitle.StartsWith(title, StringComparison.OrdinalIgnoreCase) && m.Year == year.ToString());

            if (imdbMovieInfo == null)
            {
                return(null);
            }

            var searchUrl = $"{baseUrl}/recherche/" + imdbMovieInfo.FrenchTitle.ToLower().Replace(":", "");

            var doc = await HttpRequester.GetHtmlDocumentAsync(searchUrl);

            var searchResultList = doc.DocumentNode.SelectNodes("//table[@class='table table-hover']//td//div[@class='maxi']");

            var result = new List <MovieTorrent>();

            if (searchResultList == null)
            {
                return(result);
            }

            var getTorrentTasks = new List <Task>();

            foreach (var node in searchResultList)
            {
                doc = new HtmlDocument();
                doc.LoadHtml(node.InnerHtml);

                var mediaInfo = doc.DocumentNode.SelectSingleNode("/i");
                if (mediaInfo != null && mediaInfo.Attributes["class"].Value == "Films")
                {
                    var linkNode = doc.DocumentNode.SelectSingleNode("/a");
                    if (linkNode != null &&
                        ((exactTitle && linkNode.InnerText.Replace(" ", "").Contains(imdbMovieInfo.FrenchTitle.Replace(" ", ""), StringComparison.OrdinalIgnoreCase)) || linkNode.InnerText.ContainsWords(title.Split(" "))) &&
                        linkNode.InnerText.Contains("FRENCH") &&
                        linkNode.InnerText.EndsWith(year.ToString()) &&
                        !linkNode.InnerText.Contains("MD") &&
                        (linkNode.InnerText.Contains("720p") || linkNode.InnerText.Contains("1080p") || linkNode.InnerText.Contains("DVDRIP") || linkNode.InnerText.Contains("WEBRIP"))
                        )
                    {
                        getTorrentTasks.Add(new Task(() =>
                        {
                            result.Add(new MovieTorrent()
                            {
                                Quality     = linkNode.InnerText.GetMovieQuality(),
                                DownloadUrl = GetTorrentLink(baseUrl + linkNode.Attributes["href"].Value)
                            });
                        }));
                    }
                }
            }

            getTorrentTasks.ForEach(t => t.Start());
            Task.WaitAll(getTorrentTasks.ToArray());

            return(result);
        }
        private string GetTorrentLink(string moviePageUrl)
        {
            var doc = HttpRequester.GetHtmlDocumentAsync(moviePageUrl).Result;

            var magnetNode = doc.DocumentNode.SelectSingleNode("//div[@class='btn-magnet']/a");

            return(magnetNode != null ? magnetNode.Attributes["href"].Value : null);
        }
Beispiel #6
0
        public override async Task <IEnumerable <MovieDto> > GetLastMoviesByGenreAsync(int nbMovies, string genre)
        {
            var doc = await HttpRequester.GetHtmlDocumentAsync(htmlUrlProvider.GetLastMoviesByGenreUrl(genre));

            var movieDtos = GetYtsHtmlMovieLiteDtos(doc.DocumentNode);

            return(movieDtos.Take(nbMovies));
        }
Beispiel #7
0
        public override async Task <IEnumerable <MovieDto> > GetSuggestedMoviesAsync(int nbMovies)
        {
            var doc = await HttpRequester.GetHtmlDocumentAsync(htmlUrlProvider.GetSuggestedMoviesUrl());

            var movieDtos = GetYtsHtmlMovieLiteDtos(doc.DocumentNode, true, true);

            return(movieDtos.Where(m => !string.IsNullOrEmpty(m.Synopsis)).Take(nbMovies));
        }
Beispiel #8
0
        public override async Task <IEnumerable <MovieDto> > GetMoviesByGenreAsync(string genre, int page)
        {
            var pageIndex = page <= 0 ? 1 : page;

            var doc = await HttpRequester.GetHtmlDocumentAsync(htmlUrlProvider.GetMovieSearchByGenreUrl(genre, pageIndex));

            var movieDtos = GetYtsHtmlMovieLiteDtos(doc.DocumentNode);

            return(movieDtos);
        }
Beispiel #9
0
        public async override Task <SubtitlesSearchResultDto> GetAvailableSubtitlesAsync(string imdbCode, SubtitlesLanguage subtitlesLanguage)
        {
            var searchUrl = baseUrl + "/movie-imdb/" + imdbCode;
            var doc       = await HttpRequester.GetHtmlDocumentAsync(searchUrl);

            if (doc == null)
            {
                return(null);
            }

            var nodes = doc.DocumentNode.SelectNodes("//table[@class='table other-subs']/tbody/tr");

            if (nodes == null)
            {
                return(null);
            }

            var subtitlesSourceLinks = new List <string>();

            var languageCode = GetLanguageCode(subtitlesLanguage);

            foreach (var node in nodes)
            {
                doc = new HtmlAgilityPack.HtmlDocument();
                doc.LoadHtml(node.InnerHtml);

                var languageInfo = doc.DocumentNode.SelectSingleNode("//span[@class='sub-lang']");

                if (languageInfo != null && languageInfo.InnerText == languageCode)
                {
                    var subtitleLink = doc.DocumentNode.SelectSingleNode("//td[@class='download-cell']//a")?.Attributes["href"]?.Value;

                    if (subtitleLink != null)
                    {
                        subtitlesSourceLinks.Add(baseUrl + subtitleLink);
                    }
                }
            }

            if (subtitlesSourceLinks.Any())
            {
                return(new SubtitlesSearchResultDto()
                {
                    Language = GetLanguageLabel(subtitlesLanguage),
                    SubtitlesSourceUrls = subtitlesSourceLinks.ToArray()
                });
            }

            return(null);
        }
        public override async Task <SubtitlesSearchResultDto> GetAvailableSubtitlesAsync(string imdbCode, SubtitlesLanguage subtitlesLanguage)
        {
            var openSubtitleMovieId = await GetOpenSubtitleMovieId(imdbCode);

            if (string.IsNullOrEmpty(openSubtitleMovieId))
            {
                return(null);
            }

            var doc = await HttpRequester.GetHtmlDocumentAsync(baseUrl + "/en/search/idmovie-" + openSubtitleMovieId + "/sublanguageid-" + GetLanguageCode(subtitlesLanguage));

            if (doc == null)
            {
                return(null);
            }

            var htmlTableResults = doc.DocumentNode.SelectSingleNode("//table[@id='search_results']");

            if (htmlTableResults != null)
            {
                var searchResultsHtml = new HtmlDocument();
                searchResultsHtml.LoadHtml(htmlTableResults.InnerHtml);

                return(new SubtitlesSearchResultDto()
                {
                    Language = GetLanguageLabel(subtitlesLanguage),
                    SubtitlesSourceUrls = searchResultsHtml.DocumentNode.SelectNodes("//a[contains(@onclick, '/subtitleserve/sub/')]")?
                                          .Select(n =>
                    {
                        var values = n.Attributes["href"].Value.Split('/');
                        return "https://dl.opensubtitles.org/en/download/sub/" + values[values.Length - 1];
                    }).ToArray()
                });
            }

            var singleResult = doc.DocumentNode.SelectSingleNode("//a[@id='bt-dwl-bt']")?.Attributes["href"]?.Value;

            if (!string.IsNullOrEmpty(singleResult))
            {
                return new SubtitlesSearchResultDto()
                       {
                           Language            = GetLanguageLabel(subtitlesLanguage),
                           SubtitlesSourceUrls = new string[] { baseUrl + singleResult }
                       }
            }
            ;

            return(null);
        }
Beispiel #11
0
        public override IEnumerable <SubtitlesDto> GetSubtitles(string subtitlesSourceUrl)
        {
            var doc = HttpRequester.GetHtmlDocumentAsync(subtitlesSourceUrl).Result;

            var subtitlesDownloadUrl = doc.DocumentNode.SelectSingleNode("//a[@class='btn-icon download-subtitle']")?.Attributes["href"]?.Value;

            if (string.IsNullOrEmpty(subtitlesDownloadUrl))
            {
                return(null);
            }

            DownloadSubtitlesZipFile(subtitlesDownloadUrl, null);
            var subtitlesFile = GetSubtitlesFile();

            return(SubtitlesConverter.GetSubtitles(subtitlesFile));
        }