feat(yt): use yt-dlp preset aliases

This commit is contained in:
Kristofers Solo 2025-09-23 11:37:02 +03:00
parent ef3e903a6f
commit 17f29f59be
Signed by: kristoferssolo
GPG Key ID: 74FF8144483D82C8
2 changed files with 2 additions and 14 deletions

View File

@ -7,7 +7,6 @@ services:
BINARY_NAME: tg-relay-rs BINARY_NAME: tg-relay-rs
environment: environment:
TELOXIDE_TOKEN: ${TELOXIDE_TOKEN} TELOXIDE_TOKEN: ${TELOXIDE_TOKEN}
YTDLP_FORMAT: ${YTDLP_FORMAT:-best}
COOKIES_PATH: /app/yt-cookies.txt COOKIES_PATH: /app/yt-cookies.txt
RUST_LOG: ${RUST_LOG:-info} RUST_LOG: ${RUST_LOG:-info}
restart: unless-stopped restart: unless-stopped

View File

@ -8,7 +8,6 @@ use crate::{
use futures::{StreamExt, stream}; use futures::{StreamExt, stream};
use std::{ use std::{
cmp::min, cmp::min,
env,
ffi::OsStr, ffi::OsStr,
fs::{self, metadata}, fs::{self, metadata},
path::{Path, PathBuf}, path::{Path, PathBuf},
@ -130,18 +129,13 @@ pub async fn download_ytdlp<P: AsRef<Path>>(
url: &str, url: &str,
cookies_path: Option<P>, cookies_path: Option<P>,
) -> Result<DownloadResult> { ) -> Result<DownloadResult> {
let format_selector = env::var("YTDLP_FORMAT").unwrap_or_else(|_| "best".into());
info!(format_selector = format_selector, "video format");
let base_args = [ let base_args = [
"--no-playlist", "--no-playlist",
"--merge-output-format", "-t",
"mp4", "mp4",
"-f",
// format_selector
"--restrict-filenames", "--restrict-filenames",
"-o", "-o",
"%(id)s.%(ext)s", "%(title)s.%(ext)s",
"--no-warnings", "--no-warnings",
"--quiet", "--quiet",
]; ];
@ -151,11 +145,6 @@ pub async fn download_ytdlp<P: AsRef<Path>>(
.map(ToString::to_string) .map(ToString::to_string)
.collect::<Vec<_>>(); .collect::<Vec<_>>();
match args.iter().position(|s| s == "-f") {
Some(pos) => args.insert(pos + 1, format_selector),
None => args.extend(["-f".into(), format_selector]),
}
if let Some(cookie_path) = cookies_path { if let Some(cookie_path) = cookies_path {
let path = cookie_path.as_ref(); let path = cookie_path.as_ref();
let path_str = path.to_string_lossy().to_string(); let path_str = path.to_string_lossy().to_string();