![JAR search and dependency download from the Maven repository](/logo.png)
com.hiczp.bilibili.api.web.BilibiliWebAPI Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bilibili-api Show documentation
Show all versions of bilibili-api Show documentation
Bilibili Android client API library for Kotlin
package com.hiczp.bilibili.api.web;
import com.hiczp.bilibili.api.BaseUrlDefinition;
import com.hiczp.bilibili.api.interceptor.AddFixedHeadersInterceptor;
import com.hiczp.bilibili.api.interceptor.ErrorResponseConverterInterceptor;
import com.hiczp.bilibili.api.web.cookie.SimpleCookieJar;
import com.hiczp.bilibili.api.web.live.LiveService;
import okhttp3.Cookie;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import javax.annotation.Nonnull;
import java.util.Collections;
import java.util.List;
import java.util.Map;
public class BilibiliWebAPI {
private final BrowserProperties browserProperties;
private final SimpleCookieJar cookieJar;
private LiveService liveService;
public BilibiliWebAPI(BrowserProperties browserProperties, Map> cookiesMap) {
this.browserProperties = browserProperties;
this.cookieJar = new SimpleCookieJar(cookiesMap);
}
public BilibiliWebAPI(SimpleCookieJar cookieJar) {
this(BrowserProperties.defaultSetting(), cookieJar.getCookiesMap());
}
public BilibiliWebAPI(Map> cookiesMap) {
this(BrowserProperties.defaultSetting(), cookiesMap);
}
public BilibiliWebAPI(BrowserProperties browserProperties, SimpleCookieJar cookieJar) {
this(browserProperties, cookieJar.getCookiesMap());
}
public LiveService getLiveService() {
if (liveService == null) {
liveService = getLiveService(Collections.emptyList(), HttpLoggingInterceptor.Level.BASIC);
}
return liveService;
}
public LiveService getLiveService(@Nonnull List interceptors, @Nonnull HttpLoggingInterceptor.Level logLevel) {
OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient.Builder();
okHttpClientBuilder
.cookieJar(cookieJar)
.addInterceptor(new AddFixedHeadersInterceptor(
"User-Agent", browserProperties.getUserAgent()
))
.addInterceptor(new ErrorResponseConverterInterceptor());
interceptors.forEach(okHttpClientBuilder::addInterceptor);
okHttpClientBuilder
.addNetworkInterceptor(new HttpLoggingInterceptor().setLevel(logLevel));
return new Retrofit.Builder()
.baseUrl(BaseUrlDefinition.LIVE)
.addConverterFactory(GsonConverterFactory.create())
.client(okHttpClientBuilder.build())
.build()
.create(LiveService.class);
}
public SimpleCookieJar getCookieJar() {
return cookieJar;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy