public async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query) { var releasesPerPage = 100; var releases = new List<ReleaseInfo>(); var page = (query.Offset/releasesPerPage) + 1; string episodeSearchUrl; if (string.IsNullOrEmpty(query.GetQueryString())) { episodeSearchUrl = SearchUrl + "?page=" + page; } else { var cats = MapTorznabCapsToTrackers(query); var catsUrlPart = string.Join("&", cats.Select(c => $"filter_{c}=on")); episodeSearchUrl = $"{SearchUrl}?page={page}&group=0&{catsUrlPart}&search={HttpUtility.UrlEncode(query.GetQueryString())}&pre_type=torrents&type="; } var results = await RequestStringWithCookiesAndRetry(episodeSearchUrl); if (string.IsNullOrEmpty(results.Content)) { CookieHeader = string.Empty; var pairs = new Dictionary<string, string> { {"username", configData.Username.Value}, {"password", configData.Password.Value}, {"langlang", null}, {"login", "login"} }; var response = await RequestLoginAndFollowRedirect(LoginUrl, pairs, CookieHeader, true, null, LoginUrl); await ConfigureIfOK(response.Cookies, response.Content != null && response.Content.Contains("logout.php"), () => { CQ dom = response.Content; var messageEl = dom["#loginform .warning"]; var errorMessage = messageEl.Text().Trim(); throw new ExceptionWithConfigData(errorMessage, configData); }); results = await RequestStringWithCookiesAndRetry(episodeSearchUrl); } try { CQ dom = results.Content; var rows = dom["#torrent_table tr.torrent"]; foreach (var row in rows) { var qRow = row.Cq(); var release = new ReleaseInfo { MinimumRatio = 1, MinimumSeedTime = 172800 }; var catAnchor = row.FirstChild.FirstChild; var catUrl = catAnchor.GetAttribute("href"); var catStr = Regex.Match(catUrl, "filter_(?<catNo>[0-9]+)=on").Groups["catNo"].Value; var catNo = int.Parse(catStr); var moviesCatsDanish = new[] { 2,3,10,28,29,31 }; var moviesCatsIntl = new[] { 8,9,11,22,24 }; var moviesCats = configData.OnlyDanishCategories.Value ? moviesCatsDanish : moviesCatsDanish.Concat(moviesCatsIntl); var seriesCatsDanish = new[] { 1,4,30 }; var seriesCatsIntl = new[] { 20,21 }; var seriesCats = configData.OnlyDanishCategories.Value ? seriesCatsDanish : seriesCatsDanish.Concat(seriesCatsIntl); if (moviesCats.Contains(catNo)) release.Category = TorznabCatType.Movies.ID; else if (seriesCats.Contains(catNo)) release.Category = TorznabCatType.TV.ID; else if (catNo == 12) release.Category = TorznabCatType.BooksEbook.ID; else if (catNo == 6) release.Category = TorznabCatType.AudioAudiobook.ID; else continue; var titleAnchor = qRow.Find("div.croptorrenttext a").FirstElement(); var title = titleAnchor.GetAttribute("title"); release.Title = title; var dlUrlAnchor = qRow.Find("span.right a").FirstElement(); var dlUrl = dlUrlAnchor.GetAttribute("href"); var authkey = Regex.Match(dlUrl, "authkey=(?<authkey>[0-9a-zA-Z]+)").Groups["authkey"].Value; var torrentPass = Regex.Match(dlUrl, "torrent_pass=(?<torrent_pass>[0-9a-zA-Z]+)").Groups["torrent_pass"].Value; var torrentId = Regex.Match(dlUrl, "id=(?<id>[0-9]+)").Groups["id"].Value; release.Link = new Uri($"{SearchUrl}/{title}.torrent/?action=download&authkey={authkey}&torrent_pass={torrentPass}&id={torrentId}"); var torrentLink = titleAnchor.GetAttribute("href"); release.Guid = new Uri(SiteLink + torrentLink); release.Comments = new Uri(SearchUrl + torrentLink); var addedElement = qRow.Find("span.time").FirstElement(); var addedStr = addedElement.GetAttribute("title"); release.PublishDate = DateTime.ParseExact(addedStr, "MMM dd yyyy, HH:mm", CultureInfo.InvariantCulture); var columns = qRow.Children(); var seedersElement = columns.Reverse().Skip(1).First(); release.Seeders = int.Parse(seedersElement.InnerText); var leechersElement = columns.Last().FirstElement(); release.Peers = release.Seeders + int.Parse(leechersElement.InnerText); var sizeElement = columns.Skip(2).First(); var sizeStr = sizeElement.InnerText; release.Size = ReleaseInfo.GetBytes(sizeStr); var imdbAnchor = qRow.Find(".torrentnotes a") .FirstOrDefault(a => a.GetAttribute("href").Contains("imdb.com")); if (imdbAnchor != null) { var referrerUrl = imdbAnchor.GetAttribute("href"); release.Imdb = long.Parse(Regex.Match(referrerUrl, "tt(?<imdbId>[0-9]+)").Groups["imdbId"].Value); } releases.Add(release); } } catch (Exception ex) { OnParseError(results.Content, ex); } return releases; }
public async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query) { TimeZoneInfo.TransitionTime startTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 2, 0, 0), 3, 5, DayOfWeek.Sunday); TimeZoneInfo.TransitionTime endTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 3, 0, 0), 10, 5, DayOfWeek.Sunday); TimeSpan delta = new TimeSpan(1, 0, 0); TimeZoneInfo.AdjustmentRule adjustment = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(new DateTime(1999, 10, 1), DateTime.MaxValue.Date, delta, startTransition, endTransition); TimeZoneInfo.AdjustmentRule[] adjustments = { adjustment }; TimeZoneInfo denmarkTz = TimeZoneInfo.CreateCustomTimeZone("Denmark Time", new TimeSpan(1, 0, 0), "(GMT+01:00) Denmark Time", "Denmark Time", "Denmark DST", adjustments); var releasesPerPage = 100; var releases = new List<ReleaseInfo>(); var page = (query.Offset/releasesPerPage) + 1; string episodeSearchUrl; if (string.IsNullOrEmpty(query.GetQueryString())) { episodeSearchUrl = SearchUrl + "?page=" + page; } else { var cats = MapTorznabCapsToTrackers(query); var catsUrlPart = string.Join("&", cats.Select(c => $"filter_{c}=on")); episodeSearchUrl = $"{SearchUrl}?page={page}&group=0&{catsUrlPart}&search={HttpUtility.UrlEncode(query.GetQueryString())}&pre_type=torrents&type="; } var results = await RequestStringWithCookiesAndRetry(episodeSearchUrl); if (string.IsNullOrEmpty(results.Content)) { CookieHeader = string.Empty; var pairs = new Dictionary<string, string> { {"username", configData.Username.Value}, {"password", configData.Password.Value}, {"langlang", null}, {"login", "login"} }; var response = await RequestLoginAndFollowRedirect(LoginUrl, pairs, CookieHeader, true, null, LoginUrl); await ConfigureIfOK(response.Cookies, response.Content != null && response.Content.Contains("logout.php"), () => { CQ dom = response.Content; var messageEl = dom["#loginform .warning"]; var errorMessage = messageEl.Text().Trim(); throw new ExceptionWithConfigData(errorMessage, configData); }); results = await RequestStringWithCookiesAndRetry(episodeSearchUrl); } try { CQ dom = results.Content; var rows = dom["#torrent_table tr.torrent"]; foreach (var row in rows) { var qRow = row.Cq(); var release = new ReleaseInfo { MinimumRatio = 1, MinimumSeedTime = 172800 }; var catAnchor = row.FirstChild.FirstChild; var catUrl = catAnchor.GetAttribute("href"); var catStr = Regex.Match(catUrl, "filter_(?<catNo>[0-9]+)=on").Groups["catNo"].Value; var catNo = int.Parse(catStr); var moviesCatsDanish = new[] { 2,3,10,28,29,31 }; var moviesCatsIntl = new[] { 8,9,11,22,24 }; var moviesCats = configData.OnlyDanishCategories.Value ? moviesCatsDanish : moviesCatsDanish.Concat(moviesCatsIntl); var seriesCatsDanish = new[] { 1,4,30 }; var seriesCatsIntl = new[] { 20,21 }; var seriesCats = configData.OnlyDanishCategories.Value ? seriesCatsDanish : seriesCatsDanish.Concat(seriesCatsIntl); if (moviesCats.Contains(catNo)) release.Category = TorznabCatType.Movies.ID; else if (seriesCats.Contains(catNo)) release.Category = TorznabCatType.TV.ID; else if (catNo == 12) release.Category = TorznabCatType.BooksEbook.ID; else if (catNo == 6) release.Category = TorznabCatType.AudioAudiobook.ID; else continue; var titleAnchor = qRow.Find("div.croptorrenttext a").FirstElement(); var title = titleAnchor.GetAttribute("title"); release.Title = title; var dlUrlAnchor = qRow.Find("span.right a[title=\"Direkte download link\"]").FirstElement(); var dlUrl = dlUrlAnchor.GetAttribute("href"); release.Link = new Uri(SiteLink + dlUrl); var torrentLink = titleAnchor.GetAttribute("href"); release.Guid = new Uri(SiteLink + torrentLink); release.Comments = new Uri(SearchUrl + torrentLink); var addedElement = qRow.Find("span.time").FirstElement(); var addedStr = addedElement.GetAttribute("title"); release.PublishDate = TimeZoneInfo.ConvertTimeToUtc(DateTime.ParseExact(addedStr, "MMM dd yyyy, HH:mm", CultureInfo.InvariantCulture), denmarkTz).ToLocalTime(); var columns = qRow.Children(); var seedersElement = columns.Reverse().Skip(1).First(); release.Seeders = int.Parse(seedersElement.InnerText); var leechersElement = columns.Last().FirstElement(); release.Peers = release.Seeders + int.Parse(leechersElement.InnerText); var sizeElement = columns.Skip(2).First(); var sizeStr = sizeElement.InnerText; release.Size = ReleaseInfo.GetBytes(sizeStr); var imdbAnchor = qRow.Find(".torrentnotes a") .FirstOrDefault(a => a.GetAttribute("href").Contains("imdb.com")); if (imdbAnchor != null) { var referrerUrl = imdbAnchor.GetAttribute("href"); release.Imdb = long.Parse(Regex.Match(referrerUrl, "tt(?<imdbId>[0-9]+)").Groups["imdbId"].Value); } var Files = qRow.Find("td:nth-child(3) > div"); release.Files = ParseUtil.CoerceLong(Files.Text().Split(' ')[0]); var Grabs = qRow.Find("td:nth-child(6)"); release.Grabs = ParseUtil.CoerceLong(Grabs.Text()); if (qRow.Find("span.freeleech, img[src=\"/static/common/torrents/gratis.png\"]").Length >= 1) release.DownloadVolumeFactor = 0; else release.DownloadVolumeFactor = 1; if (qRow.Find("img[src=\"/static/common/torrents/toxupload.png\"]").Length >= 1) release.UploadVolumeFactor = 2; else release.UploadVolumeFactor = 1; releases.Add(release); } } catch (Exception ex) { OnParseError(results.Content, ex); } return releases; }
public async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query) { var releasesPerPage = 100; var releases = new List<ReleaseInfo>(); var page = (query.Offset / releasesPerPage); string episodeSearchUrl; if (string.IsNullOrEmpty(query.GetQueryString())) { episodeSearchUrl = SearchUrl + "?page=" + page; } else { var cats = MapTorznabCapsToTrackers(query); var catsUrlPart = string.Join("&", cats.Select(c => $"c{c}=1")); episodeSearchUrl = string.Format("{0}?search={1}&cat=0&incldead=0&{2}&page={3}", SearchUrl, HttpUtility.UrlEncode(query.GetQueryString()), catsUrlPart, page); } var results = await RequestStringWithCookiesAndRetry(episodeSearchUrl); try { CQ dom = results.Content; var rows = dom["#torrent-table-wrapper > div"]; foreach (var row in rows.Skip(1)) { var release = new ReleaseInfo(); var qRow = row.Cq(); var qLink = qRow.Find("#torrent-udgivelse2-users > a").First(); var qDesc = qRow.Find("#torrent-udgivelse2-users > p").FirstOrDefault(); var moviesCatsDanish = new[] { 38, 23, 22, 33, 17 }; var moviesCatsIntl = new[] { 47, 5, 9 }; var moviesCats = configData.OnlyDanishCategories.Value ? moviesCatsDanish : moviesCatsDanish.Concat(moviesCatsIntl); var seriesCatsDanish = new[] { 26, 43, 46 }; var seriesCatsIntl = new[] { 4, 21, 24, 31, 45 }; var seriesCats = configData.OnlyDanishCategories.Value ? seriesCatsDanish : seriesCatsDanish.Concat(seriesCatsIntl); var catUrl = qRow.Find(".torrent-icon > a").Attr("href"); var cat = catUrl.Substring(catUrl.LastIndexOf('=') + 1); var catNo = int.Parse(cat); if (moviesCats.Contains(catNo)) release.Category = TorznabCatType.Movies.ID; else if (seriesCats.Contains(catNo)) release.Category = TorznabCatType.TV.ID; else continue; releases.Add(release); var torrentUrl = qLink.Attr("href"); var torrentId = torrentUrl.Substring(torrentUrl.LastIndexOf('=') + 1); release.MinimumRatio = 1; release.MinimumSeedTime = 172800; release.Title = qLink.Attr("title"); release.Description = qDesc != null ? qDesc.InnerText : release.Title; release.Guid = new Uri(SiteLink + torrentUrl); release.Comments = new Uri(release.Guid + "#startcomments"); var downloadUrl = $"{SiteLink}download.php?id={torrentId}&rss&passkey={configData.RSSKey.Value}"; release.Link = new Uri(downloadUrl); var qAdded = qRow.Find("#torrent-added").First(); var addedStr = qAdded.Text().Trim(); release.PublishDate = DateTime.ParseExact(addedStr, "dd-MM-yyyyHH:mm:ss", CultureInfo.InvariantCulture); release.Seeders = ParseUtil.CoerceInt(qRow.Find("#torrent-seeders").Text().Trim()); release.Peers = ParseUtil.CoerceInt(qRow.Find("#torrent-leechers").Text().Trim()) + release.Seeders; var sizeStr = qRow.Find("#torrent-size").First().Text(); release.Size = ReleaseInfo.GetBytes(sizeStr); var infoLink = qRow.Find("#infolink"); var linkContainer = infoLink.Children().First().Children().First(); var url = linkContainer.Attr("href"); var img = linkContainer.Children().First(); var imgUrl = img.Attr("src"); if (imgUrl == "/pic/imdb.png") { release.Imdb = long.Parse(url.Substring(url.LastIndexOf('t') + 1)); } else if (imgUrl == "/pic/TV.png") { release.TVDBId = long.Parse(url.Substring(url.LastIndexOf('=') + 1)); } } } catch (Exception ex) { OnParseError(results.Content, ex); } return releases; }