[Android] Add a debug constant to the open subtitles API
Nicolas Pomepuy
git at videolan.org
Thu Nov 21 13:19:11 UTC 2024
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Nov 7 09:30:23 2024 +0100| [1879a9bcf7ea6280d235452f3b2b985a6cdb6c38] | committer: Duncan McNamara
Add a debug constant to the open subtitles API
> https://code.videolan.org/videolan/vlc-android/commit/1879a9bcf7ea6280d235452f3b2b985a6cdb6c38
---
.../resources/opensubtitles/OpenSubtitleService.kt | 42 +++++++++++++---------
1 file changed, 26 insertions(+), 16 deletions(-)
diff --git a/application/resources/src/main/java/org/videolan/resources/opensubtitles/OpenSubtitleService.kt b/application/resources/src/main/java/org/videolan/resources/opensubtitles/OpenSubtitleService.kt
index bd56f6639c..aeca614759 100644
--- a/application/resources/src/main/java/org/videolan/resources/opensubtitles/OpenSubtitleService.kt
+++ b/application/resources/src/main/java/org/videolan/resources/opensubtitles/OpenSubtitleService.kt
@@ -5,7 +5,6 @@ import com.moczul.ok2curl.CurlInterceptor
import com.moczul.ok2curl.logger.Logger
import com.squareup.moshi.Moshi
import com.squareup.moshi.adapters.Rfc3339DateJsonAdapter
-import main.java.org.videolan.resources.opensubtitles.OpenSubtitlesUtils
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
import okhttp3.Interceptor
import okhttp3.OkHttpClient
@@ -23,25 +22,12 @@ import java.util.concurrent.TimeUnit
private const val BASE_URL = "https://api.opensubtitles.com/api/v1/"
const val USER_AGENT = "VLSub v0.9"
+private const val DEBUG = false
private fun buildClient() = Retrofit.Builder()
.baseUrl(BASE_URL)
.client(
- OkHttpClient.Builder()
- .addInterceptor(HttpLoggingInterceptor().apply {
- level = HttpLoggingInterceptor.Level.BODY
- })
- .addInterceptor(DomainInterceptor())
- .addInterceptor(UserAgentInterceptor(USER_AGENT))
- .addInterceptor(ConnectivityInterceptor(AppContextProvider.appContext))
- .addInterceptor(CurlInterceptor(object : Logger {
- override fun log(message: String) {
- Log.v("Ok2Curl", message)
- }
- }))
- .readTimeout(10, TimeUnit.SECONDS)
- .connectTimeout(5, TimeUnit.SECONDS)
- .build()
+ getOkHttpClient()
)
.addConverterFactory(
MoshiConverterFactory.create(
@@ -53,6 +39,30 @@ private fun buildClient() = Retrofit.Builder()
.build()
.create(IOpenSubtitleService::class.java)
+private fun getOkHttpClient(): OkHttpClient {
+ val builder = OkHttpClient.Builder()
+
+ .addInterceptor(DomainInterceptor())
+ .addInterceptor(UserAgentInterceptor(USER_AGENT))
+ .addInterceptor(ConnectivityInterceptor(AppContextProvider.appContext))
+
+ .readTimeout(10, TimeUnit.SECONDS)
+ .connectTimeout(5, TimeUnit.SECONDS)
+
+ if (DEBUG) {
+ builder
+ .addInterceptor(HttpLoggingInterceptor().apply {
+ level = HttpLoggingInterceptor.Level.BODY
+ })
+ .addInterceptor(CurlInterceptor(object : Logger {
+ override fun log(message: String) {
+ Log.v("Ok2Curl", message)
+ }
+ }))
+ }
+ return builder.build()
+}
+
private class UserAgentInterceptor(val userAgent: String): Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
More information about the Android
mailing list