Initial commit
This commit is contained in:
commit
21bfbfb139
520 changed files with 47819 additions and 0 deletions
51
app/src/main/java/ani/dantotsu/parsers/NovelParser.kt
Normal file
51
app/src/main/java/ani/dantotsu/parsers/NovelParser.kt
Normal file
|
@ -0,0 +1,51 @@
|
|||
package ani.dantotsu.parsers
|
||||
|
||||
import ani.dantotsu.FileUrl
|
||||
import ani.dantotsu.media.Media
|
||||
|
||||
abstract class NovelParser : BaseParser() {
|
||||
|
||||
abstract val volumeRegex: Regex
|
||||
|
||||
abstract suspend fun loadBook(link: String, extra: Map<String, String>?): Book
|
||||
|
||||
fun List<ShowResponse>.sortByVolume(query:String) : List<ShowResponse> {
|
||||
val sorted = groupBy { res ->
|
||||
val match = volumeRegex.find(res.name)?.groupValues
|
||||
?.firstOrNull { it.isNotEmpty() }
|
||||
?.substringAfter(" ")
|
||||
?.toDoubleOrNull() ?: Double.MAX_VALUE
|
||||
match
|
||||
}.toSortedMap().values
|
||||
|
||||
val volumes = sorted.map { showList ->
|
||||
val nonDefaultCoverShows = showList.filter { it.coverUrl.url != defaultImage }
|
||||
val bestShow = nonDefaultCoverShows.firstOrNull { it.name.contains(query) }
|
||||
?: nonDefaultCoverShows.firstOrNull()
|
||||
?: showList.first()
|
||||
bestShow
|
||||
}
|
||||
val remainingShows = sorted.flatten() - volumes.toSet()
|
||||
|
||||
return volumes + remainingShows
|
||||
}
|
||||
|
||||
suspend fun sortedSearch(mediaObj: Media): List<ShowResponse> {
|
||||
val query = mediaObj.name ?: mediaObj.nameRomaji
|
||||
return search(query).sortByVolume(query)
|
||||
}
|
||||
}
|
||||
|
||||
data class Book(
|
||||
val name: String,
|
||||
val img: FileUrl,
|
||||
val description: String? = null,
|
||||
val links: List<FileUrl>
|
||||
) {
|
||||
constructor (name: String, img: String, description: String? = null, links: List<String>) : this(
|
||||
name,
|
||||
FileUrl(img),
|
||||
description,
|
||||
links.map { FileUrl(it) }
|
||||
)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue