: upload specific video

This commit is contained in:
VC
2024-08-20 20:47:46 +02:00
parent ef40d7ad9a
commit fee6b51f45
5 changed files with 28 additions and 10 deletions

2
Cargo.lock generated
View File

@@ -1192,7 +1192,7 @@ dependencies = [
[[package]]
name = "tootube"
version = "0.7.3"
version = "0.8.0"
dependencies = [
"async-stream",
"clap",

View File

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

View File

@@ -15,7 +15,7 @@ pub use youtube::register as register_youtube;
use youtube::YouTube;
#[tokio::main]
pub async fn run(config: Config, pl: Vec<String>) {
pub async fn run(config: Config, pl: Vec<String>, pt_video_id: Option<&str>) {
// Create PeerTube struct
let peertube = match &config.peertube.oauth2 {
Some(s) => PeerTube::new(&config.peertube.base_url)
@@ -24,10 +24,17 @@ pub async fn run(config: Config, pl: Vec<String>) {
.unwrap_or_else(|e| panic!("Cannot instantiate PeerTube struct: {}", e)),
None => PeerTube::new(&config.peertube.base_url),
};
// Get the latest video object
let latest_vid = peertube.get_latest_video().await.unwrap_or_else(|e| {
panic!("Cannot retrieve the latest video, something must have gone terribly wrong: {e}")
});
// Get the latest video object or the targeted pt_video_id
let latest_vid = match pt_video_id {
None => peertube.get_latest_video().await.unwrap_or_else(|e| {
panic!("Cannot retrieve the latest video, something must have gone terribly wrong: {e}")
}),
Some(v) => peertube.get_video_detail(v).await.unwrap_or_else(|e| {
panic!(
"Cannot retrieve the specified video, something must have gone terribly wrong: {e}"
)
}),
};
// We have a refresh_token, try to use it
let source_url = match &config.peertube.oauth2 {

View File

@@ -27,12 +27,21 @@ fn main() {
.num_args(0..)
.display_order(2),
)
.arg(
Arg::new("id")
.short('i')
.long("id")
.value_name("ID")
.help("Specify the PeerTube Video ID")
.num_args(0..=1)
.display_order(3),
)
.arg(
Arg::new("vice")
.long("vice")
.aliases(["chybrare", "coquinou"])
.action(clap::ArgAction::SetTrue)
.display_order(3),
.display_order(4),
)
.subcommand(
Command::new("register")
@@ -85,7 +94,9 @@ fn main() {
.map(|v| v.to_string())
.collect();
let pt_video_id = matches.get_one::<String>("id").map(|s| s.as_str());
env_logger::init();
run(config, playlists);
run(config, playlists, pt_video_id);
}

View File

@@ -279,7 +279,7 @@ impl PeerTube {
}
/// This gets all the crispy details about one particular video
async fn get_video_detail(&self, v: &str) -> Result<PeerTubeVideo, Box<dyn Error>> {
pub async fn get_video_detail(&self, v: &str) -> Result<PeerTubeVideo, Box<dyn Error>> {
let body = self
.client
.get(format!("{}/videos/{}", self.base_url, v))