예제 #1
0
        public async Task <NicoNicoRankingEntry> GetRankingAsync(string category, int page)
        {
            try {
                var ret = new NicoNicoRankingEntry();

                ret.Period = Period;
                ret.Target = Target;

                var a = await App.ViewModelRoot.CurrentUser.Session.GetAsync(string.Format(ApiUrl, category, page));

                var doc = new HtmlDocument();
                doc.LoadHtml(a);

                ret.ItemList = new List <RankingItem>();

                var nodes = doc.DocumentNode.SelectNodes("//div[@class='contentBody video videoList01']/ul/li");
                if (nodes == null)
                {
                    return(null);
                }

                //ランキングページから各種データをXPathで取得
                foreach (var ranking in nodes)
                {
                    var item = new RankingItem();

                    item.Rank         = ranking.SelectSingleNode("div[@class='rankingNumWrap']/p[@class='rankingNum']").InnerText;
                    item.RankingPoint = ranking.SelectSingleNode("div[@class='rankingNumWrap']/p[@class='rankingPt']").InnerText;

                    var wrap = ranking.SelectSingleNode("div[@class='videoList01Wrap']");

                    item.PostAt = wrap.SelectSingleNode("p[contains(@class, 'itemTime')]").InnerText;

                    item.Length    = wrap.SelectSingleNode("div[@class='itemThumbBox']/span").InnerText;
                    item.ThumbNail = wrap.SelectSingleNode("div[@class='itemThumbBox']/div/a/img[2]").Attributes["data-original"].Value;

                    var content = ranking.SelectSingleNode("div[@class='itemContent']");

                    item.ContentUrl = "http://www.nicovideo.jp/" + content.SelectSingleNode("p/a").Attributes["href"].Value;
                    item.Title      = content.SelectSingleNode("p/a").InnerText;

                    item.Description = content.SelectSingleNode("div[@class='wrap']/p[@class='itemDescription ranking']").InnerText;

                    var itemdata = content.SelectSingleNode("div[@class='itemData']/ul");

                    item.ViewCount    = itemdata.SelectSingleNode("li[@class='count view']/span").InnerText;
                    item.CommentCount = itemdata.SelectSingleNode("li[@class='count comment']/span").InnerText;
                    item.MylistCount  = itemdata.SelectSingleNode("li[@class='count mylist']/span").InnerText;

                    NicoNicoUtil.ApplyLocalHistory(item);

                    ret.ItemList.Add(item);
                }

                return(ret);
            } catch (RequestFailed) {
                return(null);
            }
        }
예제 #2
0
        public async Task <List <NicoNicoCommunityVideoEntry> > GetCommunityVideoAsync(int page)
        {
            try {
                Owner.Status = "コミュニティ動画取得中";

                var a = await App.ViewModelRoot.CurrentUser.Session.GetAsync(CommunityUrl.Replace("community", "video") + "?page=" + page);

                var doc = new HtmlDocument();
                doc.LoadHtml(a);

                var ret = new List <NicoNicoCommunityVideoEntry>();

                foreach (var video in doc.DocumentNode.SelectNodes("//li[@class='videoItem']"))
                {
                    var entry = new NicoNicoCommunityVideoEntry();

                    var detail = video.SelectSingleNode("div[@class='videoContent']/div[@class='videoDetail']");
                    var status = video.SelectSingleNode("div[@class='videoStatus']");

                    entry.Title          = detail.SelectSingleNode("span[@class='videoTitle']").InnerText.Trim();
                    entry.ViewCounter    = int.Parse(detail.SelectSingleNode("ul/li[1]/span[2]").InnerText.Trim(), System.Globalization.NumberStyles.AllowThousands);
                    entry.CommentCounter = int.Parse(detail.SelectSingleNode("ul/li[2]/span[2]/strong").InnerText.Trim(), System.Globalization.NumberStyles.AllowThousands);

                    var mylist = detail.SelectSingleNode("ul/li[3]/a/span");

                    if (mylist != null)
                    {
                        entry.MylistCounter = int.Parse(mylist.InnerText.Trim(), System.Globalization.NumberStyles.AllowThousands);
                    }


                    entry.ThumbnailUrl = video.SelectSingleNode("div[@class='videoContent']/div[@class='videoThumbnail']/a/img").Attributes["src"].Value;
                    entry.ContentUrl   = video.SelectSingleNode("div[@class='videoContent']/div[@class='videoThumbnail']/a").Attributes["href"].Value;
                    entry.Cmsid        = Regex.Match(entry.ContentUrl, @"\d+$").Value;

                    var length = video.SelectSingleNode("div[@class='videoContent']/div[@class='videoThumbnail']/span");

                    if (length != null)
                    {
                        entry.Length = length.InnerText.Trim();
                    }

                    entry.FirstRetrieve = status.SelectSingleNode("span[@class='videoRegisterdDate']").InnerText;
                    entry.VideoStatus   = status.SelectSingleNode("span[@class='videoPermission']").InnerHtml.Trim();

                    NicoNicoUtil.ApplyLocalHistory(entry);
                    ret.Add(entry);
                }

                Owner.Status = "";
                return(ret);
            } catch (RequestFailed) {
                Owner.Status = "コミュニティ動画の取得に失敗しました";
                return(null);
            }
        }
예제 #3
0
        public async Task <NicoNicoNicoRepoResult> GetNicoRepoAsync(string type, string nextPage)
        {
            try {
                //ニコレポのhtmlを取得
                var a = await App.ViewModelRoot.CurrentUser.Session.GetAsync("http://www.nicovideo.jp/my/top/" + type + "?innerPage=1&mode=next_page" + ((nextPage == null) ? "" : "&last_timeline=" + nextPage));


                var doc = new HtmlDocument();
                doc.LoadHtml(a);

                var timeline = doc.DocumentNode.SelectNodes("//div[@class='timeline']/div");

                //無いとき
                if (timeline == null)
                {
                    return(null);
                }

                var ret = new NicoNicoNicoRepoResult();
                ret.Items = new List <NicoNicoNicoRepoResultEntry>();

                //ニコレポタイムラインを走査
                foreach (var entry in timeline)
                {
                    var item   = new NicoNicoNicoRepoResultEntry();
                    var author = entry.SelectSingleNode("div[contains(@class, 'log-author ')]");

                    if (author != null)
                    {
                        item.NicoRepoThumbNail = author.SelectSingleNode("a/img").Attributes["data-original"].Value;
                        item.AuthorUrl         = author.SelectSingleNode("a").Attributes["href"].Value;
                    }

                    var content = entry.SelectSingleNode("div[@class='log-content']");

                    if (content != null)
                    {
                        var body = content.SelectSingleNode("div[@class='log-body']");
                        if (body != null)
                        {
                            item.Title = body.InnerHtml;
                        }

                        var detail = content.SelectSingleNode("div[contains(@class, 'log-details')]");

                        if (detail != null)
                        {
                            item.Time = detail.SelectSingleNode("div/div/span/time")?.InnerText.Trim() ?? "";

                            item.ContentThumbNail = detail.SelectSingleNode("div[@class='log-target-thumbnail']/a/img")?.Attributes["data-original"].Value ?? "";

                            var target = detail.SelectSingleNode("div[@class='log-target-info']/a");
                            if (target != null)
                            {
                                item.HasContent   = true;
                                item.ContentTitle = HttpUtility.HtmlDecode(target.InnerText.Trim());
                                item.ContentUrl   = target.Attributes["href"].Value;

                                NicoNicoUtil.ApplyLocalHistory(item);
                            }
                        }
                    }

                    if (item.ContentUrl == null)
                    {
                        item.ContentUrl = item.AuthorUrl;
                    }

                    ret.Items.Add(item);
                }

                var next = doc.DocumentNode.SelectSingleNode("//a[@class='next-page-link']");

                if (next != null)
                {
                    ret.NextPage = Regex.Match(next.Attributes["href"].Value, @"\d+$").Value;
                }
                else
                {
                    ret.IsEnd    = true;
                    ret.NextPage = null;
                }
                return(ret);
            } catch (RequestFailed e) {
                if (e.FailedType == FailedType.Failed)
                {
                    Owner.Status = "ニコレポの取得に失敗しました";
                }
                else
                {
                    Owner.Status = "ニコレポの取得がタイムアウトになりました";
                }

                return(null);
            }
        }
예제 #4
0
        //リクエストのレスポンスを返す
        public async Task <NicoNicoSearchResult> Search(string keyword, SearchType type, string Sort, int page = 1)
        {
            Owner.Status = "検索中:" + keyword;

            Sort = "&sort=" + Sort.Split(':')[0] + "&order=" + Sort.Split(':')[1];

            string typestr;

            if (type == SearchType.Keyword)
            {
                typestr = "search";
            }
            else
            {
                typestr = "tag";
            }

            var result = new NicoNicoSearchResult();

            try {
                var a = await App.ViewModelRoot.CurrentUser.Session.GetAsync(SearchURL + typestr + "/" + HttpUtility.UrlEncode(keyword) + "?mode=watch" + Sort + "&page=" + page);

                //取得したJsonの全体
                var json = DynamicJson.Parse(a);

                //検索結果総数
                if (json.count())
                {
                    result.Total = (int)json.count;
                }
                else
                {
                    //連打するとエラーになる
                    Owner.Status = "アクセスしすぎです。1分ほど時間を置いてください。";
                    return(null);
                }

                //Jsonからリストを取得、データを格納
                if (json.list())
                {
                    foreach (var entry in json.list)
                    {
                        var node = new NicoNicoSearchResultEntry()
                        {
                            Cmsid          = entry.id,
                            Title          = HttpUtility.HtmlDecode(entry.title_short),
                            ViewCounter    = (int)entry.view_counter,
                            CommentCounter = (int)entry.num_res,
                            MylistCounter  = (int)entry.mylist_counter,
                            ThumbnailUrl   = entry.thumbnail_url,
                            Length         = entry.length,
                            FirstRetrieve  = entry.first_retrieve
                        };

                        node.FirstRetrieve = node.FirstRetrieve.Replace('-', '/');
                        node.ContentUrl    = "http://www.nicovideo.jp/watch/" + node.Cmsid;

                        NicoNicoUtil.ApplyLocalHistory(node);

                        result.List.Add(node);
                    }
                }

                Owner.Status = "";

                return(result);
            } catch (RequestFailed) {
                Owner.Status = "検索がタイムアウトしました";
                return(null);
            }
        }
예제 #5
0
        public async Task <List <NicoNicoUserVideoEntry> > GetUserVideoAsync(int page)
        {
            var url = Owner.UserPageUrl + "/video?page=" + page;

            Owner.Status = "投稿動画を取得中";

            var ret = new List <NicoNicoUserVideoEntry>();

            try {
                var a = await App.ViewModelRoot.CurrentUser.Session.GetAsync(url);

                var doc = new HtmlDocument();
                doc.LoadHtml(a);

                var content = doc.DocumentNode.SelectSingleNode("//div[@class='content']");

                var outers = content.SelectNodes("div[@class='articleBody']/div[@class='outer']");

                //終了
                if (outers == null)
                {
                    Owner.Status = "";
                    return(null);
                }

                foreach (var outer in outers)
                {
                    //フォームだったら飛ばす
                    if (outer.SelectSingleNode("form") != null)
                    {
                        continue;
                    }

                    var entry = new NicoNicoUserVideoEntry();

                    var thumb = outer.SelectSingleNode("div[@class='thumbContainer']");

                    entry.Cmsid        = thumb.SelectSingleNode("a").Attributes["href"].Value.Substring(6);
                    entry.ThumbnailUrl = thumb.SelectSingleNode("a/img").Attributes["src"].Value;
                    entry.Length       = thumb.SelectSingleNode("span[@class='videoTime']").InnerText.Trim();

                    var section = outer.SelectSingleNode("div[@class='section']");

                    entry.Title         = HttpUtility.HtmlDecode(section.SelectSingleNode("h5/a").InnerText.Trim());
                    entry.FirstRetrieve = section.SelectSingleNode("p").InnerText.Trim();

                    var metadata = section.SelectSingleNode("div[@class='dataOuter']/ul");

                    entry.ViewCounter    = int.Parse(metadata.SelectSingleNode("li[@class='play']").InnerText.Trim().Split(':')[1].Replace(",", ""));
                    entry.CommentCounter = int.Parse(metadata.SelectSingleNode("li[@class='comment']").InnerText.Trim().Split(':')[1].Replace(",", ""));
                    entry.MylistCounter  = int.Parse(metadata.SelectSingleNode("li[@class='mylist']/a").InnerText.Trim().Replace(",", ""));
                    entry.ContentUrl     = "http://www.nicovideo.jp/watch/" + entry.Cmsid;

                    NicoNicoUtil.ApplyLocalHistory(entry);
                    ret.Add(entry);
                }

                Owner.Status = "";
                return(ret);
            } catch (RequestFailed) {
                Owner.Status = "投稿動画の取得に失敗しました。";
                return(null);
            }
        }
예제 #6
0
        //一度nullを返してきたら二度と呼ばない
        public async Task <NicoNicoNicoRepoResult> GetUserNicoRepoAsync(string offset)
        {
            var url = Owner.UserPageUrl + "/top?innerPage=1&offset=" + offset;

            Owner.Status = "ユーザーニコレポ取得中";

            var ret = new NicoNicoNicoRepoResult();

            ret.Items = new List <NicoNicoNicoRepoResultEntry>();

            try {
                var a = await App.ViewModelRoot.CurrentUser.Session.GetAsync(url);

                var doc = new HtmlDocument();
                doc.LoadHtml(a);

                var timeline = doc.DocumentNode.SelectNodes("//div[@class='timeline']/div");

                //タイムラインを取得できなかったら終了
                if (timeline == null)
                {
                    Owner.Status = "";
                    return(null);
                }

                //ニコレポタイムライン走査
                foreach (var entry in timeline)
                {
                    var item = new NicoNicoNicoRepoResultEntry();

                    var author = entry.SelectSingleNode("div[contains(@class, 'log-author ')]");

                    if (author != null)
                    {
                        item.NicoRepoThumbNail = author.SelectSingleNode("a/img").Attributes["data-original"].Value;
                        item.AuthorUrl         = author.SelectSingleNode("a").Attributes["href"].Value;
                    }

                    var content = entry.SelectSingleNode("div[@class='log-content']");

                    if (content != null)
                    {
                        var body = content.SelectSingleNode("div[@class='log-body']");
                        if (body != null)
                        {
                            item.Title = body.InnerHtml;
                        }

                        var detail = content.SelectSingleNode("div[contains(@class, 'log-details')]");

                        if (detail != null)
                        {
                            item.Time = detail.SelectSingleNode("div/div/a/time")?.InnerText.Trim() ?? "";

                            item.ContentThumbNail = detail.SelectSingleNode("div[@class='log-target-thumbnail']/a/img")?.Attributes["data-original"].Value ?? "";

                            var target = detail.SelectSingleNode("div[@class='log-target-info']/a");
                            if (target != null)
                            {
                                item.HasContent   = true;
                                item.ContentTitle = HttpUtility.HtmlDecode(target.InnerText.Trim());
                                item.ContentUrl   = target.Attributes["href"].Value;

                                NicoNicoUtil.ApplyLocalHistory(item);
                            }
                        }
                    }

                    if (item.ContentUrl == null)
                    {
                        item.ContentUrl = item.AuthorUrl;
                    }

                    ret.Items.Add(item);

                    var next = doc.DocumentNode.SelectSingleNode("//a[@class='next-page-link']");

                    if (next != null)
                    {
                        ret.NextPage = Regex.Match(next.Attributes["href"].Value, @"\d+$").Value;
                    }
                    else
                    {
                        ret.IsEnd    = true;
                        ret.NextPage = null;
                    }
                }
                Owner.Status = "";
                return(ret);
            } catch (RequestFailed) {
                Owner.Status = "ユーザーニコレポの取得に失敗しました";
                return(null);
            }
        }