public async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query) { var loggedInCheck = await RequestStringWithCookies(SearchUrl); if (!loggedInCheck.Content.Contains("/logout.php")) { //Cookie appears to expire after a period of time or logging in to the site via browser DateTime lastLoggedInCheck; DateTime.TryParse(configData.LastLoggedInCheck.Value, out lastLoggedInCheck); if (lastLoggedInCheck < DateTime.Now.AddMinutes(-15)) { await DoLogin(); configData.LastLoggedInCheck.Value = DateTime.Now.ToString("o"); SaveConfig(); } } var releases = new List <ReleaseInfo>(); bool configFreeLeechOnly = configData.FilterString.Value.ToLowerInvariant().Contains("freeleechonly"); bool configQualityEncodeOnly = configData.FilterString.Value.ToLowerInvariant().Contains("qualityencodeonly"); string movieListSearchUrl; if (!string.IsNullOrEmpty(query.ImdbID)) { movieListSearchUrl = string.Format("{0}?action=basic&searchstr={1}", SearchUrl, HttpUtility.UrlEncode(query.ImdbID)); } else if (!string.IsNullOrEmpty(query.GetQueryString())) { movieListSearchUrl = string.Format("{0}?action=basic&searchstr={1}", SearchUrl, HttpUtility.UrlEncode(query.GetQueryString())); } else { movieListSearchUrl = SearchUrl; } var results = await RequestStringWithCookiesAndRetry(movieListSearchUrl); try { CQ mdom = results.Content; var mrows = mdom[".torrent_title_box"]; foreach (var mrow in mrows.Take(5)) { var mqRow = mrow.Cq(); Uri movieReleasesLink = new Uri(SiteLink.TrimEnd('/') + mqRow.Find("a[title='View Torrent']").First().Attr("href").Trim()); Uri commentsLink = new Uri(movieReleasesLink + "#comments"); string imdblink = mqRow.Find("span[class='imdb-number-rating']").Length > 0 ? mqRow.Find("span[class='imdb-number-rating'] > a").First().Attr("href").Trim() : ""; long imdb_id = 0; try { if (!string.IsNullOrWhiteSpace(imdblink) && imdblink.ToLowerInvariant().Contains("tt")) { imdb_id = long.Parse(imdblink.Substring(imdblink.LastIndexOf('t') + 1).Replace("/", "")); } } catch { imdb_id = 0; } var release_results = await RequestStringWithCookiesAndRetry(movieReleasesLink.ToString()); //Iterate over the releases for each movie CQ dom = release_results.Content; var rows = dom[".torrent_widget.box.pad"]; foreach (var row in rows) { var release = new ReleaseInfo(); var qRow = row.Cq(); string title = qRow.Find("[id^=desc_] > h2 > strong").First().Text().Trim(); Uri link = new Uri(SiteLink.TrimEnd('/') + qRow.Find("a[title='Download']").First().Attr("href").Trim()); Uri guid = new Uri(SiteLink.TrimEnd('/') + qRow.Find("a[title='Permalink']").First().Attr("href").Trim()); string pubDateStr = qRow.Find("div[class='box pad'] > p:contains('Uploaded by') > span").First().Attr("title").Trim(); DateTime pubDate = DateTime.ParseExact(pubDateStr, "MMM dd yyyy, HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToLocalTime(); string sizeStr = qRow.Find("[id^=desc_] > div > table > tbody > tr > td > strong:contains('Size:')").First().Parent().Parent().Find("td").Last().Text().Trim(); var seeders = ParseUtil.CoerceInt(qRow.Find("img[title='Seeders']").First().Parent().Text().Trim()); var peers = ParseUtil.CoerceInt(qRow.Find("img[title='Leechers']").First().Parent().Text().Trim()) + seeders; var CoverElement = dom.Find("div[id='poster'] > a > img"); if (CoverElement.Any()) { Uri CoverUrl = new Uri(dom.Find("div[id='poster'] > a > img").First().Attr("src").Trim()); release.BannerUrl = CoverUrl; } bool freeleech = qRow.Find("span[class='freeleech']").Length == 1 ? true : false; bool qualityEncode = qRow.Find("img[class='approved']").Length == 1 ? true : false; string grabs = qRow.Find("img[title='Snatches']").First().Parent().Text().Trim(); if (string.IsNullOrWhiteSpace(sizeStr)) { string secondSizeStr = qRow.Find("div[class='details_title'] > strong:contains('(')").Last().Text().Trim(); if (secondSizeStr.Length > 3 && secondSizeStr.Contains("(") && secondSizeStr.Contains(")")) { sizeStr = secondSizeStr.Replace("(", "").Replace(")", "").Trim(); } } if (string.IsNullOrWhiteSpace(title)) { title = dom.Find("div.title_text").Text() + " - " + qRow.Find("div.details_title > a").Text(); } release.Title = title; release.Guid = guid; release.Link = link; release.PublishDate = pubDate; release.Size = ReleaseInfo.GetBytes(sizeStr); release.Description = release.Title; release.Seeders = seeders; release.Peers = peers; release.MinimumRatio = 1; release.MinimumSeedTime = 345600; release.Category = 2000; release.Comments = movieReleasesLink; if (imdb_id > 0) { release.Imdb = imdb_id; } var files = qRow.Find("div[id^=\"filelist\"] tr").Count() - 1; release.Files = files; release.Grabs = ParseUtil.CoerceLong(grabs); if (freeleech) { release.DownloadVolumeFactor = 0; } else { release.DownloadVolumeFactor = 1; } release.UploadVolumeFactor = 1; if (configFreeLeechOnly && !freeleech) { continue; //Skip release if user only wants FreeLeech } if (configQualityEncodeOnly && !qualityEncode) { continue; //Skip release if user only wants Quality Encode } releases.Add(release); } } } catch (Exception ex) { OnParseError(results.Content, ex); } return(releases); }
private async Task <List <ReleaseInfo> > PerformQuerySearch(TorznabQuery query, bool matchWords) { var releases = new List <ReleaseInfo>(); // search only the longest word, we filter the results later var searchTerm = GetLongestWord(query.SearchTerm); var url = SiteLink + SearchUrl + searchTerm; var result = await RequestWithCookiesAsync(url, referer : url); if (result.Status != HttpStatusCode.OK) { throw new ExceptionWithConfigData(result.ContentString, configData); } try { var searchResultParser = new HtmlParser(); var doc = searchResultParser.ParseDocument(result.ContentString); var rows = doc.QuerySelectorAll("div.seccion#buscador > div.card > div.card-body > p"); if (rows.First().TextContent.Contains("Introduce alguna palabra para buscar con al menos 2 letras.")) { return(releases); //no enough search terms } foreach (var row in rows.Skip(2)) { //href=/pelicula/6981/Saga-Spiderman var link = string.Format("{0}{1}", SiteLink.TrimEnd('/'), row.QuerySelector("p > span > a").GetAttribute("href")); var title = row.QuerySelector("p > span > a").TextContent; var cat = GetCategory(title, link); var quality = ""; switch (GetCategoryFromURL(link)) { case "pelicula": case "serie": quality = Regex.Replace(row.QuerySelector("p > span > span").TextContent, "([()])", ""); break; } switch (cat) { case "pelicula": case "pelicula4k": case "serie": case "seriehd": case "musica": await ParseRelease(releases, link, title, cat, quality, query, matchWords); break; default: //ignore different categories break; } } } catch (Exception ex) { OnParseError(result.ContentString, ex); } return(releases); }