Skip to content
This repository has been archived by the owner on Mar 26, 2019. It is now read-only.

Commit

Permalink
prepare kuboo server opds handler
Browse files Browse the repository at this point in the history
  • Loading branch information
befora committed Dec 30, 2018
1 parent 16766a4 commit 0445e9a
Showing 1 changed file with 50 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,54 +171,78 @@ class HandlerOpds(private val login: Login, private val saxList: MutableList<Boo

private fun Attributes.get(value: String): String {
var string = getValue(value)
if (string.contains("/opds-books/")) {
val bits = string.split("/opds-books/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
string = bits[bits.size - 1]
} else if (string.contains("/opds-comics/")) {
val bits = string.split("/opds-comics/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
string = bits[bits.size - 1]
when {
string.contains("/opds-books/") -> {
val bits = string.split("/opds-books/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
string = bits[bits.size - 1]
}
string.contains("/opds-comics/") -> {
val bits = string.split("/opds-comics/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
string = bits[bits.size - 1]
}
string.contains("/opds/") -> {
val bits = string.split("/opds/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
string = bits[bits.size - 1]
}
}
return string
}

private fun Attributes.getLinkNavigation(value: String): String {
var string = getValue(value)
if (string.contains("/opds-books/")) {
string = try {
when {
string.contains("/opds-books/") -> string = try {
val bits = string.split("/opds-books/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
bits[bits.size - 1]
} catch (e: ArrayIndexOutOfBoundsException) {
string.replace("/opds-books/", "")
}
} else if (string.contains("/opds-comics/")) {
string = try {
string.contains("/opds-comics/") -> string = try {
val bits = string.split("/opds-comics/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
bits[bits.size - 1]
} catch (e: ArrayIndexOutOfBoundsException) {
string.replace("/opds-comics/", "")
}
string.contains("/opds/") -> string = try {
val bits = string.split("/opds/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
bits[bits.size - 1]
} catch (e: ArrayIndexOutOfBoundsException) {
string.replace("/opds/", "")
}
}
return string
}

private fun Attributes.getLinkPse(): String {
var string = getValue("href")
if (string.contains("/opds-books/")) {
val bits1 = string.split("/opds-books/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
string = bits1[bits1.size - 1]
linkPse = true
val stringTotalPages = getValue("pse:count")
val bits2 = stringTotalPages.split("/opds-books/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
entity.TotalPages = bits2[bits2.size - 1]
totalPages = true
} else if (string.contains("/opds-comics/")) {
val bits1 = string.split("/opds-comics/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
string = bits1[bits1.size - 1]
linkPse = true
val stringTotalPages = getValue("pse:count")
val bits2 = stringTotalPages.split("/opds-comics/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
entity.TotalPages = bits2[bits2.size - 1]
totalPages = true
when {
string.contains("/opds-books/") -> {
val bits1 = string.split("/opds-books/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
string = bits1[bits1.size - 1]
linkPse = true
val stringTotalPages = getValue("pse:count")
val bits2 = stringTotalPages.split("/opds-books/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
entity.TotalPages = bits2[bits2.size - 1]
totalPages = true
}
string.contains("/opds-comics/") -> {
val bits1 = string.split("/opds-comics/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
string = bits1[bits1.size - 1]
linkPse = true
val stringTotalPages = getValue("pse:count")
val bits2 = stringTotalPages.split("/opds-comics/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
entity.TotalPages = bits2[bits2.size - 1]
totalPages = true
}
string.contains("/opds/") -> {
val bits1 = string.split("/opds/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
string = bits1[bits1.size - 1]
linkPse = true
val stringTotalPages = getValue("pse:count")
val bits2 = stringTotalPages.split("/opds/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
entity.TotalPages = bits2[bits2.size - 1]
totalPages = true
}
}
return string
}
Expand Down

0 comments on commit 0445e9a

Please sign in to comment.