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 bd56f6639..aeca61475 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 {