diff --git a/codegen/Cargo.toml b/codegen/Cargo.toml index 6f48494..e3bfff8 100644 --- a/codegen/Cargo.toml +++ b/codegen/Cargo.toml @@ -11,7 +11,9 @@ tokio = { version = "1.20.0", features = ["macros", "rt-multi-thread"] } futures = "0.3.21" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0.82" -serde_with = { version = "3.0.0", default-features = false, features = ["macros"] } +serde_with = { version = "3.0.0", default-features = false, features = [ + "macros", +] } anyhow = "1.0" log = "0.4.17" env_logger = "0.10.0" @@ -24,3 +26,4 @@ num_enum = "0.6.1" path_macro = "1.0.0" intl_pluralrules = "7.0.2" unic-langid = "0.9.1" +ordered_hash_map = { version = "0.2.0", features = ["serde"] } diff --git a/codegen/src/collect_playlist_dates.rs b/codegen/src/collect_playlist_dates.rs index 4a87d36..21cce76 100644 --- a/codegen/src/collect_playlist_dates.rs +++ b/codegen/src/collect_playlist_dates.rs @@ -6,6 +6,7 @@ use std::{ }; use futures::{stream, StreamExt}; +use ordered_hash_map::OrderedHashMap; use path_macro::path; use rustypipe::{ client::RustyPipe, @@ -170,7 +171,7 @@ pub fn write_samples_to_dict() { dict_entry.months = BTreeMap::new(); if collect_nd_tokens { - dict_entry.timeago_nd_tokens = BTreeMap::new(); + dict_entry.timeago_nd_tokens = OrderedHashMap::new(); } for datestr_table in &datestr_tables { diff --git a/codegen/src/model.rs b/codegen/src/model.rs index a5f9e11..f7599cf 100644 --- a/codegen/src/model.rs +++ b/codegen/src/model.rs @@ -1,5 +1,6 @@ use std::collections::BTreeMap; +use ordered_hash_map::OrderedHashMap; use rustypipe::{client::YTContext, model::AlbumType, param::Language}; use serde::{Deserialize, Serialize}; use serde_with::{serde_as, DefaultOnError, VecSkipError}; @@ -18,7 +19,7 @@ pub struct DictEntry { /// /// Identifiers: `Y`(ear), `M`(month), `W`(eek), `D`(ay), /// `h`(our), `m`(inute), `s`(econd) - pub timeago_tokens: BTreeMap, + pub timeago_tokens: OrderedHashMap, /// Order in which to parse numeric date components. Formatted as /// a string of date identifiers (Y, M, D). /// @@ -34,7 +35,7 @@ pub struct DictEntry { /// Tokens for parsing date strings with no digits (e.g. Today, Tomorrow) /// /// Format: Parsed token -> \[Quantity\] Identifier - pub timeago_nd_tokens: BTreeMap, + pub timeago_nd_tokens: OrderedHashMap, /// Are commas (instead of points) used as decimal separators? pub comma_decimal: bool, /// Tokens for parsing decimal prefixes (K, M, B, ...) @@ -49,6 +50,10 @@ pub struct DictEntry { /// /// Format: Parsed text -> Album type pub album_types: BTreeMap, + /// Names of item types (Song, Video, Artist, Playlist) + /// + /// Format: Parsed text -> Item type + pub item_types: BTreeMap, } /// Parsed TimeAgo string, contains amount and time unit. @@ -99,6 +104,15 @@ impl TimeUnit { } } +#[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub enum ExtItemType { + Track, + Video, + Episode, + Playlist, + Artist, +} + #[derive(Debug, Serialize)] #[serde(rename_all = "camelCase")] pub struct QBrowse<'a> {