Skip to content

Commit 9c6113d

Browse files
committed
fix(Facebook): cookie validation
1 parent d72162d commit 9c6113d

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ plugins {
2727
}
2828

2929
group = "io.github.udhayarajan"
30-
version = "5.3.15"
30+
version = "5.3.16"
3131
//Version Naming incremented if "<NEW_FEATURE_ADDED>.<WORKED_ON_BUG>.<BETA_VERSION_COUNT>"
3232
//Priority on incrementing Feature > BugFix > Beta
3333

src/commonMain/kotlin/com/mugames/vidsnapkit/extractor/Facebook.kt

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import com.mugames.vidsnapkit.*
2121
import com.mugames.vidsnapkit.Util.Companion.decodeHTML
2222
import com.mugames.vidsnapkit.dataholders.*
2323
import com.mugames.vidsnapkit.network.HttpRequest
24+
import io.ktor.client.statement.*
25+
import io.ktor.http.*
2426
import org.json.JSONArray
2527
import org.json.JSONException
2628
import org.json.JSONObject
@@ -46,14 +48,22 @@ class Facebook internal constructor(url: String) : Extractor(url) {
4648

4749
private suspend fun isCookieValid(): Boolean {
4850
if (cookies.isNullOrEmpty()) return false
49-
val res = HttpRequest("https://www.facebook.com/", headers).getResponse(false) ?: return false
50-
val restrictedKeywords = listOf("Create new account", "log in or sign up", "Forgotten password")
51-
val containsRestrictedKeyword = restrictedKeywords.any { keyword ->
52-
res.contains(keyword, ignoreCase = true)
51+
val res = HttpRequest("https://www.facebook.com/", headers).getRawResponse(false) ?: return false
52+
if (res.status == HttpStatusCode.OK) {
53+
val restrictedKeywords = listOf("Create new account", "log in or sign up", "Forgotten password")
54+
val containsRestrictedKeyword = restrictedKeywords.any { keyword ->
55+
res.bodyAsText().contains(keyword, ignoreCase = true)
56+
}
57+
logger.info("Check cookie containsRestrictedKeyword=${containsRestrictedKeyword} ")
58+
return !containsRestrictedKeyword
5359
}
54-
55-
logger.info("Check cookie containsRestrictedKeyword=${containsRestrictedKeyword} ")
56-
return !containsRestrictedKeyword
60+
if (res.status == HttpStatusCode.Found){
61+
logger.info("Oops! redirection found for ${res.headers["location"]}")
62+
if (res.call.request.url.toString().contains("checkpoint")){
63+
return false
64+
}
65+
}
66+
return true
5767
}
5868

5969
override suspend fun analyze(payload: Any?) {

0 commit comments

Comments
 (0)