mirror of
https://framagit.org/veretcle/tootube.git
synced 2025-07-20 12:31:19 +02:00
✨: you can now choose to notify on shorts or not
This commit is contained in:
11
src/lib.rs
11
src/lib.rs
@@ -73,8 +73,17 @@ pub async fn run(config: &Config, pl: Vec<String>, 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);
|
||||
|
@@ -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<f32>,
|
||||
#[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,
|
||||
|
@@ -340,6 +340,7 @@ impl YouTube {
|
||||
pub async fn create_resumable_upload(
|
||||
&self,
|
||||
vid: &PeerTubeVideo,
|
||||
notify: bool,
|
||||
) -> Result<String, Box<dyn Error>> {
|
||||
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?;
|
||||
|
||||
|
Reference in New Issue
Block a user