SRNicoNico.Models.NicoNicoWrapper.NicoNicoNicoRepo.StoreData C# (CSharp) Method

StoreData() private method

private StoreData ( HtmlAgilityPack.HtmlDocument doc, IList list ) : void
doc HtmlAgilityPack.HtmlDocument
list IList
return void
        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;
            }
        }