fix some string handling

This commit is contained in:
Austin Huang 2021-06-19 17:49:55 -04:00
parent 808c841e65
commit 13dc310c5d
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F

View File

@ -1,12 +1,12 @@
package awais.instagrabber.webservices package awais.instagrabber.webservices
import android.util.Log import android.util.Log
import awais.instagrabber.models.enums.FollowingType
import awais.instagrabber.repositories.GraphQLService import awais.instagrabber.repositories.GraphQLService
import awais.instagrabber.repositories.responses.* import awais.instagrabber.repositories.responses.*
import awais.instagrabber.utils.Constants import awais.instagrabber.utils.Constants
import awais.instagrabber.utils.ResponseBodyUtils import awais.instagrabber.utils.ResponseBodyUtils
import awais.instagrabber.utils.extensions.TAG import awais.instagrabber.utils.extensions.TAG
import com.google.gson.Gson
import org.json.JSONException import org.json.JSONException
import org.json.JSONObject import org.json.JSONObject
import java.util.* import java.util.*
@ -181,9 +181,9 @@ class GraphQLRepository(private val service: GraphQLService) {
): User { ): User {
val response = service.getUser(username) val response = service.getUser(username)
val body = JSONObject(response val body = JSONObject(response
.split("<script type=\"text/javascript\">window._sharedData = ", false, 2).get(1) .split("<script type=\"text/javascript\">window._sharedData = ").get(1)
.split("</script>", false, 2).get(0) .split("</script>").get(0)
.trim().replace(Regex("};$"), "}")) .trim().replace(Regex("\\};$"), "}"))
val userJson = body val userJson = body
.getJSONObject("entry_data") .getJSONObject("entry_data")
.getJSONArray("ProfilePage") .getJSONArray("ProfilePage")
@ -241,9 +241,9 @@ class GraphQLRepository(private val service: GraphQLService) {
): Hashtag { ): Hashtag {
val response = service.getTag(tag) val response = service.getTag(tag)
val body = JSONObject(response val body = JSONObject(response
.split("<script type=\"text/javascript\">window._sharedData = ", false, 2).get(1) .split("<script type=\"text/javascript\">window._sharedData = ").get(1)
.split("</script>", false, 2).get(0) .split("</script>").get(0)
.trim().replace(Regex("};$"), "}")) .trim().replace(Regex("\\};$"), "}"))
.getJSONObject("entry_data") .getJSONObject("entry_data")
.getJSONArray("TagPage") .getJSONArray("TagPage")
.getJSONObject(0) .getJSONObject(0)
@ -265,8 +265,7 @@ class GraphQLRepository(private val service: GraphQLService) {
): Location { ): Location {
val response = service.getLocation(locationId) val response = service.getLocation(locationId)
val body = JSONObject(response val body = JSONObject(response
.split("<script type=\"text/javascript\">window._sharedData = ", false, 2).get(1) .split("<script type=\"text/javascript\">window._sharedData = ", "</script>").get(1)
.split("</script>", false, 2).get(0)
.trim().replace(Regex("};$"), "}")) .trim().replace(Regex("};$"), "}"))
.getJSONObject("entry_data") .getJSONObject("entry_data")
.getJSONArray("LocationsPage") .getJSONArray("LocationsPage")