6 Commits

Author SHA1 Message Date
VC
bf622d6989 Merge branch 'rust_1_77' into 'master'
🔖: bump version and dependencies

See merge request veretcle/tootube!18
2024-04-12 07:22:09 +00:00
VC
a687f008df 🔖: bump version and dependencies 2024-04-12 09:09:45 +02:00
VC
e2ab93c04e Merge branch 'fix_title_length' into 'master'
fix: truncate YT vid title to 100 chars

See merge request veretcle/tootube!17
2023-12-28 09:40:26 +00:00
VC
9e1c27be29 fix: truncate YT vid title to 100 chars 2023-12-28 10:37:23 +01:00
VC
ab9ea1a8ee Merge branch 'tamerelol' into 'master'
feat: add --vice option

See merge request veretcle/tootube!16
2023-10-26 09:06:47 +00:00
VC
66f288c069 feat: add --vice option 2023-10-25 15:33:10 +02:00
6 changed files with 329 additions and 280 deletions

538
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
[package]
name = "tootube"
authors = ["VC <veretcle+framagit@mateu.be>"]
version = "0.5.2"
version = "0.5.5"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@@ -6,6 +6,8 @@ use std::fs::read_to_string;
pub struct Config {
pub peertube: PeertubeConfig,
pub youtube: YoutubeConfig,
#[serde(default)]
pub tootube: TootubeConfig,
}
#[derive(Debug, Deserialize)]
@@ -20,6 +22,21 @@ pub struct YoutubeConfig {
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
pub fn parse_toml(toml_file: &str) -> Config {
let toml_config =

View File

@@ -36,9 +36,14 @@ pub async fn run(config: Config, pl: Vec<String>) {
.unwrap_or_else(|e| panic!("Cannot retrieve the uploads resumable id: {e}"));
debug!("YT upload URL: {}", &resumable_upload_url);
let yt_video_id = now_kiss(&dl_url, &resumable_upload_url, &config.youtube)
.await
.unwrap_or_else(|e| panic!("Cannot resume upload!: {e}"));
let yt_video_id = now_kiss(
&dl_url,
&resumable_upload_url,
&config.youtube,
&config.tootube,
)
.await
.unwrap_or_else(|e| panic!("Cannot resume upload!: {e}"));
debug!("YT video ID: {}", &yt_video_id);
if !pl.is_empty() {

View File

@@ -26,6 +26,14 @@ fn main() {
.num_args(0..)
.display_order(2),
)
.arg(
Arg::new("vice")
.long("vice")
.alias("chybrare")
.alias("coquinou")
.action(clap::ArgAction::SetTrue)
.display_order(3),
)
.subcommand(
Command::new("register")
.version(env!("CARGO_PKG_VERSION"))
@@ -50,7 +58,12 @@ fn main() {
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
.get_many::<String>("playlists")

View File

@@ -1,8 +1,12 @@
use crate::{config::YoutubeConfig, error::TootubeError, peertube::PeerTubeVideo};
use crate::{
config::{TootubeConfig, YoutubeConfig},
error::TootubeError,
peertube::PeerTubeVideo,
};
use async_stream::stream;
use futures_util::StreamExt;
use indicatif::{ProgressBar, ProgressStyle};
use log::debug;
use log::{debug, warn};
use reqwest::{multipart::Form, Body, Client};
use serde::{Deserialize, Serialize};
use std::{cmp::min, error::Error, io::stdin};
@@ -305,10 +309,17 @@ pub async fn create_resumable_upload(
) -> Result<String, Box<dyn Error>> {
let access_token = refresh_token(config).await?;
if vid.name.chars().count() > 100 {
warn!(
"PT Video Title ({}) is too long, it will be truncated",
&vid.name
);
}
let upload_params = YoutubeUploadParams {
snippet: {
YoutubeUploadParamsSnippet {
title: vid.name.clone(),
title: vid.name.chars().take(100).collect::<String>(),
description: vid.description.clone(),
tags: vid.tags.clone(),
..Default::default()
@@ -345,6 +356,7 @@ pub async fn now_kiss(
dl_url: &str,
r_url: &str,
config: &YoutubeConfig,
pg_conf: &TootubeConfig,
) -> Result<String, Box<dyn Error>> {
// Get access token
let access_token = refresh_token(config).await?;
@@ -358,9 +370,11 @@ pub async fn now_kiss(
// Create the progress bar
let pb = ProgressBar::new(content_lengh);
pb.set_style(ProgressStyle::default_bar()
.template("{msg}\n{spinner:.green} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {bytes}/{total_bytes} ({bytes_per_sec}, {eta})")?
.progress_chars("#>-"));
pb.set_style(
ProgressStyle::default_bar()
.template(&pg_conf.progress_bar)?
.progress_chars(&pg_conf.progress_chars),
);
pb.set_message("Transferring…");
let mut transferring: u64 = 0;