NewToki: update domain number on build (#16011)

* NewToki: update domain number on build

* update

* update
This commit is contained in:
stevenyomi 2023-04-15 22:41:22 +08:00 committed by GitHub
parent 7b6a306fe0
commit 0db59462f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 89 deletions

View File

@ -5,8 +5,44 @@ ext {
extName = 'NewToki / ManaToki'
pkgNameSuffix = 'ko.newtoki'
extClass = '.TokiFactory'
extVersionCode = 28
extVersionCode = 29
isNsfw = true
}
apply from: "$rootDir/common.gradle"
def domainNumberFileName = "src/ko/newtoki/src/eu/kanade/tachiyomi/extension/ko/newtoki/FallbackDomainNumber.kt"
def domainNumberFile = new File(domainNumberFileName)
def backupFile = new File(domainNumberFileName + "_bak")
task updateDomainNumber {
doLast {
def domainNumberUrl = "https://stevenyomi.github.io/source-domains/newtoki.txt"
def number = new URL(domainNumberUrl).withInputStream { it.readLines()[0] }
println("[NewToki] Updating domain number to $number")
domainNumberFile.renameTo(backupFile)
domainNumberFile.withPrintWriter {
it.println("// THIS FILE IS AUTO-GENERATED, DO NOT COMMIT")
it.println("package eu.kanade.tachiyomi.extension.ko.newtoki")
it.println("const val fallbackDomainNumber = \"$number\"")
}
}
}
preBuild.dependsOn updateDomainNumber
task restoreBackup {
doLast {
if (backupFile.exists()) {
println("[NewToki] Restoring placeholder file")
domainNumberFile.delete()
backupFile.renameTo(domainNumberFile)
}
}
}
tasks.whenTaskAdded { task ->
if (task.name == "assembleDebug" || task.name == "assembleRelease") {
task.finalizedBy(restoreBackup)
}
}

View File

@ -1,64 +0,0 @@
Data from either https://t.me/s/newtoki5 or https://web.archive.org.
| Date | Days | Average | Number |
| ---------: | ---: | ------: | -----: |
| 2023-02-08 | 8 | 8.0 | 217 |
| 2023-01-31 | 11 | 9.5 | 216 |
| 2023-01-20 | 4 | 7.7 | 215 |
| 2023-01-16 | 2 | 6.3 | 214 |
| 2023-01-14 | 9 | 6.8 | 170 |
| 2023-01-05 | 14 | 8.0 | 169 |
| 2022-12-22 | 7 | 7.9 | 168 |
| 2022-12-15 | 6 | 7.6 | 167 |
| 2022-12-09 | 8 | 7.7 | 166 |
| 2022-12-01 | 7 | 7.6 | 165 |
| 2022-11-24 | 7 | 7.5 | 164 |
| 2022-11-17 | 6 | 7.4 | 163 |
| 2022-11-11 | 7 | 7.4 | 162 |
| 2022-11-04 | 7 | 7.4 | 161 |
| 2022-10-28 | 7 | 7.3 | 160 |
| 2022-10-21 | 5 | 7.2 | 159 |
| 2022-10-16 | 8 | 7.2 | 158 |
| 2022-10-08 | 11 | 7.4 | 157 |
| 2022-09-27 | 6 | 7.4 | 156 |
| 2022-09-21 | 12 | 7.6 | 154 |
| 2022-09-09 | 7 | 7.6 | |
| 2022-09-02 | 8 | 7.6 | |
| 2022-08-25 | 6 | 7.5 | |
| 2022-08-19 | 11 | 7.7 | |
| 2022-08-08 | 10 | 7.8 | |
| 2022-07-29 | 8 | 7.8 | |
| 2022-07-21 | 9 | 7.8 | |
| 2022-07-12 | 7 | 7.8 | |
| 2022-07-05 | 11 | 7.9 | |
| 2022-06-24 | 6 | 7.8 | |
| 2022-06-18 | 8 | 7.8 | |
| 2022-06-10 | 3 | 7.7 | |
| 2022-06-07 | 11 | 7.8 | |
| 2022-05-27 | 6 | 7.7 | |
| 2022-05-21 | 11 | 7.8 | |
| 2022-05-10 | 11 | 7.9 | |
| 2022-04-29 | 6 | 7.9 | |
| 2022-04-23 | 8 | 7.9 | |
| 2022-04-15 | 6 | 7.8 | |
| 2022-04-09 | 10 | 7.9 | |
| 2022-03-30 | 11 | 8.0 | |
| 2022-03-19 | 9 | 8.0 | |
| 2022-03-10 | 14 | 8.1 | |
| 2022-02-24 | 12 | 8.2 | |
| 2022-02-12 | 15 | 8.4 | |
| 2022-01-28 | 9 | 8.4 | |
| 2022-01-19 | 9 | 8.4 | |
| 2022-01-10 | 17 | 8.6 | |
| 2021-12-24 | 7 | 8.5 | |
| 2021-12-17 | 6 | 8.5 | |
| 2021-12-11 | 8 | 8.5 | |
| 2021-12-03 | 9 | 8.5 | |
| 2021-11-24 | 8 | 8.5 | |
| 2021-11-16 | 11 | 8.5 | |
| 2021-11-05 | 7 | 8.5 | |
| 2021-10-29 | 9 | 8.5 | |
| 2021-10-20 | 12 | 8.6 | |
| 2021-10-08 | 8 | 8.6 | |
| 2021-09-30 | 15 | 8.7 | |
| 2021-09-15 | | | |

View File

@ -2,26 +2,10 @@ package eu.kanade.tachiyomi.extension.ko.newtoki
import android.util.Log
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.util.asJsoup
import okhttp3.Interceptor
import okhttp3.Response
import java.io.IOException
/**
* Source changes domain names every few days (e.g. newtoki31.net to newtoki32.net)
* The domain name was newtoki32 on 2019-11-14, this attempts to match the rate at which the domain changes
*
* Since 2020-09-20, They changed manga side to Manatoki.
* It was merged after shutdown of ManaMoa.
* This is by the head of Manamoa, as they decided to move to Newtoki.
*
* Updated on 2023-02-10, see `domain_log.md`.
* To avoid going too fast and to utilize redirections,
* the number is decremented by 1 initially,
* and increments every 8 days which is a bit slower than the average.
*/
val fallbackDomainNumber get() = (217 - 1) + ((System.currentTimeMillis() - 1675818000_000) / 691200_000).toInt()
var domainNumber = ""
get() {
val currentValue = field
@ -33,7 +17,7 @@ var domainNumber = ""
return prefValue
}
val fallback = fallbackDomainNumber.toString()
val fallback = fallbackDomainNumber
domainNumber = fallback
return fallback
}
@ -55,13 +39,10 @@ object DomainInterceptor : Interceptor {
Log.e("NewToki", "failed to fetch ${request.url}", e)
val newDomainNumber = try {
val document = chain.proceed(GET("https://t.me/s/newtoki5")).asJsoup()
val description = document.select("a[href^=https://newtoki]").last()!!.attr("href")
numberRegex.find(description)!!.value
val domainNumberUrl = "https://stevenyomi.github.io/source-domains/newtoki.txt"
chain.proceed(GET(domainNumberUrl)).body.string().also { it.toInt() }
} catch (_: Throwable) {
fallbackDomainNumber
.also { if (it <= domainNumber.toInt()) throw e }
.toString()
throw IOException(editDomainNumber(), e)
}
domainNumber = newDomainNumber
@ -88,5 +69,5 @@ object DomainInterceptor : Interceptor {
return response
}
private val numberRegex by lazy { Regex("""\d+""") }
private val numberRegex by lazy { Regex("""\d+|$fallbackDomainNumber""") }
}

View File

@ -0,0 +1,10 @@
package eu.kanade.tachiyomi.extension.ko.newtoki
/**
* This value will be automatically overwritten when building the extension.
* After building, this file will be restored.
*
* Even if this value is built into the extension, the network call will fail
* because of underscore character and the extension will update it on its own.
*/
const val fallbackDomainNumber = "_failed_to_fetch_domain_number"