aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/kotlin')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/parsers/SearchParser.kt15
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt8
2 files changed, 13 insertions, 10 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/parsers/SearchParser.kt b/app/src/main/kotlin/com/pitchedapps/frost/parsers/SearchParser.kt
index 0d542a80..37c09299 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/parsers/SearchParser.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/parsers/SearchParser.kt
@@ -47,23 +47,18 @@ private class SearchParserImpl : FrostParserBase<List<FrostSearch>>() {
val container: Element = doc.getElementById("BrowseResultsContainer")
?: doc.getElementById("root")
?: return null
- val hrefSet = mutableSetOf<String>()
/**
- * When mapping items, some links are duplicated because they are nested below a main one
- * We will filter out search items whose links are already in the list
*
* Removed [data-store*=result_id]
*/
return container.select("a.touchable.primary[href]").filter(Element::hasText).mapNotNull {
- val item = FrostSearch(it.attr("href").formattedFbUrlCss,
- it.select("._uok").first()?.text() ?: it.text(),
- it.select("._1tcc").first()?.text())
- if (hrefSet.contains(item.href)) return@mapNotNull null
- hrefSet.add(item.href)
- item
- }
+ FrostSearch(it.attr("href").formattedFbUrlCss,
+ it.select(".title").first()?.text() ?: "",
+ it.select(".subtitle").first()?.ownText())
+ }.filter { it.title.isNotBlank() }
}
+
override fun textToDoc(text: String): Document? = Jsoup.parse(text)
override fun debugImpl(data: List<FrostSearch>, result: MutableList<String>) {
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
index 112269c1..6d6c5381 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
@@ -32,6 +32,7 @@ import com.pitchedapps.frost.dbflow.CookieModel
import com.pitchedapps.frost.facebook.*
import com.pitchedapps.frost.utils.iab.IS_FROST_PRO
import org.jsoup.Jsoup
+import org.jsoup.nodes.Element
import java.io.IOException
import java.util.*
@@ -223,3 +224,10 @@ fun frostJsoup(url: String)
fun frostJsoup(cookie: String?, url: String)
= Jsoup.connect(url).cookie(FACEBOOK_COM, cookie).userAgent(USER_AGENT_BASIC).get()!!
+fun Element.first(vararg select: String): Element? {
+ select.forEach {
+ val e = select(it)
+ if (e.size > 0) return e.first()
+ }
+ return null
+} \ No newline at end of file