From a73aee7ab22c264553c3fd008617ebe80678602c Mon Sep 17 00:00:00 2001 From: udhayarajan Date: Tue, 27 Jun 2023 08:11:08 +0530 Subject: [PATCH] fix(General): Redirection issue fixed --- build.gradle.kts | 2 +- .../kotlin/com/mugames/vidsnapkit/extractor/Instagram.kt | 6 +++++- .../kotlin/com/mugames/vidsnapkit/network/HttpRequest.kt | 9 ++++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 5bf40f6e..bdd41c70 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -27,7 +27,7 @@ plugins { } group = "io.github.udhayarajan" -version = "5.3.12" +version = "5.3.13" //Version Naming incremented if ".." //Priority on incrementing Feature > BugFix > Beta diff --git a/src/commonMain/kotlin/com/mugames/vidsnapkit/extractor/Instagram.kt b/src/commonMain/kotlin/com/mugames/vidsnapkit/extractor/Instagram.kt index a13f389d..29e4ce6b 100644 --- a/src/commonMain/kotlin/com/mugames/vidsnapkit/extractor/Instagram.kt +++ b/src/commonMain/kotlin/com/mugames/vidsnapkit/extractor/Instagram.kt @@ -68,6 +68,11 @@ class Instagram internal constructor(url: String) : Extractor(url) { return true } } + if (res.status == HttpStatusCode.OK) { + if (res.call.request.url.toString() == "https://www.instagram.com/") { + return true + } + } logger.info("Oops!, Cookie is invalid so removing it from header") return false } @@ -212,7 +217,6 @@ class Instagram internal constructor(url: String) : Extractor(url) { } - private suspend fun extractInfoShared(page: String) { if (page == "{error:\"Invalid Cookies\"}") { onProgress(Result.Failed(Error.LoginRequired)) diff --git a/src/commonMain/kotlin/com/mugames/vidsnapkit/network/HttpRequest.kt b/src/commonMain/kotlin/com/mugames/vidsnapkit/network/HttpRequest.kt index 6a9bf7b0..f6f3edd4 100644 --- a/src/commonMain/kotlin/com/mugames/vidsnapkit/network/HttpRequest.kt +++ b/src/commonMain/kotlin/com/mugames/vidsnapkit/network/HttpRequest.kt @@ -53,7 +53,7 @@ class HttpRequest( } private fun createClient(requiresRedirection: Boolean = true): HttpInterface { - return HttpInterfaceImpl(clientGenerator().apply { config { followRedirects = requiresRedirection } }) + return HttpInterfaceImpl(clientGenerator().config { followRedirects = requiresRedirection }) } /** @@ -66,7 +66,7 @@ class HttpRequest( fun setClient( clientGenerator: () -> HttpClient, prefixUrl: String = "", - headers: Hashtable? = null + headers: Hashtable? = null, ) { this.prefixUrl = prefixUrl this.clientGenerator = clientGenerator @@ -114,7 +114,10 @@ class HttpRequest( } suspend fun getRawResponse(needsRedirection: Boolean = true, useCustomClient: Boolean = true) = - (if (useCustomClient) createClient(needsRedirection) else defaultClient(needsRedirection)).getRawResponse(getUrl(), getHeader()) + (if (useCustomClient) createClient(needsRedirection) else defaultClient(needsRedirection)).getRawResponse( + getUrl(), + getHeader() + ) suspend fun isAvailable(useCustomClient: Boolean = true): Boolean = withContext(Dispatchers.IO) {