Skip to content

Commit

Permalink
feat(xml): Parse ratings
Browse files Browse the repository at this point in the history
  • Loading branch information
Holzhaus committed Feb 2, 2025
1 parent 53d1683 commit 2191d5c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ parse-display = "0.10"
thiserror = "2.0"
quick-xml = { version = "0.37.2", features = ["serialize", "serde-types"], optional = true }
serde = { version = "1.0", features = ["derive"], optional = true }
serde_repr = { version = "0.1.19", optional = true }
chrono = { version = "0.4", features = ["serde"], optional = true }

[build-dependencies]
Expand All @@ -32,7 +33,7 @@ pretty_assertions = "1"
[features]
default = ["cli", "xml"]
cli = ["dep:clap"]
xml = ["dep:serde", "dep:quick-xml", "dep:chrono"]
xml = ["dep:serde", "dep:serde_repr", "dep:quick-xml", "dep:chrono"]

[[bin]]
name = "rekordcrate"
Expand Down
22 changes: 11 additions & 11 deletions src/xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

use chrono::naive::NaiveDate;
use serde::{de::Error, ser::Serializer, Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};
use std::borrow::Cow;

/// The XML root element of a rekordbox XML file.
Expand Down Expand Up @@ -172,7 +173,7 @@ pub struct Track {
/// Rating of the track
/// 0 star = "@0", 1 star = "51", 2 stars = "102", 3 stars = "153", 4 stars = "204", 5 stars = "255"
#[serde(rename = "@Rating")]
pub rating: Option<i32>,
pub rating: Option<StarRating>,
/// Location of the file
/// includes the file name (URI formatted)
#[serde(rename = "@Location")]
Expand Down Expand Up @@ -209,22 +210,21 @@ pub struct Track {
/// Star Rating
///
/// 0 star = "@0", 1 star = "51", 2 stars = "102", 3 stars = "153", 4 stars = "204", 5 stars = "255"
#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize)]
#[derive(Debug, PartialEq, Clone, Copy, Serialize_repr, Deserialize_repr)]
#[repr(u8)]
pub enum StarRating {
/// Zero Stars
Zero,
/// One Start
One,
Zero = 0x00,
/// One Star
One = 0x33,
/// Two Stars
Two,
Two = 0x66,
/// Three Stars
Three,
Three = 0x99,
/// Four Stars
Four,
Four = 0xCC,
/// Five Stars
Five,
/// Unknown Value
Unknown(i32),
Five = 0xFF,
}

/// For BeatGrid; More than two "TEMPO" can exist for each track
Expand Down

0 comments on commit 2191d5c

Please sign in to comment.