Example #1
0
        public void Reload()
        {
            if (string.IsNullOrWhiteSpace(Word))
            {
                ServiceFactory.MessageService.Error("検索ワードが入力されていません。");
                return;
            }

            Videos.Clear();

            string targets = IsTag ? Constants.TargetTag : Constants.TargetKeyword;
            string q       = HttpUtil.ToUrlEncode(Word);
            string fields  = Constants.Fields;
            string offset  = Offset.ToString();
            string limit   = Limit.ToString();
            string context = Constants.Context;
            string sort    = OrderBy;
            string url     = String.Format(Constants.SearchByWordUrl, q, targets, fields, sort, offset, limit, context);
            string txt     = GetSmileVideoHtmlText(url);

            // TODO 入力チェック

            var json = DynamicJson.Parse(txt);

            foreach (dynamic data in json["data"])
            {
                var video = new VideoModel()
                {
                    VideoUrl        = data["contentId"],
                    Title           = data["title"],
                    Description     = data["description"],
                    Tags            = data["tags"],
                    CategoryTag     = data["categoryTags"],
                    ViewCounter     = data["viewCounter"],
                    MylistCounter   = data["mylistCounter"],
                    CommentCounter  = data["commentCounter"],
                    StartTime       = NicoDataConverter.ToDatetime(data["startTime"]),
                    LastCommentTime = NicoDataConverter.ToDatetime(data["lastCommentTime"]),
                    LengthSeconds   = data["lengthSeconds"],
                    ThumbnailUrl    = data["thumbnailUrl"] + ThumbSize,
                    //CommunityIcon = data["communityIcon"]
                };

                // 状態に追加
                VideoStatusModel.Instance.VideoMerge(video);

                // 自身に追加
                Videos.Add(video.VideoId);
            }

            DataLength = json["meta"]["totalCount"];

            ServiceFactory.MessageService.Debug(url);
        }
        public override async Task Reload()
        {
            if (string.IsNullOrWhiteSpace(Word))
            {
                ServiceFactory.MessageService.Error("検索ワードが入力されていません。");
                return;
            }

            Videos.Clear();

            string targets = IsTag ? "tagsExact" : "title,description,tags";
            string q       = NicoDataConverter.ToUrlEncode(Word);
            string fields  = "contentId,title,description,tags,categoryTags,viewCounter,mylistCounter,commentCounter,startTime,lastCommentTime,lengthSeconds,thumbnailUrl";
            string offset  = Offset.ToString();
            string limit   = Limit.ToString();
            string context = "kaz.server-on.net/NicoV4";
            string sort    = OrderBy;
            string url     = String.Format("http://api.search.nicovideo.jp/api/v2/video/contents/search?q={0}&targets={1}&fields={2}&_sort={3}&_offset={4}&_limit={5}&_context={6}",
                                           q, targets, fields, sort, offset, limit, context
                                           );

            // TODO 入力チェック

            var json = await GetJsonAsync(url);

            Videos.Clear();

            foreach (dynamic data in json["data"])
            {
                var video = VideoStatusModel.Instance.GetVideo(NicoDataConverter.ToId(data["contentId"]));
                video.Title           = data["title"];
                video.Description     = data["description"];
                video.Tags            = data["tags"];
                video.CategoryTag     = data["categoryTags"];
                video.ViewCounter     = data["viewCounter"];
                video.MylistCounter   = data["mylistCounter"];
                video.CommentCounter  = data["commentCounter"];
                video.StartTime       = NicoDataConverter.ToDatetime(data["startTime"]);
                video.LastCommentTime = NicoDataConverter.ToDatetime(data["lastCommentTime"]);
                video.LengthSeconds   = data["lengthSeconds"];
                video.ThumbnailUrl    = data["thumbnailUrl"];
                //CommunityIcon = data["communityIcon"]

                // 自身に追加
                Videos.Add(video.VideoId);
            }

            DataLength = json["meta"]["totalCount"];

            ServiceFactory.MessageService.Debug(url);
        }