pub struct AudD { /* private fields */ }Expand description
Async client for the AudD music recognition API.
Construct with AudD::new for the common case, or AudD::builder to
override retries, timeouts, base URLs, or supply a configured
reqwest::Client.
AudD holds an internal connection pool. Drop it (or call
AudD::close) once you’re done. Cloning AudD is cheap.
Implementations§
Source§impl AudD
impl AudD
Sourcepub fn new(api_token: impl Into<String>) -> Self
pub fn new(api_token: impl Into<String>) -> Self
Build a client with the standard defaults. Pass "" to fall back on the
AUDD_API_TOKEN environment variable.
§Panics
Panics if no token is resolvable (use Self::try_new /
Self::from_env for a Result-returning sibling) or if
reqwest::Client::build() fails — exceedingly rare on a system with a
working TLS stack.
Sourcepub fn try_new(api_token: impl Into<String>) -> Result<Self, AudDError>
pub fn try_new(api_token: impl Into<String>) -> Result<Self, AudDError>
Result-returning sibling of Self::new: build a client with defaults,
falling back to AUDD_API_TOKEN when api_token is empty.
§Errors
AudDError::Configurationwhen no token can be resolved.AudDError::Connectionifreqwest::Client::build()fails.
Sourcepub fn from_env() -> Result<Self, AudDError>
pub fn from_env() -> Result<Self, AudDError>
Build a client whose token comes from the AUDD_API_TOKEN environment
variable. Equivalent to Self::try_new with an empty argument.
§Errors
AudDError::ConfigurationifAUDD_API_TOKENis unset or empty.AudDError::Connectionifreqwest::Client::build()fails.
Sourcepub fn custom_catalog(&self) -> CustomCatalog<'_>
pub fn custom_catalog(&self) -> CustomCatalog<'_>
custom_catalog.* namespace. Read the warning on
CustomCatalog::add before using.
Sourcepub fn advanced(&self) -> Advanced<'_>
pub fn advanced(&self) -> Advanced<'_>
advanced.* namespace — lyrics search and a generic raw-request escape
hatch.
Sourcepub async fn recognize(
&self,
source: impl Into<Source>,
) -> Result<Option<RecognitionResult>, AudDError>
pub async fn recognize( &self, source: impl Into<Source>, ) -> Result<Option<RecognitionResult>, AudDError>
Recognize a song from a URL, file path, raw bytes, or async reader.
Returns Ok(None) when the server returns status=success with
result=null — i.e. no match was found.
return_ accepts a slice of metadata service names (e.g.
&["apple_music".into(), "spotify".into()]).
§Errors
Returns AudDError for transport, server, or parse failures.
Sourcepub async fn recognize_with(
&self,
source: impl Into<Source>,
opts: RecognizeOptions<'_>,
) -> Result<Option<RecognitionResult>, AudDError>
pub async fn recognize_with( &self, source: impl Into<Source>, opts: RecognizeOptions<'_>, ) -> Result<Option<RecognitionResult>, AudDError>
Sourcepub async fn recognize_enterprise(
&self,
source: impl Into<Source>,
opts: EnterpriseOptions<'_>,
) -> Result<Vec<EnterpriseMatch>, AudDError>
pub async fn recognize_enterprise( &self, source: impl Into<Source>, opts: EnterpriseOptions<'_>, ) -> Result<Vec<EnterpriseMatch>, AudDError>
Sourcepub async fn close(self)
pub async fn close(self)
Drop the underlying HTTP transport explicitly. Equivalent to dropping
the AudD value (provided here for parity with the sibling SDKs’
context-manager protocol).
Sourcepub fn api_token(&self) -> String
pub fn api_token(&self) -> String
Snapshot the in-effect api_token (after any rotations).
Returns an owned String because the token sits behind an
Arc<RwLock> to support Self::set_api_token.
Sourcepub fn set_api_token(
&self,
new_token: impl Into<String>,
) -> Result<(), AudDError>
pub fn set_api_token( &self, new_token: impl Into<String>, ) -> Result<(), AudDError>
Atomically rotate the api_token used for subsequent requests.
In-flight requests continue with the previous snapshot — there’s no
abort. Thread-safe across concurrent recognize, streams.*, etc.
calls; backed by a shared Arc<RwLock<String>> so the standard and
enterprise transports both pick up the new token immediately.
§Errors
Returns AudDError::Configuration when new_token is empty.