/// <summary> /// Urlからコミュニティ情報を取得します。 /// </summary> /// <exception cref="System.TimeoutException" /> /// <exception cref="System.Net.WebException" /> public static CommunityInfo Create(int id, CookieContainer cc) { // ページを取得します。 var responseData = WebUtil.RequestHttp( NicoString.GetCommunityUrl(id), null, cc); // 失敗;; コミュニティエラー時はレスポンスが空になります。 if (responseData == null) { throw new NicoLiveException( "コミュニティページの取得に失敗しました。", LiveUtil.CommunityIdString(id)); } var text = Encoding.UTF8.GetString(responseData); return(CreateFromHtml(id, text)); }
/// <summary> /// 現在放送中の放送アドレスをコミュニティから取得します。 /// </summary> private static string GetCurrentLiveUrlFromCommunity(int communityId, CookieContainer cc) { try { var responseText = WebUtil.RequestHttpText( NicoString.GetCommunityUrl(communityId), null, cc, Encoding.UTF8); if (string.IsNullOrEmpty(responseText)) { return(null); } var m = CurrentLiveCommunityPageRegex.Match(responseText); if (!m.Success) { return(null); } var liveId = long.Parse(m.Groups[1].Value); return(NicoString.GetLiveUrl(liveId)); } catch (WebException) { // クローズコミュニティの場合はこの例外が発生します。 } catch (Exception ex) { Util.ThrowIfFatal(ex); Log.ErrorException(ex, "co{0}: コミュニティページの取得に失敗しました。", communityId); } return(null); }