Convert GalleryMultiPageViewerPTokenParser to kotlin
This commit is contained in:
1 parent
c80c892faf
commit
e7a9837da1
1 file changed
+16
-23
+16
-23
@@ -15,31 +15,24 @@
|
||||
* 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.ehviewer.client.exception.EhException
|
||||
import com.hippo.util.ExceptionUtils
|
||||
import org.json.JSONArray
|
||||
|
||||
import com.hippo.ehviewer.client.exception.EhException;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class GalleryMultiPageViewerPTokenParser {
|
||||
public static ArrayList<String> parse(String body) throws Exception {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
String imagelist = body.substring(body.indexOf("var imagelist = ") + 16, body.indexOf(";", body.indexOf("var imagelist = ")));
|
||||
try {
|
||||
JSONArray ja = new JSONArray(imagelist);
|
||||
for (int i = 0; i < ja.length(); i++) {
|
||||
JSONObject jo = ja.getJSONObject(i);
|
||||
list.add(jo.getString("k"));
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throw new EhException(body);
|
||||
object GalleryMultiPageViewerPTokenParser {
|
||||
fun parse(body: String): List<String> {
|
||||
val imagelist = body.substring(
|
||||
body.indexOf("var imagelist = ") + 16,
|
||||
body.indexOf(";", body.indexOf("var imagelist = ")),
|
||||
)
|
||||
return runCatching {
|
||||
val ja = JSONArray(imagelist)
|
||||
(0 until ja.length()).map { ja.getJSONObject(it).getString("k") }
|
||||
}.getOrElse {
|
||||
ExceptionUtils.throwIfFatal(it)
|
||||
throw EhException(body)
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user