//ニコレポ取得
        public IList <NicoNicoNicoRepoDataEntry> GetNicoRepo()
        {
            //APIと言うのか謎
            var api = PrevUrl = @"http://www.nicovideo.jp/my/top/" + Id + @"?innerPage=1&mode=next_page";

            //html
            var html = NicoNicoWrapperMain.GetSession().GetAsync(api).Result;

            IList <NicoNicoNicoRepoDataEntry> data = new List <NicoNicoNicoRepoDataEntry>();

            //XPathでhtmlから抜き出す
            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml2(html);

            //ニコレポが存在しなかったら存在しないというエントリを返す
            if (doc.DocumentNode.SelectSingleNode("/div[@class='nicorepo']/div[@class='nicorepo-page']/div").Attributes["class"].Value.Equals("empty"))
            {
                NicoNicoNicoRepoDataEntry entry = new NicoNicoNicoRepoDataEntry();

                entry.ImageUrl    = entry.IconUrl = null;
                entry.Description = "ニコレポが存在しません。";
                data.Add(entry);

                return(data);
            }

            StoreData(doc, data);

            return(data);
        }
        //ニコレポ取得
        public IList<NicoNicoNicoRepoDataEntry> GetNicoRepo()
        {
            //APIと言うのか謎
            var api = PrevUrl = @"http://www.nicovideo.jp/my/top/" + Id + @"?innerPage=1&mode=next_page";

            //html
            var html = NicoNicoWrapperMain.GetSession().GetAsync(api).Result;

            IList<NicoNicoNicoRepoDataEntry> data = new List<NicoNicoNicoRepoDataEntry>();

            //XPathでhtmlから抜き出す
            HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml2(html);

            //ニコレポが存在しなかったら存在しないというエントリを返す
            if(doc.DocumentNode.SelectSingleNode("/div[@class='nicorepo']/div[@class='nicorepo-page']/div").Attributes["class"].Value.Equals("empty")) {

                NicoNicoNicoRepoDataEntry entry = new NicoNicoNicoRepoDataEntry();

                entry.ImageUrl = entry.IconUrl = null;
                entry.Description = "ニコレポが存在しません。";
                data.Add(entry);

                return data;
            }

            StoreData(doc, data);

            return data;
        }
        //削除ボタンを利用するならこっち
        public NicoRepoResultEntryViewModel(NicoNicoNicoRepoDataEntry entry, NicoRepoListViewModel owner)
        {
            Owner = owner;
            Entry = entry;
            if(entry.IsMyNicoRepo) {

                ShowDeleteButton = true;
            }
        }
Esempio n. 4
0
        //一度nullを返してきたら二度と呼ばない
        public List <NicoNicoNicoRepoDataEntry> GetUserNicoRepo()
        {
            var url = UserPage + "/top?innerPage=1&offset=" + Offset;

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

            List <NicoNicoNicoRepoDataEntry> ret = new List <NicoNicoNicoRepoDataEntry>();

            try {
                var a   = NicoNicoWrapperMain.Session.GetAsync(url).Result;
                var doc = new HtmlDocument();
                doc.LoadHtml2(a);

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

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

                //ニコレポタイムライン走査
                foreach (HtmlNode node in timeline)
                {
                    NicoNicoNicoRepoDataEntry entry = new NicoNicoNicoRepoDataEntry();

                    entry.IconUrl = node.SelectSingleNode("child::div[contains(@class, 'log-author ')]/a/img").Attributes["data-original"].Value;
                    entry.Title   = HttpUtility.HtmlDecode(node.SelectSingleNode("child::div[@class='log-content']/div[@class='log-body']").InnerHtml.Trim());

                    HtmlNode thumbnail = node.SelectSingleNode("child::div[@class='log-content']/div/div[@class='log-target-thumbnail']/a/img");
                    entry.ImageUrl = thumbnail != null ? thumbnail.Attributes["data-original"].Value : entry.IconUrl;

                    HtmlNode desc = node.SelectSingleNode("child::div[@class='log-content']/div/div[@class='log-target-info']/a");
                    entry.Description = desc != null?HttpUtility.HtmlDecode(desc.InnerText.Trim()) : "";

                    entry.VideoUrl = desc != null ? desc.Attributes["href"].Value : "";

                    HtmlNode time = node.SelectSingleNode("child::div[@class='log-content']/div/div[@class='log-footer']/div/a[contains(@class, 'log-footer-date')]/time");
                    entry.Time = time.InnerText.Trim();

                    ret.Add(entry);
                }

                Owner.Status = "";
                Offset      += 20;
                return(ret);
            } catch (RequestTimeout) {
                Owner.Status = "ユーザーニコレポの取得に失敗しました";
                return(null);
            }
        }
 public NicoRepoResultEntryViewModel(NicoNicoNicoRepoDataEntry entry)
 {
     Entry = entry;
 }
        private void StoreData(HtmlDocument doc, IList <NicoNicoNicoRepoDataEntry> list)
        {
            var timeline = doc.DocumentNode.SelectNodes("//div[@class='timeline']/div");

            if (timeline == null)
            {
                return;
            }

            //ニコレポタイムライン走査
            foreach (HtmlNode node in timeline)
            {
                NicoNicoNicoRepoDataEntry entry = new NicoNicoNicoRepoDataEntry();

                entry.IconUrl = node.SelectSingleNode("child::div[contains(@class, 'log-author ')]/a/img").Attributes["data-original"].Value;
                entry.Title   = HttpUtility.HtmlDecode(node.SelectSingleNode("child::div[@class='log-content']/div[@class='log-body']").InnerHtml.Trim());

                HtmlNode thumbnail = node.SelectSingleNode("child::div[@class='log-content']/div/div[@class='log-target-thumbnail']/a/img");

                entry.ImageUrl = thumbnail != null ? thumbnail.Attributes["data-original"].Value : entry.IconUrl;

                HtmlNode desc = node.SelectSingleNode("child::div[@class='log-content']/div/div[@class='log-target-info']/a");

                entry.Description = desc != null?HttpUtility.HtmlDecode(desc.InnerText.Trim()) : "";

                entry.VideoUrl = desc != null ? desc.Attributes["href"].Value : "";

                HtmlNode time = node.SelectSingleNode("child::div[@class='log-content']/div/div[@class='log-footer']/div/a[contains(@class, 'log-footer-date')]/time");

                entry.Time = time.InnerText.Trim();

                //自分のニコレポだったら
                HtmlNode delete = node.SelectSingleNode("child::form");
                if (delete != null)
                {
                    entry.IsMyNicoRepo = true;

                    entry.LogId      = delete.SelectSingleNode("child::input[@name='log_id']").Attributes["value"].Value;
                    entry.Type       = delete.SelectSingleNode("child::input[@name='type']").Attributes["value"].Value;
                    entry.DeleteTime = delete.SelectSingleNode("child::input[@name='time']").Attributes["value"].Value;
                    entry.Token      = delete.SelectSingleNode("child::input[@name='token']").Attributes["value"].Value;
                }

                list.Add(entry);
            }


            if (doc.DocumentNode.SelectSingleNode("/div[@class='nicorepo']/div[@class='nicorepo-page']/div[@class='no-next-page']") != null)
            {
                NicoNicoNicoRepoDataEntry entry = new NicoNicoNicoRepoDataEntry();

                NextUrl           = "end";
                entry.ImageUrl    = entry.IconUrl = null;
                entry.Description = "これより過去のニコレポは存在しません。";
                list.Add(entry);
            }
            else
            {
                //過去ニコレポのURL
                string attr = HttpUtility.HtmlDecode(doc.DocumentNode.SelectSingleNode("/div[@class='nicorepo']/div[@class='nicorepo-page']/div[@class='next-page']/a").Attributes["href"].Value);
                NextUrl = @"http://www.nicovideo.jp" + attr;
            }
        }
Esempio n. 7
0
        private void StoreData(HtmlDocument doc, IList<NicoNicoNicoRepoDataEntry> list)
        {
            var timeline = doc.DocumentNode.SelectNodes("//div[@class='timeline']/div");

            if(timeline == null) {

                return;
            }

            //ニコレポタイムライン走査
            foreach(var node in timeline) {

                var entry = new NicoNicoNicoRepoDataEntry();

                entry.IconUrl = node.SelectSingleNode("child::div[contains(@class, 'log-author ')]/a/img").Attributes["data-original"].Value;

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

                entry.Title = HttpUtility.HtmlDecode(content.SelectSingleNode("div[@class='log-body']").InnerHtml.Trim());
                entry.LogId = content.SelectSingleNode("div[contains(@class, 'log-details')]").Attributes["class"].Value;
                var thumbnail = content.SelectSingleNode("div/div[@class='log-target-thumbnail']/a/img");

                entry.ImageUrl = thumbnail != null ? thumbnail.Attributes["data-original"].Value : entry.IconUrl;

                var desc = content.SelectSingleNode("div/div[@class='log-target-info']/a");

                entry.Description = desc != null ? HttpUtility.HtmlDecode(desc.InnerText.Trim()) : "";

                entry.VideoUrl = desc != null ? desc.Attributes["href"].Value : "";

                var time = content.SelectSingleNode("div/div[@class='log-footer']/div/a[contains(@class, 'log-footer-date')]/time");

                entry.Time = time.InnerText.Trim();

                //自分のニコレポだったら
                HtmlNode delete = node.SelectSingleNode("child::form");
                if(delete != null) {

                    entry.IsMyNicoRepo = true;

                    entry.LogId = delete.SelectSingleNode("child::input[@name='log_id']").Attributes["value"].Value;
                    entry.Type = delete.SelectSingleNode("child::input[@name='type']").Attributes["value"].Value;
                    entry.DeleteTime = delete.SelectSingleNode("child::input[@name='time']").Attributes["value"].Value;
                    entry.Token = delete.SelectSingleNode("child::input[@name='token']").Attributes["value"].Value;
                }

                list.Add(entry);

            }

            if(doc.DocumentNode.SelectSingleNode("/div[@class='nicorepo']/div[@class='nicorepo-page']/div[@class='no-next-page']") != null) {

                NicoNicoNicoRepoDataEntry entry = new NicoNicoNicoRepoDataEntry();

                NextUrl = "end";
                entry.ImageUrl = entry.IconUrl = entry.Title = entry.Time = entry.LogId = "";
                entry.Description = "これより過去のニコレポは存在しません。";
                list.Add(entry);

            } else {

                //過去ニコレポのURL
                string attr = HttpUtility.HtmlDecode(doc.DocumentNode.SelectSingleNode("/div[@class='nicorepo']/div[@class='nicorepo-page']/div[@class='next-page']/a").Attributes["href"].Value);
                NextUrl = @"http://www.nicovideo.jp" + attr;
            }
        }
Esempio n. 8
0
        //一度nullを返してきたら二度と呼ばない
        public List<NicoNicoNicoRepoDataEntry> GetUserNicoRepo()
        {
            var url = UserPage + "/top?innerPage=1&offset=" + Offset;
            Owner.Status = "ユーザーニコレポ取得中";

            List<NicoNicoNicoRepoDataEntry> ret = new List<NicoNicoNicoRepoDataEntry>();
            try {

                var a = NicoNicoWrapperMain.Session.GetAsync(url).Result;
                var doc = new HtmlDocument();
                doc.LoadHtml2(a);

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

                //タイムラインを取得できなかったら終了
                if(timeline == null) {

                    Owner.Status = "";
                    return null;
                }

                //ニコレポタイムライン走査
                foreach(HtmlNode node in timeline) {

                    NicoNicoNicoRepoDataEntry entry = new NicoNicoNicoRepoDataEntry();

                    entry.IconUrl = node.SelectSingleNode("child::div[contains(@class, 'log-author ')]/a/img").Attributes["data-original"].Value;
                    entry.Title = HttpUtility.HtmlDecode(node.SelectSingleNode("child::div[@class='log-content']/div[@class='log-body']").InnerHtml.Trim());

                    HtmlNode thumbnail = node.SelectSingleNode("child::div[@class='log-content']/div/div[@class='log-target-thumbnail']/a/img");
                    entry.ImageUrl = thumbnail != null ? thumbnail.Attributes["data-original"].Value : entry.IconUrl;

                    HtmlNode desc = node.SelectSingleNode("child::div[@class='log-content']/div/div[@class='log-target-info']/a");
                    entry.Description = desc != null ? HttpUtility.HtmlDecode(desc.InnerText.Trim()) : "";
                    entry.VideoUrl = desc != null ? desc.Attributes["href"].Value : "";

                    HtmlNode time = node.SelectSingleNode("child::div[@class='log-content']/div/div[@class='log-footer']/div/a[contains(@class, 'log-footer-date')]/time");
                    entry.Time = time.InnerText.Trim();

                    ret.Add(entry);
                }

                Owner.Status = "";
                Offset += 20;
                return ret;
            } catch(RequestTimeout) {

                Owner.Status = "ユーザーニコレポの取得に失敗しました";
                return null;
            }
        }