mirror of
https://github.com/AllanWang/Frost-for-Facebook.git
synced 2024-09-19 23:21:34 +02:00
Merge pull request #1607 from AllanWang/search-parse
Use mbasic for search parser
This commit is contained in:
commit
af1a3954a7
@ -25,6 +25,7 @@ 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/"
|
||||
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"
|
||||
|
@ -32,7 +32,8 @@ enum class FbItem(
|
||||
@StringRes val titleId: Int,
|
||||
val icon: IIcon,
|
||||
relativeUrl: String,
|
||||
val fragmentCreator: () -> BaseFragment = ::WebFragment
|
||||
val fragmentCreator: () -> BaseFragment = ::WebFragment,
|
||||
prefix: String = FB_URL_BASE
|
||||
) : EnumBundle<FbItem> {
|
||||
|
||||
ACTIVITY_LOG(R.string.activity_log, GoogleMaterial.Icon.gmd_list, "me/allactivity"),
|
||||
@ -57,11 +58,16 @@ 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"),
|
||||
_SEARCH(
|
||||
R.string.kau_search,
|
||||
GoogleMaterial.Icon.gmd_search,
|
||||
"search/top",
|
||||
prefix = FB_URL_MBASIC_BASE
|
||||
),
|
||||
SETTINGS(R.string.settings, GoogleMaterial.Icon.gmd_settings, "settings"),
|
||||
;
|
||||
|
||||
val url = "$FB_URL_BASE$relativeUrl"
|
||||
val url = "$prefix$relativeUrl"
|
||||
|
||||
val isFeed: Boolean
|
||||
get() = when (this) {
|
||||
|
@ -76,22 +76,33 @@ private class SearchParserImpl : FrostParserBase<FrostSearches>(false) {
|
||||
|
||||
override var nameRes = FbItem._SEARCH.titleId
|
||||
|
||||
override val url = "${FbItem._SEARCH.url}?q=a"
|
||||
override val url = "${FbItem._SEARCH.url}?q=google"
|
||||
|
||||
override fun parseImpl(doc: Document): FrostSearches? {
|
||||
val container: Element = doc.getElementById("BrowseResultsContainer")
|
||||
?: doc.getElementById("root")
|
||||
?: return null
|
||||
/**
|
||||
*
|
||||
* Removed [data-store*=result_id]
|
||||
*/
|
||||
return FrostSearches(container.select("a.touchable[href]").filter(Element::hasText).map {
|
||||
FrostSearch.create(
|
||||
it.attr("href").formattedFbUrl,
|
||||
it.select("._uoi").first()?.text() ?: "",
|
||||
it.select("._1tcc").first()?.text()
|
||||
)
|
||||
}.filter { it.title.isNotBlank() })
|
||||
|
||||
return FrostSearches(container.select("table[role=presentation]").mapNotNull { el ->
|
||||
// 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 url =
|
||||
a.attr("href").takeIf { it.isNotEmpty() }?.formattedFbUrl ?: 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.
|
||||
// Those elements have <span /> texts, so we will filter by div to ignore those
|
||||
val texts = a.children().filter { it.tagName() == "div" && it.hasText() }
|
||||
val title = texts.firstOrNull()?.text() ?: return@mapNotNull null
|
||||
val info = texts.takeIf { it.size > 1 }?.last()?.text()
|
||||
L.e { a }
|
||||
create(
|
||||
href = url,
|
||||
title = title,
|
||||
description = info
|
||||
).also { L.e { it } }
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,6 @@ class FbParseTest {
|
||||
@Test
|
||||
fun messageUser() = MessageParser.queryUser(COOKIE, "allan").test("allan query")
|
||||
|
||||
@Ignore("No longer works as search results don't appear in html")
|
||||
@Test
|
||||
fun search() = SearchParser.test()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user