Skip to content

Commit

Permalink
Фикс перезалива историй
Browse files Browse the repository at this point in the history
  • Loading branch information
Spliterash committed Oct 5, 2024
1 parent 9cff762 commit ceecc60
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import okhttp3.OkHttpClient
import ru.spliterash.vkVideoUnlocker.common.okHttp.executeAsync
import ru.spliterash.vkVideoUnlocker.story.exceptions.StoryNotFoundById
import ru.spliterash.vkVideoUnlocker.story.vkModels.VkStory
import ru.spliterash.vkVideoUnlocker.video.api.VideosImpl
import ru.spliterash.vkVideoUnlocker.vk.VkConst
import ru.spliterash.vkVideoUnlocker.vk.VkHelper
import ru.spliterash.vkVideoUnlocker.vk.readResponse
import ru.spliterash.vkVideoUnlocker.vk.VkConst
import ru.spliterash.vkVideoUnlocker.vk.vkModels.VkItemsResponse

@Prototype
Expand All @@ -20,6 +21,7 @@ class StoriesImpl(
override suspend fun getById(storyId: String): VkStory {
return VkConst
.requestBuilder()
.header("user-agent", VideosImpl.USER_AGENT)
.get()
.url(
VkConst.urlBuilder("stories.getById")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import okhttp3.Request
import okhttp3.executeAsync
import org.apache.commons.logging.LogFactory
import ru.spliterash.vkVideoUnlocker.common.InputStreamSource
import ru.spliterash.vkVideoUnlocker.video.api.VideosImpl
import ru.spliterash.vkVideoUnlocker.video.vkModels.VkVideo
import java.net.URL

Expand Down Expand Up @@ -82,20 +83,9 @@ class VkVideoAccessorImpl(
}

private fun builder(url: URL): Request.Builder {
val userAgent = if (url.query.contains("srcAg=GECKO"))
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0"
else
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
val userAgent = VideosImpl.USER_AGENT
return Request.Builder()
.url(url)
.header(
"Accept",
"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"
)
.header(
"Accept-Encoding",
"gzip, deflate, br"
)
.header(
"User-Agent",
userAgent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@ import com.fasterxml.jackson.module.kotlin.readValue
import io.micronaut.context.annotation.Parameter
import io.micronaut.context.annotation.Prototype
import okhttp3.OkHttpClient
import org.apache.commons.io.IOUtils
import ru.spliterash.vkVideoUnlocker.common.VkUploaderService
import ru.spliterash.vkVideoUnlocker.common.okHttp.executeAsync
import ru.spliterash.vkVideoUnlocker.common.vkModels.VkUploadUrlResponse
import ru.spliterash.vkVideoUnlocker.video.accessor.VideoAccessor
import ru.spliterash.vkVideoUnlocker.video.exceptions.VideoLockedException
import ru.spliterash.vkVideoUnlocker.video.exceptions.VideoNotFoundException
import ru.spliterash.vkVideoUnlocker.common.vkModels.VkUploadUrlResponse
import ru.spliterash.vkVideoUnlocker.video.vkModels.VkVideo
import ru.spliterash.vkVideoUnlocker.video.vkModels.VkVideoUploadResponse
import ru.spliterash.vkVideoUnlocker.vk.VkConst
import ru.spliterash.vkVideoUnlocker.vk.VkHelper
import ru.spliterash.vkVideoUnlocker.vk.readResponse
import ru.spliterash.vkVideoUnlocker.vk.vkModels.VkItemsResponse
import java.io.FileOutputStream

@Prototype
class VideosImpl(
Expand All @@ -32,7 +34,7 @@ class VideosImpl(
.get()
.addHeader(
"user-agent",
"KateMobileAndroid/99 lite-535 (Android 11; SDK 30; arm64-v8a; asus Zenfone Max Pro M1; ru)"
USER_AGENT
)
.url(
VkConst.urlBuilder("video.get")
Expand Down Expand Up @@ -81,4 +83,8 @@ class VideosImpl(
return "-${groupId}_${mapped.videoId}"
}

companion object {
const val USER_AGENT =
"KateMobileAndroid/99 lite-535 (Android 11; SDK 30; arm64-v8a; asus Zenfone Max Pro M1; ru)"
}
}

0 comments on commit ceecc60

Please sign in to comment.