@@ -312,23 +312,47 @@ struct Parser {
312
312
static func parseGalleryDetail( doc: HTMLDocument , gid: String ) throws -> ( GalleryDetail , GalleryState ) {
313
313
func parsePreviewConfig( doc: HTMLDocument ) throws -> PreviewConfig {
314
314
guard let previewMode = try ? parsePreviewMode ( doc: doc) ,
315
- let gdoNode = doc. at_xpath ( " //div [@id='gdo'] " ) ,
316
- let rows = gdoNode. at_xpath ( " //div [@id='gdo2'] " ) ? . xpath ( " //div " )
315
+ let gpcText = doc. at_xpath ( " //p [@class='gpc'] " ) ? . text,
316
+ let rangeA = gpcText. range ( of: " Showing 1 - " ) ,
317
+ let rangeB = gpcText. range ( of: " of " ) ,
318
+ let singlePageCount = Int ( gpcText [ rangeA. upperBound..< rangeB. lowerBound] )
317
319
else { throw AppError . parseFailed }
318
320
319
- for rowLink in rows where rowLink. className == " ths nosel " {
320
- guard let rowsCount = Int (
321
- rowLink. text? . replacingOccurrences (
322
- of: " rows " , with: " " ) ?? " "
323
- ) else { throw AppError . parseFailed }
321
+ if previewMode == " gdtl " {
322
+ switch singlePageCount {
323
+ case _ where singlePageCount <= 20 :
324
+ return . large( rows: 4 )
324
325
325
- if previewMode == " gdtl " {
326
- return . large( rows: rowsCount)
327
- } else {
328
- return . normal( rows: rowsCount)
326
+ case _ where singlePageCount <= 50 :
327
+ return . large( rows: 10 )
328
+
329
+ case _ where singlePageCount <= 100 :
330
+ return . large( rows: 20 )
331
+
332
+ case _ where singlePageCount <= 200 :
333
+ return . large( rows: 40 )
334
+
335
+ default :
336
+ return . large( rows: 4 )
337
+ }
338
+ } else {
339
+ switch singlePageCount {
340
+ case _ where singlePageCount <= 40 :
341
+ return . normal( rows: 4 )
342
+
343
+ case _ where singlePageCount <= 100 :
344
+ return . normal( rows: 10 )
345
+
346
+ case _ where singlePageCount <= 200 :
347
+ return . normal( rows: 20 )
348
+
349
+ case _ where singlePageCount <= 400 :
350
+ return . normal( rows: 40 )
351
+
352
+ default :
353
+ return . normal( rows: 4 )
329
354
}
330
355
}
331
- throw AppError . parseFailed
332
356
}
333
357
334
358
func parseCoverURL( node: XMLElement ? ) throws -> URL {
@@ -741,14 +765,13 @@ struct Parser {
741
765
}
742
766
743
767
static func parsePreviewMode( doc: HTMLDocument ) throws -> String {
744
- guard let gdoNode = doc. at_xpath ( " //div [@id='gdo '] " ) ,
745
- let gdo4Node = gdoNode . at_xpath ( " //div [@id='gdo4'] " )
746
- else { return " gdtm " }
747
-
748
- for link in gdo4Node . xpath ( " //div " ) where link . text == " Large " {
749
- return link [ " class " ] == " ths nosel " ? " gdtl " : " gdtm "
768
+ if doc. at_xpath ( " //div [@class='gdtm '] " ) != nil {
769
+ return " gdtm "
770
+ } else if doc . at_xpath ( " //div [@class='gdtl'] " ) != nil {
771
+ return " gdtl "
772
+ } else {
773
+ throw AppError . parseFailed
750
774
}
751
- return " gdtm "
752
775
}
753
776
754
777
static func parseMPVKeys( doc: HTMLDocument ) throws -> ( String , [ Int : String ] ) {
0 commit comments