Skip to content

Commit

Permalink
fix(Facebook): cookie validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Udhayarajan committed Jun 27, 2023
1 parent d72162d commit 9c6113d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ plugins {
}

group = "io.github.udhayarajan"
version = "5.3.15"
version = "5.3.16"
//Version Naming incremented if "<NEW_FEATURE_ADDED>.<WORKED_ON_BUG>.<BETA_VERSION_COUNT>"
//Priority on incrementing Feature > BugFix > Beta

Expand Down
24 changes: 17 additions & 7 deletions src/commonMain/kotlin/com/mugames/vidsnapkit/extractor/Facebook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import com.mugames.vidsnapkit.*
import com.mugames.vidsnapkit.Util.Companion.decodeHTML
import com.mugames.vidsnapkit.dataholders.*
import com.mugames.vidsnapkit.network.HttpRequest
import io.ktor.client.statement.*
import io.ktor.http.*
import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject
Expand All @@ -46,14 +48,22 @@ class Facebook internal constructor(url: String) : Extractor(url) {

private suspend fun isCookieValid(): Boolean {
if (cookies.isNullOrEmpty()) return false
val res = HttpRequest("https://www.facebook.com/", headers).getResponse(false) ?: return false
val restrictedKeywords = listOf("Create new account", "log in or sign up", "Forgotten password")
val containsRestrictedKeyword = restrictedKeywords.any { keyword ->
res.contains(keyword, ignoreCase = true)
val res = HttpRequest("https://www.facebook.com/", headers).getRawResponse(false) ?: return false
if (res.status == HttpStatusCode.OK) {
val restrictedKeywords = listOf("Create new account", "log in or sign up", "Forgotten password")
val containsRestrictedKeyword = restrictedKeywords.any { keyword ->
res.bodyAsText().contains(keyword, ignoreCase = true)
}
logger.info("Check cookie containsRestrictedKeyword=${containsRestrictedKeyword} ")
return !containsRestrictedKeyword
}

logger.info("Check cookie containsRestrictedKeyword=${containsRestrictedKeyword} ")
return !containsRestrictedKeyword
if (res.status == HttpStatusCode.Found){
logger.info("Oops! redirection found for ${res.headers["location"]}")
if (res.call.request.url.toString().contains("checkpoint")){
return false
}
}
return true
}

override suspend fun analyze(payload: Any?) {
Expand Down

0 comments on commit 9c6113d

Please sign in to comment.