mirror of
https://framagit.org/veretcle/tootube.git
synced 2025-07-20 20:41:17 +02:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
66f288c069 | ||
![]() |
b208daa0ea | ||
![]() |
f3ad81716d | ||
![]() |
f18ce899aa |
27
Cargo.lock
generated
27
Cargo.lock
generated
@@ -567,9 +567,9 @@ checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f"
|
||||
|
||||
[[package]]
|
||||
name = "lock_api"
|
||||
version = "0.4.10"
|
||||
version = "0.4.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16"
|
||||
checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"scopeguard",
|
||||
@@ -728,13 +728,13 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "parking_lot_core"
|
||||
version = "0.9.8"
|
||||
version = "0.9.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447"
|
||||
checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"redox_syscall",
|
||||
"redox_syscall 0.4.1",
|
||||
"smallvec",
|
||||
"windows-targets 0.48.5",
|
||||
]
|
||||
@@ -796,6 +796,15 @@ dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.10.2"
|
||||
@@ -1062,7 +1071,7 @@ checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"fastrand",
|
||||
"redox_syscall",
|
||||
"redox_syscall 0.3.5",
|
||||
"rustix",
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
@@ -1156,7 +1165,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tootube"
|
||||
version = "0.5.1"
|
||||
version = "0.5.3"
|
||||
dependencies = [
|
||||
"async-stream",
|
||||
"clap",
|
||||
@@ -1178,9 +1187,9 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52"
|
||||
|
||||
[[package]]
|
||||
name = "tracing"
|
||||
version = "0.1.39"
|
||||
version = "0.1.40"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ee2ef2af84856a50c1d430afce2fdded0a4ec7eda868db86409b4543df0797f9"
|
||||
checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef"
|
||||
dependencies = [
|
||||
"pin-project-lite",
|
||||
"tracing-core",
|
||||
|
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "tootube"
|
||||
authors = ["VC <veretcle+framagit@mateu.be>"]
|
||||
version = "0.5.1"
|
||||
version = "0.5.3"
|
||||
edition = "2021"
|
||||
|
||||
# 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 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 =
|
||||
|
21
src/lib.rs
21
src/lib.rs
@@ -7,7 +7,7 @@ pub use config::parse_toml;
|
||||
use config::Config;
|
||||
|
||||
mod peertube;
|
||||
use peertube::{get_latest_video, get_max_resolution_dl};
|
||||
use peertube::get_latest_video;
|
||||
|
||||
mod youtube;
|
||||
pub use youtube::register;
|
||||
@@ -22,7 +22,13 @@ pub async fn run(config: Config, pl: Vec<String>) {
|
||||
panic!("Cannot retrieve the latest video, something must have gone terribly wrong: {e}")
|
||||
});
|
||||
|
||||
let dl_url = get_max_resolution_dl(latest_vid.streaming_playlists.as_ref().unwrap());
|
||||
let dl_url = latest_vid.streaming_playlists.as_ref().unwrap()[0]
|
||||
.files
|
||||
.iter()
|
||||
.max()
|
||||
.unwrap()
|
||||
.file_download_url
|
||||
.clone();
|
||||
debug!("PT download URL: {}", &dl_url);
|
||||
|
||||
let resumable_upload_url = create_resumable_upload(&config.youtube, &latest_vid)
|
||||
@@ -30,9 +36,14 @@ pub async fn run(config: Config, pl: Vec<String>) {
|
||||
.unwrap_or_else(|e| panic!("Cannot retrieve the upload’s 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() {
|
||||
|
15
src/main.rs
15
src/main.rs
@@ -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")
|
||||
|
@@ -65,11 +65,6 @@ pub async fn get_latest_video(u: &str) -> Result<PeerTubeVideo, Box<dyn Error>>
|
||||
Ok(vid)
|
||||
}
|
||||
|
||||
/// This returns the direct download URL for with the maximum resolution
|
||||
pub fn get_max_resolution_dl(p: &[PeerTubeVideoStreamingPlaylists]) -> String {
|
||||
p[0].files.iter().max().unwrap().file_download_url.clone()
|
||||
}
|
||||
|
||||
/// This gets all the crispy details about one particular video
|
||||
async fn get_video_detail(u: &str, v: &str) -> Result<PeerTubeVideo, Box<dyn Error>> {
|
||||
let body = reqwest::get(format!("{}/api/v1/videos/{}", u, v))
|
||||
@@ -79,34 +74,3 @@ async fn get_video_detail(u: &str, v: &str) -> Result<PeerTubeVideo, Box<dyn Err
|
||||
|
||||
Ok(body)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_get_max_resolution_dl() {
|
||||
let str_plist: Vec<PeerTubeVideoStreamingPlaylists> =
|
||||
vec![PeerTubeVideoStreamingPlaylists {
|
||||
files: vec![
|
||||
PeerTubeVideoStreamingPlaylistsFiles {
|
||||
id: 1025,
|
||||
resolution: PeerTubeVideoStreamingPlaylistsFilesResolution { id: 990 },
|
||||
file_download_url: "meh!".to_string(),
|
||||
},
|
||||
PeerTubeVideoStreamingPlaylistsFiles {
|
||||
id: 1027,
|
||||
resolution: PeerTubeVideoStreamingPlaylistsFilesResolution { id: 1720 },
|
||||
file_download_url: "blah".to_string(),
|
||||
},
|
||||
PeerTubeVideoStreamingPlaylistsFiles {
|
||||
id: 1026,
|
||||
resolution: PeerTubeVideoStreamingPlaylistsFilesResolution { id: 360 },
|
||||
file_download_url: "nope".to_string(),
|
||||
},
|
||||
],
|
||||
}];
|
||||
|
||||
assert_eq!("blah".to_string(), get_max_resolution_dl(&str_plist));
|
||||
}
|
||||
}
|
||||
|
@@ -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 futures_util::StreamExt;
|
||||
use indicatif::{ProgressBar, ProgressStyle};
|
||||
@@ -345,6 +349,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 +363,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;
|
||||
|
||||
|
Reference in New Issue
Block a user