Commit 6bc939a9 authored by Leonardo Schwarz's avatar Leonardo Schwarz

WIP on search for Release

parent 4948e315
//! The fields that can be used in queries.
//!
//! Some field types can be used for multiple entities, to make it more user friendly the types are
//! reexported to the submodules corresponding to the names of the entities which they can be used
//! to query.
//! Some field types can be used for multiple entities, to make it more user
//! friendly the types are reexported to the submodules corresponding to the
//! names of the entities which they can be used to query.
//!
//! Link to [MusicBrainz
//! documentation](https://musicbrainz.org/doc/Indexed_Search_Syntax).
// TODO: To verify we actually implemented all fields it might make more sense to swap our type
// and the string value in the following declarations and then sort the entries alphabetically
// again.
use super::{Mbid, full_entities};
// use super::query::QueryExpression;
......@@ -31,6 +38,10 @@ macro_rules! define_fields {
}
}
// TODO consider whether we should rename `Comment` to `Disambiguation` or something like that to
// be more consistent with the rest of the crate.
//
// TODO: enums for quality, lang, script, etc
define_fields!(
Alias, String;
AreaId, Mbid;
......@@ -45,24 +56,39 @@ define_fields!(
ArtistName, String;
ArtistNameAccent, String;
ArtistType, full_entities::ArtistType;
Asin, String;
Barcode, String;
BeginArea, String;
BeginDate, PartialDate;
CatalogNumber, String;
Comment, String;
Country, String;
CreditName, String;
DataQuality, String;
EndArea, String;
EndDate, PartialDate;
Ended, bool;
Gender, String;
IpiCode, String;
LabelId, String;
Language, String;
MediumCount, u32;
MediumFormat, String;
NumDiscIds, u32;
NumDiscIdsMedium, u32;
NumTracks, u32;
NumTracksMedium, u32;
PrimaryType, full_entities::ReleaseGroupPrimaryType;
ReleaseDate, full_entities::PartialDate;
ReleaseGroupId, Mbid;
ReleaseGroupName, String;
ReleaseGroupNameAccent, String;
ReleaseId, Mbid;
ReleaseName, String;
ReleaseNameAccent, String;
ReleaseNumber, u16;
ReleaseStatus, full_entities::ReleaseStatus;
Script, String;
SecondaryType, String;
SortName, String;
Tag, String
......@@ -82,18 +108,6 @@ macro_rules! define_entity_fields {
fn name() -> &'static str;
}
/*
TODO: Implement something like this. However we will have to make sure we are escaping every value exactly one time.
impl QueryExpression for $field_trait {
type Entity = $search_entity;
fn build_query(&self) -> String {
use super::query::escape_full;
format!("{}:{}", escape_full(Self::name()), escape_full(self.to_string().as_ref()))
}
}
*/
pub mod $modname {
pub use super::$field_trait;
......@@ -149,6 +163,39 @@ define_entity_fields!(
Tag, "tag"
);
// TODO what are puids?
define_entity_fields!(
ReleaseSearchField, release;
ArtistId, "arid";
ArtistName, "artist";
Asin, "asin";
Barcode, "barcode";
CatalogNumber, "catno";
Comment, "comment";
Country, "country";
CreditName, "creditname";
ReleaseDate, "date";
NumDiscIds, "discids";
NumDiscIdsMedium, "discidsmedium";
MediumFormat, "format";
LabelId, "laid";
Language, "lang";
MediumCount, "mediums";
PrimaryType, "primarytype";
DataQuality, "quality";
ReleaseId, "reid";
ReleaseName, "release";
ReleaseNameAccent, "releaseaccent";
ReleaseGroupId, "rgid";
Script, "script";
SecondaryType, "secondarytype";
ReleaseStatus, "status";
Tag, "tag";
NumTracks, "tracks";
NumTracksMedium, "tracksmedium"
);
define_entity_fields!(
ReleaseGroupSearchField, release_group;
......
......@@ -6,7 +6,7 @@ use url::percent_encoding::{DEFAULT_ENCODE_SET, utf8_percent_encode};
use xpath_reader::{FromXml, FromXmlError, XpathReader};
pub mod fields;
use self::fields::{AreaSearchField, ArtistSearchField, ReleaseGroupSearchField};
use self::fields::{AreaSearchField, ArtistSearchField, ReleaseSearchField, ReleaseGroupSearchField};
pub mod search_entities;
use self::search_entities::SearchEntity;
......@@ -138,6 +138,16 @@ define_search_builder!(
"artist-list"
);
/* TODO
define_search_builder!(
ReleaseSearchBuilder,
ReleaseSearchField,
search_entities::Release,
full_entities::Release,
"release-list"
);
*/
define_search_builder!(
ReleaseGroupSearchBuilder,
ReleaseGroupSearchField,
......
......@@ -41,6 +41,25 @@ impl SearchEntity for Artist {
}
}
pub struct Release {
pub mbid: Mbid,
pub title: String,
pub status: full_entities::ReleaseStatus,
pub language: Option<String>,
pub script: Option<String>,
pub artists: Vec<ArtistRef>,
// release group refs (TODO)
}
impl SearchEntity for Release {
type FullEntity = full_entities::Release;
fn fetch_full(&self, client: &mut Client) -> Result<Self::FullEntity, ClientError>
{
client.get_by_mbid(&self.mbid)
}
}
pub struct ReleaseGroup {
pub mbid: Mbid,
pub title: String,
......
......@@ -51,17 +51,32 @@ impl FromXml for ReleaseTrack {
}
}
/// A medium is a collection of multiple `ReleaseTrack`. For physical releases
/// one medium might
/// equal one CD, so an album released as a release with two CDs would have two
/// associated
/// `ReleaseMedium` instances.
/*
TODO: Parse the format. We have to yet consider if everything should get its own variant or only the larger classes of mediums should get one and subclasses would be specified as string variants.
enum_mb_xml! {
/// Specifies the format of a `ReleaseMedium`.
pub enum ReleaseMediumFormat {
var DigitalMedia = "Digital Media",
}
}
*/
/// A medium is a collection of multiple `ReleaseTrack`.
///
/// For physical releases one medium might equal one CD, so an album released
/// as a release with two CDs would have two associated `ReleaseMedium`
/// instances.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ReleaseMedium {
/// The medium's position number providing a total order between all
/// mediums of one `Release`.
position: u16,
/// The format of this `ReleaseMedium`.
///
/// TODO: Parse into `ReleaseMediumFormat` enum.
format: Option<String>,
/// The tracks stored on this medium.
tracks: Vec<ReleaseTrack>,
}
......@@ -74,6 +89,7 @@ impl FromXml for ReleaseMedium {
{
Ok(ReleaseMedium {
position: reader.read(".//mb:position/text()")?,
format: reader.read_option(".//mb:format/text()")?,
tracks: reader.read_vec(".//mb:track-list/mb:track")?,
})
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment