From 8664b169f02e35b3af70001b59626b32d4d08bf5 Mon Sep 17 00:00:00 2001 From: VC Date: Tue, 3 Oct 2023 16:09:47 +0200 Subject: [PATCH] fix: get the whole upload URL instead of just the ID --- src/lib.rs | 4 ++-- src/youtube.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 100bcfe..fd7b5fa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -64,10 +64,10 @@ pub fn run(config: Config) { let local_path = dl_video(&dl_url) .unwrap_or_else(|e| panic!("Cannot download video at URL {}: {}", dl_url, e)); - let resumable_upload_id = create_resumable_upload(&config.youtube, &latest_vid) + let resumable_upload_url = create_resumable_upload(&config.youtube, &latest_vid) .unwrap_or_else(|e| panic!("Cannot retrieve the upload’s resumable id: {e}")); - upload_video(&local_path, &resumable_upload_id, &config.youtube) + upload_video(&local_path, &resumable_upload_url, &config.youtube) .unwrap_or_else(|e| panic!("Cannot resume upload!: {e}")); remove_file(&local_path).unwrap_or_else(|e| panic!("Cannot delete file {}: {}", local_path, e)); diff --git a/src/youtube.rs b/src/youtube.rs index 2f7f177..90f23ea 100644 --- a/src/youtube.rs +++ b/src/youtube.rs @@ -136,7 +136,7 @@ pub fn create_resumable_upload( if res.status().is_success() { Ok(res .headers() - .get("x-guploader-uploadid") + .get("location") .ok_or("Cannot find suitable header")? .to_str()? .to_string()) @@ -147,14 +147,14 @@ pub fn create_resumable_upload( pub fn upload_video( f_path: &str, - r_id: &str, + r_url: &str, config: &YoutubeConfig, ) -> Result<(), Box> { let access_token = refresh_token(config)?; let client = reqwest::blocking::Client::new(); - let res = client.put(format!("https://www.googleapis.com/upload/youtube/v3/videos?uploadType=resumable&part=snippet%2Cstatus&upload_id={}", r_id)) + let res = client.put(r_url) .header("Authorization", format!("Bearer {}", access_token)) .body(f_path.to_string()) .send()?;