//リクエストのレスポンスを返す 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 List <NicoNicoVideoInfoEntry> GetUserVideo() { var url = UserPage + "/video?page=" + Page++; Owner.Status = "投稿動画を取得中"; List <NicoNicoVideoInfoEntry> ret = new List <NicoNicoVideoInfoEntry>(); try { var a = NicoNicoWrapperMain.Session.GetAsync(url).Result; var doc = new HtmlDocument(); doc.LoadHtml2(a); var content = doc.DocumentNode.SelectSingleNode("//div[@class='content']"); var outers = content.SelectNodes("child::div[@class='articleBody']/div[@class='outer']"); //終了 if (outers == null) { Owner.Status = ""; return(null); } foreach (var outer in outers) { //フォームだったら飛ばす if (outer.SelectSingleNode("child::form") != null) { continue; } var entry = new NicoNicoVideoInfoEntry(); var thumb = outer.SelectSingleNode("child::div[@class='thumbContainer']"); entry.Cmsid = thumb.SelectSingleNode("child::a").Attributes["href"].Value.Substring(6); entry.ThumbnailUrl = thumb.SelectSingleNode("child::a/img").Attributes["src"].Value; entry.Length = thumb.SelectSingleNode("child::span[@class='videoTime']").InnerText.Trim(); var section = outer.SelectSingleNode("child::div[@class='section']"); entry.Title = HttpUtility.HtmlDecode(section.SelectSingleNode("child::h5/a").InnerText.Trim()); entry.FirstRetrieve = section.SelectSingleNode("child::p").InnerText.Trim(); var metadata = section.SelectSingleNode("child::div[@class='dataOuter']/ul"); entry.ViewCounter = int.Parse(metadata.SelectSingleNode("child::li[@class='play']").InnerText.Trim().Split(':')[1].Replace(",", "")); entry.CommentCounter = int.Parse(metadata.SelectSingleNode("child::li[@class='comment']").InnerText.Trim().Split(':')[1].Replace(",", "")); entry.MylistCounter = int.Parse(metadata.SelectSingleNode("child::li[@class='mylist']/a").InnerText.Trim().Replace(",", "")); ret.Add(entry); } Owner.Status = ""; return(ret); } catch (RequestTimeout) { Owner.Status = "投稿動画の取得に失敗しました。"; return(null); } }
public SearchResultEntryViewModel(NicoNicoVideoInfoEntry node) { Node = node; }
//リクエストのレスポンスを返す 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 List<NicoNicoVideoInfoEntry> GetUserVideo() { var url = UserPage + "/video?page=" + Page++; Owner.Status = "投稿動画を取得中"; List<NicoNicoVideoInfoEntry> ret = new List<NicoNicoVideoInfoEntry>(); try { var a = NicoNicoWrapperMain.Session.GetAsync(url).Result; var doc = new HtmlDocument(); doc.LoadHtml2(a); var content = doc.DocumentNode.SelectSingleNode("//div[@class='content']"); var outers = content.SelectNodes("child::div[@class='articleBody']/div[@class='outer']"); //終了 if(outers == null) { Owner.Status = ""; return null; } foreach(var outer in outers) { //フォームだったら飛ばす if(outer.SelectSingleNode("child::form") != null) { continue; } var entry = new NicoNicoVideoInfoEntry(); var thumb = outer.SelectSingleNode("child::div[@class='thumbContainer']"); entry.Cmsid = thumb.SelectSingleNode("child::a").Attributes["href"].Value.Substring(6); entry.ThumbnailUrl = thumb.SelectSingleNode("child::a/img").Attributes["src"].Value; entry.Length = thumb.SelectSingleNode("child::span[@class='videoTime']").InnerText.Trim(); var section = outer.SelectSingleNode("child::div[@class='section']"); entry.Title = HttpUtility.HtmlDecode(section.SelectSingleNode("child::h5/a").InnerText.Trim()); entry.FirstRetrieve = section.SelectSingleNode("child::p").InnerText.Trim(); var metadata = section.SelectSingleNode("child::div[@class='dataOuter']/ul"); entry.ViewCounter = int.Parse(metadata.SelectSingleNode("child::li[@class='play']").InnerText.Trim().Split(':')[1].Replace(",", "")); entry.CommentCounter = int.Parse(metadata.SelectSingleNode("child::li[@class='comment']").InnerText.Trim().Split(':')[1].Replace(",", "")); entry.MylistCounter = int.Parse(metadata.SelectSingleNode("child::li[@class='mylist']/a").InnerText.Trim().Replace(",", "")); ret.Add(entry); } Owner.Status = ""; return ret; } 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; }