mirror of
https://github.com/kristoferssolo/tg-relay-rs.git
synced 2025-12-20 11:04:41 +00:00
fix: add cookie for yt
This commit is contained in:
parent
f9bbef506f
commit
b9bdbcb1eb
1
.gitignore
vendored
1
.gitignore
vendored
@ -22,3 +22,4 @@ target/
|
||||
.logs/
|
||||
|
||||
.env
|
||||
cookies.txt
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user