Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add denied reasoning when trashing torrents and added adult parsing #888

Merged
merged 5 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
426 changes: 217 additions & 209 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ alembic = "^1.13.2"
psycopg2-binary = "^2.9.9"
apprise = "^1.8.1"
subliminal = "^2.2.1"
rank-torrent-name = "^1.0.2"
rank-torrent-name = ">=1.5,<2.0"
jsonschema = "^4.23.0"
scalar-fastapi = "^1.0.3"
psutil = "^6.0.0"
Expand Down
5 changes: 2 additions & 3 deletions src/program/apis/overseerr_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ def get_media_requests(self, service_key: str) -> list[MediaItem]:
MediaItem({
"imdb_id": imdb_id,
"requested_by": service_key,
"overseerr_id": item.media.id,
"requested_id": item.id
"overseerr_id": item.media.id
})
)
elif item.media.tmdbId:
Expand Down Expand Up @@ -137,7 +136,7 @@ def delete_request(self, mediaId: int) -> bool:
try:
response = self.request_handler.execute(HttpMethod.DELETE, f"api/v1/request/{mediaId}", headers=headers)
logger.debug(f"Deleted request {mediaId} from overseerr")
return response.is_ok == True
return response.is_ok
except Exception as e:
logger.error(f"Failed to delete request from overseerr: {str(e)}")
return False
Expand Down
4 changes: 2 additions & 2 deletions src/program/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def _update_ongoing(self) -> None:
).scalars().all()

if not item_ids:
logger.debug("PROGRAM", "No ongoing or unreleased items to update.")
logger.debug("No ongoing or unreleased items to update.")
return

logger.debug(f"Updating state for {len(item_ids)} ongoing and unreleased items.")
Expand All @@ -242,7 +242,7 @@ def _update_ongoing(self) -> None:
except Exception as e:
logger.error(f"Failed to update state for item with ID {item_id}: {e}")

logger.debug("PROGRAM", f"Found {counter} items with updated state.")
logger.debug(f"Found {counter} items with updated state.")

def _schedule_functions(self) -> None:
"""Schedule each service based on its update interval."""
Expand Down
4 changes: 2 additions & 2 deletions src/program/services/scrapers/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ def _parse_results(item: MediaItem, results: Dict[str, str], log_msg: bool = Tru
if settings_manager.settings.scraping.parse_debug and log_msg:
logger.debug(f"Skipping torrent: '{raw_title}' - {e}")
continue
except GarbageTorrent:
except GarbageTorrent as e:
if settings_manager.settings.scraping.parse_debug and log_msg:
logger.debug(f"Trashing torrent for {item.log_string}: '{raw_title}'")
logger.debug(e)
continue

if torrents:
Expand Down
2 changes: 1 addition & 1 deletion src/program/settings/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ class ScraperModel(Observable):


class RTNSettingsModel(SettingsModel, Observable):
profile: str = "default"
...


# Application Settings
Expand Down
10 changes: 5 additions & 5 deletions src/routers/secure/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,11 @@ async def remove_item(request: Request, ids: str) -> RemoveResponse:
if symlink_service:
symlink_service.delete_item_symlinks_by_id(item.id)

with db.Session() as session:
requested_id = session.execute(select(MediaItem.requested_id).where(MediaItem.id == item.id)).scalar_one()
if requested_id:
logger.debug(f"Deleting request from Overseerr with ID {requested_id}")
Overseerr.delete_request(requested_id)
if item.overseerr_id:
overseerr: Overseerr = request.app.program.services.get(Overseerr)
if overseerr:
overseerr.delete_request(item.overseerr_id)
logger.debug(f"Deleted request from Overseerr with ID {item.overseerr_id}")
Comment on lines +354 to +358
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance error handling for Overseerr request deletion

While the Overseerr integration looks good, the error handling could be improved to handle potential failures when deleting requests.

Consider wrapping the Overseerr request deletion in a try-catch block:

             if item.overseerr_id:
                 overseerr: Overseerr = request.app.program.services.get(Overseerr)
                 if overseerr:
-                    overseerr.delete_request(item.overseerr_id)
-                    logger.debug(f"Deleted request from Overseerr with ID {item.overseerr_id}")
+                    try:
+                        overseerr.delete_request(item.overseerr_id)
+                        logger.debug(f"Deleted request from Overseerr with ID {item.overseerr_id}")
+                    except Exception as e:
+                        logger.error(f"Failed to delete Overseerr request {item.overseerr_id}: {str(e)}")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if item.overseerr_id:
overseerr: Overseerr = request.app.program.services.get(Overseerr)
if overseerr:
overseerr.delete_request(item.overseerr_id)
logger.debug(f"Deleted request from Overseerr with ID {item.overseerr_id}")
if item.overseerr_id:
overseerr: Overseerr = request.app.program.services.get(Overseerr)
if overseerr:
try:
overseerr.delete_request(item.overseerr_id)
logger.debug(f"Deleted request from Overseerr with ID {item.overseerr_id}")
except Exception as e:
logger.error(f"Failed to delete Overseerr request {item.overseerr_id}: {str(e)}")


logger.debug(f"Deleting item from database with ID {item.id}")
db_functions.delete_media_item_by_id(item.id)
Expand Down
4 changes: 1 addition & 3 deletions src/routers/secure/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@ async def overseerr(request: Request) -> Dict[str, Any]:
logger.error("Overseerr not initialized")
return {"success": False, "message": "Overseerr not initialized"}

new_item = MediaItem({"imdb_id": imdb_id, "requested_by": "overseerr", "requested_id": req.request.request_id})

new_item = MediaItem({"imdb_id": imdb_id, "requested_by": "overseerr", "overseerr_id": req.request.request_id})
request.app.program.em.add_item(new_item, service="Overseerr")

return {"success": True}


Expand Down
Loading