pull/32/head
kunfei 5 years ago
parent c65aabf4f7
commit e3caa4f81f
  1. 2
      app/src/main/java/io/legado/app/model/WebBook.kt
  2. 7
      app/src/main/java/io/legado/app/model/webbook/BookList.kt
  3. 6
      app/src/main/java/io/legado/app/utils/NetworkUtils.kt

@ -33,7 +33,7 @@ class WebBook(private val bookSource: BookSource) : CoroutineScope by MainScope(
} }
return@with BookList().analyzeBookList(response, bookSource, analyzeUrl) return@with BookList().analyzeBookList(response, bookSource, analyzeUrl)
} }
ArrayList() return@with ArrayList<SearchBook>()
} }
} }

@ -4,7 +4,9 @@ import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.SearchBook import io.legado.app.data.entities.SearchBook
import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.NetworkUtils
import retrofit2.Response import retrofit2.Response
class BookList { class BookList {
@ -17,13 +19,16 @@ class BookList {
isSearch: Boolean = true isSearch: Boolean = true
): ArrayList<SearchBook> { ): ArrayList<SearchBook> {
var bookList = ArrayList<SearchBook>() var bookList = ArrayList<SearchBook>()
val baseUrl: String = NetworkUtils.getUrl(response)
val body: String? = response.body() val body: String? = response.body()
body ?: throw Exception( body ?: throw Exception(
App.INSTANCE.getString( App.INSTANCE.getString(
R.string.get_web_content_error, R.string.get_web_content_error,
analyzeUrl.url baseUrl
) )
) )
val analyzer = AnalyzeRule(null)
analyzer.setContent(body, baseUrl)
return bookList return bookList
} }

@ -1,10 +1,16 @@
package io.legado.app.utils package io.legado.app.utils
import android.text.TextUtils import android.text.TextUtils
import retrofit2.Response
import java.net.URL import java.net.URL
import java.util.* import java.util.*
object NetworkUtils { object NetworkUtils {
fun getUrl(response: Response<*>): String {
val networkResponse = response.raw().networkResponse()
return networkResponse?.request()?.url()?.toString()
?: response.raw().request().url().toString()
}
private val notNeedEncoding: BitSet by lazy { private val notNeedEncoding: BitSet by lazy {
val bitSet = BitSet(256) val bitSet = BitSet(256)

Loading…
Cancel
Save