示例#1
0
文件: LostFilm.cs 项目: y3ff/Jackett
        public override async Task <ConfigurationData> GetConfigurationForSetup()
        {
            // looks like after some failed login attempts there's a captcha
            var loginPage = await RequestStringWithCookies(LoginUrl, string.Empty);

            CQ dom         = loginPage.Content;
            CQ qCaptchaImg = dom.Find("img#captcha_pictcha").First();

            if (qCaptchaImg.Length == 1)
            {
                var CaptchaUrl   = SiteLink + qCaptchaImg.Attr("src");
                var captchaImage = await RequestBytesWithCookies(CaptchaUrl, loginPage.Cookies);

                configData.CaptchaImage.Value = captchaImage.Content;
            }
            else
            {
                configData.CaptchaImage.Value = new byte[0];
            }
            configData.CaptchaCookie.Value = loginPage.Cookies;
            UpdateCookieHeader(loginPage.Cookies);
            return(configData);
        }
        // GET: Arabbit
        public ActionResult Index()
        {
            ArrayList newsList = new ArrayList();

            CQ dom         = CQ.CreateFromUrl("http://www.arabbit.net");
            CQ mainArticle = dom.Find("div.grid-wrapper").Eq(0);

            for (int i = 0; i < mainArticle.Children().Length; i++)
            {
                newsData nData = new newsData();

                CQ article = mainArticle.Children().Eq(i).Find("a").Eq(0);

                string aText = "";
                string aImg  = "";
                string aAlt  = "";

                if (article.Length != 0)
                {
                    aText = article.Attr("title").ToString();
                    aAlt  = article.Attr("href").ToString();
                }

                nData.text    = aText;
                nData.alt_url = aAlt;
                nData.url     = "";
                CQ img = article.Children("img").Eq(0);
                if (img.Length != 0)
                {
                    aAlt = img.Attr("src").ToString();
                }
                nData.url = aAlt;
                newsList.Add(nData);
            }
            ViewBag.newsList = newsList;
            return(View());
        }
        /// <summary>

        /// Gets the outer html(excluding selector) of an html element by the class attribute and selector

        /// </summary>

        /// <param name="html">The html string to scan</param>

        /// <param name="selector">The css selector to determine what html elements to scan</param>

        /// <param name="classValue">The possible values of the class</param>

        /// <returns>The value of the html element</returns>

        public static List <string> GetInnerHTMLOfElementByClass(string html, string selector, params string[] classValue)

        {
            try

            {
                CQ csQuery = new CQ(html);

                CQ allItems = csQuery.Find(selector);

                List <string> returnValues = new List <string>();

                foreach (var item in allItems)

                {
                    foreach (var value in classValue)

                    {
                        if (item.GetAttribute("class") == value)

                        {
                            returnValues.Add(item.InnerHTML);

                            break;
                        }
                    }
                }

                return(returnValues);
            }

            catch (Exception)

            {
                return(null);
            }
        }
示例#4
0
        /// <summary>
        /// process need
        /// </summary>
        /// <param name="selector">css selector</param>
        /// <param name="result">pre process result</param>
        /// <returns>new process result</returns>
        public override ProcessResult ProcessNeed(CssSelector selector, ProcessResult result)
        {
            var pr = new ProcessResult();

            if (string.IsNullOrEmpty(selector.Selector))
            {
                return(pr);
            }

            var content = result.Content.Trim();

            if (content.StartsWith("<td"))
            {
                content = "<tr>" + content + "</tr>";
            }

            if (content.StartsWith("<tr"))
            {
            }
            else
            {
                content = "<div>" + content + "</div>";
            }

            if (selector.Type == CssTypeEnum.TEXT)
            {
                content = HtmlHelper.ClearTag(content);
            }

            CQ  cq    = CQ.Create(content, HtmlParsingMode.Auto, HtmlParsingOptions.AllowSelfClosingTags, DocType.XHTML);
            var elems = cq.Find(selector.Selector);

            pr = ProcessResult(elems, selector);

            return(pr);
        }
示例#5
0
        public List <MusicSummary> Search([FromUri] PageParams param)
        {
            List <MusicSummary> list = new List <MusicSummary>();
            string url     = $"http://music.baidu.com/search/song?s=1&key={param.Keyword ?? ""}&jump=0&start={(param.Current - 1) * param.Size}&size={param.Size}&third_type=0";
            CQ     csquery = Http.GetHttpValue(url);
            CQ     items   = csquery.Find("li.bb-dotimg");

            for (int i = 0; i < items.Length; i++)
            {
                CQ           item    = items.Eq(i);
                CQ           csTitle = item.Find("span.song-title a");
                string       title   = csTitle.Attr("title");
                string       ids     = Regex.Match(csTitle.Attr("data-songdata") ?? "", "\\d+").Value;
                MusicSummary summary = new MusicSummary
                {
                    ArtistName = item.Find("span.author_list").Text().Trim(),
                    AlbumName  = item.Find("span.album-title").Text().Trim(),
                    SongName   = title,
                    SongId     = Convert.ToInt32(ids)
                };
                list.Add(summary);
            }
            return(list);
        }
示例#6
0
        public override async Task <IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
        {
            LoadValuesFromJson(configJson);
            var responseFirstPage = await RequestStringWithCookiesAndRetry(SiteLink + "login.php?returnto=%2F", "", null);

            CQ  domFirstPage = responseFirstPage.Content;
            var validator    = domFirstPage.Find("input[name =\"validator\"]").Attr("value");
            var pairs        = new Dictionary <string, string> {
                { "validator", validator },
                { "username", configData.Username.Value },
                { "password", configData.Password.Value }
            };

            var result = await RequestLoginAndFollowRedirect(LoginUrl, pairs, responseFirstPage.Cookies, true, null, LoginUrl);

            await ConfigureIfOK(result.Cookies, result.Content != null && result.Content.Contains("logout.php"), () =>
            {
                CQ dom           = result.Content;
                var errorMessage = dom[".main"].Text().Trim();
                throw new ExceptionWithConfigData(errorMessage, configData);
            });

            return(IndexerConfigurationStatus.RequiresTesting);
        }
示例#7
0
        private List <string> GetDepartmentModelForNews(string html)
        {
            List <string> news = new List <string>();
            CQ            cq   = CQ.Create(html);

            foreach (IDomObject section in cq.Find("section"))
            {
                if (section.GetAttribute("class") == "news")
                {
                    cq = CQ.Create(section);
                    foreach (IDomObject aNews in cq.Find("article"))
                    {
                        if (aNews.GetAttribute("class") == "post")
                        {
                            cq = CQ.Create(aNews);
                            foreach (IDomObject h3News in cq.Find("h3"))
                            {
                                cq = CQ.Create(h3News);
                                foreach (IDomObject News in cq.Find("a"))
                                {
                                    news.Add(News.GetAttribute("href"));
                                }
                            }
                            cq = CQ.Create(aNews);
                            foreach (IDomObject divNews in cq.Find("div"))
                            {
                                if (divNews.GetAttribute("class") == "meta")
                                {
                                    news.Add((cq.Find("div")[0]).Cq().Text());
                                }
                            }
                        }
                    }
                }
            }
            return(news);
        }
示例#8
0
        public async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            List <ReleaseInfo> releases = new List <ReleaseInfo>();

            var searchString    = query.GetQueryString();
            var searchUrl       = SearchUrl;
            var queryCollection = new NameValueCollection();

            queryCollection.Add("action", "basic");

            if (!string.IsNullOrWhiteSpace(searchString))
            {
                queryCollection.Add("searchstr", searchString);
            }

            foreach (var cat in MapTorznabCapsToTrackers(query))
            {
                queryCollection.Add("filter_cat[" + cat + "]", "1");
            }

            searchUrl += queryCollection.GetQueryString();

            var results = await RequestStringWithCookiesAndRetry(searchUrl);

            // Occasionally the cookies become invalid, login again if that happens
            if (results.IsRedirect)
            {
                await ApplyConfiguration(null);

                results = await RequestStringWithCookiesAndRetry(searchUrl);
            }

            try
            {
                CQ  dom  = results.Content;
                var rows = dom["#torrent_table > tbody > tr.torrent"];
                foreach (var row in rows)
                {
                    CQ  qRow    = row.Cq();
                    var release = new ReleaseInfo();

                    release.MinimumRatio    = 1;
                    release.MinimumSeedTime = 172800;

                    var catStr = row.ChildElements.ElementAt(0).FirstElementChild.GetAttribute("href").Split(new char[] { '[', ']' })[1];
                    release.Category = MapTrackerCatToNewznab(catStr);

                    var qLink   = row.ChildElements.ElementAt(1).Cq().Children("a")[0].Cq();
                    var linkStr = qLink.Attr("href");
                    release.Comments = new Uri(BaseUrl + "/" + linkStr);
                    release.Guid     = release.Comments;

                    var qDownload = row.ChildElements.ElementAt(1).Cq().Find("a[title='Download']")[0].Cq();
                    release.Link = new Uri(BaseUrl + "/" + qDownload.Attr("href"));

                    var dateStr = row.ChildElements.ElementAt(3).Cq().Text().Trim().Replace(" and", "");
                    release.PublishDate = DateTimeUtil.FromTimeAgo(dateStr);

                    var sizeStr = row.ChildElements.ElementAt(4).Cq().Text();
                    release.Size = ReleaseInfo.GetBytes(sizeStr);

                    release.Files   = ParseUtil.CoerceInt(row.ChildElements.ElementAt(2).Cq().Text().Trim());
                    release.Grabs   = ParseUtil.CoerceInt(row.ChildElements.ElementAt(6).Cq().Text().Trim());
                    release.Seeders = ParseUtil.CoerceInt(row.ChildElements.ElementAt(7).Cq().Text().Trim());
                    release.Peers   = ParseUtil.CoerceInt(row.ChildElements.ElementAt(8).Cq().Text().Trim()) + release.Seeders;

                    var grabs = qRow.Find("td:nth-child(6)").Text();
                    release.Grabs = ParseUtil.CoerceInt(grabs);

                    if (qRow.Find("strong:contains(\"Freeleech!\")").Length >= 1)
                    {
                        release.DownloadVolumeFactor = 0;
                    }
                    else
                    {
                        release.DownloadVolumeFactor = 1;
                    }

                    release.UploadVolumeFactor = 1;

                    var title = qRow.Find("td:nth-child(2)");
                    title.Find("span, strong, div, br").Remove();
                    release.Title = ParseUtil.NormalizeMultiSpaces(title.Text().Replace(" - ]", "]"));

                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(results.Content, ex);
            }
            return(releases);
        }
示例#9
0
        public async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            var releases     = new List <ReleaseInfo>();
            var searchUrl    = BrowseUrl;
            var searchString = query.GetQueryString();

            var    cats = MapTorznabCapsToTrackers(query);
            string cat  = "0";

            if (cats.Count == 1)
            {
                cat = cats[0];
            }

            if (!string.IsNullOrWhiteSpace(searchString) || cat != "0")
            {
                searchUrl += string.Format("?search={0}&cat={1}&searchin=0&sort=0", HttpUtility.UrlEncode(searchString), cat);
            }



            var response = await RequestStringWithCookiesAndRetry(searchUrl, null, BrowseUrl);

            var results = response.Content;

            try
            {
                CQ  dom             = results;
                var globalFreeLeech = dom.Find("div.globalFreeLeech").Any();
                var rows            = dom[".torrentrow"];
                foreach (var row in rows)
                {
                    var release    = new ReleaseInfo();
                    var qRow       = row.Cq();
                    var qTitleLink = qRow.Find(".torrenttable:eq(1) a").First();
                    release.Title       = qRow.Find(".torrenttable:eq(1) a").Attr("title");
                    release.Description = release.Title;
                    release.Guid        = new Uri(SiteLink + qTitleLink.Attr("href"));
                    release.Comments    = release.Guid;

                    //22:05:3716/02/2013
                    var dateStr = qRow.Find(".torrenttable:eq(5)").Text().Trim() + " +0200";
                    release.PublishDate = DateTime.ParseExact(dateStr, "H:mm:ssdd/MM/yyyy zzz", CultureInfo.InvariantCulture);

                    var qLink = qRow.Find("a[href^=\"download.php?id=\"]").First();
                    release.Link = new Uri(SiteLink + qLink.Attr("href"));

                    var sizeStr = qRow.Find(".torrenttable:eq(6)").Text().Trim();
                    release.Size = ReleaseInfo.GetBytes(sizeStr);

                    release.Seeders = ParseUtil.CoerceInt(qRow.Find(".torrenttable:eq(8)").Text().Trim());
                    release.Peers   = ParseUtil.CoerceInt(qRow.Find(".torrenttable:eq(9)").Text().Trim()) + release.Seeders;

                    var catId = qRow.Find(".torrenttable:eq(0) a").First().Attr("href").Substring(15);
                    release.Category = MapTrackerCatToNewznab(catId);

                    var grabs = qRow.Find(".torrenttable:eq(7)").First().Get(0).FirstChild;
                    release.Grabs = ParseUtil.CoerceLong(catId);

                    if (globalFreeLeech || row.Cq().Find("img[alt=\"FreeLeech\"]").Any())
                    {
                        release.DownloadVolumeFactor = 0;
                    }
                    else
                    {
                        release.DownloadVolumeFactor = 1;
                    }

                    release.UploadVolumeFactor = 1;

                    // Skip Romanian releases
                    if (release.Category == TorznabCatType.MoviesForeign.ID && !configData.IncludeRomanianReleases.Value)
                    {
                        continue;
                    }

                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(results, ex);
            }

            return(releases);
        }
示例#10
0
        private async Task <IEnumerable <ReleaseInfo> > performRegularQuery(TorznabQuery query, string hebName = null)
        {
            var releases        = new List <ReleaseInfo>();
            var searchurls      = new List <string>();
            var searchUrl       = SearchUrl;
            var queryCollection = new NameValueCollection();
            var searchString    = query.GetQueryString();

            if (query.IsImdbQuery)
            {
                searchString = query.ImdbID;
            }

            if (hebName != null)
            {
                searchString = hebName + " - עונה " + query.Season + " פרק " + query.Episode;
            }
            searchUrl += "?";
            if (!string.IsNullOrWhiteSpace(searchString))
            {
                var strEncoded = WebUtilityHelpers.UrlEncode(searchString, Encoding);
                searchUrl += "&query=" + strEncoded + "&matchquery=any";
            }

            foreach (var cat in MapTorznabCapsToTrackers(query))
            {
                searchUrl += "&c[]=" + cat;
            }

            var data = await RequestStringWithCookiesAndRetry(searchUrl);

            try
            {
                CQ  dom  = data.Content;
                var rows = dom["tr.box_torrent"];
                foreach (var row in rows)
                {
                    CQ qRow = row.Cq();

                    var release         = new ReleaseInfo();
                    var main_title_link = qRow.Find("div.main_title > a");
                    release.Title = main_title_link.Attr("longtitle");
                    if (release.Title.IsNullOrEmptyOrWhitespace())
                    {
                        release.Title = main_title_link.Text();
                    }

                    release.MinimumRatio    = 1;
                    release.MinimumSeedTime = 172800;

                    int seeders, peers;
                    if (ParseUtil.TryCoerceInt(qRow.Find("td:nth-child(7) > div").Text(), out seeders))
                    {
                        release.Seeders = seeders;
                        if (ParseUtil.TryCoerceInt(qRow.Find("td:nth-child(8) > div").Text(), out peers))
                        {
                            release.Peers = peers + release.Seeders;
                        }
                    }
                    release.Grabs   = ParseUtil.CoerceLong(qRow.Find("td:nth-child(5)").Text().Replace(",", ""));
                    release.Seeders = ParseUtil.CoerceInt(qRow.Find("td:nth-child(6)").Text().Replace(",", ""));
                    release.Peers   = ParseUtil.CoerceInt(qRow.Find("td:nth-child(7)").Text().Replace(",", "")) + release.Seeders;
                    string fullSize = qRow.Find("td:nth-child(4)").Text();
                    release.Size = ReleaseInfo.GetBytes(fullSize);

                    release.Comments = new Uri(SiteLink + qRow.Find("a.threadlink[href]").Attr("href"));
                    release.Link     = new Uri(SiteLink + qRow.Find("a:has(div.dlimg)").Attr("href"));
                    release.Guid     = release.Comments;
                    try
                    {
                        release.BannerUrl = new Uri(qRow.Find("a[imgsrc]").Attr("imgsrc"));
                    }
                    catch (Exception)
                    {
                        // do nothing, some releases have invalid banner URLs, ignore the banners in this case
                    }

                    var    dateStringAll = qRow.Find("div.up_info2")[0].ChildNodes.Last().ToString();
                    var    dateParts     = dateStringAll.Split(' ');
                    string dateString    = dateParts[dateParts.Length - 2] + " " + dateParts[dateParts.Length - 1];
                    release.PublishDate = DateTime.ParseExact(dateString, "dd/MM/yy HH:mm", CultureInfo.InvariantCulture);

                    string categoryLink = qRow.Find("a[href^=\"/browse.php?cat=\"]").Attr("href");
                    var    catid        = ParseUtil.GetArgumentFromQueryString(categoryLink, "cat");
                    release.Category = MapTrackerCatToNewznab(catid);

                    if (qRow.Find("a[href^=\"?freeleech=1\"]").Length >= 1)
                    {
                        release.DownloadVolumeFactor = 0;
                    }
                    else
                    {
                        release.DownloadVolumeFactor = 1;
                    }

                    release.UploadVolumeFactor = 1;

                    var sub_title = qRow.Find("div.sub_title");
                    var imdb_link = sub_title.Find("span.imdb-inline > a");
                    release.Imdb = ParseUtil.GetLongFromString(imdb_link.Attr("href"));
                    sub_title.Find("span.imdb-inline").Remove();
                    release.Description = sub_title.Text();

                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(data.Content, ex);
            }

            return(releases);
        }
示例#11
0
        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);
        }
示例#12
0
        private async Task <IEnumerable <ReleaseInfo> > GetResults(SearchType searchType, string searchTerm)
        {
            var cleanSearchTerm = HttpUtility.UrlEncode(searchTerm);

            // The result list
            var releases = new List <ReleaseInfo>();

            var queryUrl = searchType == SearchType.Video ? SearchUrl : MusicSearchUrl;

            // Only include the query bit if its required as hopefully the site caches the non query page
            if (!string.IsNullOrWhiteSpace(searchTerm))
            {
                queryUrl += string.Format("searchstr={0}&action=advanced&search_type=title&year=&year2=&tags=&tags_type=0&sort=time_added&way=desc&hentai=2&releasegroup=&epcount=&epcount2=&artbooktitle=", cleanSearchTerm);
            }

            // Check cache first so we don't query the server for each episode when searching for each episode in a series.
            lock (cache)
            {
                // Remove old cache items
                CleanCache();

                var cachedResult = cache.Where(i => i.Query == queryUrl).FirstOrDefault();
                if (cachedResult != null)
                {
                    return(cachedResult.Results.Select(s => (ReleaseInfo)s.Clone()).ToArray());
                }
            }

            // Get the content from the tracker
            var response = await RequestStringWithCookiesAndRetry(queryUrl);

            CQ dom = response.Content;

            // Parse
            try
            {
                var releaseInfo = "S01";
                var root        = dom.Find(".group_cont");
                // We may have got redirected to the series page if we have none of these
                if (root.Count() == 0)
                {
                    root = dom.Find(".torrent_table");
                }

                foreach (var series in root)
                {
                    var seriesCq = series.Cq();

                    var    synonyms = new List <string>();
                    string mainTitle;
                    if (searchType == SearchType.Video)
                    {
                        mainTitle = seriesCq.Find(".group_title strong a").First().Text().Trim();
                    }
                    else
                    {
                        mainTitle = seriesCq.Find(".group_title strong").Text().Trim();
                    }

                    var yearStr   = seriesCq.Find(".group_title strong").First().Text().Trim().Replace("]", "").Trim();
                    int yearIndex = yearStr.LastIndexOf("[");
                    if (yearIndex > -1)
                    {
                        yearStr = yearStr.Substring(yearIndex + 1);
                    }

                    int year = 0;
                    if (!int.TryParse(yearStr, out year))
                    {
                        year = DateTime.Now.Year;
                    }

                    synonyms.Add(mainTitle);

                    // If the title contains a comma then we can't use the synonyms as they are comma seperated
                    if (!mainTitle.Contains(","))
                    {
                        var symnomnNames = string.Empty;
                        foreach (var e in seriesCq.Find(".group_statbox li"))
                        {
                            if (e.FirstChild.InnerText == "Synonyms:")
                            {
                                symnomnNames = e.InnerText;
                            }
                        }

                        if (!string.IsNullOrWhiteSpace(symnomnNames))
                        {
                            foreach (var name in symnomnNames.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
                            {
                                var theName = name.Trim();
                                if (!theName.Contains("&#") && !string.IsNullOrWhiteSpace(theName))
                                {
                                    synonyms.Add(theName);
                                }
                            }
                        }
                    }

                    foreach (var title in synonyms)
                    {
                        var releaseRows = seriesCq.Find(".torrent_group tr");

                        // Skip the first two info rows
                        for (int r = 1; r < releaseRows.Count(); r++)
                        {
                            var row   = releaseRows.Get(r);
                            var rowCq = row.Cq();
                            if (rowCq.HasClass("edition_info"))
                            {
                                releaseInfo = rowCq.Find("td").Text();

                                if (string.IsNullOrWhiteSpace(releaseInfo))
                                {
                                    // Single episodes alpha - Reported that this info is missing.
                                    // It should self correct when availible
                                    break;
                                }

                                releaseInfo = releaseInfo.Replace("Episode ", "");
                                releaseInfo = releaseInfo.Replace("Season ", "S");
                                releaseInfo = releaseInfo.Trim();
                                int test = 0;
                                if (InsertSeason && int.TryParse(releaseInfo, out test) && releaseInfo.Length == 1)
                                {
                                    releaseInfo = "S01E0" + releaseInfo;
                                }
                            }
                            else if (rowCq.HasClass("torrent"))
                            {
                                var links = rowCq.Find("a");
                                // Protect against format changes
                                if (links.Count() != 2)
                                {
                                    continue;
                                }

                                var release = new ReleaseInfo();
                                release.MinimumRatio    = 1;
                                release.MinimumSeedTime = 259200;
                                var downloadLink = links.Get(0);

                                // We dont know this so try to fake based on the release year
                                release.PublishDate = new DateTime(year, 1, 1);
                                release.PublishDate = release.PublishDate.AddDays(Math.Min(DateTime.Now.DayOfYear, 365) - 1);

                                var infoLink = links.Get(1);
                                release.Comments = new Uri(SiteLink + infoLink.Attributes.GetAttribute("href"));
                                release.Guid     = new Uri(SiteLink + infoLink.Attributes.GetAttribute("href") + "&nh=" + StringUtil.Hash(title)); // Sonarr should dedupe on this url - allow a url per name.
                                release.Link     = new Uri(downloadLink.Attributes.GetAttribute("href"), UriKind.Relative);

                                string category = null;
                                if (searchType == SearchType.Video)
                                {
                                    category = seriesCq.Find("a[title=\"View Torrent\"]").Text().Trim();
                                    if (category == "TV Series")
                                    {
                                        release.Category = TorznabCatType.TVAnime.ID;
                                    }

                                    // Ignore these categories as they'll cause hell with the matcher
                                    // TV Special, OVA, ONA, DVD Special, BD Special

                                    if (category == "Movie")
                                    {
                                        release.Category = TorznabCatType.Movies.ID;
                                    }

                                    if (category == "Manga" || category == "Oneshot" || category == "Anthology" || category == "Manhwa" || category == "Manhua" || category == "Light Novel")
                                    {
                                        release.Category = TorznabCatType.BooksComics.ID;
                                    }

                                    if (category == "Novel" || category == "Artbook")
                                    {
                                        release.Category = TorznabCatType.BooksComics.ID;
                                    }

                                    if (category == "Game" || category == "Visual Novel")
                                    {
                                        var description = rowCq.Find(".torrent_properties a:eq(1)").Text();
                                        if (description.Contains(" PSP "))
                                        {
                                            release.Category = TorznabCatType.ConsolePSP.ID;
                                        }
                                        if (description.Contains("PSX"))
                                        {
                                            release.Category = TorznabCatType.ConsoleOther.ID;
                                        }
                                        if (description.Contains(" NES "))
                                        {
                                            release.Category = TorznabCatType.ConsoleOther.ID;
                                        }
                                        if (description.Contains(" PC "))
                                        {
                                            release.Category = TorznabCatType.PCGames.ID;
                                        }
                                    }
                                }

                                if (searchType == SearchType.Audio)
                                {
                                    category = seriesCq.Find(".group_img .cat a").Text();
                                    if (category == "Single" || category == "Album" || category == "Compilation" || category == "Soundtrack" || category == "Remix CD")
                                    {
                                        var description = rowCq.Find(".torrent_properties a:eq(1)").Text();
                                        if (description.Contains(" Lossless "))
                                        {
                                            release.Category = TorznabCatType.AudioLossless.ID;
                                        }
                                        else if (description.Contains("MP3"))
                                        {
                                            release.Category = TorznabCatType.AudioMP3.ID;
                                        }
                                        else
                                        {
                                            release.Category = TorznabCatType.AudioOther.ID;
                                        }
                                    }
                                }



                                // We dont actually have a release name >.> so try to create one
                                var releaseTags = infoLink.InnerText.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList();
                                for (int i = releaseTags.Count - 1; i >= 0; i--)
                                {
                                    releaseTags[i] = releaseTags[i].Trim();
                                    if (string.IsNullOrWhiteSpace(releaseTags[i]))
                                    {
                                        releaseTags.RemoveAt(i);
                                    }
                                }

                                var group = releaseTags.Last();
                                if (group.Contains("(") && group.Contains(")"))
                                {
                                    // Skip raws if set
                                    if (group.ToLowerInvariant().StartsWith("raw") && !AllowRaws)
                                    {
                                        continue;
                                    }

                                    var start = group.IndexOf("(");
                                    group = "[" + group.Substring(start + 1, (group.IndexOf(")") - 1) - start) + "] ";
                                }
                                else
                                {
                                    group = string.Empty;
                                }

                                var infoString = "";

                                for (int i = 0; i + 1 < releaseTags.Count(); i++)
                                {
                                    if (releaseTags[i] == "Raw" && !AllowRaws)
                                    {
                                        continue;
                                    }
                                    infoString += "[" + releaseTags[i] + "]";
                                }

                                if (category == "Movie")
                                {
                                    release.Title = string.Format("{0} {1} {2}{3}", title, year, group, infoString);
                                }
                                else
                                {
                                    release.Title = string.Format("{0}{1} {2} {3}", group, title, releaseInfo, infoString);
                                }
                                release.Description = title;

                                var size = rowCq.Find(".torrent_size");
                                if (size.Count() > 0)
                                {
                                    release.Size = ReleaseInfo.GetBytes(size.First().Text());
                                }

                                //  Additional 5 hours per GB
                                release.MinimumSeedTime += (release.Size / 1000000000) * 18000;

                                // Peer info
                                release.Seeders = ParseUtil.CoerceInt(rowCq.Find(".torrent_seeders").Text());
                                release.Peers   = release.Seeders + ParseUtil.CoerceInt(rowCq.Find(".torrent_leechers").Text());

                                if (release.Category != 0)
                                {
                                    releases.Add(release);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                OnParseError(response.Content, ex);
            }

            // Add to the cache
            lock (cache)
            {
                cache.Add(new CachedQueryResult(queryUrl, releases));
            }

            return(releases.Select(s => (ReleaseInfo)s.Clone()));
        }
示例#13
0
        public void searchOth(string mess)
        {
            if (flag)
            {
                answ.Add("searchOth func started");
            }
            bool check = command(mess);

            if (check)
            {
                if (flag)
                {
                    answ.Add("bool for command == true");
                }
            }
            else
            {
                if (flag)
                {
                    answ.Add("bool for command == false");
                }
                answ.Add("Запрос будет выполнен корректно, если в нем будет указана 1 валюта и 1 город.");
                string curVal = getVal(mess);
                int    count  = 0;
                if (!curVal.IsNullOrEmpty())
                {
                    string urlMain = "https://ru.myfin.by/currency";
                    string curReg  = getReg();
                    string curUrl  = urlMain + "/" + curVal.ToLower() + "/" + curReg;
                    if (curReg.IsNullOrEmpty())
                    {
                        curUrl = curUrl.Substring(0, curUrl.Length - 1);
                    }
                    else
                    {
                    }
                    int z = getSorttype();
                    if (z <= 4)
                    {
                        curUrl += "?sort=buy_course_" + sortn;
                    }
                    if (z > 4 && z <= 8)
                    {
                        curUrl += "?sort=-sell_course_" + sortn;
                    }
                    if (flag)
                    {
                        answ.Add(curUrl);
                    }
                    CQ  dom0 = CQ.CreateFromUrl(curUrl);
                    int tr   = 0;
                    foreach (IDomObject obj in dom0.Find("td"))
                    {
                        if (tr == 0 && count < 5)
                        {
                            if (obj.ClassName == "bank_name")
                            {
                                answ.Add(obj.Cq().Text());
                                tr = 2;
                                continue;
                            }
                        }
                        if (tr == 2)
                        {
                            answ.Add(obj.Cq().Text());
                            tr--;
                            continue;
                        }
                        if (tr == 1)
                        {
                            answ.Add(obj.Cq().Text());
                            tr--;
                            count++;
                            continue;
                        }
                    }
                }
            }
        }
示例#14
0
        protected override async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            List <ReleaseInfo> releases = new List <ReleaseInfo>();

            var searchString    = query.GetQueryString();
            var searchUrl       = SearchUrl;
            var queryCollection = new NameValueCollection();

            queryCollection.Add("incldead", "1");
            queryCollection.Add("rel_type", "0"); // Alle

            if (query.ImdbID != null)
            {
                queryCollection.Add("searchin", "imdb");
                queryCollection.Add("search", query.ImdbID);
            }
            else
            {
                queryCollection.Add("searchin", "title");

                if (!string.IsNullOrWhiteSpace(searchString))
                {
                    // use AND+wildcard operator to avoid getting to many useless results
                    var searchStringArray = Regex.Split(searchString.Trim(), "[ _.-]+", RegexOptions.Compiled).ToList();
                    searchStringArray = searchStringArray.Where(x => x.Length >= 3).ToList();                                                      //  remove words with less than 3 characters
                    searchStringArray = searchStringArray.Where(x => !new string[] { "der", "die", "das", "the" }.Contains(x.ToLower())).ToList(); //  remove words with less than 3 characters
                    searchStringArray = searchStringArray.Select(x => "+" + x + "*").ToList();                                                     // add AND operators+wildcards
                    var searchStringFinal = String.Join(" ", searchStringArray);
                    queryCollection.Add("search", searchStringFinal);
                }
            }
            foreach (var cat in MapTorznabCapsToTrackers(query))
            {
                queryCollection.Add("c" + cat, "1");
            }

            searchUrl += "?" + queryCollection.GetQueryString();

            var results = await RequestStringWithCookiesAndRetry(searchUrl);

            if (results.IsRedirect)
            {
                await ApplyConfiguration(null);

                results = await RequestStringWithCookiesAndRetry(searchUrl);
            }

            try
            {
                CQ  dom             = results.Content;
                var rows            = dom["table.torrent_table > tbody > tr"];
                var globalFreeleech = dom.Find("legend:contains(\"Freeleech\")+ul > li > b:contains(\"Freeleech\")").Any();
                foreach (var row in rows.Skip(1))
                {
                    var release = new ReleaseInfo();
                    release.MinimumRatio    = 1;
                    release.MinimumSeedTime = 96 * 60 * 60;

                    var qRow = row.Cq();

                    var catStr = row.ChildElements.ElementAt(0).FirstElementChild.GetAttribute("href").Split('=')[1];
                    release.Category = MapTrackerCatToNewznab(catStr);

                    var qLink = row.ChildElements.ElementAt(2).FirstElementChild.Cq();
                    release.Link = new Uri(SiteLink + qLink.Attr("href"));
                    var torrentId = qLink.Attr("href").Split('=').Last();

                    var descCol      = row.ChildElements.ElementAt(1);
                    var qCommentLink = descCol.FirstElementChild.Cq();
                    var torrentTag   = descCol.Cq().Find("span.torrent-tag");
                    var torrentTags  = torrentTag.Elements.Select(x => x.InnerHTML).ToList();
                    release.Title       = qCommentLink.Attr("title");
                    release.Description = String.Join(", ", torrentTags);
                    release.Comments    = new Uri(SiteLink + qCommentLink.Attr("href").Replace("&hit=1", ""));
                    release.Guid        = release.Comments;

                    var      torrent_details = descCol.Cq().Find(".torrent_details").Get(0);
                    var      rawDateStr      = torrent_details.ChildNodes.ElementAt(torrent_details.ChildNodes.Length - 3).Cq().Text();
                    var      dateStr         = rawDateStr.Trim().Replace("von", "").Trim();
                    DateTime dateGerman;
                    if (dateStr.StartsWith("Heute "))
                    {
                        dateGerman = DateTime.SpecifyKind(DateTime.UtcNow.Date, DateTimeKind.Unspecified) + TimeSpan.Parse(dateStr.Split(' ')[1]);
                    }
                    else if (dateStr.StartsWith("Gestern "))
                    {
                        dateGerman = DateTime.SpecifyKind(DateTime.UtcNow.Date, DateTimeKind.Unspecified) + TimeSpan.Parse(dateStr.Split(' ')[1]) - TimeSpan.FromDays(1);
                    }
                    else
                    {
                        dateGerman = DateTime.SpecifyKind(DateTime.ParseExact(dateStr, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture), DateTimeKind.Unspecified);
                    }

                    DateTime pubDateUtc = TimeZoneInfo.ConvertTimeToUtc(dateGerman, germanyTz);
                    release.PublishDate = pubDateUtc.ToLocalTime();

                    var imdbLink = descCol.Cq().Find("a[href*=\"&searchin=imdb\"]");
                    if (imdbLink.Any())
                    {
                        release.Imdb = ParseUtil.GetLongFromString(imdbLink.Attr("href"));
                    }

                    var sizeStr = row.ChildElements.ElementAt(5).Cq().Text();
                    release.Size = ReleaseInfo.GetBytes(sizeStr);

                    release.Seeders = ParseUtil.CoerceInt(row.ChildElements.ElementAt(7).Cq().Text());
                    release.Peers   = ParseUtil.CoerceInt(row.ChildElements.ElementAt(8).Cq().Text()) + release.Seeders;

                    var grabs = qRow.Find("td:nth-child(7)").Text();
                    release.Grabs = ParseUtil.CoerceInt(grabs);

                    if (globalFreeleech)
                    {
                        release.DownloadVolumeFactor = 0;
                    }
                    else if (qRow.Find("span.torrent-tag-free").Length >= 1)
                    {
                        release.DownloadVolumeFactor = 0;
                    }
                    else
                    {
                        release.DownloadVolumeFactor = 1;
                    }

                    release.UploadVolumeFactor = 1;

                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(results.Content, ex);
            }

            return(releases);
        }
示例#15
0
        protected override async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            var releases = new List <ReleaseInfo>();

            NameValueCollection qParams = new NameValueCollection();

            qParams.Add("tor[text]", query.GetQueryString());
            qParams.Add("tor[srchIn][title]", "true");
            qParams.Add("tor[srchIn][author]", "true");
            qParams.Add("tor[searchType]", "all");
            qParams.Add("tor[searchIn]", "torrents");
            qParams.Add("tor[hash]", "");
            qParams.Add("tor[sortType]", "default");
            qParams.Add("tor[startNumber]", "0");

            List <string> catList = MapTorznabCapsToTrackers(query);

            if (catList.Any())
            {
                foreach (string cat in catList)
                {
                    qParams.Add("tor[cat][]", cat);
                }
            }
            else
            {
                qParams.Add("tor[cat][]", "0");
            }

            string urlSearch = SearchUrl;

            if (qParams.Count > 0)
            {
                urlSearch += $"?{qParams.GetQueryString()}";
            }

            var response = await RequestStringWithCookiesAndRetry(urlSearch);

            if (response.Status == System.Net.HttpStatusCode.Forbidden)
            {
                // re-login
                await ApplyConfiguration(null);

                response = await RequestStringWithCookiesAndRetry(urlSearch);
            }

            try
            {
                CQ  dom  = response.Content;
                var rows = dom["table[class='newTorTable'] > tbody > tr[id^=\"tdr\"]"];

                foreach (IDomObject row in rows)
                {
                    CQ torrentData = row.OuterHTML;
                    CQ cells       = row.Cq().Find("td");

                    string tid       = torrentData.Attr("id").Substring(4);
                    var    qTitle    = torrentData.Find("a[class='title']").First();
                    string title     = qTitle.Text().Trim();
                    var    details   = new Uri(SiteLink + qTitle.Attr("href"));
                    string author    = torrentData.Find("a[class='author']").First().Text().Trim();
                    Uri    link      = new Uri(SiteLink + "tor/download.php?tid=" + tid); // DL Link is no long available directly, build it ourself
                    long   files     = ParseUtil.CoerceLong(cells.Elements.ElementAt(4).Cq().Find("a").Text());
                    long   size      = ReleaseInfo.GetBytes(cells.Elements.ElementAt(4).Cq().Text().Split('[')[1].TrimEnd(']'));
                    int    seeders   = ParseUtil.CoerceInt(cells.Elements.ElementAt(6).Cq().Find("p").ElementAt(0).Cq().Text());
                    int    leechers  = ParseUtil.CoerceInt(cells.Elements.ElementAt(6).Cq().Find("p").ElementAt(1).Cq().Text());
                    long   grabs     = ParseUtil.CoerceLong(cells.Elements.ElementAt(6).Cq().Find("p").ElementAt(2).Cq().Text());
                    bool   freeleech = torrentData.Find("img[alt=\"freeleech\"]").Any();

                    string   pubDateStr  = cells.Elements.ElementAt(5).Cq().Text().Split('[')[0];
                    DateTime publishDate = DateTime.Parse(pubDateStr).ToLocalTime();

                    long   category = 0;
                    string cat      = torrentData.Find("a[class='newCatLink']").First().Attr("href").Remove(0, "/tor/browse.php?tor[cat][]]=".Length);
                    long.TryParse(cat, out category);

                    var release = new ReleaseInfo();

                    release.Title           = String.IsNullOrEmpty(author) ? title : String.Format("{0} by {1}", title, author);
                    release.Guid            = link;
                    release.Link            = link;
                    release.PublishDate     = publishDate;
                    release.Files           = files;
                    release.Size            = size;
                    release.Description     = release.Title;
                    release.Seeders         = seeders;
                    release.Peers           = seeders + leechers;
                    release.Grabs           = grabs;
                    release.MinimumRatio    = 1;
                    release.MinimumSeedTime = 172800;
                    release.Category        = MapTrackerCatToNewznab(category.ToString());
                    release.Comments        = details;

                    if (freeleech)
                    {
                        release.DownloadVolumeFactor = 0;
                    }
                    else
                    {
                        release.DownloadVolumeFactor = 1;
                    }

                    release.UploadVolumeFactor = 1;

                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(response.Content, ex);
            }

            return(releases);
        }
示例#16
0
        protected override async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            var releases        = new List <ReleaseInfo>();
            var searchurls      = new List <string>();
            var searchUrl       = SearchUrl;// string.Format(SearchUrl, HttpUtility.UrlEncode()));
            var queryCollection = new NameValueCollection();
            var searchString    = query.GetQueryString();

            foreach (var cat in MapTorznabCapsToTrackers(query))
            {
                searchUrl += "category%5B%5D=" + cat + "&";
            }

            if (query.ImdbID != null)
            {
                queryCollection.Add("search", query.ImdbID);
            }
            else if (!string.IsNullOrWhiteSpace(searchString))
            {
                queryCollection.Add("search", searchString);
            }

            queryCollection.Add("active", "0");
            queryCollection.Add("options", "0");

            searchUrl += queryCollection.GetQueryString().Replace("(", "%28").Replace(")", "%29"); // maually url encode brackets to prevent "hacking" detection

            var results = await RequestStringWithCookiesAndRetry(searchUrl);

            try
            {
                CQ          dom = results.Content;
                ReleaseInfo release;

                CQ     userInfo = dom[".mainmenu > table > tbody > tr:has(td[title=\"Active-Torrents\"])"][0].Cq();
                string rank     = userInfo.Find("td:nth-child(2)").Text().Substring(6);

                HashSet <string> freeleechRanks = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                freeleechRanks.Add("VIP");
                freeleechRanks.Add("Uploader");
                freeleechRanks.Add("HD Internal");
                freeleechRanks.Add("Moderator");
                freeleechRanks.Add("Administrator");
                freeleechRanks.Add("Owner");
                bool hasFreeleech = freeleechRanks.Contains(rank);

                var rows = dom[".mainblockcontenttt > tbody > tr:has(a[href^=\"details.php?id=\"])"];
                foreach (var row in rows)
                {
                    CQ qRow = row.Cq();

                    release = new ReleaseInfo();

                    release.Title       = qRow.Find("td.mainblockcontent b a").Text();
                    release.Description = qRow.Find("td:nth-child(3) > span").Text();

                    release.MinimumRatio    = 1;
                    release.MinimumSeedTime = 172800; // 48 hours

                    int tdIndex = 0;
                    if (qRow.Find("td:nth-last-child(1)").Text() == "Edit")
                    {
                        tdIndex = 1;
                    }
                    // moderators get additional delete, recomend and like links
                    if (qRow.Find("td:nth-last-child(4)").Text() == "Edit")
                    {
                        tdIndex = 4;
                    }

                    // Sometimes the uploader column is missing
                    if (ParseUtil.TryCoerceInt(qRow.Find($"td:nth-last-child({tdIndex + 3})").Text(), out int seeders))
                    {
                        release.Seeders = seeders;
                        if (ParseUtil.TryCoerceInt(qRow.Find($"td:nth-last-child({tdIndex + 2})").Text(), out int peers))
                        {
                            release.Peers = peers + release.Seeders;
                        }
                    }

                    // Sometimes the grabs column is missing
                    if (ParseUtil.TryCoerceLong(qRow.Find($"td:nth-last-child({tdIndex + 1})").Text(), out long grabs))
                    {
                        release.Grabs = grabs;
                    }

                    string fullSize = qRow.Find("td.mainblockcontent").Get(6).InnerText;
                    release.Size = ReleaseInfo.GetBytes(fullSize);

                    release.Guid     = new Uri(SiteLink + qRow.Find("td.mainblockcontent b a").Attr("href"));
                    release.Link     = new Uri(SiteLink + qRow.Find("td.mainblockcontent").Get(3).FirstChild.GetAttribute("href"));
                    release.Comments = new Uri(SiteLink + qRow.Find("td.mainblockcontent b a").Attr("href"));

                    string[] dateSplit  = qRow.Find("td.mainblockcontent").Get(5).InnerHTML.Split(',');
                    string   dateString = dateSplit[1].Substring(0, dateSplit[1].IndexOf('>')).Trim();
                    release.PublishDate = DateTime.ParseExact(dateString, "dd MMM yyyy HH:mm:ss zz00", CultureInfo.InvariantCulture).ToLocalTime();

                    string category = qRow.Find("td:eq(0) a").Attr("href").Replace("torrents.php?category=", "");
                    release.Category = MapTrackerCatToNewznab(category);

                    release.UploadVolumeFactor = 1;

                    if (qRow.Find("img[alt=\"Free Torrent\"]").Length >= 1)
                    {
                        release.DownloadVolumeFactor = 0;
                        release.UploadVolumeFactor   = 0;
                    }
                    else if (hasFreeleech)
                    {
                        release.DownloadVolumeFactor = 0;
                    }
                    else if (qRow.Find("img[alt=\"Silver Torrent\"]").Length >= 1)
                    {
                        release.DownloadVolumeFactor = 0.5;
                    }
                    else if (qRow.Find("img[alt=\"Bronze Torrent\"]").Length >= 1)
                    {
                        release.DownloadVolumeFactor = 0.75;
                    }
                    else if (qRow.Find("img[alt=\"Blue Torrent\"]").Length >= 1)
                    {
                        release.DownloadVolumeFactor = 0.25;
                    }
                    else
                    {
                        release.DownloadVolumeFactor = 1;
                    }

                    var imdblink = qRow.Find("a[href*=\"www.imdb.com/title/\"]").Attr("href");
                    release.Imdb = ParseUtil.GetLongFromString(imdblink);

                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(results.Content, ex);
            }

            return(releases);
        }
示例#17
0
        protected override async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            var releases     = new List <ReleaseInfo>();
            var searchUrl    = BrowseUrl;
            var searchString = query.GetQueryString();

            var    cats = MapTorznabCapsToTrackers(query);
            string cat  = "0";

            if (cats.Count == 1)
            {
                cat = cats[0];
            }

            var queryCollection = new NameValueCollection();

            if (query.ImdbID != null)
            {
                queryCollection.Add("search", query.ImdbID);
            }
            else if (!string.IsNullOrWhiteSpace(searchString))
            {
                queryCollection.Add("search", searchString);
            }

            queryCollection.Add("cat", cat);
            queryCollection.Add("searchin", "0");
            queryCollection.Add("sort", "0");

            searchUrl += "?" + queryCollection.GetQueryString();

            var response = await RequestStringWithCookiesAndRetry(searchUrl, null, BrowseUrl);

            // Occasionally the cookies become invalid, login again if that happens
            if (response.IsRedirect)
            {
                await ApplyConfiguration(null);

                response = await RequestStringWithCookiesAndRetry(searchUrl, null, BrowseUrl);
            }

            var results = response.Content;

            try
            {
                CQ  dom             = results;
                var globalFreeLeech = dom.Find("div.globalFreeLeech").Any();
                var rows            = dom[".torrentrow"];
                foreach (var row in rows)
                {
                    var release    = new ReleaseInfo();
                    var qRow       = row.Cq();
                    var qTitleLink = qRow.Find(".torrenttable:eq(1) a").First();
                    release.Title = qRow.Find(".torrenttable:eq(1) b").Text();
                    var longtitle = qRow.Find(".torrenttable:eq(1) a[title]").Attr("title");
                    if (!string.IsNullOrEmpty(longtitle) && !longtitle.Contains("<")) // releases with cover image have no full title
                    {
                        release.Title = longtitle;
                    }

                    if (query.ImdbID == null && !query.MatchQueryStringAND(release.Title))
                    {
                        continue;
                    }

                    release.Description = qRow.Find(".torrenttable:eq(1) > span > font.small").First().Text();

                    var tooltip = qTitleLink.Attr("title");
                    if (!string.IsNullOrEmpty(tooltip))
                    {
                        var ImgRegexp      = new Regex("src='(.*?)'");
                        var ImgRegexpMatch = ImgRegexp.Match(tooltip);
                        if (ImgRegexpMatch.Success)
                        {
                            release.BannerUrl = new Uri(ImgRegexpMatch.Groups[1].Value);
                        }
                    }

                    release.Guid     = new Uri(SiteLink + qTitleLink.Attr("href"));
                    release.Comments = release.Guid;

                    //22:05:3716/02/2013
                    var dateStr = qRow.Find(".torrenttable:eq(5)").Text().Trim() + " +0200";
                    release.PublishDate = DateTime.ParseExact(dateStr, "H:mm:ssdd/MM/yyyy zzz", CultureInfo.InvariantCulture);

                    var qLink = qRow.Find("a[href^=\"download.php?id=\"]").First();
                    release.Link = new Uri(SiteLink + qLink.Attr("href").Replace("&usetoken=1", ""));

                    var sizeStr = qRow.Find(".torrenttable:eq(6)").Text().Trim();
                    release.Size = ReleaseInfo.GetBytes(sizeStr);

                    release.Seeders = ParseUtil.CoerceInt(qRow.Find(".torrenttable:eq(8)").Text().Trim());
                    release.Peers   = ParseUtil.CoerceInt(qRow.Find(".torrenttable:eq(9)").Text().Trim()) + release.Seeders;

                    var catId = qRow.Find(".torrenttable:eq(0) a").First().Attr("href").Substring(15);
                    release.Category = MapTrackerCatToNewznab(catId);

                    var grabs = qRow.Find(".torrenttable:eq(7)").First().Get(0).FirstChild;
                    release.Grabs = ParseUtil.CoerceLong(catId);

                    if (globalFreeLeech || row.Cq().Find("img[alt=\"FreeLeech\"]").Any())
                    {
                        release.DownloadVolumeFactor = 0;
                    }
                    else
                    {
                        release.DownloadVolumeFactor = 1;
                    }

                    release.UploadVolumeFactor = 1;

                    // Skip Romanian releases
                    if (release.Category.Contains(TorznabCatType.MoviesForeign.ID) && !configData.IncludeRomanianReleases.Value)
                    {
                        continue;
                    }

                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(results, ex);
            }

            return(releases);
        }
示例#18
0
        internal static async Task DownloadMetadataAsync(
            string baseUrl, int startIndex, int count,
            string entryJsonPath, string x265JsonPath, string h264JsonPath, string ytsJsonPath, string libraryJsonPath,
            Action <string>?log = null)
        {
            log ??= message => Trace.WriteLine(message);
            List <string> entryLinks = new();

            using WebClient webClient = new();
            await Enumerable
            .Range(startIndex, count)
            .Select(index => $"{baseUrl}/page/{index}/")
            .ForEachAsync(async url =>
            {
                try
                {
                    string html = await Retry.FixedIntervalAsync(async() => await webClient.DownloadStringTaskAsync(url));
                    CQ listCQ   = html;
                    log($"Done {url}");
                    listCQ
                    .Find("h1.entry-title a")
                    .Select(entryLink => entryLink.GetAttribute("href"))
                    .ForEach(entryLinks.Add);
                }
                catch (Exception exception) when(exception.IsNotCritical())
                {
                    log(exception.ToString());
                }
            });

            ConcurrentDictionary <string, EntryMetadata> entryMetadata = new();
            await entryLinks.ParallelForEachAsync(async entryLink =>
            {
                using WebClient webClient = new();
                try
                {
                    string html  = await Retry.FixedIntervalAsync(async() => await webClient.DownloadStringTaskAsync(entryLink));
                    CQ entryCQ   = html;
                    string title = entryCQ.Find("h1.entry-title").Text().Trim();
                    log($"Done {title} {entryLink}");
                    entryMetadata[entryLink] = new EntryMetadata(
                        title,
                        entryCQ.Find("div.entry-content").Html());
                }
                catch (Exception exception) when(exception.IsNotCritical())
                {
                    log(exception.ToString());
                }
            }, 4);

            string jsonString = JsonSerializer.Serialize(entryMetadata, new() { WriteIndented = true });
            await File.WriteAllTextAsync(entryJsonPath, jsonString);

            Dictionary <string, RarbgMetadata[]> x265Metadata = JsonSerializer.Deserialize <Dictionary <string, RarbgMetadata[]> >(await File.ReadAllTextAsync(x265JsonPath)) !;
            Dictionary <string, RarbgMetadata[]> h264Metadata = JsonSerializer.Deserialize <Dictionary <string, RarbgMetadata[]> >(await File.ReadAllTextAsync(h264JsonPath)) !;
            Dictionary <string, YtsMetadata[]>   ytsMetadata  = JsonSerializer.Deserialize <Dictionary <string, YtsMetadata[]> >(await File.ReadAllTextAsync(ytsJsonPath)) !;
            Dictionary <string, Dictionary <string, VideoMetadata> > libraryMetadata = JsonSerializer.Deserialize <Dictionary <string, Dictionary <string, VideoMetadata> > >(await File.ReadAllTextAsync(libraryJsonPath)) !;

            entryMetadata
            .SelectMany(entry => Regex
                        .Matches(entry.Value.Content, "imdb.com/title/(tt[0-9]+)")
                        .Where(match => match.Success)
                        .Select(match => (Link: entry.Key, match.Groups[1].Value)))
            .Distinct(imdbId => imdbId.Value)
            .ForEach(imdbId =>
            {
                if (libraryMetadata.ContainsKey(imdbId.Value) && libraryMetadata[imdbId.Value].Any())
                {
                    libraryMetadata[imdbId.Value].ForEach(video => log(video.Key));
                    log(string.Empty);
                    return;
                }

                if (x265Metadata.ContainsKey(imdbId.Value))
                {
                    log(imdbId.Link);
                    x265Metadata[imdbId.Value].ForEach(metadata => log($"{metadata.Link} {metadata.Title}"));
                    log(string.Empty);
                    return;
                }

                if (h264Metadata.ContainsKey(imdbId.Value))
                {
                    log(imdbId.Link);
                    h264Metadata[imdbId.Value].ForEach(metadata => log($"{metadata.Link} {metadata.Title}"));
                    log(string.Empty);
                    return;
                }

                if (ytsMetadata.ContainsKey(imdbId.Value))
                {
                    log(imdbId.Link);
                    ytsMetadata[imdbId.Value].ForEach(metadata => log($"{metadata.Link} {metadata.Title}"));
                    log(string.Empty);
                }
            });
        }
示例#19
0
        private static async Task DownloadMetadataAsync(string url, string jsonPath, ConcurrentDictionary <string, RarbgMetadata[]> allSummaries, int partitionIndex, Func <int, bool>? @continue = null)
        {
            @continue ??= _ => true;
            try
            {
                using IWebDriver webDriver = WebDriverHelper.Start(@$ "D:\Temp\Chrome Profile {partitionIndex}");
                webDriver.Url = url;
                new WebDriverWait(webDriver, WebDriverHelper.DefaultWait).Until(e => e.FindElement(By.Id("pager_links")));
                webDriver.Url = url;
                IWebElement pager     = new WebDriverWait(webDriver, TimeSpan.FromSeconds(100)).Until(e => e.FindElement(By.Id("pager_links")));
                int         pageIndex = 1;
                do
                {
                    if (!@continue(pageIndex))
                    {
                        break;
                    }

                    await Task.Delay(WebDriverHelper.DefaultDomWait);

                    Trace.WriteLine($"{partitionIndex}:{pageIndex} Start {webDriver.Url}");

                    CQ page = webDriver.PageSource;
                    page
                    .Find("table.lista2t tr.lista2")
                    .Select(row =>
                    {
                        CQ cells       = row.Cq().Children();
                        string[] texts = cells.Eq(1).Text().Trim().Split("  ", StringSplitOptions.RemoveEmptyEntries).Where(text => !string.IsNullOrWhiteSpace(text)).ToArray();
                        string title   = texts[0].Trim();
                        CQ links       = cells.Eq(1).Find("a");
                        string baseUrl = new Uri(webDriver.Url).GetLeftPart(UriPartial.Authority);
                        string link    = $"{baseUrl}{links[0].GetAttribute("href")}";
                        string imdbId  = links.Length > 1
                                ? links[1].GetAttribute("href").Replace("/torrents.php?imdb=", string.Empty).Trim()
                                : string.Empty;

                        string[] genres   = new string[0];
                        string imdbRating = string.Empty;
                        if (texts.Length > 1)
                        {
                            string[] descriptions = texts[1].Trim().Split(" IMDB: ");
                            if (descriptions.Length > 0)
                            {
                                genres = descriptions[0].Split(", ").Select(genre => genre.Trim()).ToArray();
                            }

                            if (descriptions.Length > 1)
                            {
                                imdbRating = descriptions[1].Replace("/10", string.Empty).Trim();
                            }
                        }

                        string image = links[0].GetAttribute("onmouseover")?.Replace(@"return overlib('<img src=\'", string.Empty).Replace(@"\' border=0>')", string.Empty) ?? string.Empty;
                        int seed     = int.TryParse(cells.Eq(4).Text().Trim(), out int seedValue) ? seedValue : -1;
                        int leech    = int.TryParse(cells.Eq(5).Text().Trim(), out int leechValue) ? leechValue : -1;
                        return(new RarbgMetadata(link, title, imdbId, imdbRating, genres, image, cells.Eq(2).Text().Trim(), cells.Eq(3).Text().Trim(), seed, leech, cells.Eq(7).Text().Trim()));
                    })
                    .ForEach(summary =>
                    {
                        lock (AddItemLock)
                        {
                            allSummaries[summary.ImdbId] = allSummaries.ContainsKey(summary.ImdbId)
                                    ? allSummaries[summary.ImdbId].Where(existing => !string.Equals(existing.Title, summary.Title, StringComparison.OrdinalIgnoreCase)).Append(summary).ToArray()
                                    : new[] { summary };
                        }
                    });

                    if (pageIndex++ % SaveFrequency == 0)
                    {
                        SaveJson(jsonPath, allSummaries);
                    }

                    Trace.WriteLine($"{partitionIndex}:{pageIndex} End {webDriver.Url}");
                } while (webDriver.HasNextPage(ref pager));

                webDriver.Close();
                webDriver.Quit();
            }
            catch (Exception exception)
            {
                Trace.WriteLine(exception);
            }
            finally
            {
                SaveJson(jsonPath, allSummaries);
            }
        }
示例#20
0
        public async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            TimeZoneInfo.TransitionTime startTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 3, 0, 0), 3, 5, DayOfWeek.Sunday);
            TimeZoneInfo.TransitionTime endTransition   = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 4, 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 germanyTz = TimeZoneInfo.CreateCustomTimeZone("W. Europe Standard Time", new TimeSpan(1, 0, 0), "(GMT+01:00) W. Europe Standard Time", "W. Europe Standard Time", "W. Europe DST Time", adjustments);

            var releases = new List <ReleaseInfo>();

            var searchString    = query.GetQueryString();
            var searchUrl       = BrowseUrl;
            var queryCollection = new NameValueCollection();

            queryCollection.Add("showsearch", "1");
            queryCollection.Add("incldead", "1");
            queryCollection.Add("orderby", "added");
            queryCollection.Add("sort", "desc");

            if (!string.IsNullOrWhiteSpace(searchString))
            {
                queryCollection.Add("search", searchString);
            }

            foreach (var cat in MapTorznabCapsToTrackers(query))
            {
                queryCollection.Add("c" + cat, "1");
            }
            searchUrl += "?" + queryCollection.GetQueryString();

            var response = await RequestStringWithCookies(searchUrl);

            var results = response.Content;

            try
            {
                CQ  dom             = results;
                var globalFreeleech = dom.Find("div > img[alt=\"Only Upload\"][title^=\"ONLY UPLOAD \"]").Any();
                var rows            = dom["table.tableinborder > tbody > tr:has(td.tableb)"];

                foreach (var row in rows)
                {
                    var release = new ReleaseInfo();
                    var qRow    = row.Cq();

                    var qDetailsLink = qRow.Find("a[href^=details.php?id=]").First();
                    release.Title = qDetailsLink.Attr("title");

                    if (!query.MatchQueryStringAND(release.Title))
                    {
                        continue;
                    }

                    var qCatLink    = qRow.Find("a[href^=browse.php?cat=]").First();
                    var qDLLink     = qRow.Find("a[href^=download.php?torrent=]").First();
                    var qSeeders    = qRow.Find("span:contains(Seeder) > b:eq(0)");
                    var qLeechers   = qRow.Find("span:contains(Seeder) > b:eq(1)");
                    var qDateStr    = qRow.Find("td > table > tbody > tr > td:eq(7)").First();
                    var qSize       = qRow.Find("span:contains(Volumen) > b:eq(0)").First();
                    var qOnlyUpload = qRow.Find("img[title=OnlyUpload]");

                    if (qOnlyUpload.Any())
                    {
                        release.MinimumRatio    = 2;
                        release.MinimumSeedTime = 144 * 60 * 60;
                    }
                    else
                    {
                        release.MinimumRatio    = 1;
                        release.MinimumSeedTime = 72 * 60 * 60;
                    }

                    var catStr = qCatLink.Attr("href").Split('=')[1];
                    release.Category = MapTrackerCatToNewznab(catStr);

                    release.Link     = new Uri(SiteLink + qDLLink.Attr("href"));
                    release.Comments = new Uri(SiteLink + qDetailsLink.Attr("href"));
                    release.Guid     = release.Link;

                    var sizeStr = qSize.Text();
                    release.Size = ReleaseInfo.GetBytes(sizeStr);

                    release.Seeders = ParseUtil.CoerceInt(qSeeders.Text());
                    release.Peers   = ParseUtil.CoerceInt(qLeechers.Text()) + release.Seeders;

                    var      dateStr    = qDateStr.Text().Trim().Replace('\xA0', ' ');
                    DateTime dateGerman = DateTime.SpecifyKind(DateTime.ParseExact(dateStr, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture), DateTimeKind.Unspecified);

                    DateTime pubDateUtc = TimeZoneInfo.ConvertTimeToUtc(dateGerman, germanyTz);
                    release.PublishDate = pubDateUtc.ToLocalTime();

                    var files = qRow.Find("a[href*=\"&filelist=1\"] ~ font ~ b").Text();
                    release.Files = ParseUtil.CoerceInt(files);

                    var grabs = qRow.Find("a[href*=\"&tosnatchers=1\"] ~ font ~ b").Text();
                    release.Grabs = ParseUtil.CoerceInt(grabs);

                    if (globalFreeleech)
                    {
                        release.DownloadVolumeFactor = 0;
                    }
                    else if (qRow.Find("img[alt=\"OU\"]").Length >= 1)
                    {
                        release.DownloadVolumeFactor = 0;
                    }
                    else
                    {
                        release.DownloadVolumeFactor = 1;
                    }

                    release.UploadVolumeFactor = 1;

                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(results, ex);
            }

            return(releases);
        }
示例#21
0
        public async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            TimeZoneInfo.TransitionTime startTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 2, 0, 0), 3, 2, DayOfWeek.Sunday);
            TimeZoneInfo.TransitionTime endTransition   = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 2, 0, 0), 11, 1, 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 easternTz = TimeZoneInfo.CreateCustomTimeZone("Eastern Time", new TimeSpan(-5, 0, 0), "(GMT-05:00) Eastern Time", "Eastern Standard Time", "Eastern Daylight Time", adjustments);

            var releases = new List <ReleaseInfo>();

            var    categoryMapping = MapTorznabCapsToTrackers(query).Distinct();
            string category        = "0"; // Aka all

            if (categoryMapping.Count() == 1)
            {
                category = categoryMapping.First();
            }

            var episodeSearchUrl = string.Format(SearchUrl, category, HttpUtility.UrlEncode(query.GetQueryString()));
            var response         = await RequestStringWithCookiesAndRetry(episodeSearchUrl);

            try
            {
                CQ  dom  = response.Content;
                var rows = dom["table.table-condensed.table-striped.table-bordered:first"].Find("tbody > tr");

                foreach (var row in rows)
                {
                    CQ  qRow    = row.Cq();
                    var release = new ReleaseInfo();

                    release.MinimumRatio    = 1;
                    release.MinimumSeedTime = 172800;

                    release.Title    = qRow.Find("a[class='torrent-filename']").Text().Trim();
                    release.Comments = new Uri(qRow.Find("a[class='torrent-filename']").Attr("href"));
                    release.Guid     = release.Comments;

                    release.Link = new Uri(qRow.Find("a[class='torrent-download-icon']").Attr("href"));

                    //05 Aug 2016 01:08
                    var      dateString  = row.ChildElements.ElementAt(3).Cq().Find("span").Attr("title");
                    DateTime pubDateSite = DateTime.SpecifyKind(DateTime.ParseExact(dateString, "dd MMM yyyy HH:mm", CultureInfo.InvariantCulture), DateTimeKind.Unspecified);
                    release.PublishDate = TimeZoneInfo.ConvertTimeToUtc(pubDateSite, easternTz).ToLocalTime();

                    var sizeStr = row.ChildElements.ElementAt(5).Cq().Text().Trim();
                    release.Size = ReleaseInfo.GetBytes(sizeStr);

                    release.Seeders = ParseUtil.CoerceInt(row.ChildElements.ElementAt(6).Cq().Text().Trim());
                    release.Peers   = ParseUtil.CoerceInt(row.ChildElements.ElementAt(7).Cq().Text().Trim()) + release.Seeders;

                    int cat        = 0;
                    var catElement = qRow.Find("i[class$='torrent-icon']");

                    if (catElement.Length == 1)
                    {
                        string catName = catElement.Attr("title").Trim();

                        if (catName.StartsWith("TV"))
                        {
                            cat = TvCategoryParser.ParseTvShowQuality(release.Title);
                        }
                        if (catName.StartsWith("Music"))
                        {
                            cat = TorznabCatType.Audio.ID;
                        }
                        if (catName.StartsWith("Movie"))
                        {
                            cat = TorznabCatType.Movies.ID;
                        }
                    }

                    release.Category = cat;
                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(response.Content, ex);
            }
            return(releases);
        }
示例#22
0
        protected override async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            var releases     = new List <ReleaseInfo>();
            var searchString = query.GetQueryString();

            // search in normal + gems view
            foreach (var view in new string[] { "0", "1" })
            {
                var queryCollection = new NameValueCollection();

                queryCollection.Add("view", view);
                queryCollection.Add("searchtype", "1");
                queryCollection.Add("incldead", "1");
                if (!string.IsNullOrWhiteSpace(searchString))
                {
                    queryCollection.Add("search", searchString);
                }

                foreach (var cat in MapTorznabCapsToTrackers(query))
                {
                    queryCollection.Add(string.Format("c{0}", cat), "1");
                }

                var searchUrl = SearchUrl + "?" + queryCollection.GetQueryString();

                var results = await RequestStringWithCookiesAndRetry(searchUrl);

                if (results.IsRedirect)
                {
                    // re-login
                    await ApplyConfiguration(null);

                    results = await RequestStringWithCookiesAndRetry(searchUrl);
                }

                try
                {
                    CQ  dom  = results.Content;
                    var rows = dom["#torrentBrowse > table > tbody > tr"];
                    foreach (var row in rows.Skip(1))
                    {
                        var release = new ReleaseInfo();
                        CQ  qRow    = row.Cq();

                        release.MinimumRatio    = 0;
                        release.MinimumSeedTime = 2 * 24 * 60 * 60;

                        var qLink = qRow.Find("a[title][href^=\"details.php?id=\"]");
                        release.Title    = qLink.Attr("title");
                        release.Guid     = new Uri(SiteLink + qLink.Attr("href").TrimStart('/'));
                        release.Comments = release.Guid;

                        qLink        = qRow.Children().ElementAt(3).Cq().Children("a").First();
                        release.Link = new Uri(string.Format("{0}{1}", SiteLink, qLink.Attr("href")));

                        var catUrl = qRow.Children().ElementAt(0).FirstElementChild.Cq().Attr("href");
                        var catNum = catUrl.Split(new char[] { '=', '&' })[2].Replace("c", "");
                        release.Category = MapTrackerCatToNewznab(catNum);

                        var dateString = qRow.Children().ElementAt(6).Cq().Text().Trim();
                        if (dateString.Contains("ago"))
                        {
                            release.PublishDate = DateTimeUtil.FromTimeAgo(dateString);
                        }
                        else
                        {
                            release.PublishDate = DateTime.ParseExact(dateString, "yyyy-MM-ddHH:mm:ss", CultureInfo.InvariantCulture);
                        }

                        var sizeStr = qRow.Children().ElementAt(7).Cq().Text().Split(new char[] { '/' })[0];
                        release.Size = ReleaseInfo.GetBytes(sizeStr);

                        release.Seeders = ParseUtil.CoerceInt(qRow.Children().ElementAt(8).Cq().Text().Split(new char[] { '/' })[0].Trim());
                        release.Peers   = ParseUtil.CoerceInt(qRow.Children().ElementAt(8).Cq().Text().Split(new char[] { '/' })[1].Trim()) + release.Seeders;
                        release.Files   = ParseUtil.CoerceLong(qRow.Find("td:nth-child(5)").Text());
                        release.Grabs   = ParseUtil.CoerceLong(qRow.Find("a[href^=\"snatches.php?id=\"]").Text().Split(' ')[0]);

                        release.DownloadVolumeFactor = 0;
                        release.UploadVolumeFactor   = 1;

                        var desc = qRow.Find("td:nth-child(2)");
                        desc.Find("a").Remove();
                        desc.Find("small").Remove(); // Remove release name (if enabled in the user cp)
                        release.Description = desc.Text().Trim(new char[] { '-', ' ' });

                        releases.Add(release);
                    }
                }
                catch (Exception ex)
                {
                    OnParseError(results.Content, ex);
                }
            }

            return(releases);
        }
示例#23
0
文件: x264.cs 项目: y3ff/Jackett
        protected override async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            List <ReleaseInfo> releases = new List <ReleaseInfo>();

            var searchString    = query.GetQueryString();
            var searchUrl       = SearchUrl;
            var queryCollection = new NameValueCollection();

            queryCollection.Add("incldead", "1");
            queryCollection.Add("xtype", "0");
            queryCollection.Add("stype", "0");

            if (query.ImdbID != null)
            {
                queryCollection.Add("search", query.ImdbID);
            }
            else if (!string.IsNullOrWhiteSpace(searchString))
            {
                queryCollection.Add("search", searchString);
            }

            foreach (var cat in MapTorznabCapsToTrackers(query))
            {
                queryCollection.Add("c" + cat, "1");
            }

            searchUrl += "?" + queryCollection.GetQueryString();

            var results = await RequestStringWithCookiesAndRetry(searchUrl);

            try
            {
                CQ dom = results.Content;

                var sideWideFreeLeech = false;
                if (dom.Find("td > b > font[color=\"white\"]:contains(Free Leech)").Length >= 1)
                {
                    sideWideFreeLeech = true;
                }

                var rows = dom["table > tbody > tr[height=36]"];
                foreach (var row in rows)
                {
                    var release = new ReleaseInfo();
                    release.MinimumRatio    = 1;
                    release.MinimumSeedTime = 7 * 24 * 60 * 60;

                    var qRow          = row.Cq();
                    var qCatLink      = qRow.Find("a[href^=?cat]").First();
                    var qDetailsLink  = qRow.Find("a[href^=details.php]").First();
                    var qSeeders      = qRow.Find("td:eq(8)");
                    var qLeechers     = qRow.Find("td:eq(9)");
                    var qDownloadLink = qRow.Find("a[href^=\"download.php\"]").First();
                    var qImdbLink     = qRow.Find("a[href^=/redir.php?url=http://www.imdb.com]");
                    var qSize         = qRow.Find("td:eq(6)");

                    var catStr = qCatLink.Attr("href").Split('=')[1];
                    release.Category = MapTrackerCatToNewznab(catStr);

                    release.Link     = new Uri(SiteLink + qDownloadLink.Attr("href"));
                    release.Title    = qDetailsLink.Text().Trim();
                    release.Comments = new Uri(SiteLink + qDetailsLink.Attr("href"));
                    release.Guid     = release.Link;

                    var sizeStr = qSize.Text();
                    release.Size = ReleaseInfo.GetBytes(sizeStr);

                    if (qImdbLink.Length == 1)
                    {
                        var ImdbId = qImdbLink.Attr("href").Split('/').Last().Substring(2);
                        release.Imdb = ParseUtil.CoerceLong(ImdbId);
                    }

                    release.Seeders = ParseUtil.CoerceInt(qSeeders.Text());
                    release.Peers   = ParseUtil.CoerceInt(qLeechers.Text()) + release.Seeders;

                    var files = qRow.Find("td:nth-child(3)").Text();
                    release.Files = ParseUtil.CoerceInt(files);

                    var grabs = qRow.Find("td:nth-child(8)").Get(0).FirstChild.ToString();
                    release.Grabs = ParseUtil.CoerceInt(grabs);

                    if (sideWideFreeLeech || qRow.Find("font[color=\"red\"]:contains(FREE)").Length >= 1)
                    {
                        release.DownloadVolumeFactor = 0;
                    }
                    else
                    {
                        release.DownloadVolumeFactor = 1;
                    }
                    release.UploadVolumeFactor = 1;

                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(results.Content, ex);
            }

            return(releases);
        }
示例#24
0
        public async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            var releases     = new List <ReleaseInfo>();
            var searchString = query.GetQueryString();
            var searchUrl    = SearchUrl;

            // If query is empty, use the RSS Feed
            if (string.IsNullOrWhiteSpace(searchString))
            {
                var rssPage = await RequestStringWithCookiesAndRetry(RSSUrl + configData.RSSKey.Value);

                var rssDoc = XDocument.Parse(rssPage.Content);

                foreach (var item in rssDoc.Descendants("item"))
                {
                    var title       = item.Descendants("title").First().Value;
                    var description = item.Descendants("description").First().Value;
                    var link        = item.Descendants("link").First().Value;
                    var date        = item.Descendants("pubDate").First().Value;

                    var torrentIdMatch = Regex.Match(link, "(?<=download\\.php/)([a-zA-z0-9]*)");
                    var torrentId      = torrentIdMatch.Success ? torrentIdMatch.Value : string.Empty;
                    if (string.IsNullOrWhiteSpace(torrentId))
                    {
                        throw new Exception("Missing torrent id");
                    }

                    var infoMatch = Regex.Match(description, @"Category:\W(?<cat>.*)\W\n\WSize:\W(?<size>.*)\n\WStatus:\W(?<seeders>.*)\Wseeder(.*)\Wand\W(?<leechers>.*)\Wleecher(.*)\n\WAdded:\W(?<added>.*)\n\WDescription:");
                    if (!infoMatch.Success)
                    {
                        throw new Exception("Unable to find info");
                    }

                    var  imdbMatch = Regex.Match(description, "(?<=http://www.imdb.com/title/tt)([0-9]*)");
                    long?imdbID    = null;
                    if (imdbMatch.Success)
                    {
                        long l;
                        if (long.TryParse(imdbMatch.Value, out l))
                        {
                            imdbID = l;
                        }
                    }

                    var release = new ReleaseInfo()
                    {
                        Title       = title,
                        Description = title,
                        Guid        = new Uri(string.Format(DetailsURL, torrentId)),
                        Comments    = new Uri(string.Format(DetailsURL, torrentId) + "&tocomm=1"),
                        PublishDate = DateTime.ParseExact(infoMatch.Groups["added"].Value, "yyyy-MM-dd H:mm:ss", CultureInfo.InvariantCulture), //2015-08-08 21:20:31
                        Link        = new Uri(link),
                        Seeders     = ParseUtil.CoerceInt(infoMatch.Groups["seeders"].Value == "no" ? "0" : infoMatch.Groups["seeders"].Value),
                        Peers       = ParseUtil.CoerceInt(infoMatch.Groups["leechers"].Value == "no" ? "0" : infoMatch.Groups["leechers"].Value),
                        Size        = ReleaseInfo.GetBytes(infoMatch.Groups["size"].Value),
                        Category    = MapTrackerCatToNewznab(infoMatch.Groups["cat"].Value),
                        Imdb        = imdbID
                    };

                    //  if unknown category, set to "other"
                    if (release.Category.Count() == 0)
                    {
                        release.Category.Add(7000);
                    }

                    release.Peers += release.Seeders;
                    releases.Add(release);
                }
            }
            else
            {
                searchUrl += "?titleonly=1&search=" + HttpUtility.UrlEncode(searchString);
                string.Format(SearchUrl, HttpUtility.UrlEncode(searchString));

                var cats = MapTorznabCapsToTrackers(query);
                if (cats.Count > 0)
                {
                    foreach (var cat in cats)
                    {
                        searchUrl += "&c" + cat + "=1";
                    }
                }

                var results = await RequestStringWithCookiesAndRetry(searchUrl);

                try
                {
                    CQ dom = results.Content;

                    //  table header is the first <tr> in table body, get all rows except this
                    CQ qRows = dom["#torrents-table > tbody > tr:not(:first-child)"];

                    foreach (var row in qRows)
                    {
                        var release = new ReleaseInfo();

                        var qRow = row.Cq();

                        var debug = qRow.Html();

                        release.MinimumRatio    = 1;
                        release.MinimumSeedTime = 172800;

                        CQ qLink = qRow.Find(".br_right > a").First();
                        release.Guid        = new Uri(SiteLink + qLink.Attr("href"));
                        release.Comments    = new Uri(SiteLink + qLink.Attr("href") + "&tocomm=1");
                        release.Title       = qLink.Find("b").Text();
                        release.Description = release.Title;

                        var releaseLinkURI = qRow.Find("td:nth-child(4) > a").Attr("href");
                        release.Link = new Uri(SiteLink + releaseLinkURI);
                        if (releaseLinkURI != null)
                        {
                            var dateString = qRow.Find("td:nth-child(6) nobr")[0].TextContent.Trim();
                            //"2015-04-25 23:38:12"
                            //"yyyy-MMM-dd hh:mm:ss"
                            release.PublishDate = DateTime.ParseExact(dateString, "yyyy-MM-ddHH:mm:ss", CultureInfo.InvariantCulture);

                            var sizeStr = qRow.Children().ElementAt(6).InnerHTML.Trim();
                            sizeStr      = sizeStr.Substring(0, sizeStr.IndexOf('<'));
                            release.Size = ReleaseInfo.GetBytes(sizeStr);

                            release.Seeders = ParseUtil.CoerceInt(qRow.Find("td:nth-child(9)").Text());
                            release.Peers   = release.Seeders + ParseUtil.CoerceInt(qRow.Find("td:nth-child(10)").Text());

                            var category = qRow.Find(".br_type > a").Attr("href").Replace("browse.php?cat=", string.Empty);
                            release.Category = MapTrackerCatToNewznab(category);
                        }
                        releases.Add(release);
                    }
                }
                catch (Exception ex)
                {
                    OnParseError(results.Content, ex);
                }
            }

            return(releases);
        }
示例#25
0
        public async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            var releases        = new List <ReleaseInfo>();
            var searchurls      = new List <string>();
            var searchUrl       = SearchUrl;// string.Format(SearchUrl, HttpUtility.UrlEncode()));
            var queryCollection = new NameValueCollection();
            var searchString    = query.GetQueryString();


            foreach (var cat in MapTorznabCapsToTrackers(query))
            {
                searchUrl += "category%5B%5D=" + cat + "&";
            }


            if (query.ImdbID != null)
            {
                queryCollection.Add("search", query.ImdbID);
            }
            else if (!string.IsNullOrWhiteSpace(searchString))
            {
                queryCollection.Add("search", searchString);
            }



            queryCollection.Add("active", "0");
            queryCollection.Add("options", "0");

            searchUrl += queryCollection.GetQueryString().Replace("(", "%28").Replace(")", "%29"); // maually url encode brackets to prevent "hacking" detection


            var results = await RequestStringWithCookiesAndRetry(searchUrl);

            try
            {
                CQ          dom = results.Content;
                ReleaseInfo release;

                var rows = dom[".mainblockcontenttt > tbody > tr:has(a[href^=\"details.php?id=\"])"];
                foreach (var row in rows)
                {
                    CQ qRow = row.Cq();

                    release = new ReleaseInfo();

                    release.Title       = qRow.Find("td.mainblockcontent b a").Text();
                    release.Description = qRow.Find("td:nth-child(3) > span").Text();

                    if (0 != qRow.Find("td.mainblockcontent u").Length)
                    {
                        var  imdbStr = qRow.Find("td.mainblockcontent u").Parent().First().Attr("href").Replace("http://www.imdb.com/title/tt", "").Replace("/", "");
                        long imdb;
                        if (ParseUtil.TryCoerceLong(imdbStr, out imdb))
                        {
                            release.Imdb = imdb;
                        }
                    }

                    release.MinimumRatio    = 1;
                    release.MinimumSeedTime = 172800;



                    int seeders, peers;
                    if (ParseUtil.TryCoerceInt(qRow.Find("td").Get(9).FirstChild.FirstChild.InnerText, out seeders))
                    {
                        release.Seeders = seeders;
                        if (ParseUtil.TryCoerceInt(qRow.Find("td").Get(10).FirstChild.FirstChild.InnerText, out peers))
                        {
                            release.Peers = peers + release.Seeders;
                        }
                    }

                    release.Grabs = ParseUtil.CoerceLong(qRow.Find("td:nth-child(12)").Text());

                    string fullSize = qRow.Find("td.mainblockcontent").Get(6).InnerText;
                    release.Size = ReleaseInfo.GetBytes(fullSize);

                    release.Guid     = new Uri(SiteLink + qRow.Find("td.mainblockcontent b a").Attr("href"));
                    release.Link     = new Uri(SiteLink + qRow.Find("td.mainblockcontent").Get(3).FirstChild.GetAttribute("href"));
                    release.Comments = new Uri(SiteLink + qRow.Find("td.mainblockcontent b a").Attr("href"));

                    string[] dateSplit  = qRow.Find("td.mainblockcontent").Get(5).InnerHTML.Split(',');
                    string   dateString = dateSplit[1].Substring(0, dateSplit[1].IndexOf('>'));
                    release.PublishDate = DateTime.Parse(dateString, CultureInfo.InvariantCulture);

                    string category = qRow.Find("td:eq(0) a").Attr("href").Replace("torrents.php?category=", "");
                    release.Category = MapTrackerCatToNewznab(category);

                    release.UploadVolumeFactor = 1;

                    if (qRow.Find("img[alt=\"Free Torrent\"]").Length >= 1)
                    {
                        release.DownloadVolumeFactor = 0;
                        release.UploadVolumeFactor   = 0;
                    }
                    else if (qRow.Find("img[alt=\"Silver Torrent\"]").Length >= 1)
                    {
                        release.DownloadVolumeFactor = 0.5;
                    }
                    else if (qRow.Find("img[alt=\"Bronze Torrent\"]").Length >= 1)
                    {
                        release.DownloadVolumeFactor = 0.75;
                    }
                    else if (qRow.Find("img[alt=\"Blue Torrent\"]").Length >= 1)
                    {
                        release.DownloadVolumeFactor = 0.25;
                    }
                    else
                    {
                        release.DownloadVolumeFactor = 1;
                    }

                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(results.Content, ex);
            }

            return(releases);
        }
示例#26
0
        public async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            var releases   = new List <ReleaseInfo>();
            var searchurls = new List <string>();
            var searchUrl  = string.Format(SearchUrl, HttpUtility.UrlEncode(query.GetQueryString()));
            var results    = await RequestStringWithCookiesAndRetry(searchUrl);

            try
            {
                CQ          dom = results.Content;
                ReleaseInfo release;

                int rowCount = 0;
                var rows     = dom[".mainblockcontenttt > tbody > tr"];
                foreach (var row in rows)
                {
                    CQ qRow = row.Cq();
                    if (rowCount < 2 || qRow.Children().Count() != 12) //skip 2 rows because there's an empty row & a title/sort row
                    {
                        rowCount++;
                        continue;
                    }

                    release = new ReleaseInfo();

                    release.Title       = qRow.Find("td.mainblockcontent b a").Text();
                    release.Description = release.Title;

                    if (0 != qRow.Find("td.mainblockcontent u").Length)
                    {
                        var  imdbStr = qRow.Find("td.mainblockcontent u").Parent().First().Attr("href").Replace("http://www.imdb.com/title/tt", "").Replace("/", "");
                        long imdb;
                        if (ParseUtil.TryCoerceLong(imdbStr, out imdb))
                        {
                            release.Imdb = imdb;
                        }
                    }

                    release.MinimumRatio    = 1;
                    release.MinimumSeedTime = 172800;



                    int seeders, peers;
                    if (ParseUtil.TryCoerceInt(qRow.Find("td").Get(9).FirstChild.FirstChild.InnerText, out seeders))
                    {
                        release.Seeders = seeders;
                        if (ParseUtil.TryCoerceInt(qRow.Find("td").Get(10).FirstChild.FirstChild.InnerText, out peers))
                        {
                            release.Peers = peers + release.Seeders;
                        }
                    }

                    string fullSize = qRow.Find("td.mainblockcontent").Get(6).InnerText;
                    release.Size = ReleaseInfo.GetBytes(fullSize);

                    release.Guid     = new Uri(SiteLink + "/" + qRow.Find("td.mainblockcontent b a").Attr("href"));
                    release.Link     = new Uri(SiteLink + "/" + qRow.Find("td.mainblockcontent").Get(3).FirstChild.GetAttribute("href"));
                    release.Comments = new Uri(SiteLink + "/" + qRow.Find("td.mainblockcontent b a").Attr("href") + "#comments");

                    string[] dateSplit  = qRow.Find("td.mainblockcontent").Get(5).InnerHTML.Split(',');
                    string   dateString = dateSplit[1].Substring(0, dateSplit[1].IndexOf('>'));
                    release.PublishDate = DateTime.Parse(dateString, CultureInfo.InvariantCulture);

                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(results.Content, ex);
            }

            return(releases);
        }
示例#27
0
        void searchDate(string mess)
        {
            if (flag)
            {
                answ.Add("searchDate func started with string " + mess);
            }
            string urlMain = "http://www.cbr.ru/currency_base/daily/?UniDbQuery.Posted=True&UniDbQuery.To=";

            string[] inf = mess.Split(' ', 2);
            if (inf[0].Length != 3 && inf[1].Length != 10)
            {
                if (flag)
                {
                    answ.Add("wrong format for !цб search");
                }
            }
            else
            {
                if (Convert.ToInt32(inf[1].Substring(6, inf[1].Length - 6)) < 1993)
                {
                    answ.Add("Курсы волют предоставляются начиная с 1993 года");
                }
                for (int t = 0; t < 5; t++)
                {
                    if (inf[0] == val[t].Item1)
                    {
                        v2 = val[t].Item1;
                        answ.Add("Курс " + val[t].Item2 + " (" + val[t].Item1 + ")");
                    }
                }
                string curUrl = urlMain + inf[1];
                if (flag)
                {
                    answ.Add(curUrl);
                }
                CQ     dom0     = CQ.CreateFromUrl(curUrl);
                string realDate = "";
                foreach (IDomObject obj in dom0.Find("button"))
                {
                    if (obj.ClassName == "datepicker-filter_button")
                    {
                        realDate = obj.Cq().Text();
                        answ.Add("За " + realDate + " от Цб");
                        break;
                    }
                }
                int tr     = 0;
                int amount = 1;
                foreach (IDomObject obj in dom0.Find("td"))
                {
                    if (tr == 0)
                    {
                        if (obj.Cq().Text() == inf[0])
                        {
                            tr = 3;
                            continue;
                        }
                    }
                    if (tr == 3)
                    {
                        amount = Convert.ToInt32(obj.Cq().Text());
                        tr--;
                        continue;
                    }
                    if (tr == 2)
                    {
                        tr--;
                        continue;
                    }
                    if (tr == 1)
                    {
                        answ.Add(obj.Cq().Text() + " руб. за " + amount + " ед.");
                        if (realDate != inf[1])
                        {
                            answ.Add("Проверьте корректость введенных данных " + inf[1]);
                        }
                        break;
                    }
                }
            }
        }
示例#28
0
        public async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            var releases = new List <ReleaseInfo>();

            var    categoryMapping = MapTorznabCapsToTrackers(query).Distinct();
            string category        = "0"; // Aka all

            if (categoryMapping.Count() == 1)
            {
                category = categoryMapping.First();
            }


            var episodeSearchUrl = string.Format(SearchUrl, category, HttpUtility.UrlEncode(query.GetQueryString()));

            var response = await RequestStringWithCookiesAndRetry(episodeSearchUrl);

            try
            {
                CQ  dom  = response.Content;
                var rows = dom["table:has(thead) > tbody > tr"];
                foreach (var row in rows)
                {
                    CQ  qRow    = row.Cq();
                    var release = new ReleaseInfo();

                    release.MinimumRatio    = 1;
                    release.MinimumSeedTime = 172800;

                    var qLink = qRow.Find("a.torrent-filename");;
                    release.Title    = qLink.Text().Trim();
                    release.Comments = new Uri(qLink.Attr("href"));
                    release.Guid     = release.Comments;

                    var qDownload = qRow.Find("a.torrent-download-icon");;
                    release.Link = new Uri(qDownload.Attr("href"));

                    var dateStr = qRow.Find("td:eq(3) > span").Text().Trim();
                    release.PublishDate = DateTimeUtil.FromTimeAgo(dateStr);

                    var sizeStr = qRow.Find("td:eq(5) > span").Text().Trim();
                    release.Size = ReleaseInfo.GetBytes(sizeStr);

                    release.Seeders = ParseUtil.CoerceInt(qRow.Find("td:eq(6)").Text().Trim());
                    release.Peers   = ParseUtil.CoerceInt(qRow.Find("td:eq(7)").Text().Trim()) + release.Seeders;

                    var cat = row.Cq().Find("td:eq(0) i").First().Attr("class")
                              .Replace("torrent-icon", string.Empty)
                              .Replace("fa fa-", string.Empty)
                              .Replace("film", "1")
                              .Replace("tv", "2")
                              .Replace("music", "3")
                              .Replace("text-pink", string.Empty);
                    release.Category = MapTrackerCatToNewznab(cat.Trim());

                    var grabs = row.Cq().Find("td:nth-child(9)").Text();
                    release.Grabs = ParseUtil.CoerceInt(grabs);

                    if (row.Cq().Find("i.fa-star").Any())
                    {
                        release.DownloadVolumeFactor = 0;
                    }
                    else if (row.Cq().Find("i.fa-star-half-o").Any())
                    {
                        release.DownloadVolumeFactor = 0.5;
                    }
                    else
                    {
                        release.DownloadVolumeFactor = 1;
                    }

                    if (row.Cq().Find("i.fa-diamond").Any())
                    {
                        release.UploadVolumeFactor = 2;
                    }
                    else
                    {
                        release.UploadVolumeFactor = 1;
                    }

                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(response.Content, ex);
            }
            return(releases);
        }
示例#29
0
文件: SpeedCD.cs 项目: mordae/Jackett
        public async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            var releases = new List <ReleaseInfo>();

            NameValueCollection qParams = new NameValueCollection();

            if (!string.IsNullOrWhiteSpace(query.ImdbID))
            {
                qParams.Add("search", query.ImdbID);
                qParams.Add("d", "on");
            }
            else if (!string.IsNullOrEmpty(query.GetQueryString()))
            {
                qParams.Add("search", query.GetQueryString());
            }

            List <string> catList = MapTorznabCapsToTrackers(query);

            foreach (string cat in catList)
            {
                qParams.Add("c" + cat, "1");
            }

            string urlSearch = SearchUrl;

            if (qParams.Count > 0)
            {
                urlSearch += $"?{qParams.GetQueryString()}";
            }

            var response = await RequestStringWithCookiesAndRetry(urlSearch);

            if (!response.Content.Contains("/logout.php"))
            {
                //Cookie appears to expire after a period of time or logging in to the site via browser
                await DoLogin();

                response = await RequestStringWithCookiesAndRetry(urlSearch);
            }

            try
            {
                CQ  dom  = response.Content;
                var rows = dom["div[id='torrentTable'] > div[class='box torrentBox'] > div[class='boxContent'] > table > tbody > tr"];

                foreach (IDomObject row in rows)
                {
                    CQ torrentData = row.OuterHTML;
                    CQ cells       = row.Cq().Find("td");

                    string title    = torrentData.Find("a[class='torrent']").First().Text().Trim();
                    Uri    link     = new Uri(SiteLink + torrentData.Find("img[class='icos save']").First().Parent().Attr("href").Trim());
                    Uri    guid     = new Uri(SiteLink + torrentData.Find("a[class='torrent']").First().Attr("href").Trim().TrimStart('/'));
                    long   size     = ReleaseInfo.GetBytes(cells.Elements.ElementAt(4).Cq().Text());
                    int    seeders  = ParseUtil.CoerceInt(cells.Elements.ElementAt(5).Cq().Text());
                    int    leechers = ParseUtil.CoerceInt(cells.Elements.ElementAt(6).Cq().Text());

                    string   pubDateStr  = torrentData.Find("span[class^='elapsedDate']").First().Attr("title").Trim().Replace(" at", "");
                    DateTime publishDate = DateTime.ParseExact(pubDateStr, "dddd, MMMM d, yyyy h:mmtt", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToLocalTime();

                    long   category = 0;
                    string cat      = torrentData.Find("a[class='cat']").First().Attr("id").Trim();
                    long.TryParse(cat, out category);


                    var release = new ReleaseInfo();

                    release.Title           = title;
                    release.Guid            = guid;
                    release.Link            = link;
                    release.PublishDate     = publishDate;
                    release.Size            = size;
                    release.Seeders         = seeders;
                    release.Peers           = seeders + leechers;
                    release.MinimumRatio    = 1;
                    release.MinimumSeedTime = 172800;
                    release.Category        = MapTrackerCatToNewznab(category.ToString());
                    release.Comments        = guid;

                    if (torrentData.Find("span:contains(\"[Freeleech]\")").Any())
                    {
                        release.DownloadVolumeFactor = 0;
                    }
                    else
                    {
                        release.DownloadVolumeFactor = 1;
                    }

                    release.UploadVolumeFactor = 1;

                    releases.Add(release);
                }
            }
            catch (Exception ex)
            {
                OnParseError(response.Content, ex);
            }
            return(releases);
        }
示例#30
0
        List <ReleaseInfo> parseTorrents(WebClientStringResult results, String seasonep, TorznabQuery query, int already_founded, int limit)
        {
            var releases = new List <ReleaseInfo>();

            try
            {
                CQ dom = results.Content;

                ReleaseInfo release;
                var         rows = dom[".box_torrent_all"].Find(".box_torrent");

                // Check torrents only till we reach the query Limit
                for (int i = 0; (i < rows.Length && ((already_founded + releases.Count) < limit)); i++)
                {
                    try
                    {
                        CQ  qRow = rows[i].Cq();
                        var key  = dom["link[rel=alternate]"].First().Attr("href").Split('=').Last();

                        release = new ReleaseInfo();
                        var torrentTxt = qRow.Find(".torrent_txt, .torrent_txt2").Find("a").Get(0);
                        //if (torrentTxt == null) continue;
                        release.Title       = torrentTxt.GetAttribute("title");
                        release.Description = qRow.Find("span").Get(0).GetAttribute("title") + " " + qRow.Find("a.infolink").Text();

                        release.MinimumRatio         = 1;
                        release.MinimumSeedTime      = 172800;
                        release.DownloadVolumeFactor = 0;
                        release.UploadVolumeFactor   = 1;

                        string downloadLink = SiteLink + torrentTxt.GetAttribute("href");
                        string downloadId   = downloadLink.Substring(downloadLink.IndexOf("&id=") + 4);

                        release.Link     = new Uri(SiteLink.ToString() + "torrents.php?action=download&id=" + downloadId + "&key=" + key);
                        release.Comments = new Uri(SiteLink.ToString() + "torrents.php?action=details&id=" + downloadId);
                        release.Guid     = new Uri(release.Comments.ToString() + "#comments");;
                        release.Seeders  = ParseUtil.CoerceInt(qRow.Find(".box_s2").Find("a").First().Text());
                        release.Peers    = ParseUtil.CoerceInt(qRow.Find(".box_l2").Find("a").First().Text()) + release.Seeders;
                        var imdblink = qRow.Find("a[href*=\".imdb.com/title\"]").Attr("href");
                        release.Imdb = ParseUtil.GetLongFromString(imdblink);
                        var banner = qRow.Find("img.infobar_ico").Attr("onmouseover");
                        if (banner != null)
                        {
                            Regex BannerRegEx = new Regex(@"mutat\('(.*?)', '", RegexOptions.Compiled);
                            var   BannerMatch = BannerRegEx.Match(banner);
                            var   bannerurl   = BannerMatch.Groups[1].Value;
                            release.BannerUrl = new Uri(bannerurl);
                        }
                        release.PublishDate = DateTime.Parse(qRow.Find(".box_feltoltve2").Get(0).InnerHTML.Replace("<br />", " "), CultureInfo.InvariantCulture);
                        string[] sizeSplit = qRow.Find(".box_meret2").Get(0).InnerText.Split(' ');
                        release.Size = ReleaseInfo.GetBytes(sizeSplit[1].ToLower(), ParseUtil.CoerceFloat(sizeSplit[0]));
                        string catlink = qRow.Find("a:has(img[class='categ_link'])").First().Attr("href");
                        string cat     = ParseUtil.GetArgumentFromQueryString(catlink, "tipus");
                        release.Category = MapTrackerCatToNewznab(cat);

                        /* if the release name not contains the language we add it because it is know from category */
                        if (cat.Contains("hun") && !release.Title.Contains("hun"))
                        {
                            release.Title += ".hun";
                        }

                        if (seasonep == null)
                        {
                            releases.Add(release);
                        }

                        else
                        {
                            if (query.MatchQueryStringAND(release.Title, null, seasonep))
                            {
                                /* For sonnar if the search querry was english the title must be english also so we need to change the Description and Title */
                                var temp = release.Title;

                                // releasedata everithing after Name.S0Xe0X
                                String releasedata = release.Title.Split(new[] { seasonep }, StringSplitOptions.None)[1].Trim();

                                /* if the release name not contains the language we add it because it is know from category */
                                if (cat.Contains("hun") && !releasedata.Contains("hun"))
                                {
                                    releasedata += ".hun";
                                }

                                // release description contains [imdb: ****] but we only need the data before it for title
                                String[] description = { release.Description, "" };
                                if (release.Description.Contains("[imdb:"))
                                {
                                    description    = release.Description.Split('[');
                                    description[1] = "[" + description[1];
                                }

                                release.Title = (description[0].Trim() + "." + seasonep.Trim() + "." + releasedata.Trim('.')).Replace(' ', '.');

                                // if search is done for S0X than we dont want to put . between S0X and E0X
                                Match match = Regex.Match(releasedata, @"^E\d\d?");
                                if (seasonep.Length == 3 && match.Success)
                                {
                                    release.Title = (description[0].Trim() + "." + seasonep.Trim() + releasedata.Trim('.')).Replace(' ', '.');
                                }

                                // add back imdb points to the description [imdb: 8.7]
                                release.Description = temp + " " + description[1];
                                release.Description = release.Description.Trim();
                                releases.Add(release);
                            }
                        }
                    }
                    catch (FormatException ex)
                    {
                        logger.Error("Problem of parsing Torrent:" + rows[i].InnerHTML);
                        logger.Error("Exception was the following:" + ex);
                    }
                }
            }
            catch (Exception ex)
            {
                OnParseError(results.Content, ex);
            }

            return(releases);
        }