mirror of
https://framagit.org/veretcle/tootube.git
synced 2025-07-20 12:31:19 +02:00
✨: upload specific video
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -1192,7 +1192,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tootube"
|
name = "tootube"
|
||||||
version = "0.7.3"
|
version = "0.8.0"
|
||||||
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.7.3"
|
version = "0.8.0"
|
||||||
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
|
||||||
|
15
src/lib.rs
15
src/lib.rs
@@ -15,7 +15,7 @@ pub use youtube::register as register_youtube;
|
|||||||
use youtube::YouTube;
|
use youtube::YouTube;
|
||||||
|
|
||||||
#[tokio::main]
|
#[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
|
// Create PeerTube struct
|
||||||
let peertube = match &config.peertube.oauth2 {
|
let peertube = match &config.peertube.oauth2 {
|
||||||
Some(s) => PeerTube::new(&config.peertube.base_url)
|
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)),
|
.unwrap_or_else(|e| panic!("Cannot instantiate PeerTube struct: {}", e)),
|
||||||
None => PeerTube::new(&config.peertube.base_url),
|
None => PeerTube::new(&config.peertube.base_url),
|
||||||
};
|
};
|
||||||
// Get the latest video object
|
// Get the latest video object or the targeted pt_video_id
|
||||||
let latest_vid = peertube.get_latest_video().await.unwrap_or_else(|e| {
|
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}")
|
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
|
// We have a refresh_token, try to use it
|
||||||
let source_url = match &config.peertube.oauth2 {
|
let source_url = match &config.peertube.oauth2 {
|
||||||
|
15
src/main.rs
15
src/main.rs
@@ -27,12 +27,21 @@ fn main() {
|
|||||||
.num_args(0..)
|
.num_args(0..)
|
||||||
.display_order(2),
|
.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(
|
||||||
Arg::new("vice")
|
Arg::new("vice")
|
||||||
.long("vice")
|
.long("vice")
|
||||||
.aliases(["chybrare", "coquinou"])
|
.aliases(["chybrare", "coquinou"])
|
||||||
.action(clap::ArgAction::SetTrue)
|
.action(clap::ArgAction::SetTrue)
|
||||||
.display_order(3),
|
.display_order(4),
|
||||||
)
|
)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
Command::new("register")
|
Command::new("register")
|
||||||
@@ -85,7 +94,9 @@ fn main() {
|
|||||||
.map(|v| v.to_string())
|
.map(|v| v.to_string())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
let pt_video_id = matches.get_one::<String>("id").map(|s| s.as_str());
|
||||||
|
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
run(config, playlists);
|
run(config, playlists, pt_video_id);
|
||||||
}
|
}
|
||||||
|
@@ -279,7 +279,7 @@ impl PeerTube {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// This gets all the crispy details about one particular video
|
/// 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
|
let body = self
|
||||||
.client
|
.client
|
||||||
.get(format!("{}/videos/{}", self.base_url, v))
|
.get(format!("{}/videos/{}", self.base_url, v))
|
||||||
|
Reference in New Issue
Block a user