audd 1.5.2

Official Rust SDK for the AudD music recognition API
Documentation
//! Tokenless longpoll consumer — for browser widgets, Twitch extensions, mobile apps.
//!
//! Run: `cargo run --example tokenless_longpoll -- <category>`

#![allow(clippy::result_large_err)] // matches lib.rs — `AudDError` is intentionally rich

use audd::longpoll::LongpollIterateOptions;
use audd::{AudDError, LongpollConsumer};
use futures_util::StreamExt;

#[tokio::main]
async fn main() -> Result<(), AudDError> {
    let category = std::env::args()
        .nth(1)
        .ok_or_else(|| AudDError::Source("usage: tokenless_longpoll <category>".into()))?;

    let consumer = LongpollConsumer::new(category);
    let mut poll = consumer.iterate(LongpollIterateOptions {
        timeout: 30,
        ..Default::default()
    });

    loop {
        tokio::select! {
            biased;
            Some(err) = poll.errors.next() => {
                eprintln!("longpoll error: {err}");
                break;
            }
            Some(notif) = poll.notifications.next() => {
                eprintln!(
                    "[notification] radio_id={} code={} {}",
                    notif.radio_id, notif.notification_code, notif.notification_message,
                );
            }
            Some(m) = poll.matches.next() => {
                println!(
                    "[match] radio_id={} {}{}",
                    m.radio_id, m.song.artist, m.song.title,
                );
            }
            else => break,
        }
    }
    poll.close().await;
    Ok(())
}