Skip to content

Commit

Permalink
feat!: Return dates and FeedbackTokenRemoveFromHistory from GetHistor…
Browse files Browse the repository at this point in the history
…yQuery. Closes #109 (#121)

* Skeleton work, and implement parse_history_item_song
* Add parsing functions for all history item types;
* Implement error handling for when a JsonCrawlerIterator is expected not to be empty
* Upgrade tests and docs
* Update README.md

BREAKING CHANGE: Changed type returned from GetHistoryQuery, removed new unused types TableListItem, TableListVideo and TableListEpisode.
  • Loading branch information
nick42d authored Aug 5, 2024
1 parent b0316f5 commit 04c3e63
Show file tree
Hide file tree
Showing 13 changed files with 23,256 additions and 21,785 deletions.
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Chrome example (Select manually and paste):
|GetLibraryArtists|[x]|[ ]|
|GetLibrarySubscriptions|[x]|[ ]|
|GetLikedSongs|[ ]||
|GetHistory|[x]*||
|GetHistory|[x]||
|AddHistoryItem|[x]||
|RemoveHistoryItem|[x]||
|RateSong|[x]||
Expand Down Expand Up @@ -138,10 +138,7 @@ Chrome example (Select manually and paste):
\* get artist is partially implemented only
- only returns albums and songs

\* get history is partially implemented only
- does not return a date, and remove from history feedback items are not generated.

\* only the tracking url from get song is implemented
\* only the tracking url from get song is implemented - as GetSongTrackingUrl.

## Developer notes
See the wiki for additional information
Expand Down
38 changes: 38 additions & 0 deletions ytmapi-rs/src/crawler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ pub(crate) trait JsonCrawlerIterator: Iterator {
fn find_path(self, path: impl AsRef<str>) -> Result<Self::Item>;
/// Consume self to return (`source`, `path`).
fn get_context(self) -> (Arc<String>, String);
/// Return the last item of the array, or return an error with context.
fn try_last(self) -> Result<Self::Item>;
}

pub(crate) struct JsonCrawlerArrayIterMut<'a> {
Expand Down Expand Up @@ -157,6 +159,24 @@ impl<'a> JsonCrawlerIterator for JsonCrawlerArrayIterMut<'a> {
let Self { source, path, .. } = self;
(source, path.into())
}
fn try_last(self) -> Result<Self::Item> {
let Self {
source,
array,
mut path,
..
} = self;
let len = array.len();
path.push(JsonPath::IndexNum(len));
let Some(last_item) = array.last() else {
return Err(Error::array_size(path, source, 0));
};
Ok(Self::Item {
source,
crawler: last_item,
path,
})
}
}

impl Iterator for JsonCrawlerArrayIntoIter {
Expand Down Expand Up @@ -206,6 +226,24 @@ impl JsonCrawlerIterator for JsonCrawlerArrayIntoIter {
let Self { source, path, .. } = self;
(source, path.into())
}
fn try_last(self) -> Result<Self::Item> {
let Self {
source,
array,
mut path,
..
} = self;
let len = array.len();
path.push(JsonPath::IndexNum(len));
let Some(last_item) = array.last() else {
return Err(Error::array_size(path, source, 0));
};
Ok(Self::Item {
source,
crawler: last_item,
path,
})
}
}

impl<'a> JsonCrawlerBorrowed<'a> {
Expand Down
2 changes: 1 addition & 1 deletion ytmapi-rs/src/nav_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub const MUSIC_SHELF: &str = "/musicShelfRenderer";
pub const MUSIC_CARD_SHELF: &str = "/musicCardShelfRenderer";
pub const GRID: &str = "/gridRenderer";
pub const MENU: &str = "/menu/menuRenderer";
pub const _MENU_SERVICE: &str = "/menuServiceItemRenderer/serviceEndpoint";
pub const MENU_SERVICE: &str = "/menuServiceItemRenderer/serviceEndpoint";
pub const _TOGGLE_MENU: &str = "/toggleMenuServiceItemRenderer";
pub const PLAY_BUTTON: &str =
"/overlay/musicItemThumbnailOverlayRenderer/content/musicPlayButtonRenderer";
Expand Down
1 change: 1 addition & 0 deletions ytmapi-rs/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use std::fmt::Debug;

pub use album::*;
pub use artist::*;
pub use history::*;
pub use library::*;
pub use playlists::*;
pub use recommendations::*;
Expand Down
40 changes: 0 additions & 40 deletions ytmapi-rs/src/parse/artist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,52 +340,12 @@ pub struct TableListSong {
pub playlist_id: PlaylistID<'static>,
}

#[derive(PartialEq, Debug, Clone, Deserialize, Serialize)]
pub struct TableListVideo {
pub video_id: VideoID<'static>,
pub duration: String,
pub title: String,
// Could be 'ParsedVideoChannel'
pub channel_name: String,
pub channel_id: ChannelID<'static>,
// TODO: Song like feedback tokens.
pub like_status: LikeStatus,
pub thumbnails: Vec<super::Thumbnail>,
pub is_available: bool,
/// Id of the playlist that will get created when pressing 'Start Radio'.
pub playlist_id: PlaylistID<'static>,
}

#[derive(PartialEq, Debug, Clone, Deserialize, Serialize)]
pub struct TableListEpisode {
pub video_id: VideoID<'static>,
// May be live or non-live...
pub date: EpisodeDate,
pub duration: EpisodeDuration,
pub title: String,
pub podcast_name: String,
pub podcast_id: PlaylistID<'static>,
// TODO: Song like feedback tokens.
pub like_status: LikeStatus,
pub thumbnails: Vec<super::Thumbnail>,
pub is_available: bool,
}

#[derive(PartialEq, Debug, Clone, Deserialize, Serialize)]
pub enum PlaylistItem {
Song(PlaylistSong),
Video(PlaylistVideo),
}

#[derive(PartialEq, Debug, Clone, Deserialize, Serialize)]
// Potentially should be HistoryItem
pub enum TableListItem {
Song(TableListSong),
Video(TableListVideo),
Episode(TableListEpisode),
UploadSong(TableListUploadSong),
}

// Should be at higher level in mod structure.
#[derive(Debug)]
enum ArtistTopReleaseCategory {
Expand Down
Loading

0 comments on commit 04c3e63

Please sign in to comment.