Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement library queries - resolves #56 #57

Merged
merged 8 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PKGBUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Maintainer: Nick Dowsett <[email protected]>

pkgname=youtui
pkgver=0.0.4
pkgver=0.0.5
pkgrel=1
pkgdesc="A simple TUI YouTube Music player written in Rust aiming to implement an Artist->Albums workflow for searching for music, and using discoverability principles for navigation. Writtten in Rust."
url="https://github.com/nick42d/youtui"
Expand Down
102 changes: 46 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,66 +63,56 @@ Chrome example (Select manually and paste):
- [x] OAuth authentication
- [ ] i18n

|Endpoint | Implemented |
|Endpoint | Implemented: Query | Implemented: Continuations |
|--- | --- |
|GetArtist | [x] |
|GetAlbum | [x] |
|GetArtistAlbums | [x] |
|Search | [ ]\* |
|GetSearchSuggestions|[x]|
|GetHome|[ ]|
|GetAlbumBrowseId|[ ]|
|GetUser|[ ]|
|GetUserPlaylists|[ ]|
|GetSong|[ ]|
|GetSongRelated|[ ]|
|GetLyrics|[x]|
|GetTasteProfile|[ ]|
|SetTasteProfile|[ ]|
|GetMoodCategories|[ ]|
|GetMoodPlaylists|[ ]|
|GetCharts|[ ]|
|GetWatchPlaylist|[ ]\*|
|GetLibraryPlaylists|[ ]\*|
|GetLibrarySongs|[ ]|
|GetLibraryAlbums|[ ]|
|GetLibraryArtists|[ ]\*|
|GetLibrarySubscriptions|[ ]|
|GetLikedSongs|[ ]|
|GetHistory|[ ]|
|AddHistoryItem|[ ]|
|RemoveHistoryItem|[ ]|
|RateSong|[ ]|
|EditSongLibraryStatus|[ ]|
|RatePlaylist|[ ]|
|SubscribeArtists|[ ]|
|UnsubscribeArtists|[ ]|
|GetPlaylist|[ ]*|
|CreatePlaylist|[x]|
|EditPlaylist|[x]|
|DeletePlaylist|[x]|
|AddPlaylistItems|[x]|
|RemovePlaylistItems|[x]|
|GetLibraryUploadSongs|[ ]|
|GetLibraryUploadArtists|[ ]|
|GetLibraryUploadAlbums|[ ]|
|GetLibraryUploadArtist|[ ]|
|GetLibraryUploadAlbum|[ ]|
|UploadAlbum|[ ]|
|DeleteUploadEntity|[ ]|

\* search is partially implemented only
- does not implement continuations - only first x results returned.
|GetArtist | [x] ||
|GetAlbum | [x] ||
|GetArtistAlbums | [x] ||
|Search | [x] |[ ]|
|GetSearchSuggestions|[x]||
|GetHome|[ ]||
|GetAlbumBrowseId|[ ]||
|GetUser|[ ]||
|GetUserPlaylists|[ ]||
|GetSong|[ ]||
|GetSongRelated|[ ]||
|GetLyrics|[x]||
|GetTasteProfile|[ ]||
|SetTasteProfile|[ ]||
|GetMoodCategories|[ ]||
|GetMoodPlaylists|[ ]||
|GetCharts|[ ]||
|GetWatchPlaylist|[ ]\*|[ ]|
|GetLibraryPlaylists|[x]|[ ]|
|GetLibrarySongs|[x]|[ ]|
|GetLibraryAlbums|[x]|[ ]|
|GetLibraryArtists|[x]|[ ]|
|GetLibrarySubscriptions|[x]|[ ]|
|GetLikedSongs|[ ]||
|GetHistory|[ ]||
|AddHistoryItem|[ ]||
|RemoveHistoryItem|[ ]||
|RateSong|[ ]||
|EditSongLibraryStatus|[ ]||
|RatePlaylist|[ ]||
|SubscribeArtists|[ ]||
|UnsubscribeArtists|[ ]||
|GetPlaylist|[x]|[ ]|
|CreatePlaylist|[x]||
|EditPlaylist|[x]||
|DeletePlaylist|[x]||
|AddPlaylistItems|[x]||
|RemovePlaylistItems|[x]||
|GetLibraryUploadSongs|[ ]||
|GetLibraryUploadArtists|[ ]||
|GetLibraryUploadAlbums|[ ]||
|GetLibraryUploadArtist|[ ]||
|GetLibraryUploadAlbum|[ ]||
|UploadAlbum|[ ]||
|DeleteUploadEntity|[ ]||

\* get watch playlist is partially implemented only
- only returns playlist and lyrics ids
- does not implement continuations - only first x results returned.

\* get library playlists & artists are partially implemented only
- does not implement continuations - only first x results returned.

\* get playlist is partially implemented only
- does not implement continuations - only first x results returned.

# Additional information
See the wiki for additional information
Expand Down
2 changes: 1 addition & 1 deletion youtui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MIT"
description = "A simple TUI YouTube Music player"
homepage = "https://github.com/nick42d/youtui"
repository = "https://github.com/nick42d/youtui"
readme = "README.md"
readme = "../README.md"
keywords = ["youtube", "music", "player", "tui"]
categories = ["multimedia::audio"]
# Required for async trait support
Expand Down
2 changes: 1 addition & 1 deletion youtui/src/app/view/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use ratatui::{
prelude::{Margin, Rect},
style::{Modifier, Style},
symbols::{block, line},
text::{Line, Text},
text::{Line},
widgets::{
block::{Position, Title},
Block, Borders, Cell, List, ListItem, ListState, Paragraph, Row, Scrollbar,
Expand Down
13 changes: 12 additions & 1 deletion youtui/src/cli/querybuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use ytmapi_rs::{
AddPlaylistItemsQuery, AlbumsFilter, ArtistsFilter, CommunityPlaylistsFilter,
CreatePlaylistQuery, DeletePlaylistQuery, EditPlaylistQuery, EpisodesFilter,
FeaturedPlaylistsFilter, GetAlbumQuery, GetArtistAlbumsQuery, GetArtistQuery,
GetLibraryArtistsQuery, GetLibraryPlaylistsQuery, GetPlaylistQuery,
GetLibraryAlbumsQuery, GetLibraryArtistSubscriptionsQuery, GetLibraryArtistsQuery,
GetLibraryPlaylistsQuery, GetLibrarySongsQuery, GetPlaylistQuery,
GetSearchSuggestionsQuery, PlaylistsFilter, PodcastsFilter, ProfilesFilter, Query,
RemovePlaylistItemsQuery, SearchQuery, SongsFilter, VideosFilter,
},
Expand Down Expand Up @@ -237,6 +238,16 @@ pub async fn command_to_query<A: AuthToken>(
)
.await
}
Command::GetLibrarySongs => {
get_string_output_of_query(yt, GetLibrarySongsQuery::default(), cli_query).await
}
Command::GetLibraryAlbums => {
get_string_output_of_query(yt, GetLibraryAlbumsQuery::default(), cli_query).await
}
Command::GetLibraryArtistSubscriptions => {
get_string_output_of_query(yt, GetLibraryArtistSubscriptionsQuery::default(), cli_query)
.await
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion youtui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ enum Command {
playlist_id: String,
},
GetLibraryPlaylists,
GetLibraryArtists, //TODO: Allow sorting
GetLibraryArtists, //TODO: Allow sorting
GetLibrarySongs, //TODO: Allow sorting
GetLibraryAlbums, //TODO: Allow sorting
GetLibraryArtistSubscriptions, //TODO: Allow sorting
Search {
query: String,
},
Expand Down
11 changes: 8 additions & 3 deletions ytmapi-rs/src/auth/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,17 @@ impl AuthToken for BrowserToken {
"Error message received from server, but doesn't have an error code",
));
};
let message = error
.pointer("/message")
.and_then(|s| s.as_str())
.map(|s| s.to_string())
.unwrap_or_default();
match code {
// Assuming Error:NotAuthenticated means browser token has expired.
// May be incorrect - browser token may be invalid?
// TODO: Investigate.
401 => return Err(Error::browser_authentication_failed()),
other => return Err(Error::other_code(other)),
other => return Err(Error::other_code(other, message)),
}
}
Ok(processed)
Expand Down Expand Up @@ -107,15 +112,15 @@ impl BrowserToken {
.split_once("INNERTUBE_CLIENT_VERSION\":\"")
.ok_or(Error::header())?
.1
.split_once("\"")
.split_once('\"')
.ok_or(Error::header())?
.0
.to_string();
let sapisid = cookies
.split_once("SAPISID=")
.ok_or(Error::header())?
.1
.split_once(";")
.split_once(';')
.ok_or(Error::header())?
.0
.to_string();
Expand Down
15 changes: 8 additions & 7 deletions ytmapi-rs/src/auth/oauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,13 @@ impl AuthToken for OAuthToken {
"Error message received from server, but doesn't have an error code",
));
};
match code {
// TODO: Add some errors for specific cases for this token - example below from
// BrowserToken 401 => return
// Err(Error::browser_authentication_failed()),
other => return Err(Error::other_code(other)),
}
let message = error
.pointer("/message")
.and_then(|s| s.as_str())
.map(|s| s.to_string())
.unwrap_or_default();
// TODO: Error matching
return Err(Error::other_code(code, message));
}
Ok(processed)
}
Expand Down Expand Up @@ -256,6 +257,6 @@ impl OAuthTokenGenerator {
.await?
.text()
.await?;
Ok(serde_json::from_str(&result).map_err(|_| Error::response(&result))?)
serde_json::from_str(&result).map_err(|_| Error::response(&result))
}
}
4 changes: 2 additions & 2 deletions ytmapi-rs/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use serde::{Deserialize, Serialize};
use std::borrow::Cow;

use crate::{impl_youtube_id, Error};
use crate::Error;

/// A search suggestion containing a list of TextRuns.
/// May be a history suggestion.
Expand Down Expand Up @@ -50,7 +50,7 @@ impl SearchSuggestion {
pub fn get_text(&self) -> String {
self.runs
.iter()
.fold(String::new(), |acc, r| acc + &r.get_text())
.fold(String::new(), |acc, r| acc + r.get_text())
}
pub(crate) fn new(suggestion_type: SuggestionType, runs: Vec<TextRun>) -> Self {
Self {
Expand Down
Loading
Loading