fix: add cookie for yt

This commit is contained in:
Kristofers Solo 2025-09-19 23:47:14 +03:00
parent f9bbef506f
commit b9bdbcb1eb
Signed by: kristoferssolo
GPG Key ID: 8687F2D3EEE6F0ED
5 changed files with 18 additions and 7 deletions

1
.gitignore vendored
View File

@ -22,3 +22,4 @@ target/
.logs/
.env
cookies.txt

View File

@ -7,8 +7,10 @@ services:
BINARY_NAME: tg-relay-rs
environment:
TELOXIDE_TOKEN: ${TELOXIDE_TOKEN}
COOKIES_PATH: /app/yt-cookies.txt
RUST_LOG: ${RUST_LOG:-info}
restart: unless-stopped
# If you need persistent storage (e.g. caching):
volumes:
- ./data:/app/data
- ./comments.txt:/app/comments.txt:ro
- ~/.config/yt-cookies.txt:/app/yt-cookies.txt:ro

View File

@ -88,16 +88,23 @@ pub async fn download_instaloader(shortcode: &str) -> Result<DownloadResult> {
/// # Errors
///
/// - Propagates `run_command_in_tempdir` errors.
pub async fn download_ytdlp(url: &str) -> Result<DownloadResult> {
let args = [
pub async fn download_ytdlp(url: &str, cookies: Option<&str>) -> Result<DownloadResult> {
let mut args = vec![
"--no-playlist",
"--merge-output-format",
"mp4",
"--restrict-filenames",
"-o",
"%(id)s.%(ext)s",
url,
];
if let Some(c) = cookies {
args.push("--cookies");
args.push(c);
}
args.push(url);
run_command_in_tempdir("yt-dlp", &args).await
}

View File

@ -3,7 +3,7 @@ use crate::{
error::Result,
};
use regex::Regex;
use std::sync::OnceLock;
use std::{env, sync::OnceLock};
use teloxide::{Bot, types::ChatId};
use tracing::info;
@ -44,7 +44,8 @@ impl SocialHandler for YouTubeShortsHandler {
async fn handle(&self, bot: &Bot, chat_id: ChatId, url: String) -> Result<()> {
info!(handler = %self.name(), url = %url, "handling youtube code");
let dr = download_ytdlp(&url).await?;
let cookies_path = env::var("COOKIES_PATH");
let dr = download_ytdlp(&url, cookies_path.as_deref().ok()).await?;
process_download_result(bot, chat_id, dr).await
}

View File

@ -46,7 +46,7 @@ async fn main() -> color_eyre::Result<()> {
error!(%err, "handler failed");
let _ = bot_for_task
.send_message(chat, "Failed to fetch media, you foking dokey.")
.send_message(chat, "Failed to fetch media, you foking donkey.")
.await;
}
});