From ca46d001757870758667912891e5bbdaeda81a20 Mon Sep 17 00:00:00 2001 From: VC Date: Mon, 16 Sep 2024 09:54:27 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8:=20you=20can=20now=20choose=20to=20no?= =?UTF-8?q?tify=20on=20shorts=20or=20not?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib.rs | 11 ++++++++++- src/peertube.rs | 12 ++++++++++++ src/youtube.rs | 5 ++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1d228d1..0b74111 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -73,8 +73,17 @@ pub async fn run(config: &Config, pl: Vec, pt_video_id: Option<&str>) -> .await .unwrap_or_else(|e| panic!("Cannot instantiate YouTube struct: {}", e)); + // Do not notify when notify_subscribers_on_shorts = False and latest_id is a short + debug!( + "Will user get notified? {}", + !(!config.youtube.notify_subscribers_on_shorts & latest_vid.is_short()) + ); + let resumable_upload_url = youtube - .create_resumable_upload(&latest_vid) + .create_resumable_upload( + &latest_vid, + !(!config.youtube.notify_subscribers_on_shorts & latest_vid.is_short()), + ) .await .unwrap_or_else(|e| panic!("Cannot retrieve the upload’s resumable id: {e}")); debug!("YT upload URL: {}", &resumable_upload_url); diff --git a/src/peertube.rs b/src/peertube.rs index 6672e8f..d436bc6 100644 --- a/src/peertube.rs +++ b/src/peertube.rs @@ -19,6 +19,9 @@ pub struct PeerTubeVideo { pub name: String, pub uuid: String, pub description: String, + pub duration: u64, + #[serde(rename = "aspectRatio")] + pub aspect_ratio: Option, #[serde(rename = "previewPath")] pub preview_path: String, #[serde(rename = "streamingPlaylists")] @@ -27,6 +30,15 @@ pub struct PeerTubeVideo { pub channel: PeerTubeVideoChannel, } +impl PeerTubeVideo { + pub fn is_short(&self) -> bool { + if self.duration < 60 && self.aspect_ratio.is_some_and(|x| x == 0.5625) { + return true; + } + false + } +} + #[derive(Debug, Deserialize)] pub struct PeerTubeVideoChannel { pub id: u8, diff --git a/src/youtube.rs b/src/youtube.rs index f365b07..da2af05 100644 --- a/src/youtube.rs +++ b/src/youtube.rs @@ -340,6 +340,7 @@ impl YouTube { pub async fn create_resumable_upload( &self, vid: &PeerTubeVideo, + notify: bool, ) -> Result> { if vid.name.chars().count() > 100 { warn!( @@ -365,7 +366,9 @@ impl YouTube { }; debug!("YT upload params: {:?}", &upload_params); - let res = self.client.post("https://www.googleapis.com/upload/youtube/v3/videos?uploadType=resumable&part=snippet%2Cstatus") + let notify_subscriber = notify.then_some(()).map_or("False", |_| "True"); + + let res = self.client.post(format!("https://www.googleapis.com/upload/youtube/v3/videos?uploadType=resumable&part=snippet%2Cstatus¬ifySubscribers={}", notify_subscriber)) .json(&upload_params) .send().await?;