Skip to content

Commit

Permalink
Merge pull request #35 from Udhayarajan/facebook-bugs
Browse files Browse the repository at this point in the history
Regular update
  • Loading branch information
Udhayarajan authored Jul 21, 2023
2 parents 6486af9 + 124746e commit 5f95c9f
Show file tree
Hide file tree
Showing 5 changed files with 204 additions and 96 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ plugins {
}

group = "io.github.udhayarajan"
version = "5.6.6"
version = "5.6.7"
// Version Naming incremented if "<NEW_FEATURE_ADDED>.<WORKED_ON_BUG>.<BETA_VERSION_COUNT_OR_PRE_RELEASE>"
// Priority on incrementing Feature > BugFix > Beta

Expand Down
47 changes: 25 additions & 22 deletions src/commonMain/kotlin/com/mugames/vidsnapkit/extractor/Extractor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import io.ktor.client.plugins.*
import kotlinx.coroutines.*
import kotlinx.coroutines.future.future
import org.slf4j.LoggerFactory
import java.net.SocketException
import java.util.*
import java.util.regex.Pattern
import javax.net.ssl.SSLHandshakeException
Expand Down Expand Up @@ -58,6 +59,22 @@ abstract class Extractor(
fun findExtractor(
url: String,
): Extractor? {
if (url.contains("facebook")) {
if (url.contains("instagram.com")) {
logger.info("Insta embedded FB post, redirecting to Instagram")
val instaURL = Pattern.compile("\\?.*?u=(.*?)(?:&|/|)\$").matcher(url).run {
if (find())
Util.decodeHTML(group(1))
else
null
}
return instaURL?.let {
Instagram(
it
)
}
}
}
return when {
url.contains("facebook|fb\\.".toRegex()) -> Facebook(url)
url.contains("instagram") -> Instagram(url)
Expand Down Expand Up @@ -118,24 +135,6 @@ abstract class Extractor(

private suspend fun safeAnalyze() {
try {
if (inputUrl.contains("facebook")) {
if (inputUrl.contains("instagram.com")) {
logger.info("Insta embedded FB post, redirecting to Instagram")
val instaURL = Pattern.compile("\\?.*?u=(.*?)(?:&|/|)\$").matcher(inputUrl).run {
if (find())
Util.decodeHTML(group(1))
else
null
}
Instagram(
instaURL ?: run {
logger.error("Fail to match the regex url=$inputUrl")
internalError("unable to match the instagram url")
return
}
)
}
}
if (inputUrl.contains("instagram")) {
inputUrl = if (cookies == null) {
inputUrl.replace("/reels/", "/reel/")
Expand All @@ -153,11 +152,11 @@ abstract class Extractor(
} else clientRequestError()
} catch (e: Exception) {
if (e is SSLHandshakeException)
clientRequestError()
else if (e is ClientRequestException && inputUrl.contains("instagram"))
internalError("problem with SSL try again")
if (e is ClientRequestException && inputUrl.contains("instagram"))
onProgress(Result.Failed(Error.Instagram404Error(cookies != null)))
else if (e is SocketTimeoutException)
onProgress(Result.Failed(Error.NonFatalError("socket can't connect please try again")))
else if (e is SocketTimeoutException || e is SocketException)
internalError("socket can't connect please try again")
else
onProgress(Result.Failed(Error.InternalError("Error in SafeAnalyze", e)))
}
Expand Down Expand Up @@ -240,6 +239,10 @@ abstract class Extractor(
onProgress(Result.Failed(Error.InternalError(msg, e)))
}

protected fun missingLogic() {
onProgress(Result.Failed(Error.MethodMissingLogic))
}

abstract suspend fun testWebpage(string: String)

// list of ua supported by both fb & insta
Expand Down
Loading

0 comments on commit 5f95c9f

Please sign in to comment.