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/
|
.logs/
|
||||||
|
|
||||||
.env
|
.env
|
||||||
|
cookies.txt
|
||||||
|
|||||||
@ -7,8 +7,10 @@ services:
|
|||||||
BINARY_NAME: tg-relay-rs
|
BINARY_NAME: tg-relay-rs
|
||||||
environment:
|
environment:
|
||||||
TELOXIDE_TOKEN: ${TELOXIDE_TOKEN}
|
TELOXIDE_TOKEN: ${TELOXIDE_TOKEN}
|
||||||
|
COOKIES_PATH: /app/yt-cookies.txt
|
||||||
RUST_LOG: ${RUST_LOG:-info}
|
RUST_LOG: ${RUST_LOG:-info}
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
# If you need persistent storage (e.g. caching):
|
# If you need persistent storage (e.g. caching):
|
||||||
volumes:
|
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
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// - Propagates `run_command_in_tempdir` errors.
|
/// - Propagates `run_command_in_tempdir` errors.
|
||||||
pub async fn download_ytdlp(url: &str) -> Result<DownloadResult> {
|
pub async fn download_ytdlp(url: &str, cookies: Option<&str>) -> Result<DownloadResult> {
|
||||||
let args = [
|
let mut args = vec![
|
||||||
"--no-playlist",
|
"--no-playlist",
|
||||||
"--merge-output-format",
|
"--merge-output-format",
|
||||||
"mp4",
|
"mp4",
|
||||||
"--restrict-filenames",
|
"--restrict-filenames",
|
||||||
"-o",
|
"-o",
|
||||||
"%(id)s.%(ext)s",
|
"%(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
|
run_command_in_tempdir("yt-dlp", &args).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@ use crate::{
|
|||||||
error::Result,
|
error::Result,
|
||||||
};
|
};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::sync::OnceLock;
|
use std::{env, sync::OnceLock};
|
||||||
use teloxide::{Bot, types::ChatId};
|
use teloxide::{Bot, types::ChatId};
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
|
|
||||||
@ -44,7 +44,8 @@ impl SocialHandler for YouTubeShortsHandler {
|
|||||||
|
|
||||||
async fn handle(&self, bot: &Bot, chat_id: ChatId, url: String) -> Result<()> {
|
async fn handle(&self, bot: &Bot, chat_id: ChatId, url: String) -> Result<()> {
|
||||||
info!(handler = %self.name(), url = %url, "handling youtube code");
|
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
|
process_download_result(bot, chat_id, dr).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -46,7 +46,7 @@ async fn main() -> color_eyre::Result<()> {
|
|||||||
error!(%err, "handler failed");
|
error!(%err, "handler failed");
|
||||||
|
|
||||||
let _ = bot_for_task
|
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;
|
.await;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user