Beispiel #1
0
        public async Task<ReleaseInfo[]> PerformQuery(TorznabQuery query)
        {
            List<ReleaseInfo> releases = new List<ReleaseInfo>();


            foreach (var title in query.ShowTitles ?? new string[] { string.Empty })
            {

                var searchString = title + " " + query.GetEpisodeSearchString();
                var episodeSearchUrl = string.Format("{0}?search={1}&cat=0", SearchUrl, HttpUtility.UrlEncode(searchString));
                var results = await client.GetStringAsync(episodeSearchUrl);
                try
                {
                    CQ dom = results;

                    var table = dom["tbody > tr > .latest"].Parent().Parent();

                    foreach (var row in table.Children().Skip(1))
                    {
                        var release = new ReleaseInfo();

                        CQ qDetailsCol = row.ChildElements.ElementAt(1).Cq();
                        CQ qLink = qDetailsCol.Children("a").First();

                        release.MinimumRatio = 1;
                        release.MinimumSeedTime = 172800;
                        release.Comments = new Uri(BaseUrl + "/" + qLink.Attr("href"));
                        release.Guid = release.Comments;
                        release.Title = qLink.Attr("title");
                        release.Description = release.Title;

                        //"Tuesday, June 11th 2013 at 03:52:53 AM" to...
                        //"Tuesday June 11 2013 03:52:53 AM"
                        var timestamp = qDetailsCol.Children("font").Text().Trim() + " ";
                        var timeParts = new List<string>(timestamp.Replace(" at", "").Replace(",", "").Split(' '));
                        timeParts[2] = Regex.Replace(timeParts[2], "[^0-9.]", "");
                        var formattedTimeString = string.Join(" ", timeParts.ToArray()).Trim();
                        release.PublishDate = DateTime.ParseExact(formattedTimeString, "dddd MMMM d yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);

                        release.Link = new Uri(BaseUrl + "/" + row.ChildElements.ElementAt(2).Cq().Children("a.index").Attr("href"));

                        var sizeCol = row.ChildElements.ElementAt(6);
                        var sizeVal = float.Parse(sizeCol.ChildNodes[0].NodeValue);
                        var sizeUnit = sizeCol.ChildNodes[2].NodeValue;
                        release.Size = ReleaseInfo.GetBytes(sizeUnit, sizeVal);

                        release.Seeders = int.Parse(row.ChildElements.ElementAt(8).Cq().Text(), NumberStyles.AllowThousands);
                        release.Peers = int.Parse(row.ChildElements.ElementAt(9).Cq().Text(), NumberStyles.AllowThousands) + release.Seeders;

                        //if (!release.Title.ToLower().Contains(title.ToLower()))
                        //    continue;

                        releases.Add(release);
                    }
                }
                catch (Exception ex)
                {
                    OnResultParsingError(this, results, ex);
                    throw ex;
                }
            }

            return releases.ToArray();

        }
Beispiel #2
0
        public async Task<ReleaseInfo[]> PerformQuery(TorznabQuery query)
        {
            List<ReleaseInfo> releases = new List<ReleaseInfo>();

            foreach (var title in query.ShowTitles ?? new string[] { string.Empty })
            {
                string episodeSearchUrl;

                if (string.IsNullOrEmpty(title))
                    episodeSearchUrl = SearchUrl;
                else
                {
                    var searchString = title + " " + query.GetEpisodeSearchString();
                    episodeSearchUrl = string.Format("{0}?search={1}&cat=0", SearchUrl, HttpUtility.UrlEncode(searchString));
                }

                var request = CreateHttpRequest(new Uri(episodeSearchUrl));
                var response = await client.SendAsync(request);
                var results = await response.Content.ReadAsStringAsync();
                try
                {
                    CQ dom = results;

                    var rows = dom["#highlight > tbody > tr"];

                    foreach (var row in rows.Skip(1))
                    {
                        var release = new ReleaseInfo();

                        var qRow = row.Cq();
                        var qLink = qRow.Find("a.torrent_name_link").First();

                        release.MinimumRatio = 1;
                        release.MinimumSeedTime = 172800;
                        release.Title = qLink.Attr("title");
                        release.Description = release.Title;
                        release.Guid = new Uri(BaseUrl + qLink.Attr("href"));
                        release.Comments = release.Guid;
                        release.Link = new Uri(BaseUrl + qRow.Find("td.table_links > a").First().Attr("href"));

                        DateTime pubDate;
                        var dateString = qRow.Find("td.table_added").Text().Trim();
                        if (dateString.StartsWith("Today "))
                            pubDate = (DateTime.UtcNow + TimeSpan.Parse(dateString.Split(' ')[1])).ToLocalTime();
                        else if (dateString.StartsWith("Yesterday "))
                            pubDate = (DateTime.UtcNow + TimeSpan.Parse(dateString.Split(' ')[1]) - TimeSpan.FromDays(1)).ToLocalTime();
                        else
                            pubDate = DateTime.ParseExact(dateString, "d-MMM-yyyy HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToLocalTime();
                        release.PublishDate = pubDate;

                        release.Seeders = int.Parse(qRow.Find("td.table_seeders").Text().Trim(), NumberStyles.AllowThousands);
                        release.Peers = int.Parse(qRow.Find("td.table_leechers").Text().Trim(), NumberStyles.AllowThousands) + release.Seeders;

                        var sizeCol = qRow.Find("td.table_size")[0];
                        var sizeVal = float.Parse(sizeCol.ChildNodes[0].NodeValue.Trim());
                        var sizeUnit = sizeCol.ChildNodes[2].NodeValue.Trim();
                        release.Size = ReleaseInfo.GetBytes(sizeUnit, sizeVal);

                        releases.Add(release);
                    }
                }
                catch (Exception ex)
                {
                    OnResultParsingError(this, results, ex);
                    throw ex;
                }
            }

            return releases.ToArray();
        }
Beispiel #3
0
        public async Task <ReleaseInfo[]> PerformQuery(TorznabQuery query)
        {
            List <ReleaseInfo> releases = new List <ReleaseInfo>();

            foreach (var title in query.ShowTitles ?? new string[] { string.Empty })
            {
                string episodeSearchUrl;

                if (string.IsNullOrEmpty(title))
                {
                    episodeSearchUrl = SearchUrl;
                }
                else
                {
                    var searchString = title + " " + query.GetEpisodeSearchString();
                    episodeSearchUrl = string.Format("{0}?search={1}&cat=0", SearchUrl, HttpUtility.UrlEncode(searchString));
                }

                var request  = CreateHttpRequest(new Uri(episodeSearchUrl));
                var response = await client.SendAsync(request);

                var results = await response.Content.ReadAsStringAsync();

                try
                {
                    CQ dom = results;

                    var rows = dom["#highlight > tbody > tr"];

                    foreach (var row in rows.Skip(1))
                    {
                        var release = new ReleaseInfo();

                        var qRow  = row.Cq();
                        var qLink = qRow.Find("a.torrent_name_link").First();

                        release.MinimumRatio    = 1;
                        release.MinimumSeedTime = 172800;
                        release.Title           = qLink.Attr("title");
                        release.Description     = release.Title;
                        release.Guid            = new Uri(BaseUrl + qLink.Attr("href"));
                        release.Comments        = release.Guid;
                        release.Link            = new Uri(BaseUrl + qRow.Find("td.table_links > a").First().Attr("href"));

                        DateTime pubDate;
                        var      dateString = qRow.Find("td.table_added").Text().Trim();
                        if (dateString.StartsWith("Today "))
                        {
                            pubDate = (DateTime.UtcNow + TimeSpan.Parse(dateString.Split(' ')[1])).ToLocalTime();
                        }
                        else if (dateString.StartsWith("Yesterday "))
                        {
                            pubDate = (DateTime.UtcNow + TimeSpan.Parse(dateString.Split(' ')[1]) - TimeSpan.FromDays(1)).ToLocalTime();
                        }
                        else
                        {
                            pubDate = DateTime.ParseExact(dateString, "d-MMM-yyyy HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToLocalTime();
                        }
                        release.PublishDate = pubDate;

                        release.Seeders = int.Parse(qRow.Find("td.table_seeders").Text().Trim(), NumberStyles.AllowThousands);
                        release.Peers   = int.Parse(qRow.Find("td.table_leechers").Text().Trim(), NumberStyles.AllowThousands) + release.Seeders;

                        var sizeCol  = qRow.Find("td.table_size")[0];
                        var sizeVal  = float.Parse(sizeCol.ChildNodes[0].NodeValue.Trim());
                        var sizeUnit = sizeCol.ChildNodes[2].NodeValue.Trim();
                        release.Size = ReleaseInfo.GetBytes(sizeUnit, sizeVal);

                        releases.Add(release);
                    }
                }
                catch (Exception ex)
                {
                    OnResultParsingError(this, results, ex);
                    throw ex;
                }
            }

            return(releases.ToArray());
        }