/// <summary> /// ニコニコ動画(原宿)バージョンのアカウント情報を取得します。 /// </summary> private static AccountInfo GetAccountHarajuku(int id, string userPage) { var result = new AccountInfo() { Id = id, }; if (userPage.IndexOf("短時間での連続アクセスはご遠慮ください") >= 0) { throw new NicoException( "連続アクセスエラーです。"); } // ニックネームを取得します。 var m = Regex.Match( userPage, "<div id=\"headingUser\" class=\"cmnHeading\">" + "\\s*<h2><strong>([^\n]+)</strong>さん</h2>"); if (!m.Success) { throw new NicoException( "ニックネームの取得に失敗しました。"); } result.NickName = m.Groups[1].Value; // プレミアム会員かどうか調べます。 m = Regex.Match( userPage, "<dt>ID…</dt><dd>[^\n]+ ([^\n]+)会員</dd>"); if (!m.Success) { throw new NicoException( "プレミアム会員かどうかの取得に失敗しました。"); } result.IsPremium = (m.Groups[1].Value == "プレミアム"); // 性別を調べます。 m = Regex.Match( userPage, "<dt>性別…</dt><dd>([^<]+)</dd>"); if (!m.Success) { throw new NicoException( "性別の取得に失敗しました。"); } if (m.Groups[1].Value == "男性") { result.Gender = Gender.Male; } else if (m.Groups[1].Value == "女性") { result.Gender = Gender.Female; } else { result.Gender = Gender.Unknown; } // 生年月日を調べます。 // 住んでいる地域を調べます。 m = Regex.Match( userPage, "<dt>お住いの(地域|国)…</dt><dd class=\"last\">([^\n]+)</dd>"); if (!m.Success) { throw new NicoException( "住んでいる国の取得に失敗しました。"); } result.Place = (m.Groups[1].Value != "非公開" ? m.Groups[1].Value : null); return result; }
/// <summary> /// ニコニコ動画(Q)バージョンのアカウント情報を取得します。 /// </summary> private static AccountInfo GetAccountQ(int id, string userPage) { var result = new AccountInfo() { Id = id, }; /*if (userPage.IndexOf("短時間での連続アクセスはご遠慮ください") >= 0) { throw new NicoException( "連続アクセスエラーです。"); }*/ // ニックネームを取得します。 var m = Regex.Match( userPage, "<span id=\"siteHeaderUserNickNameContainer\">([^\n]+) さん</span>"); if (!m.Success) { throw new NicoException( "ニックネームの取得に失敗しました。"); } result.NickName = m.Groups[1].Value; // プレミアム会員かどうか調べます。 m = Regex.Match( userPage, "<p class=\"accountNumber\">ID:<span>\\d+([(][^)]+[)])? ([^\n]+)会員</span></p>"); if (!m.Success) { throw new NicoException( "プレミアム会員かどうかの取得に失敗しました。"); } result.IsPremium = (m.Groups[2].Value == "プレミアム"); // 性別を調べます。 m = Regex.Match( userPage, "<p>性別:<span>([^\n]*)</span></p>"); if (!m.Success) { throw new NicoException( "性別の取得に失敗しました。"); } if (m.Groups[1].Value == "男性") { result.Gender = Gender.Male; } else if (m.Groups[1].Value == "女性") { result.Gender = Gender.Female; } else { result.Gender = Gender.Unknown; } // 生年月日を調べます。 // 住んでいる地域を調べます。 m = Regex.Match( userPage, "<p>お住まいの(地域|国):<span>([^\n]*)</span></p>"); if (!m.Success) { throw new NicoException( "住んでいる地域の取得に失敗しました。"); } result.Place = (m.Groups[1].Value != "非公開" ? m.Groups[1].Value : null); return result; }