Ejemplo n.º 1
0
        public async Task <IEnumerable <YggTorrentItem> > Seach(string seachStr)
        {
            var builder = new SearchUrlBuilder();

            var url = builder.Search(seachStr, SortTorrent.name, OrderTorrent.desc);

            var html = await DownloadPageAsync(url);

            var doc = new HtmlDocument();

            doc.LoadHtml(html);

            var table    = doc.DocumentNode.SelectSingleNode("//table//tbody");
            var torrents = table.ChildNodes.Where(n => n.Name == "tr");


            _islogged = YggHtmlParser.IsConnected(doc);
            var tmpLst = new List <YggTorrentItem>();

            foreach (var torrent in torrents)
            {
                tmpLst.Add(YggHtmlParser.ParseTorrentHtml(torrent));
            }

            return(tmpLst);
        }
Ejemplo n.º 2
0
        public async Task <ICommandResponse> SearchAsync(string keyword, SearchType?type = null, int?season = null, int?appId = null, bool launch = false)
        {
            if (!this.Info.IsSearchEnabled)
            {
                throw new InvalidOperationException("Search is not supported for this device.");
            }

            SearchUrlBuilder builder = new SearchUrlBuilder
            {
                Keyword    = keyword,
                SearchType = type,
                Season     = season,
                AppId      = appId,
                Launch     = launch
            };
            var url = builder.BuildSearchUrlFor(this.Url);

            var request = _requestFactory.Create();

            using (var response = await request.GetResponseAsync(url, "POST"))
            {
                return(new CommandResponse(response));
            }
        }
Ejemplo n.º 3
0
 public string Perform(Uri baseUri)
 {
     _builder = new SearchUrlBuilder(baseUri);
     return(_builder.BuildUrl(SearchParameters));
 }
Ejemplo n.º 4
0
        void BuildSearchUrlFor_method()
        {
            string result  = null;
            Uri    rokuUri = new Uri("http://198.1.0.1");

            describe["validation handling"] = () =>
            {
                before = () =>
                {
                    subject.Keyword = "anykeyword";
                };

                describe["when the keyword is omitted"] = () =>
                {
                    it["should throw ArgumentNullException"] = () =>
                    {
                        subject.Keyword = null;
                        act.ShouldThrow <ArgumentNullException>();
                    };
                };

                describe["when the season value is wrong"] = () =>
                {
                    it["should throw ArgumentOutOfRangeException"] = () =>
                    {
                        subject.Season = -1;
                        act.ShouldThrow <ArgumentOutOfRangeException>();
                    };
                };
            };

            describe["the url result"] = () =>
            {
                string keyword = "War for the Planent of the Apes";

                before = () => subject.Keyword = keyword;

                it["should contain the escaped keyword in the query string"] = () =>
                {
                    result.Should().Contain($"?keyword={Uri.EscapeDataString(keyword)}");
                };

                describe["when the search type is included"] = () =>
                {
                    SearchType?searchType = null;

                    before = () =>
                    {
                        searchType         = SearchType.Person;
                        subject.SearchType = searchType;
                    };

                    it["should include the type in the querystring"] = () =>
                    {
                        result.Should().Contain($"&type={ConversionUtils.SearchTypeToQuerystringValue(searchType.Value)}");
                    };

                    describe["when season is also provided"] = () =>
                    {
                        int season = 2;
                        before = () => subject.Season = season;

                        describe["when the search type is tv show"] = () =>
                        {
                            before = () => subject.SearchType = SearchType.TVShow;
                            it["should include the season in the querystring"] = () =>
                            {
                                result.Should().Contain($"&season={season}");
                            };
                        };

                        describe["when the search type any other value"] = () =>
                        {
                            before = () => subject.SearchType = SearchType.Movie;
                            it["should not include the season in the querystring"] = () =>
                            {
                                result.Should().NotContain($"&season={season}");
                            };
                        };
                    };
                };

                describe["when the appId is included"] = () =>
                {
                    int appId = 12345;

                    before = () => subject.AppId = appId;
                    it["should include the appId in the querystring"] = () =>
                    {
                        result.Should().Contain($"&provider-id={appId}");
                    };

                    describe["when launch app is also requested"] = () =>
                    {
                        before = () => subject.Launch = true;
                        it["should include the launch request in the querystring"] = () =>
                        {
                            result.Should().Contain("&launch=true");
                        };
                    };
                };
            };

            before = () => subject = new SearchUrlBuilder();
            act    = () => result = subject.BuildSearchUrlFor(rokuUri);
        }