feat: shorten video url
This commit is contained in:
parent
5aaf02f062
commit
ef898dfb76
2 changed files with 47 additions and 3 deletions
16
src/main.rs
16
src/main.rs
|
@ -68,15 +68,17 @@ enum Step {
|
||||||
Converting,
|
Converting,
|
||||||
Uploading,
|
Uploading,
|
||||||
Thumbnail,
|
Thumbnail,
|
||||||
|
Shortening,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Step {
|
impl Step {
|
||||||
fn button_text(&self) -> &'static str {
|
fn button_text(&self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
Step::Waiting => "Send",
|
Step::Waiting => "Send",
|
||||||
Step::Converting => "Converting...",
|
Step::Converting => "Converting video...",
|
||||||
Step::Uploading => "Uploading...",
|
Step::Uploading => "Uploading...",
|
||||||
Step::Thumbnail => "Generating thumbnail...",
|
Step::Thumbnail => "Generating thumbnail...",
|
||||||
|
Step::Shortening => "Shortening url...",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -389,6 +391,8 @@ impl AsyncComponent for Tyrolienne {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO check for ffmpeg
|
||||||
|
// TODO app icon
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
tracing_subscriber::fmt()
|
tracing_subscriber::fmt()
|
||||||
.with_env_filter(EnvFilter::from_default_env().add_directive(Level::INFO.into()))
|
.with_env_filter(EnvFilter::from_default_env().add_directive(Level::INFO.into()))
|
||||||
|
@ -477,11 +481,17 @@ async fn the_process(app: UploadInfo, sender: &Sender<ProgressMessage>) -> Resul
|
||||||
.thumbnail_url(&app.config)
|
.thumbnail_url(&app.config)
|
||||||
.ok_or_eyre("could not get thumbnail url")?;
|
.ok_or_eyre("could not get thumbnail url")?;
|
||||||
|
|
||||||
Ok(format!(
|
sender.emit(ProgressMessage::SetStep(Step::Shortening));
|
||||||
|
|
||||||
|
let full_url = format!(
|
||||||
"https://autocompressor.net/av1?v={}&i={}&w={}&h={}",
|
"https://autocompressor.net/av1?v={}&i={}&w={}&h={}",
|
||||||
Encoded(&zp_file.url),
|
Encoded(&zp_file.url),
|
||||||
Encoded(&thumbnail_url),
|
Encoded(&thumbnail_url),
|
||||||
video_meta.width,
|
video_meta.width,
|
||||||
video_meta.height,
|
video_meta.height,
|
||||||
))
|
);
|
||||||
|
|
||||||
|
let shortened_url = zipline::shorten_url(&app.config, &full_url).await?;
|
||||||
|
|
||||||
|
Ok(shortened_url)
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,11 @@ pub struct ZiplineThumbnail {
|
||||||
pub path: String,
|
pub path: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, serde::Deserialize)]
|
||||||
|
pub struct ZiplineShortUrl {
|
||||||
|
url: String,
|
||||||
|
}
|
||||||
|
|
||||||
impl ZiplineFileInfo {
|
impl ZiplineFileInfo {
|
||||||
pub fn thumbnail_url(&self, config: &Config) -> Option<String> {
|
pub fn thumbnail_url(&self, config: &Config) -> Option<String> {
|
||||||
self.thumbnail
|
self.thumbnail
|
||||||
|
@ -169,3 +174,32 @@ pub async fn get_file_details(config: &Config, id: &str) -> Result<ZiplineFileIn
|
||||||
res.json().await.map_err(Into::into)
|
res.json().await.map_err(Into::into)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn shorten_url(config: &Config, to_shorten: &str) -> Result<String> {
|
||||||
|
let url = format!("{}api/user/urls", config.fixed_url());
|
||||||
|
|
||||||
|
let body = serde_json::json!({
|
||||||
|
"destination": to_shorten,
|
||||||
|
"enabled": true,
|
||||||
|
"vanity": null
|
||||||
|
});
|
||||||
|
|
||||||
|
let res = CLIENT
|
||||||
|
.post(url)
|
||||||
|
.json(&body)
|
||||||
|
.header(AUTHORIZATION, &config.zipline_token)
|
||||||
|
.send()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
if res.status() != StatusCode::OK {
|
||||||
|
bail!(
|
||||||
|
"an error occurred ({}): {}",
|
||||||
|
res.status(),
|
||||||
|
res.text().await?
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
let out: ZiplineShortUrl = res.json().await?;
|
||||||
|
|
||||||
|
Ok(out.url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue