mirror of
https://framagit.org/veretcle/tootube.git
synced 2025-07-20 12:31:19 +02:00
Merge branch '11-select-a-pt-video-id-directly' into 'master'
✨: upload specific video Closes #11 See merge request veretcle/tootube!26
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -1192,7 +1192,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tootube"
|
||||
version = "0.7.3"
|
||||
version = "0.8.0"
|
||||
dependencies = [
|
||||
"async-stream",
|
||||
"clap",
|
||||
|
@@ -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
|
||||
|
17
src/lib.rs
17
src/lib.rs
@@ -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 {
|
||||
|
15
src/main.rs
15
src/main.rs
@@ -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);
|
||||
}
|
||||
|
@@ -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))
|
||||
|
Reference in New Issue
Block a user