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
|
.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 upload’s resumable id: {e}"));
|
.unwrap_or_else(|e| panic!("Cannot retrieve the upload’s resumable id: {e}"));
|
||||||
debug!("YT upload URL: {}", &resumable_upload_url);
|
debug!("YT upload URL: {}", &resumable_upload_url);
|
||||||
|
@@ -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,
|
||||||
|
@@ -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¬ifySubscribers={}", notify_subscriber))
|
||||||
.json(&upload_params)
|
.json(&upload_params)
|
||||||
.send().await?;
|
.send().await?;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user