audiot_core 0.2.0

Library that helps build the search database through the CLI, and eventually can be used to read data from that same database.
Documentation
use serde::{Deserialize, Serialize};

use crate::brainz::{Relation, ReleaseGroupReference, Url};

#[derive(Debug, Deserialize, Serialize)]
pub struct Release {
    pub id: String,
    #[serde(alias = "release-group")]
    pub release_group: ReleaseGroupReference,
    #[serde(default)]
    pub relations: Vec<Relation>,
}

pub struct UrlRelation {
    pub url: Url,
    pub relation_type: String,
}

impl Release {
    pub fn streaming_urls(&self) -> Vec<UrlRelation> {
        self.relations
            .iter()
            .filter_map(|relation| {
                let ended = relation.ended.unwrap_or(false);
                if relation.relation_type.contains("stream") && !ended {
                    relation.url.clone().map(|url| UrlRelation {
                        url,
                        relation_type: relation.relation_type.clone(),
                    })
                } else {
                    None
                }
            })
            .collect()
    }

    pub fn release_group_id(&self) -> String {
        self.release_group.id.clone()
    }
}