From 314eec1c70d3678a093c21e386aedf8900828f14 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sun, 19 Jan 2020 22:52:58 -0800 Subject: Only use mbasic for parsing --- .../kotlin/com/pitchedapps/frost/facebook/FbConst.kt | 3 ++- .../kotlin/com/pitchedapps/frost/facebook/FbItem.kt | 8 ++++++++ .../frost/facebook/parsers/SearchParser.kt | 20 +++++++++++++++----- 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 @@ -59,6 +59,14 @@ enum class FbItem( * Note that this url only works if a query (?q=) is provided */ _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", 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 by SearchParserImpl() { fun query(cookie: String?, input: String): ParseResponse? { - 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(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(false) { // Our assumption is that search entries start with an image, followed by general info // There may be other s, but we will not be parsing them // Furthermore, the 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
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. -- cgit v1.2.3 From 59669214b1f7edbf2fa38d61903e8b48476726c0 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sun, 19 Jan 2020 22:58:13 -0800 Subject: Update changelog --- app/src/main/res/xml/frost_changelog.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/xml/frost_changelog.xml b/app/src/main/res/xml/frost_changelog.xml index 125c12cb..8e400347 100644 --- a/app/src/main/res/xml/frost_changelog.xml +++ b/app/src/main/res/xml/frost_changelog.xml @@ -9,7 +9,7 @@ - + -- cgit v1.2.3