style(audiobooks_library): ruff changes

This commit is contained in:
Lucas Vivo committed 2026-11-20 15:58:04 +01:00
1 parent 06f290e99a
commit cc4b092a08
1 file changed
+9 -7
@@ -6,14 +6,14 @@ import logging
import re import re
import sqlite3 import sqlite3
import subprocess import subprocess
import requests
import sys import sys
from typing import Any
import tempfile import tempfile
from collections import defaultdict from collections import defaultdict
from concurrent.futures import ThreadPoolExecutor, as_completed from concurrent.futures import ThreadPoolExecutor, as_completed
from pathlib import Path from pathlib import Path
from typing import Any
import requests
from mutagen import File from mutagen import File
from mutagen.id3 import ( from mutagen.id3 import (
COMM, COMM,
@@ -35,11 +35,11 @@ from serverlibrary import (
CustomLogger, CustomLogger,
blue_tag, blue_tag,
green_tag, green_tag,
parser_add_loglevel,
red_tag, red_tag,
score_match_jaccard, score_match_jaccard,
setup_logging, setup_logging,
words, words,
parser_add_loglevel
) )
ID3_FRAME_CLASSES = { ID3_FRAME_CLASSES = {
@@ -1359,20 +1359,21 @@ class AudiobookLibrary:
self.embed_metadata_for_book(item_id) self.embed_metadata_for_book(item_id)
except Exception as e: except Exception as e:
logger.error(f"Failed: {book_name}: {e}") logger.error(f"Failed: {book_name}: {e}")
raise
def embed_metadata_from_file(self, filename: str) -> None: def embed_metadata_from_file(self, filename: str) -> None:
filename = Path(filename).expanduser().resolve() resolved_path = Path(filename).expanduser().resolve()
with open(filename, encoding="utf-8") as f: with open(resolved_path, encoding="utf-8") as f:
item_ids = [ item_ids = [
line.strip() line.strip()
for line in f for line in f
if line.strip() and not line.startswith("#") if line.strip() and not line.startswith("#")
] ]
logger.info(f"Loaded {len(item_ids)} item IDs from {filename}") logger.info(f"Loaded {len(item_ids)} item IDs from {resolved_path}")
for item_id in item_ids: for item_id in item_ids:
book = next( books = next(
(b for b in self.books if b["id"] == item_id), (b for b in self.books if b["id"] == item_id),
None None
) )
@@ -1380,6 +1381,7 @@ class AudiobookLibrary:
self.embed_metadata_for_book(item_id) self.embed_metadata_for_book(item_id)
except Exception as e: except Exception as e:
logger.error(f"Failed: {item_id}: {e}") logger.error(f"Failed: {item_id}: {e}")
raise
def add(self, book: Audiobook): def add(self, book: Audiobook):