Skip to content

Commit

Permalink
fixed providers + code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
LagradOst committed Jan 30, 2024
1 parent 6b80aae commit adcbfab
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 63 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
package com.lagradost.quicknovel.providers

import com.lagradost.quicknovel.*
import com.lagradost.quicknovel.ErrorLoadingException
import com.lagradost.quicknovel.HeadMainPageResponse
import com.lagradost.quicknovel.LoadResponse
import com.lagradost.quicknovel.MainAPI
import com.lagradost.quicknovel.MainActivity.Companion.app
import org.jsoup.Jsoup
import com.lagradost.quicknovel.R
import com.lagradost.quicknovel.STATUS_COMPLETE
import com.lagradost.quicknovel.STATUS_NULL
import com.lagradost.quicknovel.STATUS_ONGOING
import com.lagradost.quicknovel.SearchResponse
import com.lagradost.quicknovel.fixUrlNull
import com.lagradost.quicknovel.newChapterData
import com.lagradost.quicknovel.newSearchResponse
import com.lagradost.quicknovel.newStreamResponse
import kotlin.math.roundToInt

open class AllNovelProvider : MainAPI() {
override val name = "AllNovel"
Expand Down Expand Up @@ -121,9 +133,10 @@ open class AllNovelProvider : MainAPI() {
app.get("$mainUrl/search?keyword=$query").document // AJAX, MIGHT ADD QUICK SEARCH

return document.select("#list-page>.archive>.list>.row").mapNotNull { h ->
val title = h.selectFirst(">div>div>.truyen-title>a") ?: return@mapNotNull null
val title = h.selectFirst(">div>div>.truyen-title>a")
?: h.selectFirst(">div>div>.novel-title>a") ?: return@mapNotNull null
newSearchResponse(title.text(), title.attr("href") ?: return@mapNotNull null) {
posterUrl = fixUrlNull(h.selectFirst(">div>div>img")?.attr("href"))
posterUrl = fixUrlNull(h.selectFirst(">div>div>img")?.attr("src"))
}
}
}
Expand Down Expand Up @@ -157,8 +170,8 @@ open class AllNovelProvider : MainAPI() {
peopleVoted =
document.selectFirst(" div.small > em > strong:nth-child(3) > span")?.text()
?.toIntOrNull() ?: 0
rating = document.selectFirst(" div.small > em > strong:nth-child(1) > span")?.text()
?.toIntOrNull() ?: 0
rating = document.selectFirst("div.small > em > strong:nth-child(1) > span")?.text()
?.toFloatOrNull()?.times(100)?.roundToInt()

this.status =
when (document.selectFirst("div.info > div:nth-child(5) > a")?.selectFirst("a")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.fasterxml.jackson.annotation.JsonProperty
import com.lagradost.quicknovel.DownloadExtractLink
import com.lagradost.quicknovel.DownloadLink
import com.lagradost.quicknovel.DownloadLinkType
import com.lagradost.quicknovel.EpubResponse
import com.lagradost.quicknovel.LoadResponse
import com.lagradost.quicknovel.MainAPI
import com.lagradost.quicknovel.MainActivity.Companion.app
Expand Down Expand Up @@ -52,9 +51,10 @@ class AnnasArchive : MainAPI() {
private suspend fun loadFromJsonUrl(md5: String): LoadResponse {
return app.get("$mainUrl/db/md5/$md5.json").parsed<AnnasArchiveRoot>().let { root ->
newEpubResponse(
name = root.fileUnifiedData?.titleBest ?: root.additional.topBox.title?: root.fileUnifiedData?.titleAdditional!!.first(),
name = root.fileUnifiedData?.titleBest ?: root.additional.topBox.title
?: root.fileUnifiedData?.titleAdditional!!.first(),
url = "$mainUrl/md5/$md5",
links = root.additional.downloadUrls.mapNotNull { list ->
links = root.additional.downloadUrls.mapNotNull { list ->
val name = list.getOrNull(0) ?: return@mapNotNull null
val link = list.getOrNull(1) ?: return@mapNotNull null
extract(link, name)
Expand All @@ -79,15 +79,18 @@ class AnnasArchive : MainAPI() {
}

// backup non json parser
val response = app.get(url).document

return newEpubResponse(name = response.selectFirst("main > div > div.text-3xl")?.ownText()!!,url = url, links = response.select("div.mb-6 > ul.mb-4 > li > a").mapNotNull { element ->
val link = fixUrlNull(element.attr("href")) ?: return@mapNotNull null
extract(link, element.text())
}) {
posterUrl = response.selectFirst("main > div > img")?.attr("src")
author = response.selectFirst("main > div > div.italic")?.ownText()
synopsis = response.selectFirst("main > div > div.js-md5-top-box-description")?.text()
val document = app.get(url).document

return newEpubResponse(
name = document.selectFirst("main > div > div.text-3xl")?.ownText()!!,
url = url,
links = document.select("div.mb-6 > ul.mb-4 > li > a").mapNotNull { element ->
val link = fixUrlNull(element.attr("href")) ?: return@mapNotNull null
extract(link, element.text())
}) {
posterUrl = document.selectFirst("main > div > img")?.attr("src")
author = document.selectFirst("main > div > div.italic")?.ownText()
synopsis = document.selectFirst("main > div > div.js-md5-top-box-description")?.text()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
package com.lagradost.quicknovel.providers

import com.lagradost.quicknovel.*
import com.lagradost.quicknovel.LoadResponse
import com.lagradost.quicknovel.MainAPI
import com.lagradost.quicknovel.MainActivity.Companion.app
import org.jsoup.Jsoup
import com.lagradost.quicknovel.STATUS_COMPLETE
import com.lagradost.quicknovel.STATUS_NULL
import com.lagradost.quicknovel.STATUS_ONGOING
import com.lagradost.quicknovel.SearchResponse
import com.lagradost.quicknovel.fixUrlNull
import com.lagradost.quicknovel.newChapterData
import com.lagradost.quicknovel.newSearchResponse
import com.lagradost.quicknovel.newStreamResponse
import com.lagradost.quicknovel.textClean

class BestLightNovelProvider : MainAPI() {
override val name = "BestLightNovel"
override val mainUrl = "https://bestlightnovel.com"

override suspend fun loadHtml(url: String): String? {
val response = app.get(url)
val document = Jsoup.parse(response.text)
val document = app.get(url).document
val res = document.selectFirst("div.vung_doc")
return res?.html().textClean?.replace("[Updated from F r e e w e b n o v e l. c o m]", "")?.replace("Find authorized novels in Webnovel,faster updates, better experience,Please click for visiting. ","")
return res?.html().textClean?.replace("[Updated from F r e e w e b n o v e l. c o m]", "")
?.replace(
"Find authorized novels in Webnovel,faster updates, better experience,Please click for visiting. ",
""
)
}

override suspend fun search(query: String): List<SearchResponse> {
val response = app.get("$mainUrl/search_novels/${query.replace(' ', '_')}")
val document = app.get("$mainUrl/search_novels/${query.replace(' ', '_')}").document

val document = Jsoup.parse(response.text)
val headers = document.select("div.danh_sach > div.list_category")
return headers.mapNotNull {
val head = it.selectFirst("> a")
Expand All @@ -33,9 +44,8 @@ class BestLightNovelProvider : MainAPI() {
}

override suspend fun load(url: String): LoadResponse? {
val response = app.get(url)
val document = app.get(url).document

val document = Jsoup.parse(response.text)
val infoHeaders = document.select("ul.truyen_info_right > li")

val name = infoHeaders[0].selectFirst("> h1")?.text() ?: return null
Expand All @@ -50,7 +60,7 @@ class BestLightNovelProvider : MainAPI() {
}
}.reversed()

return newStreamResponse(url = url, name = name, data= chapterHeaders) {
return newStreamResponse(url = url, name = name, data = chapterHeaders) {
for (a in infoHeaders[1].select("> a")) {
val href = a?.attr("href")
if (a.hasText() && (href?.length
Expand Down Expand Up @@ -78,7 +88,8 @@ class BestLightNovelProvider : MainAPI() {
?.times(200))?.toInt() ?: 0

peopleVoted = ratingHeader?.get(2)?.text()?.replace(",", "")?.toInt() ?: 0
} catch (_: Throwable) { }
} catch (_: Throwable) {
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,18 +169,6 @@ open class BoxNovelProvider : MainAPI() {
?.replace("\n", "")
?.replace("\t", "") ?: return null

var synopsis = ""
var synopsisParts = document.select("#editdescription > p")
if (synopsisParts.size == 0) synopsisParts = document.select("div.j_synopsis > p")
if (synopsisParts.size == 0) synopsisParts = document.select("div.summary__content > p")
for (s in synopsisParts) {
if (s.hasText() && !s.text().lowercase(Locale.getDefault())
.contains(mainUrl)
) { // FUCK ADS
synopsis += s.text() + "\n\n"
}
}

val data = getChapters(
app.post(
"${url}ajax/chapters/",
Expand All @@ -200,7 +188,20 @@ open class BoxNovelProvider : MainAPI() {
break
}
}

var synopsis = ""
var synopsisParts = document.select("#editdescription > p")
if (synopsisParts.size == 0) synopsisParts = document.select("div.j_synopsis > p")
if (synopsisParts.size == 0) synopsisParts = document.select("div.summary__content > p")
for (s in synopsisParts) {
if (s.hasText() && !s.text().lowercase(Locale.getDefault())
.contains(mainUrl)
) { // FUCK ADS
synopsis += s.text() + "\n\n"
}
}
if (synopsis.isNotEmpty()) {
this.synopsis = synopsis
}
status =
when (document.select("div.post-status > div.post-content_item > div.summary-content")
.last()?.text()?.lowercase()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class ComrademaoProvider : MainAPI() {

override suspend fun search(query: String): List<SearchResponse> {
val url = "$mainUrl/?s=$query&post_type=novel"
val response = app.get(url)
val document = Jsoup.parse(response.text)
val document = app.get(url).document

val items = document.select(".bs")
return items.mapNotNull {
val titleHolder = it.selectFirst("a")
Expand All @@ -25,15 +25,15 @@ class ComrademaoProvider : MainAPI() {
}

override suspend fun loadHtml(url: String): String? {
val response = app.get(url)
val document = Jsoup.parse(response.text)
val document = app.get(url).document

return document.selectFirst("div[readability]")?.html()
?.replace("(end of this chapter)", "", ignoreCase = true)
}

override suspend fun load(url: String): LoadResponse? {
val response = app.get(url)
val document = Jsoup.parse(response.text)
val document = app.get(url).document

val novelInfo = document.selectFirst("div.thumb > img")
val mainDivs = document.select("div.infox")

Expand All @@ -50,12 +50,15 @@ class ComrademaoProvider : MainAPI() {
txt.contains("Genre") -> {
genres = ArrayList(element.select("a").map { it.text() })
}

txt.contains("Tag") -> {
tags = ArrayList(element.select("a").map { it.text() })
}

txt.contains("Publisher") -> {
author = element.selectFirst("a")?.text()
}

txt.contains("Status") -> {
status = element.selectFirst("a")?.text()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,52 @@ package com.lagradost.quicknovel.providers
import com.lagradost.quicknovel.*
import com.lagradost.quicknovel.MainActivity.Companion.app
import org.jsoup.Jsoup

class FreewebnovelProvider : LibReadProvider() {
override val name = "FreeWebNovel"
override val mainUrl = "https://freewebnovel.com"
override val hasMainPage = true

override val iconId = R.drawable.icon_freewebnovel

override val iconBackgroundId = R.color.wuxiaWorldOnlineColor

override suspend fun loadMainPage(
page: Int,
mainCategory: String?,
orderBy: String?,
tag: String?
): HeadMainPageResponse {
val url =
if (tag.isNullOrBlank()) "$mainUrl/latest-release/$page" else "$mainUrl/genres/$tag/$page"
val document = app.get(url).document
val headers = document.select("div.ul-list1.ul-list1-2.ss-custom > div.li-row")
val returnValue = headers.mapNotNull { h ->
val h3 = h?.selectFirst("h3.tit > a") ?: return@mapNotNull null
newSearchResponse(
name = h3.attr("title"),
url = h3.attr("href") ?: return@mapNotNull null
) {
posterUrl = fixUrlNull(h.selectFirst("div.pic > a > img")?.attr("src"))
latestChapter = h.select("div.item")[2].selectFirst("> div > a")?.text()
}
}
return HeadMainPageResponse(url, returnValue)
}

override suspend fun loadHtml(url: String): String? {
val response = app.get(url)
val document = Jsoup.parse(
response.text
.replace("New novel chapters are published on Freewebnovel.com.", "")
.replace("The source of this content is Freewebnᴏvel.com.", "").replace(
"☞ We are moving Freewebnovel.com to Libread.com, Please visit libread.com for more chapters! ☜",
""
)
)
return document.selectFirst("div.txt>.notice-text")?.html()
}
}


/*
class FreewebnovelProvider : MainAPI() {
override val name = "FreeWebNovel"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ class KolNovelProvider : MainAPI() {
}

override suspend fun loadHtml(url: String): String? {
val response = app.get(url)
val document = Jsoup.parse(response.text)
val document = app.get(url).document
return document.selectFirst("div.entry-content")?.html()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class NovelsOnlineProvider : MainAPI() {
"Yaoi" to "yaoi",
"Yuri" to "yuri",
)
val interceptor = CloudflareKiller()
private val interceptor = CloudflareKiller()

override suspend fun loadMainPage(
page: Int,
Expand All @@ -75,7 +75,8 @@ class NovelsOnlineProvider : MainAPI() {
url = adata.attr("href"),
) {
posterHeaders = interceptor.getCookieHeaders(url).toMap()
posterUrl = h.selectFirst("div.top-novel-content > div.top-novel-cover > a > img")!!.attr("src")
posterUrl = h.selectFirst("div.top-novel-content > div.top-novel-cover > a > img")!!
.attr("src")
}
}
return HeadMainPageResponse(url, list)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,7 @@ open class ReadfromnetProvider : MainAPI() {

val returnValue = document.select("div.box_in").mapNotNull { h ->
val name = h?.selectFirst("h2")?.text() ?: return@mapNotNull null
val cUrl = h.selectFirst(" div > h2.title > a ")?.attr("href") ?: return@mapNotNull null
val cUrl = h.selectFirst(" div > h2.title > a ")?.attr("href") ?: return@mapNotNull null

newSearchResponse(name = name, url = cUrl) {
posterUrl = fixUrlNull(h.selectFirst("div > a.highslide > img")?.attr("src"))
Expand All @@ -1391,8 +1391,7 @@ open class ReadfromnetProvider : MainAPI() {
}

override suspend fun loadHtml(url: String): String? {
val response = app.get(url, headers = baseHeaders)
val document = Jsoup.parse(response.text)
val document = app.get(url, headers = baseHeaders).document
document.select("div.splitnewsnavigation").remove()
document.select("div.splitnewsnavigation2").remove()
return document.selectFirst("#textToRead")?.html()
Expand Down Expand Up @@ -1462,7 +1461,10 @@ open class ReadfromnetProvider : MainAPI() {
?.text()

posterUrl =
fixUrlNull(document.selectFirst("div.box_in > center:nth-child(1) > div > a > img")?.attr("src"))
fixUrlNull(
document.selectFirst("div.box_in > center:nth-child(1) > div > a > img")
?.attr("src")
)
}
}
}
Loading

0 comments on commit adcbfab

Please sign in to comment.