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 #2
0
        //リクエストのレスポンスを返す
        public NicoNicoSearchResult Search()
        {
            string typeString;  //表示文字列
            string type;        //クエリ文字列

            if (Type == SearchType.Keyword)
            {
                typeString = "テキスト";
                type       = "search";
            }
            else
            {
                typeString = "タグ";
                type       = "tag";
            }
            SearchVM.Status = "検索中(" + typeString + ":" + Keyword + ")";

            NicoNicoSearchResult result = new NicoNicoSearchResult();

            //テキスト検索のとき、urlの場合はそれも検索結果に表示する
            if (Type == SearchType.Keyword)
            {
                Match match = Regex.Match(Keyword, @"^(:?http://(:?www.nicovideo.jp/watch/|nico.ms/))?(?<cmsid>\w{0,2}\d+).*?$");
                if (match.Success)
                {
                    NicoNicoVitaApiVideoData data = NicoNicoVitaApi.GetVideoData(match.Groups["cmsid"].Value);
                    NicoNicoVideoInfoEntry   node = new NicoNicoVideoInfoEntry();
                    node.Cmsid          = data.Id;
                    node.Title          = HttpUtility.HtmlDecode(data.Title);
                    node.ViewCounter    = data.ViewCounter;
                    node.CommentCounter = data.CommentCounter;
                    node.MylistCounter  = data.MylistCounter;
                    node.ThumbnailUrl   = data.ThumbnailUrl;
                    node.Length         = data.Length;
                    node.FirstRetrieve  = data.FirstRetrieve.Replace('-', '/');

                    result.List.Add(node);

                    result.Total++;
                }
            }

            //URLに検索キーワードやその他いろいろをGETリクエストする
            string search = SearchURL + type + "/" + Keyword + "?mode=watch" + Sort + Order + "&page=" + CurrentPage++;

            string jsonString = NicoNicoWrapperMain.GetSession().GetAsync(search).Result;

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

            //検索結果総数
            if (json.count())
            {
                result.Total += (ulong)json.count;
            }

            //Jsonからリストを取得、データを格納
            if (json.list())
            {
                foreach (var entry in json.list)
                {
                    NicoNicoVideoInfoEntry node = new NicoNicoVideoInfoEntry();

                    node.Cmsid          = entry.id;
                    node.Title          = entry.title_short;
                    node.ViewCounter    = (int)entry.view_counter;
                    node.CommentCounter = (int)entry.num_res;
                    node.MylistCounter  = (int)entry.mylist_counter;
                    node.ThumbnailUrl   = entry.thumbnail_url;
                    node.Length         = entry.length;
                    node.FirstRetrieve  = entry.first_retrieve;

                    result.List.Add(node);
                }
            }
            SearchVM.Status = "検索完了(" + typeString + ":" + Keyword + ")";


            return(result);
        }