osu_file_parser/osu_file/metadata/
mod.rs

1pub mod error;
2
3use nom::{
4    bytes::complete::{tag, take_till},
5    multi::separated_list0,
6    Parser,
7};
8
9use super::Integer;
10use crate::helper::macros::*;
11
12pub use error::*;
13
14versioned_field!(Title, String, no_versions, |s| { Ok(s.to_string()) } -> (),,);
15versioned_field!(TitleUnicode, String, no_versions, |s| { Ok(s.to_string()) } -> (),,);
16versioned_field!(Artist, String, no_versions, |s| { Ok(s.to_string()) } -> (),,);
17versioned_field!(ArtistUnicode, String, no_versions, |s| { Ok(s.to_string()) } -> (),,);
18versioned_field!(Creator, String, no_versions, |s| { Ok(s.to_string()) } -> (),,);
19versioned_field!(Version, String, no_versions, |s| { Ok(s.to_string()) } -> (),,);
20versioned_field!(Source, String, no_versions, |s| { Ok(s.to_string()) } -> (),,);
21versioned_field!(Tags, Vec<String>, no_versions,
22    |s| {
23        let mut space_separated_list = separated_list0(
24            tag::<_, _, nom::error::Error<_>>(" "),
25            take_till(|c| c == ' '),
26        )
27        .map(|tags: Vec<&str>| tags.iter().map(|tag| tag.to_string()).collect());
28
29        Ok(space_separated_list.parse(s).unwrap().1)
30    } -> (),
31    |v| { v.join(" ") }, Vec::new()
32);
33versioned_field!(BeatmapID, Integer, no_versions, |s| { Ok(s.parse::<Integer>().unwrap()) } -> (),,);
34versioned_field!(BeatmapSetID, Integer, no_versions, |s| { Ok(s.parse::<Integer>().unwrap()) } -> (),,);
35
36general_section!(
37    /// A struct representing the metadata section of an osu file.
38    pub struct Metadata {
39        /// Romanised song title.
40        pub title: Title,
41        /// Song title.
42        pub title_unicode: TitleUnicode,
43        /// ROmanised song artist.
44        pub artist: Artist,
45        /// Song artist.
46        pub artist_unicode: ArtistUnicode,
47        /// Beatmap creator.
48        pub creator: Creator,
49        /// Difficulty name.
50        pub version: Version,
51        /// Original media the song was produced for.
52        pub source: Source,
53        /// Search terms.
54        pub tags: Tags,
55        /// Difficulty ID.
56        pub beatmap_id: BeatmapID,
57        /// Beatmap ID.
58        pub beatmap_set_id: BeatmapSetID,
59    },
60    ParseError,
61    "",
62);