mirror of
https://framagit.org/veretcle/tootube.git
synced 2025-07-20 12:31:19 +02:00
✨: upload thumbnail
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -1192,7 +1192,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tootube"
|
name = "tootube"
|
||||||
version = "0.7.2"
|
version = "0.7.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-stream",
|
"async-stream",
|
||||||
"clap",
|
"clap",
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "tootube"
|
name = "tootube"
|
||||||
authors = ["VC <veretcle+framagit@mateu.be>"]
|
authors = ["VC <veretcle+framagit@mateu.be>"]
|
||||||
version = "0.7.2"
|
version = "0.7.3"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
@@ -75,6 +75,14 @@ pub async fn run(config: Config, pl: Vec<String>) {
|
|||||||
.unwrap_or_else(|e| panic!("Cannot resume upload!: {e}"));
|
.unwrap_or_else(|e| panic!("Cannot resume upload!: {e}"));
|
||||||
debug!("YT video ID: {}", &yt_video_id);
|
debug!("YT video ID: {}", &yt_video_id);
|
||||||
|
|
||||||
|
youtube
|
||||||
|
.set_thumbnail(
|
||||||
|
&yt_video_id,
|
||||||
|
&format!("{}{}", &config.peertube.base_url, latest_vid.preview_path),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap_or_else(|e| panic!("Cannot upload the thumbnail: {}", e));
|
||||||
|
|
||||||
if !pl.is_empty() {
|
if !pl.is_empty() {
|
||||||
youtube
|
youtube
|
||||||
.add_video_to_playlists(&yt_video_id, &pl)
|
.add_video_to_playlists(&yt_video_id, &pl)
|
||||||
|
@@ -20,6 +20,8 @@ pub struct PeerTubeVideo {
|
|||||||
pub name: String,
|
pub name: String,
|
||||||
pub uuid: String,
|
pub uuid: String,
|
||||||
pub description: String,
|
pub description: String,
|
||||||
|
#[serde(rename = "previewPath")]
|
||||||
|
pub preview_path: String,
|
||||||
#[serde(rename = "streamingPlaylists")]
|
#[serde(rename = "streamingPlaylists")]
|
||||||
pub streaming_playlists: Option<Vec<PeerTubeVideoStreamingPlaylists>>,
|
pub streaming_playlists: Option<Vec<PeerTubeVideoStreamingPlaylists>>,
|
||||||
pub tags: Option<Vec<String>>,
|
pub tags: Option<Vec<String>>,
|
||||||
|
@@ -236,6 +236,32 @@ impl YouTube {
|
|||||||
|
|
||||||
Ok(youtube)
|
Ok(youtube)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This function uploads the thumbnail from PeerTube
|
||||||
|
pub async fn set_thumbnail(
|
||||||
|
&self,
|
||||||
|
video_id: &str,
|
||||||
|
preview_url: &str,
|
||||||
|
) -> Result<(), Box<dyn Error>> {
|
||||||
|
let res = reqwest::get(preview_url).await?;
|
||||||
|
let stream = res.bytes_stream();
|
||||||
|
|
||||||
|
let res = self
|
||||||
|
.client
|
||||||
|
.post(&format!(
|
||||||
|
"https://www.googleapis.com/upload/youtube/v3/thumbnails/set?videoId={}&uploadType=media",
|
||||||
|
video_id
|
||||||
|
))
|
||||||
|
.header("Content-Type", "application/octet-stream")
|
||||||
|
.body(Body::wrap_stream(stream))
|
||||||
|
.send()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
res.status().is_success().then_some(()).ok_or(
|
||||||
|
TootubeError::new(&format!("Thumbnail not uploaded: {}", res.text().await?)).into(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/// This function takes a list of playlists keyword and returns a list of playlist ID
|
/// This function takes a list of playlists keyword and returns a list of playlist ID
|
||||||
async fn get_playlist_ids(&self, pl: &[String]) -> Result<Vec<String>, Box<dyn Error>> {
|
async fn get_playlist_ids(&self, pl: &[String]) -> Result<Vec<String>, Box<dyn Error>> {
|
||||||
let mut page_token = String::new();
|
let mut page_token = String::new();
|
||||||
@@ -341,17 +367,18 @@ impl YouTube {
|
|||||||
.json(&upload_params)
|
.json(&upload_params)
|
||||||
.send().await?;
|
.send().await?;
|
||||||
|
|
||||||
if res.status().is_success() {
|
res.status()
|
||||||
Ok(res
|
.is_success()
|
||||||
.headers()
|
.then_some(
|
||||||
.get("location")
|
res.headers()
|
||||||
.ok_or("Cannot find suitable header")?
|
.get("location")
|
||||||
.to_str()?
|
.ok_or("Cannot find suitable header")?
|
||||||
.to_string())
|
.to_str()?
|
||||||
} else {
|
.to_string(),
|
||||||
Err(TootubeError::new("Cannot create resumable upload!").into())
|
)
|
||||||
}
|
.ok_or(TootubeError::new("Cannot create resumable upload!").into())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This takes the PT stream for download, connects it to YT stream for upload
|
/// This takes the PT stream for download, connects it to YT stream for upload
|
||||||
pub async fn now_kiss(
|
pub async fn now_kiss(
|
||||||
&self,
|
&self,
|
||||||
|
Reference in New Issue
Block a user