mirror of
https://framagit.org/veretcle/tootube.git
synced 2025-07-20 12:31:19 +02:00
🔧: add youtube option/put youtube oauth2 in its own struct
This commit is contained in:
@@ -58,6 +58,11 @@ client_secret="<YOUR CLIENT_SECRET>"
|
|||||||
refresh_token="<YOUR CLIENT TOKEN>"
|
refresh_token="<YOUR CLIENT TOKEN>"
|
||||||
|
|
||||||
[youtube]
|
[youtube]
|
||||||
|
notify_subscribers_on_shorts=false # will you notify subscribers for shorts?
|
||||||
|
# optional
|
||||||
|
# allows you to notify subscribers when transferring shorts, defaults to false
|
||||||
|
|
||||||
|
[youtube.oauth2]
|
||||||
refresh_token="" # leave empty for now
|
refresh_token="" # leave empty for now
|
||||||
client_id="<YOUR CLIENT_ID>"
|
client_id="<YOUR CLIENT_ID>"
|
||||||
client_secret="<YOUR CLIENT_SECRET>"
|
client_secret="<YOUR CLIENT_SECRET>"
|
||||||
|
@@ -40,6 +40,13 @@ pub struct PeertubeConfigOauth2 {
|
|||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
pub struct YoutubeConfig {
|
pub struct YoutubeConfig {
|
||||||
|
#[serde(default)]
|
||||||
|
pub notify_subscribers_on_shorts: bool,
|
||||||
|
pub oauth2: YoutubeConfigOauth2,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
|
pub struct YoutubeConfigOauth2 {
|
||||||
pub refresh_token: String,
|
pub refresh_token: String,
|
||||||
pub client_id: String,
|
pub client_id: String,
|
||||||
pub client_secret: String,
|
pub client_secret: String,
|
||||||
@@ -79,3 +86,33 @@ impl Config {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use std::fs::{remove_file, write};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_minimal_conf() {
|
||||||
|
let file_name = "/tmp/test_minimal_conf.toml";
|
||||||
|
let data = r#"
|
||||||
|
[peertube]
|
||||||
|
base_url = 'https://p.nintendojo.fr'
|
||||||
|
|
||||||
|
[youtube.oauth2]
|
||||||
|
refresh_token = 'rt_N/A'
|
||||||
|
client_id = 'ci_N/A'
|
||||||
|
client_secret = 'cs_N/A'
|
||||||
|
"#;
|
||||||
|
write(file_name, data).unwrap();
|
||||||
|
let config = Config::new(file_name);
|
||||||
|
|
||||||
|
assert_eq!(config.youtube.notify_subscribers_on_shorts, false);
|
||||||
|
assert_eq!(config.tootube.progress_chars, "#>-");
|
||||||
|
assert_eq!(config.youtube.oauth2.refresh_token, "rt_N/A");
|
||||||
|
assert_eq!(config.youtube.oauth2.client_id, "ci_N/A");
|
||||||
|
assert_eq!(config.youtube.oauth2.client_secret, "cs_N/A");
|
||||||
|
|
||||||
|
remove_file(file_name).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -66,9 +66,9 @@ pub async fn run(config: &Config, pl: Vec<String>, pt_video_id: Option<&str>) ->
|
|||||||
debug!("PT download URL: {}", &dl_url);
|
debug!("PT download URL: {}", &dl_url);
|
||||||
|
|
||||||
let youtube = YouTube::new(
|
let youtube = YouTube::new(
|
||||||
&config.youtube.client_id,
|
&config.youtube.oauth2.client_id,
|
||||||
&config.youtube.client_secret,
|
&config.youtube.oauth2.client_secret,
|
||||||
&config.youtube.refresh_token,
|
&config.youtube.oauth2.refresh_token,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap_or_else(|e| panic!("Cannot instantiate YouTube struct: {}", e));
|
.unwrap_or_else(|e| panic!("Cannot instantiate YouTube struct: {}", e));
|
||||||
|
@@ -69,10 +69,10 @@ fn main() {
|
|||||||
let mut config = Config::new(sub_m.get_one::<String>("config").unwrap());
|
let mut config = Config::new(sub_m.get_one::<String>("config").unwrap());
|
||||||
|
|
||||||
if sub_m.get_flag("youtube") {
|
if sub_m.get_flag("youtube") {
|
||||||
let yt_refresh_token = register_youtube(&config.youtube)
|
let yt_refresh_token = register_youtube(&config.youtube.oauth2)
|
||||||
.unwrap_or_else(|e| panic!("Cannot register to YouTube API: {}", e));
|
.unwrap_or_else(|e| panic!("Cannot register to YouTube API: {}", e));
|
||||||
|
|
||||||
config.youtube.refresh_token = yt_refresh_token;
|
config.youtube.oauth2.refresh_token = yt_refresh_token;
|
||||||
}
|
}
|
||||||
|
|
||||||
if sub_m.get_flag("peertube") {
|
if sub_m.get_flag("peertube") {
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
config::{TootubeConfig, YoutubeConfig},
|
config::{TootubeConfig, YoutubeConfigOauth2},
|
||||||
error::TootubeError,
|
error::TootubeError,
|
||||||
peertube::PeerTubeVideo,
|
peertube::PeerTubeVideo,
|
||||||
};
|
};
|
||||||
@@ -162,7 +162,7 @@ struct YoutubePlaylistListResponseItemSnippet {
|
|||||||
/// This function makes the registration process a little bit easier
|
/// This function makes the registration process a little bit easier
|
||||||
/// It returns the expected refresh_token so that it can be written back to the file
|
/// It returns the expected refresh_token so that it can be written back to the file
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
pub async fn register(config: &YoutubeConfig) -> Result<String, Box<dyn Error>> {
|
pub async fn register(config: &YoutubeConfigOauth2) -> Result<String, Box<dyn Error>> {
|
||||||
println!("Click on the link below to authorize {} to upload to YouTube and deal with your playlists:", env!("CARGO_PKG_NAME"));
|
println!("Click on the link below to authorize {} to upload to YouTube and deal with your playlists:", env!("CARGO_PKG_NAME"));
|
||||||
println!("https://accounts.google.com/o/oauth2/v2/auth?client_id={}&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=https://www.googleapis.com/auth/youtube%20https://www.googleapis.com/auth/youtube.upload&response_type=code", config.client_id);
|
println!("https://accounts.google.com/o/oauth2/v2/auth?client_id={}&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=https://www.googleapis.com/auth/youtube%20https://www.googleapis.com/auth/youtube.upload&response_type=code", config.client_id);
|
||||||
println!("Paste the returned authorization code:");
|
println!("Paste the returned authorization code:");
|
||||||
|
Reference in New Issue
Block a user