Adjustments

This commit is contained in:
Zakhar Timoshenko
2021-10-18 06:51:57 +03:00
committed by Koitharu
parent c280af9a5b
commit 904fc572d0
21 changed files with 51 additions and 99 deletions

View File

@@ -35,7 +35,7 @@ import org.koitharu.kotatsu.R
*/
class FadingSnackbar @JvmOverloads constructor(
context: Context,
attrs: AttributeSet,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr) {

View File

@@ -10,7 +10,7 @@ data class MangaChapter(
val number: Int,
val url: String,
val scanlator: String? = null,
val date_upload: Long,
val uploadDate: Long,
val branch: String? = null,
val source: MangaSource
) : Parcelable

View File

@@ -87,7 +87,7 @@ class AnibelRepository(loaderContext: MangaLoaderContext) : RemoteMangaRepositor
name = "Глава " + a.selectFirst("a")?.text().orEmpty(),
number = i + 1,
url = href,
date_upload = 0L,
uploadDate = 0L,
source = source
)
}

View File

@@ -84,10 +84,10 @@ abstract class ChanRepository(loaderContext: MangaLoaderContext) : RemoteMangaRe
val href = tr?.selectFirst("a")?.relUrl("href") ?: return@mapIndexedNotNull null
MangaChapter(
id = generateUid(href),
name = tr.select("a").text().trim(),
name = tr.selectFirst("a")?.text().orEmpty(),
number = i + 1,
url = href,
date_upload = parseChapterDate(tr.select("div.date").text()),
uploadDate = parseChapterDate(tr.selectFirst("div.date")?.text().orEmpty()),
source = source
)
}
@@ -156,16 +156,7 @@ abstract class ChanRepository(loaderContext: MangaLoaderContext) : RemoteMangaRe
}
private fun parseChapterDate(string: String): Long {
return try {
dateFormat.parse(string)?.time ?: 0
} catch (_: ParseException) {
0
}
return SimpleDateFormat("yyyy-MM-dd", Locale.US).tryParse(string)
}
companion object {
private val dateFormat by lazy {
SimpleDateFormat("yyyy-MM-dd", Locale.US)
}
}
}

View File

@@ -99,7 +99,7 @@ class DesuMeRepository(loaderContext: MangaLoaderContext) : RemoteMangaRepositor
id = generateUid(chid),
source = manga.source,
url = "$baseChapterUrl$chid",
date_upload = it.getLong("date") * 1000,
uploadDate = it.getLong("date") * 1000,
name = if (title.isEmpty()) volChap else "$volChap: $title",
number = totalChapters - i
)

View File

@@ -141,7 +141,7 @@ class ExHentaiRepository(
name = "${manga.title} #$i",
number = i,
url = url,
date_upload = 0L,
uploadDate = 0L,
source = source,
)
}

View File

@@ -124,21 +124,22 @@ abstract class GroupleRepository(loaderContext: MangaLoaderContext) :
)
},
chapters = root.selectFirst("div.chapters-link")?.selectFirst("table")
?.select("tr:has(td > a)")?.asReversed()?.mapIndexed { i, tr ->
val href = tr.selectFirst("a")?.relUrl("href")
?.select("tr:has(td > a)")?.asReversed()?.mapIndexedNotNull { i, tr ->
val a = tr.selectFirst("a") ?: return@mapIndexedNotNull null
val href = a.relUrl("href")
var translators = ""
val translatorElement = tr.select("a").attr("title")
val translatorElement = a.attr("title")
if (!translatorElement.isNullOrBlank()) {
translators = translatorElement
.replace("(Переводчик),", "&")
.removeSuffix(" (Переводчик)")
}
MangaChapter(
id = generateUid(href!!),
name = tr.select("a").text().removePrefix(manga.title).trim(),
id = generateUid(href),
name = tr.selectFirst("a")?.text().orEmpty().removePrefix(manga.title).trim(),
number = i + 1,
url = href,
date_upload = parseChapterDate(tr.select("td.d-none").text()),
uploadDate = parseChapterDate(tr.select("td.d-none").text()),
scanlator = translators,
source = source
)
@@ -234,11 +235,7 @@ abstract class GroupleRepository(loaderContext: MangaLoaderContext) :
}
private fun parseChapterDate(string: String): Long {
return try {
dateFormat.parse(string)?.time ?: 0
} catch (_: ParseException) {
0
}
return SimpleDateFormat("dd.MM.yy", Locale.US).tryParse(string)
}
private companion object {
@@ -248,9 +245,6 @@ abstract class GroupleRepository(loaderContext: MangaLoaderContext) :
private val HEADER = Headers.Builder()
.add("User-Agent", "readmangafun")
.build()
private val dateFormat by lazy {
SimpleDateFormat("dd.MM.yy", Locale.US)
}
}
}

View File

@@ -49,7 +49,7 @@ class HenChanRepository(loaderContext: MangaLoaderContext) : ChanRepository(load
url = readLink,
source = source,
number = 1,
date_upload = 0L,
uploadDate = 0L,
name = manga.title
)
)

View File

@@ -113,7 +113,7 @@ open class MangaLibRepository(loaderContext: MangaLoaderContext) :
url = url,
source = source,
number = total - i,
date_upload = parseChapterDate(item.getString("chapter_created_at").substringBefore(" ")),
uploadDate = parseChapterDate(item.getString("chapter_created_at").substringBefore(" ")),
scanlator = scanlator,
name = if (nameChapter.isNullOrBlank()) fullNameChapter else "$fullNameChapter - $nameChapter"
)
@@ -243,16 +243,7 @@ open class MangaLibRepository(loaderContext: MangaLoaderContext) :
}
private fun parseChapterDate(string: String): Long {
return try {
dateFormat.parse(string)?.time ?: 0
} catch (_: ParseException) {
0
}
return SimpleDateFormat("yyy-MM-dd", Locale.US).tryParse(string)
}
companion object {
private val dateFormat by lazy {
SimpleDateFormat("yyy-MM-dd", Locale.US)
}
}
}

View File

@@ -100,7 +100,7 @@ class MangaOwlRepository(loaderContext: MangaLoaderContext) : RemoteMangaReposit
name = a.select("label").text(),
number = i + 1,
url = href,
date_upload = parseChapterDate(li.select("small:last-of-type").text()),
uploadDate = parseChapterDate(li.select("small:last-of-type").text()),
source = MangaSource.MANGAOWL
)
}
@@ -159,17 +159,7 @@ class MangaOwlRepository(loaderContext: MangaLoaderContext) : RemoteMangaReposit
}
private fun parseChapterDate(string: String): Long {
return try {
dateFormat.parse(string)?.time ?: 0
} catch (_: ParseException) {
0
}
}
companion object {
private val dateFormat by lazy {
SimpleDateFormat("MM/dd/yyyy", Locale.US)
}
return SimpleDateFormat("MM/dd/yyyy", Locale.US).tryParse(string)
}
}

View File

@@ -118,7 +118,7 @@ class MangaTownRepository(loaderContext: MangaLoaderContext) :
url = href,
source = MangaSource.MANGATOWN,
number = i + 1,
date_upload = parseChapterDate(li.select("span.time").text()),
uploadDate = parseChapterDate(li.selectFirst("span.time")?.text().orEmpty()),
name = name.ifEmpty { "${manga.title} - ${i + 1}" }
)
}
@@ -173,13 +173,7 @@ class MangaTownRepository(loaderContext: MangaLoaderContext) :
return when {
date.contains("Today") -> Calendar.getInstance().timeInMillis
date.contains("Yesterday") -> Calendar.getInstance().apply { add(Calendar.DAY_OF_MONTH, -1) }.timeInMillis
else -> {
try {
SimpleDateFormat("MMM dd,yyyy", Locale.US).parse(date)?.time ?: 0L
} catch (e: Exception) {
0L
}
}
else -> SimpleDateFormat("MMM dd,yyyy", Locale.US).tryParse(date)
}
}

View File

@@ -4,6 +4,7 @@ import org.koitharu.kotatsu.base.domain.MangaLoaderContext
import org.koitharu.kotatsu.core.exceptions.ParseException
import org.koitharu.kotatsu.core.model.*
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
import org.koitharu.kotatsu.utils.WordSet
import org.koitharu.kotatsu.utils.ext.*
import java.text.SimpleDateFormat
import java.util.*
@@ -139,7 +140,7 @@ class MangareadRepository(
name = a!!.ownText(),
number = i + 1,
url = href,
date_upload = parseChapterDate(doc2.select("span.chapter-release-date i").firstOrNull()?.text()),
uploadDate = parseChapterDate(doc2.selectFirst("span.chapter-release-date i")?.text()),
source = MangaSource.MANGAREAD
)
}
@@ -166,15 +167,6 @@ class MangareadRepository(
private fun parseChapterDate(date: String?): Long {
date ?: return 0
fun SimpleDateFormat.tryParse(string: String): Long {
return try {
parse(string)?.time ?: 0
} catch (_: ParseException) {
0
}
}
return when {
date.endsWith(" ago", ignoreCase = true) -> {
parseRelativeDate(date)
@@ -254,5 +246,3 @@ class MangareadRepository(
}
}
}
class WordSet(private vararg val words: String) { fun anyWordIn(dateString: String): Boolean = words.any { dateString.contains(it, ignoreCase = true) } }

View File

@@ -112,7 +112,7 @@ abstract class NineMangaRepository(
name = a.text(),
number = i + 1,
url = href,
date_upload = parseChapterDateByLang(li.select("span").text()),
uploadDate = parseChapterDateByLang(li.selectFirst("span")?.text().orEmpty()),
source = source,
)
}
@@ -166,11 +166,7 @@ abstract class NineMangaRepository(
if (dateWords.size == 3) {
if (dateWords[1].contains(",")) {
return try {
SimpleDateFormat("MMM d, yyyy", Locale.ENGLISH).parse(date)?.time ?: 0L
} catch (e: ParseException) {
0L
}
SimpleDateFormat("MMM d, yyyy", Locale.ENGLISH).tryParse(date)
} else {
val timeAgo = Integer.parseInt(dateWords[0])
return Calendar.getInstance().apply {

View File

@@ -127,7 +127,7 @@ class RemangaRepository(loaderContext: MangaLoaderContext) : RemoteMangaReposito
append(name)
}
},
date_upload = parseChapterDate(jo.getString("upload_date")),
uploadDate = parseChapterDate(jo.getString("upload_date")),
scanlator = publishers.optJSONObject(0)?.getStringOrNull("name"),
source = MangaSource.REMANGA
)
@@ -179,11 +179,7 @@ class RemangaRepository(loaderContext: MangaLoaderContext) : RemoteMangaReposito
)
private fun parseChapterDate(string: String): Long {
return try {
dateFormat.parse(string)?.time ?: 0
} catch (_: ParseException) {
0
}
return SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.US).tryParse(string)
}
private companion object {
@@ -194,9 +190,5 @@ class RemangaRepository(loaderContext: MangaLoaderContext) : RemoteMangaReposito
const val STATUS_FINISHED = 0
val LAST_URL_PATH_REGEX = Regex("/[^/]+/?$")
private val dateFormat by lazy {
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.US)
}
}
}

View File

@@ -29,7 +29,7 @@ class YaoiChanRepository(loaderContext: MangaLoaderContext) : ChanRepository(loa
name = a.text().trim(),
number = i + 1,
url = href,
date_upload = 0L,
uploadDate = 0L,
source = source
)
}

View File

@@ -31,8 +31,8 @@ fun chapterListItemAD(
val settings = GlobalContext.get().get<AppSettings>()
val descriptions = mutableListOf<CharSequence>()
val dateFormat = settings.dateFormat()
if (item.chapter.date_upload > 0) {
descriptions.add(dateFormat.format(Date(item.chapter.date_upload)))
if (item.chapter.uploadDate > 0) {
descriptions.add(dateFormat.format(Date(item.chapter.uploadDate)))
}
if (!item.chapter.scanlator.isNullOrBlank()) {
descriptions.add(item.chapter.scanlator!!)

View File

@@ -72,7 +72,7 @@ class MangaIndex(source: String?) {
jo.put("number", chapter.number)
jo.put("url", chapter.url)
jo.put("name", chapter.name)
jo.put("date_upload", chapter.date_upload)
jo.put("uploadDate", chapter.uploadDate)
jo.put("scanlator", chapter.scanlator)
jo.put("branch", chapter.branch)
jo.put("entries", "%03d\\d{3}".format(chapter.number))
@@ -100,7 +100,7 @@ class MangaIndex(source: String?) {
name = v.getString("name"),
url = v.getString("url"),
number = v.getInt("number"),
date_upload = v.getLong("date_upload"),
uploadDate = v.getLong("uploadDate"),
scanlator = v.getStringOrNull("scanlator"),
branch = v.getStringOrNull("branch"),
source = source

View File

@@ -123,7 +123,7 @@ class LocalMangaRepository(private val context: Context) : MangaRepository {
name = s.ifEmpty { title },
number = i + 1,
source = MangaSource.LOCAL,
date_upload = 0L,
uploadDate = 0L,
url = uriBuilder.fragment(s).build().toString()
)
}

View File

@@ -0,0 +1,9 @@
package org.koitharu.kotatsu.utils
class WordSet(private vararg val words: String) {
fun anyWordIn(dateString: String): Boolean = words.any {
dateString.contains(it, ignoreCase = true)
}
}

View File

@@ -10,6 +10,7 @@ import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import org.jsoup.nodes.Node
import org.jsoup.select.Elements
import java.text.SimpleDateFormat
fun Response.parseHtml(): Document {
try {
@@ -97,4 +98,8 @@ fun Element.css(property: String): String? {
val regex = Regex("${Regex.escape(property)}\\s*:\\s*[^;]+")
val css = attr("style").find(regex) ?: return null
return css.substringAfter(':').removeSuffix(';').trim()
}
}
fun SimpleDateFormat.tryParse(str: String): Long = runCatching {
parse(str)?.time ?: 0L
}.getOrDefault(0L)