Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

Commit

Permalink
feat: apple music special handling (#41)
Browse files Browse the repository at this point in the history
Co-authored-by: Paul Makles <paulmakles@gmail.com>
  • Loading branch information
infi and insertish authored Sep 5, 2024
1 parent aaf9085 commit 2675699
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/structs/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ impl Metadata {
static ref RE_SPOTIFY: Regex = Regex::new("^(?:https?://)?open.spotify.com/(track|user|artist|album|playlist)/([A-z0-9]+)").unwrap();
static ref RE_SOUNDCLOUD: Regex = Regex::new("^(?:https?://)?soundcloud.com/([a-zA-Z0-9-]+)/([A-z0-9-]+)").unwrap();
static ref RE_BANDCAMP: Regex = Regex::new("^(?:https?://)?(?:[A-z0-9_-]+).bandcamp.com/(track|album)/([A-z0-9_-]+)").unwrap();
static ref RE_APPLE_MUSIC: Regex = Regex::new("^(?:https?://)?music\\.apple\\.com/(?:[a-z]{2}/)?album/(?:[a-zA-Z0-9-]+)/(\\d+)(?:\\?i=(\\d+))?").unwrap();

static ref RE_STREAMABLE: Regex = Regex::new("^(?:https?://)?(?:www\\.)?streamable\\.com/([\\w\\d-]+)").unwrap();

Expand Down Expand Up @@ -287,6 +288,11 @@ impl Metadata {
}
} else if RE_GIF.is_match(&self.original_url) {
return Ok(Special::GIF);
} else if let Some(captures) = RE_APPLE_MUSIC.captures_iter(&self.original_url).next() {
return Ok(Special::AppleMusic {
album_id: captures[1].to_string(),
track_id: captures.get(2).map(|m| m.as_str().to_string()),
});
}

Ok(Special::None)
Expand All @@ -300,6 +306,7 @@ impl Metadata {
Special::Lightspeed { .. } => self.colour = Some("#7445D9".to_string()),
Special::Spotify { .. } => self.colour = Some("#1ABC9C".to_string()),
Special::Soundcloud { .. } => self.colour = Some("#FF7F50".to_string()),
Special::AppleMusic { .. } => self.colour = Some("#FA233B".to_string()),
_ => {}
}

Expand Down
6 changes: 6 additions & 0 deletions src/structs/special.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ pub enum Special {
content_type: BandcampType,
id: String,
},
AppleMusic {
album_id: String,

#[serde(skip_serializing_if = "Option::is_none")]
track_id: Option<String>,
},
Streamable {
id: String,
},
Expand Down

0 comments on commit 2675699

Please sign in to comment.