//リクエストのレスポンスを返す 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 NicoNicoWrapperMain.Session.GetAsync(SearchURL + typestr + "/" + 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 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; node.FirstRetrieve = node.FirstRetrieve.Replace('-', '/'); result.List.Add(node); } } Owner.Status = ""; return(result); } catch (RequestTimeout) { Owner.Status = "検索がタイムアウトしました"; return(null); } }
//リクエストのレスポンスを返す 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 NicoNicoWrapperMain.Session.GetAsync(SearchURL + typestr + "/" + 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 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; node.FirstRetrieve = node.FirstRetrieve.Replace('-', '/'); result.List.Add(node); } } Owner.Status = ""; return result; } catch(RequestTimeout) { Owner.Status = "検索がタイムアウトしました"; return null; } }
//リクエストのレスポンスを返す 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; }
//リクエストのレスポンスを返す 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); }
//リクエストのレスポンスを返す 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); } }