Skip to main content

BpiClient

Struct BpiClient 

Source
pub struct BpiClient { /* private fields */ }
Expand description

Bilibili API client.

Implementations§

Source§

impl BpiClient

Source

pub fn new() -> Result<Self, BpiError>

Creates an owned client with default configuration.

Source

pub fn builder() -> BpiClientBuilder

Starts configuring a client.

Examples found in repository?
examples/module_clients.rs (line 35)
33fn client_from_env() -> BpiResult<BpiClient> {
34    match env::var("BPI_COOKIE") {
35        Ok(cookie) if !cookie.trim().is_empty() => BpiClient::builder().cookie(cookie).build(),
36        _ => BpiClient::builder().build(),
37    }
38}
Source

pub fn set_account(&self, account: Account) -> Result<(), BpiError>

Sets account information and updates this client’s cookie state.

Source

pub fn clear_account(&self)

Clears account information from this client.

Sets account information from a raw Cookie header string.

Source

pub fn has_login_cookies(&self) -> bool

Checks whether this client has login cookies.

Source

pub fn get_account(&self) -> Option<Account>

Returns the current account information.

Source

pub fn csrf(&self) -> Result<String, BpiError>

Gets the current CSRF token from account information.

Source

pub fn get(&self, url: &str) -> RequestBuilder

Creates a GET request with this client’s default Bilibili headers.

Source

pub fn post(&self, url: &str) -> RequestBuilder

Creates a POST request with this client’s default Bilibili headers.

Source§

impl BpiClient

Source

pub fn activity(&self) -> ActivityClient<'_>

Creates an activity domain client.

Source

pub fn article(&self) -> ArticleClient<'_>

Creates an article domain client.

Source

pub fn audio(&self) -> AudioClient<'_>

Creates an audio domain client.

Source

pub fn bangumi(&self) -> BangumiClient<'_>

Creates a bangumi domain client.

Examples found in repository?
examples/module_clients.rs (line 22)
9async fn main() -> BpiResult<()> {
10    let client = client_from_env()?;
11    let video_params = VideoViewParams::from_bvid("BV1xx411c7mD".parse::<Bvid>()?);
12    let bangumi_params = BangumiInfoParams::new(MediaId::new(28_220_978)?);
13
14    if !run_live_example() {
15        println!("module-client quickstart compiled; set BPI_RUN_EXAMPLE=1 to call live APIs");
16        return Ok(());
17    }
18
19    let video = client.video().view(video_params).await?;
20    println!("video: {}", video.title);
21
22    let bangumi = client.bangumi().info(bangumi_params).await?;
23    println!("bangumi: {}", bangumi.media.title);
24
25    if env::var_os("BPI_COOKIE").is_some() {
26        let nav = client.login().nav().await?;
27        println!("logged in: {}", nav.is_login);
28    }
29
30    Ok(())
31}
Source

pub fn cheese(&self) -> CheeseClient<'_>

Creates a cheese course domain client.

Source

pub fn clientinfo(&self) -> ClientInfoClient<'_>

Creates a client info domain client.

Source

pub fn comment(&self) -> CommentClient<'_>

Creates a comment domain client.

Source

pub fn creativecenter(&self) -> CreativeCenterClient<'_>

Creates a creative center domain client.

Source

pub fn danmaku(&self) -> DanmakuClient<'_>

Creates a danmaku domain client.

Source

pub fn dynamic(&self) -> DynamicClient<'_>

Creates a dynamic domain client.

Source

pub fn electric(&self) -> ElectricClient<'_>

Creates an electric charging domain client.

Source

pub fn fav(&self) -> FavClient<'_>

Creates a favorite domain client.

Source

pub fn historytoview(&self) -> HistoryToViewClient<'_>

Creates a history and to-view domain client.

Source

pub fn login(&self) -> LoginClient<'_>

Creates a login domain client.

Examples found in repository?
examples/module_clients.rs (line 26)
9async fn main() -> BpiResult<()> {
10    let client = client_from_env()?;
11    let video_params = VideoViewParams::from_bvid("BV1xx411c7mD".parse::<Bvid>()?);
12    let bangumi_params = BangumiInfoParams::new(MediaId::new(28_220_978)?);
13
14    if !run_live_example() {
15        println!("module-client quickstart compiled; set BPI_RUN_EXAMPLE=1 to call live APIs");
16        return Ok(());
17    }
18
19    let video = client.video().view(video_params).await?;
20    println!("video: {}", video.title);
21
22    let bangumi = client.bangumi().info(bangumi_params).await?;
23    println!("bangumi: {}", bangumi.media.title);
24
25    if env::var_os("BPI_COOKIE").is_some() {
26        let nav = client.login().nav().await?;
27        println!("logged in: {}", nav.is_login);
28    }
29
30    Ok(())
31}
Source

pub fn live(&self) -> LiveClient<'_>

Creates a live domain client.

Source

pub fn manga(&self) -> MangaClient<'_>

Creates a manga domain client.

Source

pub fn misc(&self) -> MiscClient<'_>

Creates a misc domain client.

Source

pub fn message(&self) -> MessageClient<'_>

Creates a message domain client.

Source

pub fn note(&self) -> NoteClient<'_>

Creates a note domain client.

Source

pub fn opus(&self) -> OpusClient<'_>

Creates an opus domain client.

Source

pub fn search(&self) -> SearchClient<'_>

Creates a search domain client.

Source

pub fn video(&self) -> VideoClient<'_>

Creates a video domain client.

Examples found in repository?
examples/module_clients.rs (line 19)
9async fn main() -> BpiResult<()> {
10    let client = client_from_env()?;
11    let video_params = VideoViewParams::from_bvid("BV1xx411c7mD".parse::<Bvid>()?);
12    let bangumi_params = BangumiInfoParams::new(MediaId::new(28_220_978)?);
13
14    if !run_live_example() {
15        println!("module-client quickstart compiled; set BPI_RUN_EXAMPLE=1 to call live APIs");
16        return Ok(());
17    }
18
19    let video = client.video().view(video_params).await?;
20    println!("video: {}", video.title);
21
22    let bangumi = client.bangumi().info(bangumi_params).await?;
23    println!("bangumi: {}", bangumi.media.title);
24
25    if env::var_os("BPI_COOKIE").is_some() {
26        let nav = client.login().nav().await?;
27        println!("logged in: {}", nav.is_login);
28    }
29
30    Ok(())
31}
Source

pub fn video_ranking(&self) -> VideoRankingClient<'_>

Creates a video ranking domain client.

Source

pub fn vip(&self) -> VipClient<'_>

Creates a VIP domain client.

Source

pub fn wallet(&self) -> WalletClient<'_>

Creates a wallet domain client.

Source

pub fn user(&self) -> UserClient<'_>

Creates a user domain client.

Source

pub fn web_widget(&self) -> WebWidgetClient<'_>

Creates a web widget domain client.

Source

pub fn from_config(config: &Account) -> Result<Self, BpiError>

Creates a client from structured account configuration.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more