/// <summary> /// ニコニコのgetthumbinfo APIから動画情報を取得します。 /// </summary> /// <remarks> /// 参考URL) /// http://dic.nicovideo.jp/a/%E3%83%8B%E3%82%B3%E3%83%8B%E3%82%B3%E5%8B%95%E7%94%BBapi /// </remarks> public static VideoData CreateFromApi(string videoStr) { if (string.IsNullOrEmpty(videoStr)) { throw new ArgumentNullException("videoStr"); } var videoId = VideoUtil.GetVideoId(videoStr); if (string.IsNullOrEmpty(videoId)) { throw new NicoVideoException( $"{videoStr}: 不正な動画IDです。"); } var url = string.Format( "http://ext.nicovideo.jp/api/getthumbinfo/{0}", videoId); var node = NicoUtil.GetXml(url, null); return(new VideoData(videoId, node)); }
/// <summary> /// 動画番号が含まれる文字列から情報を作成します。 /// </summary> public static VideoData CreateFromPage(string videoStr, CookieContainer cc) { if (string.IsNullOrEmpty(videoStr)) { throw new ArgumentNullException("videoStr"); } if (cc == null) { throw new ArgumentNullException("cc"); } var videoId = VideoUtil.GetVideoId(videoStr); if (string.IsNullOrEmpty(videoId)) { throw new NicoVideoException( $"{videoStr}: 不正な動画IDです。"); } // urlを取得します。 var responseData = WebUtil.RequestHttp( NicoString.GetVideoUrl(videoId), null, cc); // 失敗;; エラー時はレスポンスが空になります。 if (responseData == null) { throw new NicoVideoException( "放送ページの取得に失敗しました。", videoId); } var text = Encoding.UTF8.GetString(responseData); return(CreateFromPageHtml(text)); }