@@ -15,6 +15,7 @@ public ApiGetCommunityLivesException()
1515
1616 }
1717 }
18+ class NotLoggedInException : Exception { }
1819 class UserInfo
1920 {
2021 public string Nickname { get ; set ; }
@@ -53,12 +54,12 @@ public static async Task<CommunityLiveInfo[]> GetCommunityLives(IDataSource serv
5354 var url = $ "https://com.nicovideo.jp/api/v1/communities/{ communityIdWithoutCo } /lives.json";
5455 var res = await server . GetAsync ( url , cc ) ;
5556 dynamic d = JsonConvert . DeserializeObject ( res ) ;
56- if ( d . meta . status != 200 )
57+ if ( d . meta . status != 200 )
5758 {
5859 throw new ApiGetCommunityLivesException ( ) ;
5960 }
6061 var lives = new List < CommunityLiveInfo > ( ) ;
61- foreach ( var liveDyn in d . data . lives )
62+ foreach ( var liveDyn in d . data . lives )
6263 {
6364 var live = new CommunityLiveInfo
6465 {
@@ -82,14 +83,31 @@ public class CommunityLiveInfo
8283 public long UserId { get ; set ; }
8384 public string WatchUrl { get ; set ; }
8485 }
86+ /// <summary>
87+ ///
88+ /// </summary>
89+ /// <param name="server"></param>
90+ /// <param name="cc"></param>
91+ /// <returns></returns>
92+ /// <exception cref="NotLoggedInException">未ログインの場合</exception>
93+ /// <exception cref="SpecChangedException"></exception>
8594 public static async Task < MyInfo > GetMyInfo ( IDataSource server , CookieContainer cc )
8695 {
8796 var url = "https://www.nicovideo.jp/my" ;
8897 var html = await server . GetAsync ( url , cc ) ;
8998 var match = Regex . Match ( html , "data-common-header=\" (.+)\" ></div>" ) ;
9099 if ( ! match . Success )
91100 {
92- throw new SpecChangedException ( html ) ;
101+ var matchHtmlTitle = Regex . Match ( html , "<title>([^<]*)</title>" ) ;
102+ var title = matchHtmlTitle . Groups [ 1 ] . Value ;
103+ if ( matchHtmlTitle . Success && title . Contains ( "ログイン" ) )
104+ {
105+ throw new NotLoggedInException ( ) ;
106+ }
107+ else
108+ {
109+ throw new SpecChangedException ( html ) ;
110+ }
93111 }
94112 var json = match . Groups [ 1 ] . Value . Replace ( """ , "\" " ) ;
95113 dynamic d = JsonConvert . DeserializeObject ( json ) ;
0 commit comments