: you can now choose to notify on shorts or not

This commit is contained in:
VC
2024-09-16 09:54:27 +02:00
parent 9b777dcf57
commit ca46d00175
3 changed files with 26 additions and 2 deletions

View File

@@ -73,8 +73,17 @@ pub async fn run(config: &Config, pl: Vec<String>, pt_video_id: Option<&str>) ->
.await .await
.unwrap_or_else(|e| panic!("Cannot instantiate YouTube struct: {}", e)); .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 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 .await
.unwrap_or_else(|e| panic!("Cannot retrieve the uploads resumable id: {e}")); .unwrap_or_else(|e| panic!("Cannot retrieve the uploads resumable id: {e}"));
debug!("YT upload URL: {}", &resumable_upload_url); debug!("YT upload URL: {}", &resumable_upload_url);

View File

@@ -19,6 +19,9 @@ pub struct PeerTubeVideo {
pub name: String, pub name: String,
pub uuid: String, pub uuid: String,
pub description: String, pub description: String,
pub duration: u64,
#[serde(rename = "aspectRatio")]
pub aspect_ratio: Option<f32>,
#[serde(rename = "previewPath")] #[serde(rename = "previewPath")]
pub preview_path: String, pub preview_path: String,
#[serde(rename = "streamingPlaylists")] #[serde(rename = "streamingPlaylists")]
@@ -27,6 +30,15 @@ pub struct PeerTubeVideo {
pub channel: PeerTubeVideoChannel, 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)] #[derive(Debug, Deserialize)]
pub struct PeerTubeVideoChannel { pub struct PeerTubeVideoChannel {
pub id: u8, pub id: u8,

View File

@@ -340,6 +340,7 @@ impl YouTube {
pub async fn create_resumable_upload( pub async fn create_resumable_upload(
&self, &self,
vid: &PeerTubeVideo, vid: &PeerTubeVideo,
notify: bool,
) -> Result<String, Box<dyn Error>> { ) -> Result<String, Box<dyn Error>> {
if vid.name.chars().count() > 100 { if vid.name.chars().count() > 100 {
warn!( warn!(
@@ -365,7 +366,9 @@ impl YouTube {
}; };
debug!("YT upload params: {:?}", &upload_params); 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&notifySubscribers={}", notify_subscriber))
.json(&upload_params) .json(&upload_params)
.send().await?; .send().await?;