diff options
Diffstat (limited to '')
-rwxr-xr-x | python_update/raw_update.py | 11 | ||||
-rw-r--r-- | src/main.rs | 2 | ||||
-rw-r--r-- | src/update/mod.rs | 26 |
3 files changed, 30 insertions, 9 deletions
diff --git a/python_update/raw_update.py b/python_update/raw_update.py index 6f5b78d..c443960 100755 --- a/python_update/raw_update.py +++ b/python_update/raw_update.py @@ -50,7 +50,7 @@ class Video: logger = logging.getLogger("yt") -logging.basicConfig(encoding="utf-8", level=logging.DEBUG) +logging.basicConfig(encoding="utf-8", level=int(sys.argv[3])) _ytdl_logger = logging.getLogger("yt_dlp") _ytdl_logger.propagate = False @@ -107,6 +107,7 @@ class Fetcher: else: entries = info.get("entries", []) for entry in take(self.max_items, entries): + logger.debug(json.dumps(entry)) id = str.encode(yt_dlp.utils.unsmuggle_url(entry["id"])[0]) ehash = blake3(id).hexdigest() if ehash not in hashes: @@ -144,7 +145,7 @@ class Updater: self.hashes = None async def update_url(self, url: str): - print(f"Updating {url}...", file=sys.stderr) + logger.info(f"Updating {url}...") new_entries = await self.fetcher.get_unprocessed_entries(url, self.hashes) await asyncio.gather( @@ -163,8 +164,10 @@ def update(): max_backlog = int(sys.argv[1]) subscriptions_number = int(sys.argv[2]) u = Updater(max_backlog=max_backlog) - u.update(sys.argv[3:(3 + subscriptions_number)], sys.argv[(3 + subscriptions_number):]) + u.update( + sys.argv[4 : (4 + subscriptions_number)], sys.argv[(4 + subscriptions_number) :] + ) -print(sys.argv, file=sys.stderr) +logger.debug(sys.argv) update() diff --git a/src/main.rs b/src/main.rs index ebbb45f..53cfc9e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -95,7 +95,7 @@ async fn main() -> Result<()> { } } - update::update(&app, max_backlog, subscriptions, concurrent_processes).await?; + update::update(&app, max_backlog, subscriptions, args.verbosity).await?; } Command::Subscriptions { cmd } => match cmd { diff --git a/src/update/mod.rs b/src/update/mod.rs index d96e3d1..c913195 100644 --- a/src/update/mod.rs +++ b/src/update/mod.rs @@ -12,7 +12,7 @@ use std::{collections::HashMap, process::Stdio, str::FromStr}; use anyhow::{Context, Ok, Result}; use chrono::{DateTime, Utc}; -use log::{error, info, warn}; +use log::{debug, error, info, warn}; use tokio::{ io::{AsyncBufReadExt, BufReader}, process::Command, @@ -35,10 +35,18 @@ pub async fn update( app: &App, max_backlog: u32, subs_to_update: Vec<String>, - _concurrent_processes: usize, + verbosity: u8, ) -> Result<()> { let subscriptions = get_subscriptions(&app).await?; let mut back_subs: HashMap<Url, Subscription> = HashMap::new(); + let logging = verbosity > 0; + let log_level = match verbosity { + // 0 => 50, // logging.CRITICAL + 0 => 40, // logging.ERROR + 1 => 30, // logging.WARNING + 2 => 20, // logging.INFO + 3.. => 10, // logging.DEBUG + }; let mut urls: Vec<String> = vec![]; for (name, sub) in subscriptions.0 { @@ -60,10 +68,15 @@ pub async fn update( let mut child = Command::new("raw_update.py") .arg(max_backlog.to_string()) .arg(urls.len().to_string()) + .arg(log_level.to_string()) .args(&urls) .args(&hashes.iter().map(|haz| haz.to_string()).collect::<Vec<_>>()) .stdout(Stdio::piped()) - .stderr(Stdio::null()) + .stderr(if logging { + Stdio::inherit() + } else { + Stdio::null() + }) .stdin(Stdio::null()) .spawn() .context("Failed to call python3 update_raw")?; @@ -95,7 +108,12 @@ pub async fn update( let out = child.wait().await?; if !out.success() { - error!("The update_raw.py invokation failed for all subscriptions.") + error!( + "The update_raw.py invokation failed (exit code: {}).", + out.code() + .map(|f| f.to_string()) + .unwrap_or("<No exit code>".to_owned()) + ) } Ok(()) |