Beispiel #1
0
        public static NicoNicoVitaApiMylistData GetMylistData(string mylistId)
        {
            string detail = "0"; //より細かい1も存在
            string result = NicoNicoWrapperMain.GetSession().GetAsync(MylistDataApiUrl + detail + "&group_id=" + mylistId).Result;

            var json     = DynamicJson.Parse(result);
            var response = json.nicovideo_mylistgroup_response;

            NicoNicoVitaApiMylistData ret = new NicoNicoVitaApiMylistData();

            ret.Id                = response.mylistgroup.id;
            ret.UserId            = response.mylistgroup.user_id;
            ret.ViewCount         = response.mylistgroup.view_counter;
            ret.Name              = response.mylistgroup.name;
            ret.Description       = response.mylistgroup.description;
            ret.isPublic          = response.mylistgroup.@public == "1" ? true : false;
            ret.DefaultSort       = int.Parse(response.mylistgroup.default_sort);
            ret.DefaultSortMethod = response.mylistgroup.default_sort_method;
            ret.SortOrder         = int.Parse(response.mylistgroup.sort_order);
            ret.DefaultSortOrder  = response.mylistgroup.default_sort_order;
            ret.IconId            = response.mylistgroup.icon_id;
            ret.UpdateTime        = NicoNicoUtil.DateFromVitaFormatDate(response.mylistgroup.update_time);
            ret.CreateTime        = NicoNicoUtil.DateFromVitaFormatDate(response.mylistgroup.create_time);
            ret.Count             = int.Parse(response.mylistgroup.count);

            NicoNicoVitaApiUserData re = NicoNicoVitaUserApi.GetUserData(ret.UserId);

            ret.UserName = re.Name;

            return(ret);
        }
        public static NicoNicoVitaApiVideoData GetVideoData(string cmsid)
        {
            if (cmsid.Contains("?"))
            {
                cmsid = cmsid.Substring(0, cmsid.IndexOf('?'));
            }


            string result = NicoNicoWrapperMain.Session.GetAsync(VideoDataApiUrl + cmsid).Result;

            var json     = DynamicJson.Parse(result);
            var response = json.nicovideo_video_response;

            var ret = new NicoNicoVitaApiVideoData();

            if (!response.video())
            {
                ret.Success = false;
                return(ret);
            }

            ret.Id             = response.video.id;
            ret.Title          = response.video.title;
            ret.FirstRetrieve  = NicoNicoUtil.DateFromVitaFormatDate(response.video.first_retrieve);
            ret.ViewCounter    = int.Parse(response.video.view_counter);
            ret.CommentCounter = int.Parse(response.thread.num_res);
            ret.MylistCounter  = int.Parse(response.video.mylist_counter);
            ret.Length         = NicoNicoUtil.ConvertTime(long.Parse(response.video.length_in_seconds));
            ret.Description    = response.video.description;
            ret.ThumbnailUrl   = response.video.thumbnail_url;
            return(ret);
        }
Beispiel #3
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);
            }
        }
        //ユーザーIDからユーザーネームを取得する
        public static string LookupUserName(string userId)
        {
            string uri = UserLookUpURL + userId;

            string json = NicoNicoUtil.XmlToJson(NicoNicoWrapperMain.GetSession().GetAsync(uri).Result);

            return(DynamicJson.Parse(json).response.user.nickname);
        }
        //ストーリーボードのデータを取得する
        private NicoNicoStoryBoardData GetStoryBoardInternalData()
        {
            try {
                var result = NicoNicoWrapperMain.Session.GetResponseAsync(StoryBoardApiBaseUrl + "&sb=1").Result;

                //見つからなかったり見せてもらえなかったりしたら
                if (result.StatusCode == HttpStatusCode.Forbidden || result.StatusCode == HttpStatusCode.NotFound || result.Content.Headers.ContentDisposition.FileName.Contains("smile"))
                {
                    return(null);
                }

                byte[] response = result.Content.ReadAsByteArrayAsync().Result;

                var xml = new string(Encoding.ASCII.GetChars(response));
                xml = xml.Substring(39);
                var json = NicoNicoUtil.XmlToJson(xml);
                json = json.Replace("@", "");

                var root = DynamicJson.Parse(json);

                if (root.smile.storyboard.IsArray)
                {
                    foreach (var entry in root.smile.storyboard)
                    {
                        return(new NicoNicoStoryBoardData()
                        {
                            Id = entry.id() ? entry.id : "1",
                            Cols = int.Parse(entry.board_cols),
                            Rows = int.Parse(entry.board_rows),
                            Count = int.Parse(entry.board_number),
                            Width = int.Parse(entry.thumbnail_width),
                            Height = int.Parse(entry.thumbnail_height),
                            Interval = int.Parse(entry.thumbnail_interval),
                            Number = int.Parse(entry.thumbnail_number)
                        });
                    }
                }
                else
                {
                    var entry = root.smile.storyboard;

                    return(new NicoNicoStoryBoardData()
                    {
                        Id = entry.id() ? entry.id : "1",
                        Cols = int.Parse(entry.board_cols),
                        Rows = int.Parse(entry.board_rows),
                        Count = int.Parse(entry.board_number),
                        Width = int.Parse(entry.thumbnail_width),
                        Height = int.Parse(entry.thumbnail_height),
                        Interval = int.Parse(entry.thumbnail_interval),
                        Number = int.Parse(entry.thumbnail_number)
                    });
                }
            } catch (RequestTimeout) {
            }

            return(null);
        }
Beispiel #6
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);
            }
        }
        private void OnReceive(object sender, XmlSocketReceivedEventArgs e)
        {
            var xml = new XmlDocument();

            try {
                xml.LoadXml(e.Xml);

                Console.WriteLine(e.Xml);

                var thread = xml.SelectSingleNode("/thread");
                if (thread != null)
                {
                    Ticket = thread.Attributes["ticket"].Value;
                    if (thread.Attributes["last_res"] != null)
                    {
                        LastRes = int.Parse(thread.Attributes["last_res"].Value);
                    }
                    ResFrom = LastRes + 1;

                    return;
                }

                var chat = xml.SelectSingleNode("/chat");
                if (chat != null)
                {
                    var comment = new NicoNicoCommentEntry();
                    comment.No    = (++CommentNum).ToString();
                    comment.Vpos  = chat.Attributes["vpos"].Value;
                    comment.Mail  = chat.Attributes["mail"] != null ? chat.Attributes["mail"].Value : "";
                    comment.Score = chat.Attributes["score"] != null?int.Parse(chat.Attributes["score"].Value) : 0;

                    comment.UserId  = chat.Attributes["user_id"].Value;
                    comment.Date    = NicoNicoUtil.GetTimeFromVpos(Status, comment.Vpos);
                    comment.Content = chat.InnerText;

                    Owner.CommentList.Add(comment);

                    //コマンドは弾く
                    if (chat.InnerText.StartsWith("/"))
                    {
                        return;
                    }
                    Handler.InvokeScript("AsInjectOneComment", comment.ToJson());
                }
            } catch (XmlException) {
                return;
            }
        }
Beispiel #8
0
        public override void Execute(NicoNicoCommentEntry target)
        {
            if (!Settings.Instance.DisableJumpCommand)
            {
                var seek = SeekPattern.Match(Entry.Content);

                if (seek.Success)
                {
                    Owner.Owner.Handler.Seek(NicoNicoUtil.ConvertTime(seek.Groups[1].Value));
                    return;
                }
                var split = Entry.Content.Split(' ');

                if (Regex.IsMatch(split[1], "\\d"))
                {
                    Owner.Owner.VideoUrl = "http://www.nicovideo.jp/watch/" + split[1];
                    Owner.Owner.Initialize();
                }
            }
        }
Beispiel #9
0
        public async Task HeartbeatAsync(string id)
        {
            try {
                var query = new GetRequestQuery(Dmc.ApiUrls.First() + "/" + id);
                query.AddQuery("_format", "json");
                query.AddQuery("_method", "PUT");

                var request = new HttpRequestMessage(HttpMethod.Post, new Uri(query.TargetUrl));

                request.Content = new StringContent(LastResponseXml);
                request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                var a = await App.ViewModelRoot.CurrentUser.Session.GetAsync(request);

                if (!NicoNicoUtil.IsValidJson(a))
                {
                    return;
                }
                var doc = DynamicJson.Parse(a);

                if (doc.data())
                {
                    var data = doc.data;
                    if (data != null)
                    {
                        LastResponseXml = data.ToString();
                    }
                    else
                    {
                    }
                }


                return;
            } catch (RequestFailed) {
                return;
            }
        }
        private void StoreEntry(HtmlDocument doc, List <NicoNicoCommentEntry> list)
        {
            var nodes = doc.DocumentNode.SelectNodes("/packet/chat");

            if (nodes == null)
            {
                return;
            }

            foreach (var node in nodes)
            {
                var attr = node.Attributes;

                //削除されていたら登録しない もったいないしね
                if (attr.Contains("deleted"))
                {
                    continue;
                }

                var entry = new NicoNicoCommentEntry();

                entry.No         = attr["no"].Value;
                entry.Vpos       = attr["vpos"].Value;
                entry.RenderTime = NicoNicoUtil.GetTimeFromVpos(entry.Vpos);
                var unix = UnixTime.FromUnixTime(long.Parse(attr["date"].Value));

                entry.Date    = unix.ToLongDateString() + " " + unix.ToLongTimeString();
                entry.UserId  = attr.Contains("user_id") ? attr["user_id"].Value : "contributor";
                entry.Mail    = attr.Contains("mail") ? attr["mail"].Value : "";
                entry.Content = HttpUtility.HtmlDecode(node.InnerText);
                entry.Score   = attr.Contains("score") ? int.Parse(attr["score"].Value) : 0;

                if (!NicoNicoNGComment.Filter(entry))
                {
                    list.Add(entry);
                }
            }
        }
Beispiel #11
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);
            }
        }
Beispiel #12
0
        //jsonをパースしてリストにする
        private void StoreItem(dynamic json, List <NicoNicoMylistData> ret)
        {
            foreach (var entry in json.mylistitem)
            {
                NicoNicoMylistData data = new NicoNicoMylistData();
                data.CreateTime  = UnixTime.FromUnixTime((long)entry.create_time).ToString();
                data.Description = entry.description;
                data.ItemId      = entry.item_id;

                var item = entry.item_data;
                data.Title = HttpUtility.HtmlDecode(item.title);

                if (entry.item_type is string)
                {
                    data.Type = int.Parse(entry.item_type);
                }
                else if (entry.item_type is double)
                {
                    data.Type = (int)entry.item_type;
                }

                //動画
                if (data.Type == 0)
                {
                    data.UpdateTime     = UnixTime.FromUnixTime((long)item.update_time).ToString();
                    data.FirstRetrieve  = UnixTime.FromUnixTime((long)item.first_retrieve).ToString();
                    data.Length         = NicoNicoUtil.ConvertTime(long.Parse(item.length_seconds));
                    data.Id             = item.video_id;
                    data.ViewCounter    = int.Parse(item.view_counter);
                    data.CommentCounter = int.Parse(item.num_res);
                    data.MylistCounter  = int.Parse(item.mylist_counter);
                    data.ThumbNailUrl   = item.thumbnail_url;
                }
                else if (data.Type == 5)    //静画

                {
                    data.UpdateTime     = UnixTime.FromUnixTime((long)item.update_time).ToString();
                    data.FirstRetrieve  = UnixTime.FromUnixTime((long)item.create_time).ToString();
                    data.Id             = item.id.ToString();
                    data.ViewCounter    = (int)item.view_count;
                    data.CommentCounter = (int)item.comment_count;
                    data.MylistCounter  = (int)item.mylist_count;
                    data.ThumbNailUrl   = item.thumbnail_url;
                }
                else if (data.Type == 6)    //書籍

                {
                    data.UpdateTime     = UnixTime.FromUnixTime((long)entry.update_time).ToString();
                    data.FirstRetrieve  = UnixTime.FromUnixTime((long)item.released_at).ToString();
                    data.Id             = "bk" + item.id;
                    data.ViewCounter    = (int)item.view_count;
                    data.CommentCounter = (int)item.comment_count;
                    data.MylistCounter  = (int)item.mylist_count;
                    data.ThumbNailUrl   = item.thumbnail;
                }
                else if (data.Type == 13)    //ブロマガ

                {
                    data.UpdateTime     = UnixTime.FromUnixTime((long)item.commented_time).ToString();
                    data.FirstRetrieve  = UnixTime.FromUnixTime((long)item.create_time).ToString();
                    data.Id             = "ar" + item.id;
                    data.CommentCounter = (int)item.comment_count;
                    data.MylistCounter  = int.Parse(item.mylist_count);
                    data.ThumbNailUrl   = item.thumbnail_url;
                }
                ret.Add(data);
            }
        }
Beispiel #13
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);
            }
        }
Beispiel #14
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);
            }
        }
Beispiel #15
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);
            }
        }