|  |  |  | @ -3,6 +3,7 @@ package io.legado.app.model | 
			
		
	
		
			
				
					|  |  |  |  | import android.annotation.SuppressLint | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.data.entities.Book | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.data.entities.BookChapter | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.data.entities.RssSource | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.help.coroutine.CompositeCoroutine | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.utils.htmlFormat | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.utils.isAbsUrl | 
			
		
	
	
		
			
				
					|  |  |  | @ -21,7 +22,7 @@ object SourceDebug { | 
			
		
	
		
			
				
					|  |  |  |  |     @Synchronized | 
			
		
	
		
			
				
					|  |  |  |  |     fun printLog( | 
			
		
	
		
			
				
					|  |  |  |  |         sourceUrl: String?, | 
			
		
	
		
			
				
					|  |  |  |  |         msg: String?, | 
			
		
	
		
			
				
					|  |  |  |  |         msg: String? = "", | 
			
		
	
		
			
				
					|  |  |  |  |         print: Boolean = true, | 
			
		
	
		
			
				
					|  |  |  |  |         isHtml: Boolean = false, | 
			
		
	
		
			
				
					|  |  |  |  |         showTime: Boolean = true, | 
			
		
	
	
		
			
				
					|  |  |  | @ -48,6 +49,16 @@ object SourceDebug { | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     fun startDebug(rssSource: RssSource) { | 
			
		
	
		
			
				
					|  |  |  |  |         Rss.getArticles(rssSource) | 
			
		
	
		
			
				
					|  |  |  |  |             .onSuccess { | 
			
		
	
		
			
				
					|  |  |  |  |                 printLog(debugSource, "︽正文页解析完成", state = 1000) | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |             .onError { | 
			
		
	
		
			
				
					|  |  |  |  |                 printLog(debugSource, it.localizedMessage, state = -1) | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     fun startDebug(webBook: WebBook, key: String) { | 
			
		
	
		
			
				
					|  |  |  |  |         cancelDebug() | 
			
		
	
		
			
				
					|  |  |  |  |         startTime = System.currentTimeMillis() | 
			
		
	
	
		
			
				
					|  |  |  | @ -56,58 +67,32 @@ object SourceDebug { | 
			
		
	
		
			
				
					|  |  |  |  |                 val book = Book() | 
			
		
	
		
			
				
					|  |  |  |  |                 book.origin = webBook.sourceUrl | 
			
		
	
		
			
				
					|  |  |  |  |                 book.bookUrl = key | 
			
		
	
		
			
				
					|  |  |  |  |                 printLog( | 
			
		
	
		
			
				
					|  |  |  |  |                     webBook.sourceUrl, | 
			
		
	
		
			
				
					|  |  |  |  |                     "⇒开始访问详情页:$key" | 
			
		
	
		
			
				
					|  |  |  |  |                 ) | 
			
		
	
		
			
				
					|  |  |  |  |                 printLog(webBook.sourceUrl, "⇒开始访问详情页:$key") | 
			
		
	
		
			
				
					|  |  |  |  |                 infoDebug(webBook, book) | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |             key.contains("::") -> { | 
			
		
	
		
			
				
					|  |  |  |  |                 val url = key.substring(key.indexOf("::") + 2) | 
			
		
	
		
			
				
					|  |  |  |  |                 printLog( | 
			
		
	
		
			
				
					|  |  |  |  |                     webBook.sourceUrl, | 
			
		
	
		
			
				
					|  |  |  |  |                     "⇒开始访问发现页:$url" | 
			
		
	
		
			
				
					|  |  |  |  |                 ) | 
			
		
	
		
			
				
					|  |  |  |  |                 printLog(webBook.sourceUrl, "⇒开始访问发现页:$url") | 
			
		
	
		
			
				
					|  |  |  |  |                 exploreDebug(webBook, url) | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |             else -> { | 
			
		
	
		
			
				
					|  |  |  |  |                 printLog( | 
			
		
	
		
			
				
					|  |  |  |  |                     webBook.sourceUrl, | 
			
		
	
		
			
				
					|  |  |  |  |                     "⇒开始搜索关键字:$key" | 
			
		
	
		
			
				
					|  |  |  |  |                 ) | 
			
		
	
		
			
				
					|  |  |  |  |                 printLog(webBook.sourceUrl, "⇒开始搜索关键字:$key") | 
			
		
	
		
			
				
					|  |  |  |  |                 searchDebug(webBook, key) | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private fun exploreDebug(webBook: WebBook, url: String) { | 
			
		
	
		
			
				
					|  |  |  |  |         printLog( | 
			
		
	
		
			
				
					|  |  |  |  |             debugSource, | 
			
		
	
		
			
				
					|  |  |  |  |             "︾开始解析发现页" | 
			
		
	
		
			
				
					|  |  |  |  |         ) | 
			
		
	
		
			
				
					|  |  |  |  |         printLog(debugSource, "︾开始解析发现页") | 
			
		
	
		
			
				
					|  |  |  |  |         val explore = webBook.exploreBook(url, 1) | 
			
		
	
		
			
				
					|  |  |  |  |             .onSuccess { exploreBooks -> | 
			
		
	
		
			
				
					|  |  |  |  |                 exploreBooks?.let { | 
			
		
	
		
			
				
					|  |  |  |  |                     if (exploreBooks.isNotEmpty()) { | 
			
		
	
		
			
				
					|  |  |  |  |                         printLog( | 
			
		
	
		
			
				
					|  |  |  |  |                             debugSource, | 
			
		
	
		
			
				
					|  |  |  |  |                             "︽发现页解析完成" | 
			
		
	
		
			
				
					|  |  |  |  |                         ) | 
			
		
	
		
			
				
					|  |  |  |  |                         printLog( | 
			
		
	
		
			
				
					|  |  |  |  |                             debugSource, | 
			
		
	
		
			
				
					|  |  |  |  |                             "", | 
			
		
	
		
			
				
					|  |  |  |  |                             showTime = false | 
			
		
	
		
			
				
					|  |  |  |  |                         ) | 
			
		
	
		
			
				
					|  |  |  |  |                         infoDebug( | 
			
		
	
		
			
				
					|  |  |  |  |                             webBook, | 
			
		
	
		
			
				
					|  |  |  |  |                             exploreBooks[0].toBook() | 
			
		
	
		
			
				
					|  |  |  |  |                         ) | 
			
		
	
		
			
				
					|  |  |  |  |                         printLog(debugSource, "︽发现页解析完成") | 
			
		
	
		
			
				
					|  |  |  |  |                         printLog(debugSource, showTime = false) | 
			
		
	
		
			
				
					|  |  |  |  |                         infoDebug(webBook, exploreBooks[0].toBook()) | 
			
		
	
		
			
				
					|  |  |  |  |                     } else { | 
			
		
	
		
			
				
					|  |  |  |  |                         printLog( | 
			
		
	
		
			
				
					|  |  |  |  |                             debugSource, | 
			
		
	
		
			
				
					|  |  |  |  |                             "︽未获取到书籍", | 
			
		
	
		
			
				
					|  |  |  |  |                             state = -1 | 
			
		
	
		
			
				
					|  |  |  |  |                         ) | 
			
		
	
		
			
				
					|  |  |  |  |                         printLog(debugSource, "︽未获取到书籍", state = -1) | 
			
		
	
		
			
				
					|  |  |  |  |                     } | 
			
		
	
		
			
				
					|  |  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
	
		
			
				
					|  |  |  | @ -122,114 +107,56 @@ object SourceDebug { | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private fun searchDebug(webBook: WebBook, key: String) { | 
			
		
	
		
			
				
					|  |  |  |  |         printLog( | 
			
		
	
		
			
				
					|  |  |  |  |             debugSource, | 
			
		
	
		
			
				
					|  |  |  |  |             "︾开始解析搜索页" | 
			
		
	
		
			
				
					|  |  |  |  |         ) | 
			
		
	
		
			
				
					|  |  |  |  |         printLog(debugSource, "︾开始解析搜索页") | 
			
		
	
		
			
				
					|  |  |  |  |         val search = webBook.searchBook(key, 1) | 
			
		
	
		
			
				
					|  |  |  |  |             .onSuccess { searchBooks -> | 
			
		
	
		
			
				
					|  |  |  |  |                 searchBooks?.let { | 
			
		
	
		
			
				
					|  |  |  |  |                     if (searchBooks.isNotEmpty()) { | 
			
		
	
		
			
				
					|  |  |  |  |                         printLog( | 
			
		
	
		
			
				
					|  |  |  |  |                             debugSource, | 
			
		
	
		
			
				
					|  |  |  |  |                             "︽搜索页解析完成" | 
			
		
	
		
			
				
					|  |  |  |  |                         ) | 
			
		
	
		
			
				
					|  |  |  |  |                         printLog( | 
			
		
	
		
			
				
					|  |  |  |  |                             debugSource, | 
			
		
	
		
			
				
					|  |  |  |  |                             "", | 
			
		
	
		
			
				
					|  |  |  |  |                             showTime = false | 
			
		
	
		
			
				
					|  |  |  |  |                         ) | 
			
		
	
		
			
				
					|  |  |  |  |                         infoDebug( | 
			
		
	
		
			
				
					|  |  |  |  |                             webBook, | 
			
		
	
		
			
				
					|  |  |  |  |                             searchBooks[0].toBook() | 
			
		
	
		
			
				
					|  |  |  |  |                         ) | 
			
		
	
		
			
				
					|  |  |  |  |                         printLog(debugSource, "︽搜索页解析完成") | 
			
		
	
		
			
				
					|  |  |  |  |                         printLog(debugSource, showTime = false) | 
			
		
	
		
			
				
					|  |  |  |  |                         infoDebug(webBook, searchBooks[0].toBook()) | 
			
		
	
		
			
				
					|  |  |  |  |                     } else { | 
			
		
	
		
			
				
					|  |  |  |  |                         printLog( | 
			
		
	
		
			
				
					|  |  |  |  |                             debugSource, | 
			
		
	
		
			
				
					|  |  |  |  |                             "︽未获取到书籍", | 
			
		
	
		
			
				
					|  |  |  |  |                             state = -1 | 
			
		
	
		
			
				
					|  |  |  |  |                         ) | 
			
		
	
		
			
				
					|  |  |  |  |                         printLog(debugSource, "︽未获取到书籍", state = -1) | 
			
		
	
		
			
				
					|  |  |  |  |                     } | 
			
		
	
		
			
				
					|  |  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |             .onError { | 
			
		
	
		
			
				
					|  |  |  |  |                 printLog( | 
			
		
	
		
			
				
					|  |  |  |  |                     debugSource, | 
			
		
	
		
			
				
					|  |  |  |  |                     it.localizedMessage, | 
			
		
	
		
			
				
					|  |  |  |  |                     state = -1 | 
			
		
	
		
			
				
					|  |  |  |  |                 ) | 
			
		
	
		
			
				
					|  |  |  |  |                 printLog(debugSource, it.localizedMessage, state = -1) | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |         tasks.add(search) | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private fun infoDebug(webBook: WebBook, book: Book) { | 
			
		
	
		
			
				
					|  |  |  |  |         printLog( | 
			
		
	
		
			
				
					|  |  |  |  |             debugSource, | 
			
		
	
		
			
				
					|  |  |  |  |             "︾开始解析详情页" | 
			
		
	
		
			
				
					|  |  |  |  |         ) | 
			
		
	
		
			
				
					|  |  |  |  |         printLog(debugSource, "︾开始解析详情页") | 
			
		
	
		
			
				
					|  |  |  |  |         val info = webBook.getBookInfo(book) | 
			
		
	
		
			
				
					|  |  |  |  |             .onSuccess { | 
			
		
	
		
			
				
					|  |  |  |  |                 printLog( | 
			
		
	
		
			
				
					|  |  |  |  |                     debugSource, | 
			
		
	
		
			
				
					|  |  |  |  |                     "︽详情页解析完成" | 
			
		
	
		
			
				
					|  |  |  |  |                 ) | 
			
		
	
		
			
				
					|  |  |  |  |                 printLog( | 
			
		
	
		
			
				
					|  |  |  |  |                     debugSource, | 
			
		
	
		
			
				
					|  |  |  |  |                     "", | 
			
		
	
		
			
				
					|  |  |  |  |                     showTime = false | 
			
		
	
		
			
				
					|  |  |  |  |                 ) | 
			
		
	
		
			
				
					|  |  |  |  |                 printLog(debugSource, "︽详情页解析完成") | 
			
		
	
		
			
				
					|  |  |  |  |                 printLog(debugSource, showTime = false) | 
			
		
	
		
			
				
					|  |  |  |  |                 tocDebug(webBook, book) | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |             .onError { | 
			
		
	
		
			
				
					|  |  |  |  |                 printLog( | 
			
		
	
		
			
				
					|  |  |  |  |                     debugSource, | 
			
		
	
		
			
				
					|  |  |  |  |                     it.localizedMessage, | 
			
		
	
		
			
				
					|  |  |  |  |                     state = -1 | 
			
		
	
		
			
				
					|  |  |  |  |                 ) | 
			
		
	
		
			
				
					|  |  |  |  |                 printLog(debugSource, it.localizedMessage, state = -1) | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |         tasks.add(info) | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private fun tocDebug(webBook: WebBook, book: Book) { | 
			
		
	
		
			
				
					|  |  |  |  |         printLog( | 
			
		
	
		
			
				
					|  |  |  |  |             debugSource, | 
			
		
	
		
			
				
					|  |  |  |  |             "︾开始解析目录页" | 
			
		
	
		
			
				
					|  |  |  |  |         ) | 
			
		
	
		
			
				
					|  |  |  |  |         printLog(debugSource, "︾开始解析目录页") | 
			
		
	
		
			
				
					|  |  |  |  |         val chapterList = webBook.getChapterList(book) | 
			
		
	
		
			
				
					|  |  |  |  |             .onSuccess { chapterList -> | 
			
		
	
		
			
				
					|  |  |  |  |                 chapterList?.let { | 
			
		
	
		
			
				
					|  |  |  |  |                     if (it.isNotEmpty()) { | 
			
		
	
		
			
				
					|  |  |  |  |                         printLog( | 
			
		
	
		
			
				
					|  |  |  |  |                             debugSource, | 
			
		
	
		
			
				
					|  |  |  |  |                             "︽目录页解析完成" | 
			
		
	
		
			
				
					|  |  |  |  |                         ) | 
			
		
	
		
			
				
					|  |  |  |  |                         printLog( | 
			
		
	
		
			
				
					|  |  |  |  |                             debugSource, | 
			
		
	
		
			
				
					|  |  |  |  |                             "", | 
			
		
	
		
			
				
					|  |  |  |  |                             showTime = false | 
			
		
	
		
			
				
					|  |  |  |  |                         ) | 
			
		
	
		
			
				
					|  |  |  |  |                         printLog(debugSource, "︽目录页解析完成") | 
			
		
	
		
			
				
					|  |  |  |  |                         printLog(debugSource, showTime = false) | 
			
		
	
		
			
				
					|  |  |  |  |                         val nextChapterUrl = if (it.size > 1) it[1].url else null | 
			
		
	
		
			
				
					|  |  |  |  |                         contentDebug( | 
			
		
	
		
			
				
					|  |  |  |  |                             webBook, | 
			
		
	
		
			
				
					|  |  |  |  |                             book, | 
			
		
	
		
			
				
					|  |  |  |  |                             it[0], | 
			
		
	
		
			
				
					|  |  |  |  |                             nextChapterUrl | 
			
		
	
		
			
				
					|  |  |  |  |                         ) | 
			
		
	
		
			
				
					|  |  |  |  |                         contentDebug(webBook, book, it[0], nextChapterUrl) | 
			
		
	
		
			
				
					|  |  |  |  |                     } else { | 
			
		
	
		
			
				
					|  |  |  |  |                         printLog( | 
			
		
	
		
			
				
					|  |  |  |  |                             debugSource, | 
			
		
	
		
			
				
					|  |  |  |  |                             "︽目录列表为空", | 
			
		
	
		
			
				
					|  |  |  |  |                             state = -1 | 
			
		
	
		
			
				
					|  |  |  |  |                         ) | 
			
		
	
		
			
				
					|  |  |  |  |                         printLog(debugSource, "︽目录列表为空", state = -1) | 
			
		
	
		
			
				
					|  |  |  |  |                     } | 
			
		
	
		
			
				
					|  |  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |             .onError { | 
			
		
	
		
			
				
					|  |  |  |  |                 printLog( | 
			
		
	
		
			
				
					|  |  |  |  |                     debugSource, | 
			
		
	
		
			
				
					|  |  |  |  |                     it.localizedMessage, | 
			
		
	
		
			
				
					|  |  |  |  |                     state = -1 | 
			
		
	
		
			
				
					|  |  |  |  |                 ) | 
			
		
	
		
			
				
					|  |  |  |  |                 printLog(debugSource, it.localizedMessage, state = -1) | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |         tasks.add(chapterList) | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
	
		
			
				
					|  |  |  | @ -240,24 +167,13 @@ object SourceDebug { | 
			
		
	
		
			
				
					|  |  |  |  |         bookChapter: BookChapter, | 
			
		
	
		
			
				
					|  |  |  |  |         nextChapterUrl: String? | 
			
		
	
		
			
				
					|  |  |  |  |     ) { | 
			
		
	
		
			
				
					|  |  |  |  |         printLog( | 
			
		
	
		
			
				
					|  |  |  |  |             debugSource, | 
			
		
	
		
			
				
					|  |  |  |  |             "︾开始解析正文页" | 
			
		
	
		
			
				
					|  |  |  |  |         ) | 
			
		
	
		
			
				
					|  |  |  |  |         printLog(debugSource, "︾开始解析正文页") | 
			
		
	
		
			
				
					|  |  |  |  |         val content = webBook.getContent(book, bookChapter, nextChapterUrl) | 
			
		
	
		
			
				
					|  |  |  |  |             .onSuccess { | 
			
		
	
		
			
				
					|  |  |  |  |                 printLog( | 
			
		
	
		
			
				
					|  |  |  |  |                     debugSource, | 
			
		
	
		
			
				
					|  |  |  |  |                     "︽正文页解析完成", | 
			
		
	
		
			
				
					|  |  |  |  |                     state = 1000 | 
			
		
	
		
			
				
					|  |  |  |  |                 ) | 
			
		
	
		
			
				
					|  |  |  |  |                 printLog(debugSource, "︽正文页解析完成", state = 1000) | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |             .onError { | 
			
		
	
		
			
				
					|  |  |  |  |                 printLog( | 
			
		
	
		
			
				
					|  |  |  |  |                     debugSource, | 
			
		
	
		
			
				
					|  |  |  |  |                     it.localizedMessage, | 
			
		
	
		
			
				
					|  |  |  |  |                     state = -1 | 
			
		
	
		
			
				
					|  |  |  |  |                 ) | 
			
		
	
		
			
				
					|  |  |  |  |                 printLog(debugSource, it.localizedMessage, state = -1) | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |         tasks.add(content) | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
	
		
			
				
					|  |  |  | 
 |