about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-08-22 20:21:27 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-08-22 20:21:27 +0200
commit85943861ea66ee5eaf40aa2c405892636b59ce71 (patch)
tree765b376c7de957f1be59a1f07bdba2e62e3e54be
parentfix(package): Actually provide the blake3 library to the python interpreter (diff)
downloadyt-85943861ea66ee5eaf40aa2c405892636b59ce71.tar.gz
yt-85943861ea66ee5eaf40aa2c405892636b59ce71.zip
fix(update): Propagate the logging options to the `update_raw.py` script
Diffstat (limited to '')
-rwxr-xr-xpython_update/raw_update.py11
-rw-r--r--src/main.rs2
-rw-r--r--src/update/mod.rs26
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(())