🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
// Code generated by ndpgen. DO NOT EDIT.
//
// This file contains client wrappers for the ScrobbleRetriever host service.
// It is intended for use in Navidrome plugins built with extism-pdk.
use extism_pdk::*;
use serde::{Deserialize, Serialize};
/// ScrobbleCountOptions carries optional parameters for counting user scrobbles
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ScrobbleCountOptions {
#[serde(default)]
pub from_timestamp: Option<i64>,
#[serde(default)]
pub to_timestamp: Option<i64>,
}
/// ScrobbleOptions carries optional parameters for retrieving user scrobbles
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ScrobbleOptions {
#[serde(default)]
pub from_timestamp: Option<i64>,
#[serde(default)]
pub to_timestamp: Option<i64>,
pub descending: bool,
pub max_items: i32,
#[serde(default)]
pub offset: i32,
}
/// ScrobbleRef represents one instance of a scrobble (instance id, file id, submission time)
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ScrobbleRef {
pub id: i64,
pub media_file_id: String,
pub submission_time: i64,
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
struct ScrobbleRetrieverGetFirstTimestampRequest {
username: String,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
struct ScrobbleRetrieverGetFirstTimestampResponse {
#[serde(default)]
result: Option<i64>,
#[serde(default)]
error: Option<String>,
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
struct ScrobbleRetrieverGetLastTimestampRequest {
username: String,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
struct ScrobbleRetrieverGetLastTimestampResponse {
#[serde(default)]
result: Option<i64>,
#[serde(default)]
error: Option<String>,
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
struct ScrobbleRetrieverGetScrobblesRequest {
username: String,
options: ScrobbleOptions,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
struct ScrobbleRetrieverGetScrobblesResponse {
#[serde(default)]
scrobbles: Vec<ScrobbleRef>,
#[serde(default)]
next: Option<ScrobbleOptions>,
#[serde(default)]
error: Option<String>,
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
struct ScrobbleRetrieverGetScrobbleCountRequest {
username: String,
options: ScrobbleCountOptions,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
struct ScrobbleRetrieverGetScrobbleCountResponse {
#[serde(default)]
result: i64,
#[serde(default)]
error: Option<String>,
}
#[host_fn]
extern "ExtismHost" {
fn scrobbleretriever_getfirsttimestamp(input: Json<ScrobbleRetrieverGetFirstTimestampRequest>) -> Json<ScrobbleRetrieverGetFirstTimestampResponse>;
fn scrobbleretriever_getlasttimestamp(input: Json<ScrobbleRetrieverGetLastTimestampRequest>) -> Json<ScrobbleRetrieverGetLastTimestampResponse>;
fn scrobbleretriever_getscrobbles(input: Json<ScrobbleRetrieverGetScrobblesRequest>) -> Json<ScrobbleRetrieverGetScrobblesResponse>;
fn scrobbleretriever_getscrobblecount(input: Json<ScrobbleRetrieverGetScrobbleCountRequest>) -> Json<ScrobbleRetrieverGetScrobbleCountResponse>;
}
/// GetFirstTimestamp returns the unix timestamp of the oldest scrobble for the user.
/// If the user has no scrobbles, returns nil
///
/// # Arguments
/// * `username` - String parameter.
///
/// # Returns
/// The result value.
///
/// # Errors
/// Returns an error if the host function call fails.
pub fn get_first_timestamp(username: &str) -> Result<Option<i64>, Error> {
let response = unsafe {
scrobbleretriever_getfirsttimestamp(Json(ScrobbleRetrieverGetFirstTimestampRequest {
username: username.to_owned(),
}))?
};
if let Some(err) = response.0.error {
return Err(Error::msg(err));
}
Ok(response.0.result)
}
/// GetLastTimestamp returns the unix timestamp of the most recent scrobble for the user
/// If the user has no scrobbles, return nil
///
/// # Arguments
/// * `username` - String parameter.
///
/// # Returns
/// The result value.
///
/// # Errors
/// Returns an error if the host function call fails.
pub fn get_last_timestamp(username: &str) -> Result<Option<i64>, Error> {
let response = unsafe {
scrobbleretriever_getlasttimestamp(Json(ScrobbleRetrieverGetLastTimestampRequest {
username: username.to_owned(),
}))?
};
if let Some(err) = response.0.error {
return Err(Error::msg(err));
}
Ok(response.0.result)
}
/// GetScrobbles returns one page of scrobbles for a user.
///
/// Parameters:
/// - username: the user to query for scrobbles
/// - options.FromTimestamp: If specified, the first UNIX timestamp to start fetching scrobbles (inclusive). Otherwise, start from the first scrobble
/// - options.ToTimestamp: If specified, the last UNIX timestamp to fetch (inclusive). Otherwise, end at the last scrobble
/// - options.Descending: If true, order from newest to oldest. Otherwise, oldest to newest
/// - options.MaxItems: The maximum number of items to retrieve. The maximum value (and default) if not specified is 5000
/// - options.Offset: Pagination state; only valid as received on the options returned by a previous call. Never set it manually
///
/// Returns:
/// - scrobbles: The scrobbles in the requested range, ordered by submission time
/// (ties broken by scrobble ID) in the direction given by options.Descending
/// - next: The options for the following page, or nil once no scrobbles remain.
/// Pass it back to GetScrobbles unchanged and repeat until it is nil. It carries an
/// adjusted FromTimestamp/ToTimestamp, so keep a copy if you still need the original range
///
/// # Arguments
/// * `username` - String parameter.
/// * `options` - ScrobbleOptions parameter.
///
/// # Returns
/// A tuple of (scrobbles, next).
///
/// # Errors
/// Returns an error if the host function call fails.
pub fn get_scrobbles(username: &str, options: ScrobbleOptions) -> Result<(Vec<ScrobbleRef>, Option<ScrobbleOptions>), Error> {
let response = unsafe {
scrobbleretriever_getscrobbles(Json(ScrobbleRetrieverGetScrobblesRequest {
username: username.to_owned(),
options: options,
}))?
};
if let Some(err) = response.0.error {
return Err(Error::msg(err));
}
Ok((response.0.scrobbles, response.0.next))
}
/// GetScrobbleCount returns the number of scrobbles for a user in a given range
///
/// Parameters:
/// - username: the user to query for scrobbles
/// - options.FromTimestamp: If specified, the first UNIX timestamp to start fetching scrobbles (inclusive). Otherwise, start from the first scrobble
/// - options.ToTimestamp: If specified, the last UNIX timestamp to fetch (inclusive). Otherwise, end at the last scrobble
///
/// Returns:
/// - the number of scrobbles in the given range, or 0
///
/// # Arguments
/// * `username` - String parameter.
/// * `options` - ScrobbleCountOptions parameter.
///
/// # Returns
/// The result value.
///
/// # Errors
/// Returns an error if the host function call fails.
pub fn get_scrobble_count(username: &str, options: ScrobbleCountOptions) -> Result<i64, Error> {
let response = unsafe {
scrobbleretriever_getscrobblecount(Json(ScrobbleRetrieverGetScrobbleCountRequest {
username: username.to_owned(),
options: options,
}))?
};
if let Some(err) = response.0.error {
return Err(Error::msg(err));
}
Ok(response.0.result)
}