Convert GalleryNotAvailableParser to kotlin
This commit is contained in:
1 parent
5f67e5ab03
commit
5f6c3f1078
2 files changed
+17
-24
No files matched your search
@@ -98,7 +98,7 @@ private fun rethrowExactly(code: Int, headers: Headers, body: String, e: Throwab
|
||||
// Check Gallery Not Available
|
||||
if (body.contains("Gallery Not Available - ")) {
|
||||
val error = GalleryNotAvailableParser.parse(body)
|
||||
if (error.isNotBlank()) {
|
||||
if (!error.isNullOrBlank()) {
|
||||
throw EhException(error)
|
||||
}
|
||||
}
|
||||
@@ -263,7 +263,8 @@ object EhEngine {
|
||||
val referer = EhUrl.referer
|
||||
Log.d(TAG, url)
|
||||
return EhRequestBuilder(url, referer).executeAndParsingWith {
|
||||
GalleryDetailParser.parsePreviewList(this) to GalleryDetailParser.parsePreviewPages(this)
|
||||
GalleryDetailParser.parsePreviewList(this) to
|
||||
GalleryDetailParser.parsePreviewPages(this)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,30 +15,22 @@
|
||||
* You should have received a copy of the GNU General Public License along with EhViewer.
|
||||
* If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.hippo.ehviewer.client.parser
|
||||
|
||||
package com.hippo.ehviewer.client.parser;
|
||||
import com.hippo.util.ExceptionUtils
|
||||
import com.hippo.util.JsoupUtils
|
||||
import org.jsoup.Jsoup
|
||||
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.util.JsoupUtils;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
|
||||
public class GalleryNotAvailableParser {
|
||||
|
||||
public static String parse(String body) {
|
||||
String error = null;
|
||||
try {
|
||||
Document document = Jsoup.parse(body);
|
||||
Element d = JsoupUtils.getElementByClass(document, "d");
|
||||
//noinspection ConstantConditions
|
||||
error = d.child(0).html();
|
||||
error = error.replace("<br>", "\n");
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
e.printStackTrace();
|
||||
object GalleryNotAvailableParser {
|
||||
fun parse(body: String): String? {
|
||||
return runCatching {
|
||||
val document = Jsoup.parse(body)
|
||||
val d = JsoupUtils.getElementByClass(document, "d")
|
||||
d!!.child(0).html().replace("<br>", "\n")
|
||||
}.getOrElse {
|
||||
ExceptionUtils.throwIfFatal(it)
|
||||
it.printStackTrace()
|
||||
null
|
||||
}
|
||||
return error;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user