Skip to content

Commit

Permalink
feat! Move convenience functions behind feature gate and add document…
Browse files Browse the repository at this point in the history
…ation. Resolves #76 (#81)

* Move simplified queries to own module
* Cargo fix and one documentation change
* Documentation - continued
* Complete documentation for library
* Additional documentation, and improve some of the simplified queries
* Additional documentation
* Add doctests to CI, fix a typo
* Continue adding documentation
* Continue adding documentation
* Complete adding documentation

BREAKING CHANGE: Simplified queries now feature gated (though enabled by default). Improved interface for some simplified queries - e.g get_library_artists. Removed impl for Lyrics. Fixed the AlbumID on SearchResultAlbum (was chowing ChannelID instead). YtMusic::process_json() moved out of impl to function. Removed erroneous public field from GetArtistAlbumsQuery.
  • Loading branch information
nick42d authored Jul 19, 2024
1 parent 68b6a15 commit 52bddc7
Show file tree
Hide file tree
Showing 25 changed files with 924 additions and 462 deletions.
1 change: 1 addition & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ jobs:
- name: Run tests
run: |
cargo test --verbose --bins --lib
cargo test --verbose --doc
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Chrome example (Select manually and paste):
|Endpoint | Implemented: Query | Implemented: Continuations |
|--- | --- | --- |
|GetArtist | [x] ||
|GetAlbum | [ ]* ||
|GetAlbum | [x]* ||
|GetArtistAlbums | [x] ||
|Search | [x] |[ ]|
|GetSearchSuggestions|[x]||
Expand All @@ -82,14 +82,14 @@ Chrome example (Select manually and paste):
|GetMoodCategories|[ ]||
|GetMoodPlaylists|[ ]||
|GetCharts|[ ]||
|GetWatchPlaylist|[ ]\*|[ ]|
|GetWatchPlaylist|[x]\*|[ ]|
|GetLibraryPlaylists|[x]|[ ]|
|GetLibrarySongs|[x]|[ ]|
|GetLibraryAlbums|[x]|[ ]|
|GetLibraryArtists|[x]|[ ]|
|GetLibrarySubscriptions|[x]|[ ]|
|GetLikedSongs|[ ]||
|GetHistory|[x]||
|GetHistory|[x]*||
|AddHistoryItem|[ ]||
|RemoveHistoryItem|[x]||
|RateSong|[x]||
Expand Down Expand Up @@ -117,6 +117,9 @@ 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.

# Additional information
See the wiki for additional information
https://github.com/nick42d/youtui/wiki
19 changes: 3 additions & 16 deletions youtui/src/app/server/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,7 @@ impl Api {
// Should this be a ChannelID or BrowseID? Should take a trait?.
// Should this actually take ChannelID::try_from(BrowseID::Artist) ->
// ChannelID::Artist?
let artist = api
.get_artist(ytmapi_rs::query::GetArtistQuery::new(
ytmapi_rs::ChannelID::from_raw(browse_id.get_raw()),
))
.await;
let artist = api.get_artist(browse_id).await;
let artist = match artist {
Ok(a) => a,
Err(e) => {
Expand Down Expand Up @@ -298,13 +294,7 @@ impl Api {
unreachable!("Checked not none above")
};

let albums = match api
.get_artist_albums(ytmapi_rs::query::GetArtistAlbumsQuery::new(
ytmapi_rs::ChannelID::from_raw(temp_browse_id.get_raw()),
temp_params,
))
.await
{
let albums = match api.get_artist_albums(temp_browse_id, temp_params).await {
Ok(r) => r,
Err(e) => {
error!("Received error on get_artist_albums query \"{}\"", e);
Expand Down Expand Up @@ -332,10 +322,7 @@ impl Api {
"Spawning request for caller tracks for request ID {:?}",
id
);
let album = match api
.get_album(ytmapi_rs::query::GetAlbumQuery::new(&b_id))
.await
{
let album = match api.get_album(&b_id).await {
Ok(album) => album,
Err(e) => {
error!("Error <{e}> getting album {:?}", b_id);
Expand Down
10 changes: 6 additions & 4 deletions ytmapi-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,25 @@ chrono = "0.4.38"
rand = "0.8.5"

[features]
default = ["default-tls", "simplified-queries"]
# Provide alternative TLS options, but use reqwest's default by default.
# NOTE: To use an alternative TLS, you will need to specify default-features = false
# NOTE: To use an alternative TLS with the standard builders,
# you will need to specify default-features = false.
# As reqwest preferentially uses default-tls when multiple TLS features are enabled.
# See reqwest docs for more information.
# https://docs.rs/reqwest/latest/reqwest/tls/index.html
# TODO: Implement builder functions that allow us to ensure we use a specific TLS.
default = ["default-tls"]
default-tls = ["reqwest/default-tls"]
native-tls = ["reqwest/native-tls"]
rustls-tls = ["reqwest/rustls-tls"]
# Enable the use of simplified queries such as YtMusic::search("xx")
simplified-queries = []

# Dev only section

[dev-dependencies]
pretty_assertions = "1.4.0"

# docs.rs-specific configuration
# docs.rs-specific configuration required to enable nightly documentation features
[package.metadata.docs.rs]
# document all features
all-features = true
Expand Down
9 changes: 9 additions & 0 deletions ytmapi-rs/src/auth/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::{
use reqwest::Client;
use serde::{Deserialize, Serialize};
use serde_json::json;
use std::fmt::Debug;
use std::path::Path;

#[derive(Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -138,3 +139,11 @@ impl BrowserToken {
BrowserToken::from_str(&contents, client).await
}
}

// Don't use default Debug implementation for BrowserToken - contents are
// private
impl Debug for BrowserToken {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Private BrowserToken")
}
}
8 changes: 8 additions & 0 deletions ytmapi-rs/src/auth/oauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,11 @@ impl OAuthTokenGenerator {
serde_json::from_str(&result).map_err(|_| Error::response(&result))
}
}
// Don't use default Debug implementation for BrowserToken - contents are
// private
// TODO: Display some fields, such as time.
impl std::fmt::Debug for OAuthToken {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Private BrowserToken")
}
}
18 changes: 0 additions & 18 deletions ytmapi-rs/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,6 @@ impl_youtube_id!(FeedbackTokenAddToLibrary<'a>);
impl<'a> BrowseID<'a> for PlaylistID<'a> {}
impl<'a> BrowseID<'a> for ChannelID<'a> {}

impl<'a> From<&'a AlbumID<'a>> for AlbumID<'a> {
fn from(value: &'a AlbumID<'a>) -> Self {
let core = &value.0;
AlbumID(core.as_ref().into())
}
}

impl<'a> BrowseParams<'a> {
pub fn from_raw<S>(raw_str: S) -> BrowseParams<'a>
where
Expand Down Expand Up @@ -244,15 +237,4 @@ pub mod browsing {
pub lyrics: String,
pub source: String,
}
impl Lyrics {
pub fn get_lyrics(&self) -> &str {
self.lyrics.as_str()
}
pub fn get_source(&self) -> &str {
self.source.as_str()
}
pub fn new(lyrics: String, source: String) -> Self {
Self { lyrics, source }
}
}
}
Loading

0 comments on commit 52bddc7

Please sign in to comment.