aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/facebook
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/facebook')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt4
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/FbRegex.kt1
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt5
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt19
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Images.kt17
5 files changed, 33 insertions, 13 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt
index e5f0b8fe..38de6150 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt
@@ -20,6 +20,10 @@ import io.reactivex.subjects.SingleSubject
*/
object FbCookie {
+ /**
+ * Retrieves the facebook cookie if it exists
+ * Note that this is a synchronized call
+ */
inline val webCookie: String?
get() = CookieManager.getInstance().getCookie(FB_URL_BASE)
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbRegex.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbRegex.kt
index 4ba3c80d..cfa2796c 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbRegex.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbRegex.kt
@@ -26,6 +26,7 @@ val FB_MESSAGE_NOTIF_ID_MATCHER: Regex by lazy { Regex("[thread|user]_fbid_([0-9
val FB_CSS_URL_MATCHER: Regex by lazy { Regex("url\\([\"|']?(.*?)[\"|']?\\)") }
val FB_JSON_URL_MATCHER: Regex by lazy { Regex("\"(http.*?)\"") }
val FB_IMAGE_ID_MATCHER: Regex by lazy { Regex("fbcdn.*?/[0-9]+_([0-9]+)_") }
+val FB_REDIRECT_URL_MATCHER: Regex by lazy { Regex("url=(.*?fbcdn.*?)\"") }
operator fun MatchResult?.get(groupIndex: Int) = this?.groupValues?.get(groupIndex)
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt
index f21c03e9..add35154 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt
@@ -43,6 +43,7 @@ class FbUrlFormatter(url: String) {
L.e(e) { "Failed url formatting" }
return url
}
+ cleanedUrl = cleanedUrl.replace("&", "&")
if (changed && !cleanedUrl.contains("?")) //ensure we aren't missing '?'
cleanedUrl = cleanedUrl.replaceFirst("&", "?")
val qm = cleanedUrl.indexOf("?")
@@ -54,8 +55,6 @@ class FbUrlFormatter(url: String) {
cleanedUrl = cleanedUrl.substring(0, qm)
}
discardableQueries.forEach { queries.remove(it) }
- //final cleanup
- misc.forEach { (k, v) -> cleanedUrl = cleanedUrl.replace(k, v, true) }
if (cleanedUrl.startsWith("/")) cleanedUrl = FB_URL_BASE + cleanedUrl.substring(1)
cleanedUrl = cleanedUrl.replaceFirst(".facebook.com//", ".facebook.com/") //sometimes we are given a bad url
L.v { "Formatted url from $url to $cleanedUrl" }
@@ -101,8 +100,6 @@ class FbUrlFormatter(url: String) {
VIDEO_REDIRECT
)
- val misc = arrayOf("&" to "&")
-
val discardableQueries = arrayOf("ref", "refid", "acontext", "SharedWith")
val converter = listOf(
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt
index b5c2e4e9..692312a1 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt
@@ -6,7 +6,10 @@ import com.pitchedapps.frost.rx.RxFlyweight
import com.pitchedapps.frost.utils.L
import io.reactivex.Single
import io.reactivex.schedulers.Schedulers
-import okhttp3.*
+import okhttp3.Call
+import okhttp3.FormBody
+import okhttp3.OkHttpClient
+import okhttp3.Request
import okhttp3.logging.HttpLoggingInterceptor
import org.apache.commons.text.StringEscapeUtils
@@ -92,12 +95,16 @@ internal fun List<Pair<String, Any?>>.withEmptyData(vararg key: String): List<Pa
return newList
}
-private fun String.requestBuilder() = Request.Builder()
- .header("Cookie", this)
- .header("User-Agent", USER_AGENT_BASIC)
- .cacheControl(CacheControl.FORCE_NETWORK)
+internal fun String?.requestBuilder(): Request.Builder {
+ val builder = Request.Builder()
+ .header("User-Agent", USER_AGENT_BASIC)
+ if (this != null)
+ builder.header("Cookie", this)
+// .cacheControl(CacheControl.FORCE_NETWORK)
+ return builder
+}
-fun Request.Builder.call() = httpClient.newCall(build())!!
+fun Request.Builder.call(): Call = httpClient.newCall(build())
fun String.getAuth(): RequestAuth {
L.v { "Getting auth for ${hashCode()}" }
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Images.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Images.kt
index 453400d3..8eeef08d 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Images.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Images.kt
@@ -11,9 +11,8 @@ import com.bumptech.glide.load.model.MultiModelLoaderFactory
import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.request.target.Target
import com.bumptech.glide.signature.ObjectKey
-import com.pitchedapps.frost.facebook.FB_IMAGE_ID_MATCHER
-import com.pitchedapps.frost.facebook.FB_URL_BASE
-import com.pitchedapps.frost.facebook.get
+import com.pitchedapps.frost.facebook.*
+import io.reactivex.Maybe
import okhttp3.Call
import okhttp3.Request
import java.io.IOException
@@ -27,6 +26,18 @@ fun RequestAuth.getFullSizedImage(fbid: Long) = frostRequest(::getJsonUrl) {
get()
}
+val test: () -> InputStream? = { null }
+
+/**
+ * Attempts to get the fbcdn url of the supplied image redirect url
+ */
+fun String.getFullSizedImageUrl(url: String): Maybe<String?> = Maybe.fromCallable {
+ val redirect = requestBuilder().url(url).get().call()
+ .execute().body()?.string() ?: return@fromCallable null
+ return@fromCallable FB_REDIRECT_URL_MATCHER.find(redirect)[1]?.formattedFbUrl
+ ?: return@fromCallable null
+}.onErrorComplete()
+
/**
* Request loader for a potentially hd version of a url
* In this case, each url may potentially return an id,