mirror of
https://framagit.org/veretcle/tootube.git
synced 2025-07-20 12:31:19 +02:00
feat: add --vice option
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -1165,7 +1165,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tootube"
|
name = "tootube"
|
||||||
version = "0.5.2"
|
version = "0.5.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-stream",
|
"async-stream",
|
||||||
"clap",
|
"clap",
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "tootube"
|
name = "tootube"
|
||||||
authors = ["VC <veretcle+framagit@mateu.be>"]
|
authors = ["VC <veretcle+framagit@mateu.be>"]
|
||||||
version = "0.5.2"
|
version = "0.5.3"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
@@ -6,6 +6,8 @@ use std::fs::read_to_string;
|
|||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub peertube: PeertubeConfig,
|
pub peertube: PeertubeConfig,
|
||||||
pub youtube: YoutubeConfig,
|
pub youtube: YoutubeConfig,
|
||||||
|
#[serde(default)]
|
||||||
|
pub tootube: TootubeConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
@@ -20,6 +22,21 @@ pub struct YoutubeConfig {
|
|||||||
pub client_secret: String,
|
pub client_secret: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
pub struct TootubeConfig {
|
||||||
|
pub progress_bar: String,
|
||||||
|
pub progress_chars: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for TootubeConfig {
|
||||||
|
fn default() -> Self {
|
||||||
|
TootubeConfig {
|
||||||
|
progress_bar: "{msg}\n{spinner:.green} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {bytes}/{total_bytes} ({bytes_per_sec}, {eta})".to_string(),
|
||||||
|
progress_chars: "#>-".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Parses the TOML file into a Config struct
|
/// Parses the TOML file into a Config struct
|
||||||
pub fn parse_toml(toml_file: &str) -> Config {
|
pub fn parse_toml(toml_file: &str) -> Config {
|
||||||
let toml_config =
|
let toml_config =
|
||||||
|
@@ -36,7 +36,12 @@ pub async fn run(config: Config, pl: Vec<String>) {
|
|||||||
.unwrap_or_else(|e| panic!("Cannot retrieve the upload’s resumable id: {e}"));
|
.unwrap_or_else(|e| panic!("Cannot retrieve the upload’s resumable id: {e}"));
|
||||||
debug!("YT upload URL: {}", &resumable_upload_url);
|
debug!("YT upload URL: {}", &resumable_upload_url);
|
||||||
|
|
||||||
let yt_video_id = now_kiss(&dl_url, &resumable_upload_url, &config.youtube)
|
let yt_video_id = now_kiss(
|
||||||
|
&dl_url,
|
||||||
|
&resumable_upload_url,
|
||||||
|
&config.youtube,
|
||||||
|
&config.tootube,
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap_or_else(|e| panic!("Cannot resume upload!: {e}"));
|
.unwrap_or_else(|e| panic!("Cannot resume upload!: {e}"));
|
||||||
debug!("YT video ID: {}", &yt_video_id);
|
debug!("YT video ID: {}", &yt_video_id);
|
||||||
|
15
src/main.rs
15
src/main.rs
@@ -26,6 +26,14 @@ fn main() {
|
|||||||
.num_args(0..)
|
.num_args(0..)
|
||||||
.display_order(2),
|
.display_order(2),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::new("vice")
|
||||||
|
.long("vice")
|
||||||
|
.alias("chybrare")
|
||||||
|
.alias("coquinou")
|
||||||
|
.action(clap::ArgAction::SetTrue)
|
||||||
|
.display_order(3),
|
||||||
|
)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
Command::new("register")
|
Command::new("register")
|
||||||
.version(env!("CARGO_PKG_VERSION"))
|
.version(env!("CARGO_PKG_VERSION"))
|
||||||
@@ -50,7 +58,12 @@ fn main() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let config = parse_toml(matches.get_one::<String>("config").unwrap());
|
let mut config = parse_toml(matches.get_one::<String>("config").unwrap());
|
||||||
|
|
||||||
|
if matches.get_flag("vice") {
|
||||||
|
config.tootube.progress_bar = "{msg}\n[{elapsed_precise}] 8{wide_bar:.magenta}ᗺ {bytes}/{total_bytes} ({bytes_per_sec}, {eta})".to_string();
|
||||||
|
config.tootube.progress_chars = "=D ".to_string();
|
||||||
|
}
|
||||||
|
|
||||||
let playlists: Vec<String> = matches
|
let playlists: Vec<String> = matches
|
||||||
.get_many::<String>("playlists")
|
.get_many::<String>("playlists")
|
||||||
|
@@ -1,4 +1,8 @@
|
|||||||
use crate::{config::YoutubeConfig, error::TootubeError, peertube::PeerTubeVideo};
|
use crate::{
|
||||||
|
config::{TootubeConfig, YoutubeConfig},
|
||||||
|
error::TootubeError,
|
||||||
|
peertube::PeerTubeVideo,
|
||||||
|
};
|
||||||
use async_stream::stream;
|
use async_stream::stream;
|
||||||
use futures_util::StreamExt;
|
use futures_util::StreamExt;
|
||||||
use indicatif::{ProgressBar, ProgressStyle};
|
use indicatif::{ProgressBar, ProgressStyle};
|
||||||
@@ -345,6 +349,7 @@ pub async fn now_kiss(
|
|||||||
dl_url: &str,
|
dl_url: &str,
|
||||||
r_url: &str,
|
r_url: &str,
|
||||||
config: &YoutubeConfig,
|
config: &YoutubeConfig,
|
||||||
|
pg_conf: &TootubeConfig,
|
||||||
) -> Result<String, Box<dyn Error>> {
|
) -> Result<String, Box<dyn Error>> {
|
||||||
// Get access token
|
// Get access token
|
||||||
let access_token = refresh_token(config).await?;
|
let access_token = refresh_token(config).await?;
|
||||||
@@ -358,9 +363,11 @@ pub async fn now_kiss(
|
|||||||
|
|
||||||
// Create the progress bar
|
// Create the progress bar
|
||||||
let pb = ProgressBar::new(content_lengh);
|
let pb = ProgressBar::new(content_lengh);
|
||||||
pb.set_style(ProgressStyle::default_bar()
|
pb.set_style(
|
||||||
.template("{msg}\n{spinner:.green} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {bytes}/{total_bytes} ({bytes_per_sec}, {eta})")?
|
ProgressStyle::default_bar()
|
||||||
.progress_chars("#>-"));
|
.template(&pg_conf.progress_bar)?
|
||||||
|
.progress_chars(&pg_conf.progress_chars),
|
||||||
|
);
|
||||||
pb.set_message("Transferring…");
|
pb.set_message("Transferring…");
|
||||||
let mut transferring: u64 = 0;
|
let mut transferring: u64 = 0;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user