Skip to content

Commit aa38114

Browse files
committed
3.1.9 Fixed libread + rr
1 parent 6c5bd3f commit aa38114

File tree

7 files changed

+99
-60
lines changed

7 files changed

+99
-60
lines changed

app/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ android {
1515
minSdkVersion 21
1616
targetSdkVersion 34
1717
versionCode 55
18-
versionName "3.1.8"
18+
versionName "3.1.9"
1919
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2020
}
2121

app/src/main/java/com/lagradost/quicknovel/APIRepository.kt

+30-22
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.lagradost.quicknovel
22

33
import com.lagradost.quicknovel.mvvm.Resource
44
import com.lagradost.quicknovel.mvvm.logError
5-
import com.lagradost.quicknovel.mvvm.normalSafeApiCall
65
import com.lagradost.quicknovel.mvvm.safeApiCall
76
import com.lagradost.quicknovel.util.Coroutines.threadSafeListOf
87

@@ -52,34 +51,43 @@ class APIRepository(val api: MainAPI) {
5251

5352
suspend fun load(url: String, allowCache: Boolean = true): Resource<LoadResponse> {
5453
return safeApiCall {
55-
val fixedUrl = api.fixUrl(url)
56-
val lookingForHash = api.name to fixedUrl
57-
58-
if (allowCache) {
59-
synchronized(cache) {
60-
for (item in cache) {
61-
// 10 min save
62-
if (item.hash == lookingForHash && (unixTime - item.unixTime) < cacheTimeSec) {
63-
return@safeApiCall item.response
64-
}
65-
}
54+
try {
55+
if (api.hasRateLimit) {
56+
api.rateLimitMutex.lock()
6657
}
67-
}
58+
val fixedUrl = api.fixUrl(url)
59+
val lookingForHash = api.name to fixedUrl
6860

69-
api.load(fixedUrl)?.also { response ->
70-
// Remove all blank tags as early as possible
71-
val add = SavedLoadResponse(unixTime, response, lookingForHash)
7261
if (allowCache) {
7362
synchronized(cache) {
74-
if (cache.size > cacheSize) {
75-
cache[cacheIndex] = add // rolling cache
76-
cacheIndex = (cacheIndex + 1) % cacheSize
77-
} else {
78-
cache.add(add)
63+
for (item in cache) {
64+
// 10 min save
65+
if (item.hash == lookingForHash && (unixTime - item.unixTime) < cacheTimeSec) {
66+
return@safeApiCall item.response
67+
}
68+
}
69+
}
70+
}
71+
72+
api.load(fixedUrl)?.also { response ->
73+
// Remove all blank tags as early as possible
74+
val add = SavedLoadResponse(unixTime, response, lookingForHash)
75+
if (allowCache) {
76+
synchronized(cache) {
77+
if (cache.size > cacheSize) {
78+
cache[cacheIndex] = add // rolling cache
79+
cacheIndex = (cacheIndex + 1) % cacheSize
80+
} else {
81+
cache.add(add)
82+
}
7983
}
8084
}
85+
} ?: throw ErrorLoadingException("No data")
86+
} finally {
87+
if (api.hasRateLimit) {
88+
api.rateLimitMutex.unlock()
8189
}
82-
} ?: throw ErrorLoadingException("No data")
90+
}
8391
}
8492
}
8593

app/src/main/java/com/lagradost/quicknovel/BookDownloader2.kt

+43-27
Original file line numberDiff line numberDiff line change
@@ -578,19 +578,28 @@ object BookDownloader2Helper {
578578
}
579579
rFile.parentFile?.mkdirs()
580580
if (rFile.isDirectory) rFile.delete()
581-
581+
val rateLimit = api.rateLimitTime > 0
582582
for (i in 0..maxTries) {
583-
val page = api.loadHtml(data.url)
584-
585-
if (!page.isNullOrBlank()) {
586-
rFile.createNewFile() // only create the file when actually needed
587-
rFile.writeText("${data.name}\n${page}")
588-
return@withContext true
589-
} else {
590-
delay(5000) // ERROR
583+
if (rateLimit) {
584+
api.api.rateLimitMutex.lock()
591585
}
592-
if (api.rateLimitTime > 0) {
593-
delay(api.rateLimitTime)
586+
try {
587+
val page = api.loadHtml(data.url)
588+
589+
if (!page.isNullOrBlank()) {
590+
rFile.createNewFile() // only create the file when actually needed
591+
rFile.writeText("${data.name}\n${page}")
592+
return@withContext true
593+
} else {
594+
delay(5000) // ERROR
595+
}
596+
if (api.rateLimitTime > 0) {
597+
delay(api.rateLimitTime)
598+
}
599+
} finally {
600+
if (rateLimit) {
601+
api.api.rateLimitMutex.unlock()
602+
}
594603
}
595604
}
596605
return@withContext false
@@ -852,7 +861,6 @@ object NotificationHelper {
852861
.setColor(context.colorFromAttribute(R.attr.colorPrimary))
853862
.setContentText(
854863
if (stateProgressState.total > 1) {
855-
856864
val extra = if (progressInBytes) {
857865
val bytesToKiloBytes = 1024
858866
"${stateProgressState.progress / bytesToKiloBytes} Kb/${stateProgressState.total / bytesToKiloBytes} Kb"
@@ -985,23 +993,29 @@ object ImageDownloader {
985993
private val cachedBitmaps = hashMapOf<String, Bitmap>()
986994

987995
suspend fun getImageBitmapFromUrl(url: String): Bitmap? {
988-
cachedBitmapMutex.withLock {
989-
if (cachedBitmaps.containsKey(url)) {
990-
return cachedBitmaps[url]
996+
try {
997+
cachedBitmapMutex.withLock {
998+
if (cachedBitmaps.containsKey(url)) {
999+
return cachedBitmaps[url]
1000+
}
9911001
}
992-
}
9931002

994-
val bitmap =
995-
withContext(Dispatchers.IO) {
996-
Glide.with(activity ?: return@withContext null)
997-
.asBitmap()
998-
.load(url).submit(720, 720).get()
999-
} ?: return null
1003+
val bitmap =
1004+
withContext(Dispatchers.IO) {
1005+
Glide.with(activity ?: return@withContext null)
1006+
.asBitmap()
1007+
.load(url).submit(720, 720).get()
1008+
} ?: return null
10001009

1001-
cachedBitmapMutex.withLock {
1002-
cachedBitmaps[url] = bitmap
1010+
cachedBitmapMutex.withLock {
1011+
cachedBitmaps[url] = bitmap
1012+
}
1013+
return bitmap
1014+
} catch (t: Throwable) {
1015+
logError(t)
1016+
return null
10031017
}
1004-
return bitmap
1018+
10051019
}
10061020
}
10071021

@@ -1681,8 +1695,8 @@ object BookDownloader2 {
16811695
pFile.writeBytes(bytes)
16821696
}
16831697
}
1684-
} catch (e: Exception) {
1685-
logError(e)
1698+
} catch (t: Throwable) {
1699+
logError(t)
16861700
//delay(1000)
16871701
}
16881702
}
@@ -1801,6 +1815,8 @@ object BookDownloader2 {
18011815
progressState
18021816
)
18031817
}
1818+
} catch (t: Throwable) {
1819+
logError(t)
18041820
} finally {
18051821
currentDownloadsMutex.withLock {
18061822
currentDownloads -= id

app/src/main/java/com/lagradost/quicknovel/MainAPI.kt

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.lagradost.quicknovel.MainActivity.Companion.app
66
import com.lagradost.quicknovel.mvvm.logError
77
import com.lagradost.quicknovel.ui.UiImage
88
import com.lagradost.quicknovel.ui.img
9+
import kotlinx.coroutines.sync.Mutex
910
import org.jsoup.Jsoup
1011

1112
const val USER_AGENT =
@@ -18,6 +19,8 @@ abstract class MainAPI {
1819
open val lang = "en" // ISO_639_1 check SubtitleHelper
1920

2021
open val rateLimitTime: Long = 0
22+
val hasRateLimit : Boolean get() = rateLimitTime > 0L
23+
val rateLimitMutex : Mutex = Mutex()
2124

2225
open val usesCloudFlareKiller = false
2326

app/src/main/java/com/lagradost/quicknovel/providers/FreeWebNovelProvider.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class FreewebnovelProvider : LibReadProvider() {
1919
tag: String?
2020
): HeadMainPageResponse {
2121
val url =
22-
if (tag.isNullOrBlank()) "$mainUrl/latest-release/$page" else "$mainUrl/genres/$tag/$page"
22+
if (tag.isNullOrBlank()) "$mainUrl/latest-release-novels/$page" else "$mainUrl/genres/$tag/$page"
2323
val document = app.get(url).document
2424
val headers = document.select("div.ul-list1.ul-list1-2.ss-custom > div.li-row")
2525
val returnValue = headers.mapNotNull { h ->

app/src/main/java/com/lagradost/quicknovel/providers/LibReadProvider.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ open class LibReadProvider : MainAPI() {
99
override val name = "LibRead"
1010
override val mainUrl = "https://libread.com"
1111
override val hasMainPage = true
12+
1213
open val removeHtml = false // because the two sites use .html or not for no reason
1314

1415
override val iconId = R.drawable.icon_libread
@@ -156,7 +157,7 @@ open class LibReadProvider : MainAPI() {
156157
?.get(0)
157158
?.text()
158159
?.splitToSequence(", ")?.toList()
159-
posterUrl = document.select(" div.pic > img").attr("src")
160+
posterUrl = fixUrlNull(document.select(" div.pic > img").attr("src"))
160161
synopsis = document.selectFirst("div.inner")?.text()
161162
val votes = document.selectFirst("div.m-desc > div.score > p:nth-child(2)")
162163
if (votes != null) {

app/src/main/java/com/lagradost/quicknovel/providers/RoyalRoadProvider.kt

+19-8
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,30 @@ package com.lagradost.quicknovel.providers
22

33
import android.annotation.SuppressLint
44
import com.fasterxml.jackson.annotation.JsonProperty
5-
import com.lagradost.quicknovel.*
5+
import com.lagradost.quicknovel.ErrorLoadingException
6+
import com.lagradost.quicknovel.HeadMainPageResponse
7+
import com.lagradost.quicknovel.LoadResponse
8+
import com.lagradost.quicknovel.MainAPI
69
import com.lagradost.quicknovel.MainActivity.Companion.app
10+
import com.lagradost.quicknovel.R
11+
import com.lagradost.quicknovel.STATUS_COMPLETE
12+
import com.lagradost.quicknovel.STATUS_DROPPED
13+
import com.lagradost.quicknovel.STATUS_ONGOING
14+
import com.lagradost.quicknovel.STATUS_PAUSE
15+
import com.lagradost.quicknovel.SearchResponse
16+
import com.lagradost.quicknovel.UserReview
17+
import com.lagradost.quicknovel.fixUrlNull
718
import com.lagradost.quicknovel.mvvm.logError
19+
import com.lagradost.quicknovel.newChapterData
20+
import com.lagradost.quicknovel.newSearchResponse
21+
import com.lagradost.quicknovel.newStreamResponse
822
import org.jsoup.Jsoup
9-
import java.lang.Exception
10-
import java.util.*
11-
import kotlin.collections.ArrayList
23+
import java.util.Date
1224

1325
class RoyalRoadProvider : MainAPI() {
1426
override val name = "Royal Road"
1527
override val mainUrl = "https://www.royalroad.com"
16-
28+
override val rateLimitTime = 5000L
1729
override val hasMainPage = true
1830

1931
override val iconId = R.drawable.big_icon_royalroad
@@ -311,9 +323,8 @@ class RoyalRoadProvider : MainAPI() {
311323
override suspend fun load(url: String): LoadResponse? {
312324
val response = app.get(url)
313325
val document = response.document
314-
315-
val name = document.selectFirst("h1.font-white")?.text() ?: return null
316-
326+
val name = document.selectFirst("h1.font-white")?.text()
327+
?: throw ErrorLoadingException("Null name")
317328
val fictionId =
318329
response.text.substringAfter("window.fictionId = ").substringBefore(";").toIntOrNull()
319330

0 commit comments

Comments
 (0)