Skip to content

Commit

Permalink
fix: add infohash to scraped log msg. added exclude for unreleased to…
Browse files Browse the repository at this point in the history
… retry lib.
  • Loading branch information
dreulavelle committed Sep 13, 2024
1 parent f7668c6 commit 9491e53
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/program/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def _retry_library(self) -> None:
with db.Session() as session:
count = session.execute(
select(func.count(MediaItem._id))
.where(MediaItem.last_state != States.Completed)
.where(MediaItem.last_state.not_in([States.Completed, States.Unreleased]))
.where(MediaItem.type.in_(["movie", "show"]))
).scalar_one()

Expand All @@ -207,7 +207,7 @@ def _retry_library(self) -> None:
items_to_submit = []
items_to_submit += session.execute(
select(MediaItem)
.where(MediaItem.last_state != States.Completed)
.where(MediaItem.last_state.not_in([States.Completed, States.Unreleased]))
.where(MediaItem.type.in_(["movie", "show"]))
.order_by(MediaItem.requested_at.desc())
.limit(number_of_rows_per_page)
Expand Down
19 changes: 10 additions & 9 deletions src/program/scrapers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import threading
from copy import copy
from datetime import datetime
from typing import Dict, Generator, List, Union

Expand All @@ -18,7 +17,6 @@
from program.scrapers.torrentio import Torrentio
from program.scrapers.zilean import Zilean
from program.settings.manager import settings_manager
from RTN import Torrent
from utils.logger import logger


Expand Down Expand Up @@ -117,20 +115,23 @@ def run_service(service, item,):
top_results = list(sorted_streams.values())[:10]
for sorted_tor in top_results:
if isinstance(item, (Movie, Show)):
logger.debug(f"[{item_type}] Parsed '{sorted_tor.parsed_title}' with rank {sorted_tor.rank} and ratio {sorted_tor.lev_ratio:.2f}: '{sorted_tor.raw_title}'")
logger.debug(f"[{item_type}] Parsed '{sorted_tor.parsed_title}' with rank {sorted_tor.rank} ({sorted_tor.infohash}): '{sorted_tor.raw_title}'")
if isinstance(item, Season):
logger.debug(f"[{item_type} {item.number}] Parsed '{sorted_tor.parsed_title}' with rank {sorted_tor.rank} and ratio {sorted_tor.lev_ratio:.2f}: '{sorted_tor.raw_title}'")
logger.debug(f"[{item_type} {item.number}] Parsed '{sorted_tor.parsed_title}' with rank {sorted_tor.rank} ({sorted_tor.infohash}): '{sorted_tor.raw_title}'")
elif isinstance(item, Episode):
logger.debug(f"[{item_type} {item.parent.number}:{item.number}] Parsed '{sorted_tor.parsed_title}' with rank {sorted_tor.rank} and ratio {sorted_tor.lev_ratio:.2f}: '{sorted_tor.raw_title}'")
logger.debug(f"[{item_type} {item.parent.number}:{item.number}] Parsed '{sorted_tor.parsed_title}' with rank {sorted_tor.rank} ({sorted_tor.infohash}): '{sorted_tor.raw_title}'")
return sorted_streams

@classmethod
def can_we_scrape(cls, item: MediaItem) -> bool:
"""Check if we can scrape an item."""
if item.is_released and cls.should_submit(item):
return True
logger.debug(f"Conditions not met, will not scrape {item.log_string}")
return False
if not item.is_released:
logger.debug(f"Cannot scrape {item.log_string}: Item is not released")
return False
if not cls.should_submit(item):
logger.debug(f"Cannot scrape {item.log_string}: Item has been scraped recently, backing off")
return False
return True

@staticmethod
def should_submit(item: MediaItem) -> bool:
Expand Down

0 comments on commit 9491e53

Please sign in to comment.