@@ -103,14 +103,24 @@ class IllustParser {
103103 async parseContext ( ) {
104104 this . parseUrl ( this . url ) ;
105105
106- await this . parseInfo ( this . context . id ) ;
106+ if ( this . context . unlistedId ) {
107+ await this . parseUnlistedInfo ( ) ;
107108
108- if ( [ IllustParser . ILLUST_TYPE , IllustParser . MANGA_TYPE ] . indexOf ( this . context . illustType ) > - 1 ) {
109- await this . parsePages ( this . context . id ) ;
110- } else if ( this . context . illustType === IllustParser . UGOIRA_TYPE ) {
111- await this . parseUgoiraMeta ( this . context . id ) ;
109+ if ( [ IllustParser . ILLUST_TYPE , IllustParser . MANGA_TYPE ] . indexOf ( this . context . illustType ) > - 1 ) {
110+ await this . parseUnlistedPages ( ) ;
111+ } else {
112+ throw new RuntimeError ( `Invalid unlisted illust type ${ this . context . illustType } ` ) ;
113+ }
112114 } else {
113- throw new RuntimeError ( `Invalid illust type ${ this . context . illustType } ` ) ;
115+ await this . parseInfo ( this . context . id ) ;
116+
117+ if ( [ IllustParser . ILLUST_TYPE , IllustParser . MANGA_TYPE ] . indexOf ( this . context . illustType ) > - 1 ) {
118+ await this . parsePages ( this . context . id ) ;
119+ } else if ( this . context . illustType === IllustParser . UGOIRA_TYPE ) {
120+ await this . parseUgoiraMeta ( this . context . id ) ;
121+ } else {
122+ throw new RuntimeError ( `Invalid illust type ${ this . context . illustType } ` ) ;
123+ }
114124 }
115125 }
116126
@@ -121,6 +131,14 @@ class IllustParser {
121131 * @throws {RuntimeError }
122132 */
123133 parseUrl ( url ) {
134+ const unlistedPattern = / a r t w o r k s \/ ( u n l i s t e d ) \/ ( [ a - z \d ] + ) / i;
135+ const unlistedMatches = url . match ( unlistedPattern ) ;
136+
137+ if ( unlistedMatches ) {
138+ this . context . unlistedId = unlistedMatches [ 2 ]
139+ return ;
140+ }
141+
124142 let patterns = [ / i l l u s t _ i d = ( \d + ) / i, / a r t w o r k s \/ ( \d + ) / i] ;
125143
126144 for ( let pattern of patterns ) {
@@ -135,6 +153,10 @@ class IllustParser {
135153 throw new RuntimeError ( `Can't parse the illust id out. url: ${ this . url } ` ) ;
136154 }
137155
156+ buildUnlistedInfoUrl ( ) {
157+ return `https://www.pixiv.net/ajax/illust/unlisted/${ this . context . unlistedId } ` ;
158+ }
159+
138160 /**
139161 * Build url which will represet illust's information.
140162 * @param {string } id
@@ -178,10 +200,37 @@ class IllustParser {
178200 // contexts from parsed
179201 year : dateFormatter . getYear ( ) ,
180202 month : dateFormatter . getMonth ( ) ,
181- day : dateFormatter . getDay ( )
203+ day : dateFormatter . getDay ( ) ,
204+ __raw : context
182205 }
183206 }
184207
208+ /**
209+ * Parse unlisted illust base information
210+ */
211+ parseUnlistedInfo ( ) {
212+ return new Promise ( ( resolve , reject ) => {
213+ this . request = new Request ( this . buildUnlistedInfoUrl ( ) , { method : 'GET' } ) ;
214+
215+ this . request . addListener ( 'onload' , data => {
216+ let textDecoder = new TextDecoder ( ) ;
217+ let json = JSON . parse ( textDecoder . decode ( data ) ) ;
218+
219+ if ( json && json . body ) {
220+ this . context = this . standardContext ( json . body ) ;
221+
222+ resolve ( ) ;
223+ }
224+ } ) ;
225+
226+ this . request . addListener ( 'onerror' , error => {
227+ reject ( error ) ;
228+ } )
229+
230+ this . request . send ( ) ;
231+ } ) ;
232+ }
233+
185234 /**
186235 * Parse illust base information
187236 * @param {string } id
@@ -219,6 +268,11 @@ class IllustParser {
219268 return `https://www.pixiv.net/ajax/illust/${ id } /pages` ;
220269 }
221270
271+ parseUnlistedPages ( ) {
272+ this . context . pages = [ this . context . __raw . urls . original ] ;
273+ this . context . totalPages = 1 ;
274+ }
275+
222276 /**
223277 * Parse illust's pages
224278 * @param {string } id
0 commit comments