mirror of
https://framagit.org/veretcle/tootube.git
synced 2025-12-06 08:33:14 +01:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9d168bfc6c | ||
|
|
1d4ce867e5 | ||
|
|
27402df1fd | ||
|
|
a960ec5b02 | ||
|
|
c0a20a86cc | ||
|
|
ca46d00175 | ||
|
|
9b777dcf57 | ||
|
|
7c6a52d2ed | ||
|
|
47be0abbf4 | ||
|
|
7a652f19a5 |
20
.gitea/workflows/check.yml
Normal file
20
.gitea/workflows/check.yml
Normal file
@@ -0,0 +1,20 @@
|
||||
---
|
||||
|
||||
name: rust-check
|
||||
|
||||
on: # yamllint disable-line rule:truthy
|
||||
- push
|
||||
|
||||
jobs:
|
||||
rust-check:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
components: "clippy,rustfmt"
|
||||
- run: cargo fmt -- --check
|
||||
- run: cargo check
|
||||
- run: cargo clippy -- -D warnings
|
||||
- run: cargo test
|
||||
- run: cargo build
|
||||
23
.gitea/workflows/release.yml
Normal file
23
.gitea/workflows/release.yml
Normal file
@@ -0,0 +1,23 @@
|
||||
---
|
||||
|
||||
name: rust-release
|
||||
|
||||
on: # yamllint disable-line rule:truthy
|
||||
push:
|
||||
tags:
|
||||
- 'v[0-9]+.[0-9]+.[0-9]+'
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: dtolnay/rust-toolchain@stable
|
||||
- name: Get package name
|
||||
run: echo "CARGO_PKG_NAME=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].name')" >> $GITEA_ENV
|
||||
- run: cargo build --release
|
||||
- uses: https://gitea.com/actions/gitea-release-action@v1
|
||||
with:
|
||||
files: |-
|
||||
target/release/${{ env.CARGO_PKG_NAME }}
|
||||
api_key: '${{ secrets.RELEASE_TOKEN }}'
|
||||
1008
Cargo.lock
generated
1008
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "tootube"
|
||||
authors = ["VC <veretcle+framagit@mateu.be>"]
|
||||
version = "0.9.0"
|
||||
version = "0.10.1"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
@@ -58,6 +58,11 @@ client_secret="<YOUR CLIENT_SECRET>"
|
||||
refresh_token="<YOUR CLIENT TOKEN>"
|
||||
|
||||
[youtube]
|
||||
notify_subscribers_on_shorts=false # will you notify subscribers for shorts?
|
||||
# optional
|
||||
# allows you to notify subscribers when transferring shorts, defaults to false
|
||||
|
||||
[youtube.oauth2]
|
||||
refresh_token="" # leave empty for now
|
||||
client_id="<YOUR CLIENT_ID>"
|
||||
client_secret="<YOUR CLIENT_SECRET>"
|
||||
|
||||
@@ -40,6 +40,13 @@ pub struct PeertubeConfigOauth2 {
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct YoutubeConfig {
|
||||
#[serde(default)]
|
||||
pub notify_subscribers_on_shorts: bool,
|
||||
pub oauth2: YoutubeConfigOauth2,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct YoutubeConfigOauth2 {
|
||||
pub refresh_token: String,
|
||||
pub client_id: String,
|
||||
pub client_secret: String,
|
||||
@@ -79,3 +86,33 @@ impl Config {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::fs::{remove_file, write};
|
||||
|
||||
#[test]
|
||||
fn test_minimal_conf() {
|
||||
let file_name = "/tmp/test_minimal_conf.toml";
|
||||
let data = r#"
|
||||
[peertube]
|
||||
base_url = 'https://p.nintendojo.fr'
|
||||
|
||||
[youtube.oauth2]
|
||||
refresh_token = 'rt_N/A'
|
||||
client_id = 'ci_N/A'
|
||||
client_secret = 'cs_N/A'
|
||||
"#;
|
||||
write(file_name, data).unwrap();
|
||||
let config = Config::new(file_name);
|
||||
|
||||
assert_eq!(config.youtube.notify_subscribers_on_shorts, false);
|
||||
assert_eq!(config.tootube.progress_chars, "#>-");
|
||||
assert_eq!(config.youtube.oauth2.refresh_token, "rt_N/A");
|
||||
assert_eq!(config.youtube.oauth2.client_id, "ci_N/A");
|
||||
assert_eq!(config.youtube.oauth2.client_secret, "cs_N/A");
|
||||
|
||||
remove_file(file_name).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
17
src/lib.rs
17
src/lib.rs
@@ -66,15 +66,24 @@ pub async fn run(config: &Config, pl: Vec<String>, pt_video_id: Option<&str>) ->
|
||||
debug!("PT download URL: {}", &dl_url);
|
||||
|
||||
let youtube = YouTube::new(
|
||||
&config.youtube.client_id,
|
||||
&config.youtube.client_secret,
|
||||
&config.youtube.refresh_token,
|
||||
&config.youtube.oauth2.client_id,
|
||||
&config.youtube.oauth2.client_secret,
|
||||
&config.youtube.oauth2.refresh_token,
|
||||
)
|
||||
.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);
|
||||
|
||||
@@ -69,10 +69,10 @@ fn main() {
|
||||
let mut config = Config::new(sub_m.get_one::<String>("config").unwrap());
|
||||
|
||||
if sub_m.get_flag("youtube") {
|
||||
let yt_refresh_token = register_youtube(&config.youtube)
|
||||
let yt_refresh_token = register_youtube(&config.youtube.oauth2)
|
||||
.unwrap_or_else(|e| panic!("Cannot register to YouTube API: {}", e));
|
||||
|
||||
config.youtube.refresh_token = yt_refresh_token;
|
||||
config.youtube.oauth2.refresh_token = yt_refresh_token;
|
||||
}
|
||||
|
||||
if sub_m.get_flag("peertube") {
|
||||
@@ -112,6 +112,8 @@ fn main() {
|
||||
client_id: y.client_id,
|
||||
client_secret: y.client_secret,
|
||||
refresh_token: x,
|
||||
})
|
||||
});
|
||||
|
||||
let _ = config.dump(matches.get_one::<String>("config").unwrap());
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
config::{TootubeConfig, YoutubeConfig},
|
||||
config::{TootubeConfig, YoutubeConfigOauth2},
|
||||
error::TootubeError,
|
||||
peertube::PeerTubeVideo,
|
||||
};
|
||||
@@ -79,6 +79,8 @@ impl Default for YoutubeUploadParamsSnippet {
|
||||
struct YoutubeUploadParamsStatus {
|
||||
#[serde(rename = "selfDeclaredMadeForKids")]
|
||||
self_declared_made_for_kids: bool,
|
||||
#[serde(rename = "containsSyntheticMedia")]
|
||||
contains_synthetic_media: bool,
|
||||
#[serde(rename = "privacyStatus")]
|
||||
privacy_status: String,
|
||||
license: String,
|
||||
@@ -88,6 +90,7 @@ impl Default for YoutubeUploadParamsStatus {
|
||||
fn default() -> Self {
|
||||
YoutubeUploadParamsStatus {
|
||||
self_declared_made_for_kids: false,
|
||||
contains_synthetic_media: false,
|
||||
privacy_status: "public".to_string(),
|
||||
license: "creativeCommon".to_string(),
|
||||
}
|
||||
@@ -162,7 +165,7 @@ struct YoutubePlaylistListResponseItemSnippet {
|
||||
/// This function makes the registration process a little bit easier
|
||||
/// It returns the expected refresh_token so that it can be written back to the file
|
||||
#[tokio::main]
|
||||
pub async fn register(config: &YoutubeConfig) -> Result<String, Box<dyn Error>> {
|
||||
pub async fn register(config: &YoutubeConfigOauth2) -> Result<String, Box<dyn Error>> {
|
||||
println!("Click on the link below to authorize {} to upload to YouTube and deal with your playlists:", env!("CARGO_PKG_NAME"));
|
||||
println!("https://accounts.google.com/o/oauth2/v2/auth?client_id={}&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=https://www.googleapis.com/auth/youtube%20https://www.googleapis.com/auth/youtube.upload&response_type=code", config.client_id);
|
||||
println!("Paste the returned authorization code:");
|
||||
@@ -340,6 +343,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 +369,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