aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2020-01-19 22:52:58 -0800
committerAllan Wang <me@allanwang.ca>2020-01-19 22:52:58 -0800
commit314eec1c70d3678a093c21e386aedf8900828f14 (patch)
treef6ad9143fa6babfe05a9943a7573ec354c274644 /app/src/main/kotlin/com
parenta6f97c81e0e33a649b137bc60b336b0b736e132a (diff)
downloadfrost-314eec1c70d3678a093c21e386aedf8900828f14.tar.gz
frost-314eec1c70d3678a093c21e386aedf8900828f14.tar.bz2
frost-314eec1c70d3678a093c21e386aedf8900828f14.zip
Only use mbasic for parsing
Diffstat (limited to 'app/src/main/kotlin/com')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt3
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/FbItem.kt8
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/SearchParser.kt20
3 files changed, 25 insertions, 6 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt
index f0f6ca7e..e36abd15 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt
@@ -25,7 +25,8 @@ const val FBCDN_NET = "fbcdn.net"
const val WWW_FACEBOOK_COM = "www.$FACEBOOK_COM"
const val FACEBOOK_BASE_COM = "m.$FACEBOOK_COM"
const val FB_URL_BASE = "https://$FACEBOOK_BASE_COM/"
-const val FB_URL_MBASIC_BASE = "https://mbasic.$FACEBOOK_COM/"
+const val FACEBOOK_MBASIC_COM = "mbasic.$FACEBOOK_COM"
+const val FB_URL_MBASIC_BASE = "https://$FACEBOOK_MBASIC_COM/"
fun profilePictureUrl(id: Long) = "https://graph.facebook.com/$id/picture?type=large"
const val FB_LOGIN_URL = "${FB_URL_BASE}login"
const val FB_HOME_URL = "${FB_URL_BASE}home.php"
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbItem.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbItem.kt
index 4df99878..8d200c4f 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbItem.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbItem.kt
@@ -61,6 +61,14 @@ enum class FbItem(
_SEARCH(
R.string.kau_search,
GoogleMaterial.Icon.gmd_search,
+ "search/top"
+ ),
+ /**
+ * Non mbasic search cannot be parsed.
+ */
+ _SEARCH_PARSE(
+ R.string.kau_search,
+ GoogleMaterial.Icon.gmd_search,
"search/top",
prefix = FB_URL_MBASIC_BASE
),
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/SearchParser.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/SearchParser.kt
index e4339d4f..28b4a556 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/SearchParser.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/SearchParser.kt
@@ -17,6 +17,8 @@
package com.pitchedapps.frost.facebook.parsers
import ca.allanwang.kau.searchview.SearchItem
+import com.pitchedapps.frost.facebook.FACEBOOK_BASE_COM
+import com.pitchedapps.frost.facebook.FACEBOOK_MBASIC_COM
import com.pitchedapps.frost.facebook.FbItem
import com.pitchedapps.frost.facebook.formattedFbUrl
import com.pitchedapps.frost.facebook.parsers.FrostSearch.Companion.create
@@ -29,7 +31,7 @@ import org.jsoup.nodes.Element
*/
object SearchParser : FrostParser<FrostSearches> by SearchParserImpl() {
fun query(cookie: String?, input: String): ParseResponse<FrostSearches>? {
- val url = "${FbItem._SEARCH.url}?q=${if (input.isNotBlank()) input else "a"}"
+ val url = "${FbItem._SEARCH_PARSE.url}?q=${if (input.isNotBlank()) input else "a"}"
L._i { "Search Query $url" }
return parseFromUrl(cookie, url)
}
@@ -74,9 +76,12 @@ data class FrostSearch(val href: String, val title: String, val description: Str
private class SearchParserImpl : FrostParserBase<FrostSearches>(false) {
- override var nameRes = FbItem._SEARCH.titleId
+ override var nameRes = FbItem._SEARCH_PARSE.titleId
- override val url = "${FbItem._SEARCH.url}?q=google"
+ override val url = "${FbItem._SEARCH_PARSE.url}?q=google"
+
+ private val String.formattedSearchUrl: String
+ get() = replace(FACEBOOK_MBASIC_COM, FACEBOOK_BASE_COM)
override fun parseImpl(doc: Document): FrostSearches? {
val container: Element = doc.getElementById("BrowseResultsContainer")
@@ -87,9 +92,14 @@ private class SearchParserImpl : FrostParserBase<FrostSearches>(false) {
// Our assumption is that search entries start with an image, followed by general info
// There may be other <td />s, but we will not be parsing them
// Furthermore, the <td /> entry wraps a link, containing all the necessary info
- val a = el.select("td").getOrNull(1)?.selectFirst("a") ?: return@mapNotNull null
+ val a = el.select("td")
+ .getOrNull(1)
+ ?.selectFirst("a")
+ ?: return@mapNotNull null
val url =
- a.attr("href").takeIf { it.isNotEmpty() }?.formattedFbUrl ?: return@mapNotNull null
+ a.attr("href").takeIf { it.isNotEmpty() }
+ ?.formattedFbUrl?.formattedSearchUrl
+ ?: return@mapNotNull null
// Currently, children should all be <div /> elements, where the first entry is the name/title
// And the other entries are additional info.
// There are also cases of nested tables, eg for the "join" button in groups.