Skip to content

Commit

Permalink
fix!: Update default auth method - closes #179 (#181)
Browse files Browse the repository at this point in the history
* Update default auth
* Fix failing tests with async-callback-manager

BREAKING CHANGE: Youtui default auth method has changed from OAuth to Browser.
  • Loading branch information
nick42d authored Nov 18, 2024
1 parent e08dfb2 commit b206a8e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 21 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@ This project is not supported or endorsed by Google.
`cargo install youtui`

## Running youtui
The default option is to use oauth authentication. To change this to browser authentication, a `config.toml` file can be added to the local youtui config directory (e.g `~/.config/youtui/` on Linux), with the value `auth_type = "Browser"`. Please note however that config file format is currently unstable and could change in the future.
The default option is to use browser authentication, oauth authentication is likely being phased out by Google. To change this to oauth authentication, a `config.toml` file can be added to the local youtui config directory (e.g `~/.config/youtui/` on Linux), with the value `auth_type = "OAuth"`. Please note however that config file format is currently unstable and could change in the future.
### Commands
1. To run the TUI application, execute `youtui` with no arguments.
1. To use the API in command-line mode, execute `youtui --help` to see available commands.
### OAuth Setup Steps
1. Setup the oauth token in the default configuration directory by running `youtui setup-oauth` and following the instructions.
### Browser Auth Setup Steps
1. Open YouTube Music in your browser - ensure you are logged in.
1. Open web developer tools (F12).
Expand All @@ -45,6 +43,10 @@ Firefox example (Right click and Copy Value):
![image](https://github.com/nick42d/youtui/assets/133559267/c7fda32c-10bc-4ebe-b18e-ee17c13f6bd0)
Chrome example (Select manually and paste):
![image](https://github.com/nick42d/youtui/assets/133559267/bd2ec37b-1a78-490f-b313-694145bb4854)
### OAuth Setup Steps
1. Setup the oauth token in the default configuration directory by running `youtui setup-oauth` and following the instructions.
### Other Setup
1. If music downloads always return an error, you are able to supply a PO Token by saving it to the file `po_token.txt` into your local youtui config directory. For more information on PO Tokens and how to obtain them, see [here](https://github.com/yt-dlp/yt-dlp/wiki/Extractors#po-token-guide).

## Dependencies note
### General
Expand Down
11 changes: 9 additions & 2 deletions async-callback-manager/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ impl<Bkend, Cstrnt: PartialEq> AsyncCallbackManager<Bkend, Cstrnt> {
self.spawn_task(backend, task);
Some(ManagedEventType::SpawnedTask)
},
Some(response) = self.tasks_list.process_next_response() => {
Some((response, forwarder)) = self.tasks_list.process_next_response() => {
if let Some(forwarder) = forwarder {
let _ = forwarder.await;
}
(self.on_response_received)(response);
Some(ManagedEventType::ReceivedResponse)
}
Expand All @@ -125,7 +128,11 @@ impl<Bkend, Cstrnt: PartialEq> AsyncCallbackManager<Bkend, Cstrnt> {
/// Note that the 'on_next_response' callback is not called, you're given
/// the ResponseInformation directly.
pub async fn process_next_response(&mut self) -> Option<ResponseInformation> {
self.tasks_list.process_next_response().await
let (response, forwarder) = self.tasks_list.process_next_response().await?;
if let Some(forwarder) = forwarder {
let _ = forwarder.await;
}
Some(response)
}
fn spawn_task(&mut self, backend: &Bkend, task: TaskFromFrontend<Bkend, Cstrnt>) {
(self.on_task_received)(task.get_information());
Expand Down
32 changes: 17 additions & 15 deletions async-callback-manager/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,13 @@ impl<Cstrnt: PartialEq> TaskList<Cstrnt> {
pub(crate) fn new() -> Self {
Self { inner: vec![] }
}
/// Returns Some(ResponseInformation) if a task existed in the list, and it
/// was processed. Returns None, if no tasks were in the list.
pub(crate) async fn process_next_response(&mut self) -> Option<ResponseInformation> {
/// Returns Some(ResponseInformation, Option<DynFallibleFuture>) if a task
/// existed in the list, and it was processed. Returns None, if no tasks
/// were in the list. The DynFallibleFuture represents a future that
/// forwards messages from the manager back to the sender.
pub(crate) async fn process_next_response(
&mut self,
) -> Option<(ResponseInformation, Option<DynFallibleFuture>)> {
let task_completed = self
.inner
.iter_mut()
Expand Down Expand Up @@ -134,22 +138,20 @@ impl<Cstrnt: PartialEq> TaskList<Cstrnt> {
.await;
let (maybe_completed_id, maybe_forwarder, type_id, type_name, sender_id, task_id) =
task_completed?;
if let Some(forwarder) = maybe_forwarder {
// Whilst this seems inefficient, this removes an await point and therefore
// makes this function cancellation safe.
tokio::spawn(forwarder);
}
if let Some(task_completed) = maybe_completed_id {
// Safe - this value is in range as produced from enumerate on original list.
self.inner.swap_remove(task_completed);
}
Some(ResponseInformation {
type_id,
type_name,
sender_id,
task_id,
task_is_now_finished: maybe_completed_id.is_some(),
})
Some((
ResponseInformation {
type_id,
type_name,
sender_id,
task_id,
task_is_now_finished: maybe_completed_id.is_some(),
},
maybe_forwarder,
))
}
pub(crate) fn push(&mut self, task: Task<Cstrnt>) {
self.inner.push(task)
Expand Down
2 changes: 1 addition & 1 deletion youtui/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ pub struct Config {
#[derive(ValueEnum, Copy, Clone, Default, Debug, Serialize, Deserialize)]
pub enum AuthType {
#[value(name = "oauth")]
#[default]
OAuth,
#[default]
Browser,
}

Expand Down

0 comments on commit b206a8e

Please sign in to comment.