Skip to content

Commit

Permalink
fix: housekeeping
Browse files Browse the repository at this point in the history
  • Loading branch information
dreulavelle committed Sep 26, 2024
1 parent 40636dc commit 2308ce5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 26 deletions.
7 changes: 2 additions & 5 deletions src/controllers/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from program.settings.versions import models
from program.settings.manager import settings_manager
from program.media.stream import Stream
from program.scrapers.shared import rtn
from program.types import Event
from utils.logger import logger

Expand Down Expand Up @@ -84,7 +85,7 @@ async def get_items(
filter_lower = state.lower()
filter_state = None
for state_enum in States:
if Levenshtein.distance(filter_lower, state_enum.name.lower()) <= 0.82:
if Levenshtein.ratio(filter_lower, state_enum.name.lower()) <= 0.82:
filter_state = state_enum
break
if filter_state:
Expand Down Expand Up @@ -307,10 +308,6 @@ def create_stream(hash, torrent_info):
def set_torrent_rd(request: Request, id: int, torrent_id: str):

downloader: Downloader = request.app.program.services.get(Downloader)
settings_model = settings_manager.settings.ranking
ranking_model = models.get(settings_model.profile)
rtn = RTN(settings_model, ranking_model)

with db.Session() as session:
item: MediaItem = session.execute(select(MediaItem).where(MediaItem._id == id).outerjoin(MediaItem.streams)).unique().scalar_one_or_none()

Expand Down
23 changes: 2 additions & 21 deletions src/program/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,7 @@
from queue import Empty

from apscheduler.schedulers.background import BackgroundScheduler
from rich.console import Console
from rich.live import Live
from rich.progress import (
BarColumn,
Progress,
SpinnerColumn,
TextColumn,
TimeRemainingColumn,
)

import utils.websockets.manager as ws_manager
from program.content import Listrr, Mdblist, Overseerr, PlexWatchlist, TraktContent
Expand All @@ -32,7 +24,7 @@
from program.updaters import Updater
from utils import data_dir_path
from utils.event_manager import EventManager
from utils.logger import log_cleaner, logger
from utils.logger import create_progress_bar, log_cleaner, logger

from .state_transition import process_event
from .symlink import Symlinker
Expand Down Expand Up @@ -357,18 +349,7 @@ def _init_db_from_symlinks(self):
if settings_manager.settings.map_metadata:
logger.log("PROGRAM", "Collecting items from symlinks, this may take a while depending on library size")
items = self.services[SymlinkLibrary].run()
console = Console()
progress = Progress(
SpinnerColumn(),
TextColumn("[progress.description]{task.description}"),
BarColumn(),
TextColumn("[progress.percentage]{task.percentage:>3.0f}%"),
TimeRemainingColumn(),
TextColumn("[progress.completed]{task.completed}/{task.total}", justify="right"),
TextColumn("[progress.log]{task.fields[log]}", justify="right"),
console=console,
transient=True
)
progress, console = create_progress_bar(len(items))

task = progress.add_task("Enriching items with metadata", total=len(items), log="")
with Live(progress, console=console, refresh_per_second=10):
Expand Down
24 changes: 24 additions & 0 deletions src/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@

from loguru import logger
from rich.console import Console
from rich.progress import (
BarColumn,
Progress,
SpinnerColumn,
TextColumn,
TimeRemainingColumn,
)

from program.settings.manager import settings_manager
from utils import data_dir_path
Expand Down Expand Up @@ -124,6 +131,23 @@ def log_cleaner():
logger.error(f"Failed to clean old logs: {e}")


def create_progress_bar(total_items: int) -> Progress:
"""Setup a progress bar for the console"""
console = Console()
progress = Progress(
SpinnerColumn(),
TextColumn("[progress.description]{task.description}"),
BarColumn(),
TextColumn("[progress.percentage]{task.percentage:>3.0f}%"),
TimeRemainingColumn(),
TextColumn(f"[progress.completed]{{task.completed}}/{total_items}", justify="right"),
TextColumn("[progress.log]{task.fields[log]}", justify="right"),
console=console,
transient=True
)
return progress, console


console = Console()
log_level = "DEBUG" if settings_manager.settings.debug else "INFO"
setup_logger(log_level)

0 comments on commit 2308ce5

Please sign in to comment.