Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

Commit

Permalink
add more struct
Browse files Browse the repository at this point in the history
  • Loading branch information
liulifox233 committed Dec 7, 2024
1 parent 2eb2b8e commit c538834
Show file tree
Hide file tree
Showing 15 changed files with 551 additions and 53 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ramdl"
version = "1.0.2"
version = "1.0.3"
edition = "2021"
license = "GPL-3.0-or-later"
description = "A Rust library for downloading Apple Music songs/music videos/posts"
Expand Down
141 changes: 141 additions & 0 deletions src/api/albums.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
use super::artwork::Artwork;
use super::editorial_notes::EditorialNotes;
use super::play_parameters::PlayParameters;

#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Albums {
/// The identifier for the album.
pub id: String,
/// This value is always albums.
#[serde(rename = "type")]
pub type_: String,
/// The relative location for the album resource.
pub href: String,
/// The attributes for the album.
pub attributes: Option<Attributes>,
/// The relationships for the album.
pub relationships: Option<Relationships>,
}

#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Attributes {
/// The name of the primary artist associated with the album.
pub artist_name: String,
/// The URL of the artist for this content.
pub artist_url: Option<String>,
/// The artwork for the album.
pub artwork: Artwork,
/// Indicates the specific audio variant for the album.
pub audio_variants: Option<Vec<String>>,
/// The Recording Industry Association of America (RIAA) rating of the content.
pub content_rating: Option<String>,
/// The copyright text.
pub copyright: Option<String>,
/// The notes about the album that appear in the iTunes Store.
pub editorial_notes: Option<EditorialNotes>,
/// The names of the genres associated with the album.
pub genre_names: Vec<String>,
/// Indicates whether the album is marked as a compilation.
pub is_compilation: bool,
/// Indicates whether the album is complete.
pub is_complete: bool,
/// Indicates whether the response delivered the album as an Apple Digital Master.
pub is_mastered_for_itunes: bool,
/// Indicates whether the album contains a single song.
pub is_single: bool,
/// The localized name of the album.
pub name: String,
/// Indicates that one or more tracks on the album are available to play with an Apple Music subscription.
pub play_params: Option<PlayParameters>,
/// The name of the record label for the album.
pub record_label: Option<String>,
/// The release date of the album, when known.
pub release_date: Option<String>,
/// The number of tracks for the album.
pub track_count: i32,
/// The Universal Product Code for the album.
pub upc: Option<String>,
/// The URL for sharing the album in Apple Music.
pub url: String,
}

#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Relationships {
// /// The artists associated with the album. By default, artists includes identifiers only.
// pub artists: Option<AlbumsArtistsRelationship>,
// /// The genres for the album. By default, genres not included.
// pub genres: Option<AlbumsGenresRelationship>,
// /// The songs and music videos on the album. By default, tracks includes objects.
// pub tracks: Option<AlbumsTracksRelationship>,
// /// The album in the user’s library for the catalog album, if any.
// pub library: Option<AlbumsLibraryRelationship>,
// /// The record labels for the album.
// pub record_labels: Option<AlbumsRecordLabelsRelationship>,
}

// #[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
// #[serde(rename_all = "camelCase")]
// pub struct AlbumsArtistsRelationship {
// /// The relative location to fetch the relationship directly.
// pub href: String,
// /// The relative location to request the next page of resources in the collection, if additional resources are available for fetching.
// pub next: Option<String>,
// /// The artists for the album.
// pub data: Vec<Artist>,
// }

// #[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
// #[serde(rename_all = "camelCase")]
// pub struct AlbumsGenresRelationship {
// /// The relative location to fetch the relationship directly.
// pub href: String,
// /// The relative location to request the next page of resources in the collection, if additional resources are available for fetching.
// pub next: Option<String>,
// /// The album’s associated genre.
// pub data: Vec<Genre>,
// }

// #[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
// #[serde(rename_all = "camelCase")]
// pub struct AlbumsTracksRelationship {
// /// The relative location to fetch the relationship directly.
// pub href: String,
// /// The relative location to request the next page of resources in the collection, if additional resources are available for fetching.
// pub next: Option<String>,
// /// The tracks for the album.
// pub data: Vec<TrackData>,
// }

// #[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
// #[serde(rename_all = "camelCase")]
// pub enum TrackData {
// #[serde(rename = "songs")]
// Songs(Songs),
// #[serde(rename = "music-videos")]
// MusicVideos(MusicVideos),
// }

// #[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
// #[serde(rename_all = "camelCase")]
// pub struct AlbumsLibraryRelationship {
// /// The relative location to fetch the relationship directly.
// pub href: String,
// /// The relative location to request the next page of resources in the collection, if additional resources are available for fetching.
// pub next: Option<String>,
// /// The library content this album is associated with if added to the user’s library.
// pub data: Vec<LibraryAlbums>,
// }

// #[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
// #[serde(rename_all = "camelCase")]
// pub struct AlbumsRecordLabelsRelationship {
// /// The relative location to fetch the relationship directly.
// pub href: String,
// /// The relative location to request the next page of resources in the collection, if additional resources are available for fetching.
// pub next: Option<String>,
// /// The album’s associated record label.
// pub data: Vec<RecordLabels>,
// }
1 change: 1 addition & 0 deletions src/api/artists.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

21 changes: 21 additions & 0 deletions src/api/artwork.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Artwork {
/// The average background color of the image.
pub bg_color: Option<String>,
/// The maximum height available for the image.
pub height: i32,
/// The maximum width available for the image.
pub width: i32,
/// The primary text color used if the background color gets displayed.
pub text_color1: String,
/// The secondary text color used if the background color gets displayed.
pub text_color2: String,
/// The tertiary text color used if the background color gets displayed.
pub text_color3: String,
/// The final post-tertiary text color used if the background color gets displayed.
pub text_color4: String,
/// The URL to request the image asset. {w}x{h}must precede image filename, as placeholders for the width and height values as described above. For example, {w}x{h}bb.jpeg).
pub url: String,
pub has_p3: Option<bool>,
}
11 changes: 11 additions & 0 deletions src/api/editorial_notes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
pub struct EditorialNotes {
/// Abbreviated notes shown inline or when the content appears alongside other content.
pub short: Option<String>,
/// Notes shown when the content is prominently displayed.
pub standard: Option<String>,
/// Name for the editorial notes.
pub name: Option<String>,
/// The tag line for the editorial notes.
pub tagline: Option<String>,
}
26 changes: 26 additions & 0 deletions src/api/genres.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Genre {
/// The identifier for the genre.
pub id: String,
/// This value must always be genres.
#[serde(rename = "type")]
pub type_field: String,
/// The relative location for the genre resource.
pub href: String,
/// The attributes for the genre.
pub attributes: Attributes,
}

#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Attributes {
/// The localized name of the genre.
pub name: String,
/// The identifier of the parent for the genre.
pub parent_id: Option<String>,
/// The localized name of the parent genre.
pub parent_name: Option<String>,
/// A localized string to use when displaying the genre in relation to charts.
pub chart_label: Option<String>,
}
99 changes: 99 additions & 0 deletions src/api/library_albums.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
use super::albums::Albums;
use super::artwork::Artwork;
use super::play_parameters::PlayParameters;
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct LibraryAlbums {
/// The identifier for the library album.
pub id: String,
/// This value is always library-albums.
#[serde(rename = "type")]
pub type_: String,
/// The relative location for the library album resource.
pub href: String,
/// The attributes for the library album.
pub attributes: Option<Attributes>,
/// The relationships for the library album.
pub relationships: Option<Relationships>,
}

#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Attributes {
/// The artist’s name.
pub artist_name: String,
/// The album artwork.
pub artwork: Artwork,
/// The Recording Industry Association of America (RIAA) rating of the content.
/// The possible values for this rating are clean and explicit. No value means no rating.
pub content_rating: Option<String>,
/// The date the album was added to the library, in YYYY-MM-DD or YYYY format.
pub date_added: Option<String>,
/// The localized name of the album.
pub name: String,
/// When present, this attribute indicates that tracks from the album are available to play.
/// The value map may be used to initiate playback of available tracks on the album.
pub play_params: Option<PlayParameters>,
/// The release date of the album, when known, in YYYY-MM-DD or YYYY format.
/// Pre-release albums may have an expected release date in the future.
pub release_date: Option<String>,
/// The number of tracks.
pub track_count: i32,
/// The names of the genres associated with this album.
pub genre_names: Vec<String>,
}

#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Relationships {
// /// The library artists associated with the album. By default, artists not included.
// /// Fetch limits: 10 default, 10 maximum
// pub artists: Option<LibraryAlbumsArtistsRelationship>,
// /// The album in the Apple Music catalog the library album is associated with, when known.
// /// Fetch limits: None (associated with at most one catalog album)
// pub catalog: Option<LibraryAlbumsCatalogRelationship>,
// /// The library songs and library music videos on the album. Only available when fetching single library album resource by ID. By default, tracks includes objects.
// /// Fetch limits: 300 default, 300 maximum.
// pub tracks: Option<LibraryAlbumsTracksRelationship>,
}

// #[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
// #[serde(rename_all = "camelCase")]
// pub struct LibraryAlbumsArtistsRelationship {
// /// The relative location to fetch the relationship directly.
// pub href: String,
// /// The relative location to request the next page of resources in the collection, if additional resources are available for fetching.
// pub next: Option<String>,
// /// The library artists for the library album.
// pub data: Vec<LibraryArtists>,
// }

#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct LibraryAlbumsCatalogRelationship {
/// The relative location to fetch the relationship directly.
pub href: String,
/// The relative location to request the next page of resources in the collection, if additional resources are available for fetching.
pub next: Option<String>,
/// The album from the Apple Music catalog associated with the library album, if any.
pub data: Vec<Albums>,
}

// #[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
// #[serde(rename_all = "camelCase")]
// pub struct LibraryAlbumsTracksRelationship {
// /// The relative location to fetch the relationship directly.
// pub href: String,
// /// The relative location to request the next page of resources in the collection, if additional resources are available for fetching.
// pub next: Option<String>,
// /// The songs and music videos from the library album’s tracklist added to the user’s library.
// pub data: Vec<LibraryTracks>,
// }

// #[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
// #[serde(rename_all = "camelCase")]
// #[serde(tag = "type")]
// pub enum LibraryTracks {
// LibraryMusicVideos(LibraryMusicVideos),
// LibrarySongs(LibrarySongs),
// }
24 changes: 23 additions & 1 deletion src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
//! the API struct of Apple Music.
/// A resource object that represents an album.
pub mod albums;
/// A resource object that represents the artist of an album where an artist can be one or more people.
pub mod artists;
/// An object that represents artwork.
pub mod artwork;
/// An object that represents a notes attribute.
/// ## Discussion
/// Notes may include XML tags for formatting (&lt;b&gt; for bold, &lt;i&gt; for italic, or &lt;br&gt; for line break) and special characters (&amp;amp; for &, &amp;lt; for <, &amp;gt; for >, &amp;apos; for ‘, and &amp;quot; for “).
pub mod editorial_notes;
/// A resource object that represents a music genre.
pub mod genres;
/// A resource object that represents a library album.
pub mod library_albums;
/// /v1/catalog/:store_front/songs/:song_id?include=lyrics,syllable-lyrics
pub mod lyrics;
/// /v1/catalog/:store_front/music-videos/:id
pub mod music_videos;
/// An object that represents play parameters for resources.
pub mod play_parameters;
/// /v1/catalog/:store_front/playlists/:id
pub mod playlists;
/// An object that represents a preview for resources.
pub mod previews;
/// /v1/catalog/:store_front/search
pub mod search;
/// /v1/catalog/:store_front/songs/:song_id?include=albums
/// /v1/catalog/:store_front/songs/:id?include=albums
pub mod songs;
/// WEBPLAYBACK_API_URL
pub mod webplayback;
Loading

0 comments on commit c538834

Please sign in to comment.