Skip to content

Commit

Permalink
fix: handle removal of nested media items in remove_item function (#840)
Browse files Browse the repository at this point in the history
- Ensure cancellation and deletion of episodes and seasons for shows
- Add handling for nested media items in the remove_item function
  • Loading branch information
iPromKnight authored Nov 2, 2024
1 parent f91ffec commit 2096a4e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/routers/secure/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,23 @@ class RemoveResponse(BaseModel):
async def remove_item(request: Request, ids: str) -> RemoveResponse:
ids: list[str] = handle_ids(ids)
try:
media_items: list[str] = db_functions.get_items_by_ids(ids, ["movie", "show"])
media_items: list[MediaItem] = db_functions.get_items_by_ids(ids, ["movie", "show"])
if not media_items:
return HTTPException(status_code=404, detail="Item(s) not found")
for item in media_items:
logger.debug(f"Removing item with ID {item.id}")
request.app.program.em.cancel_job(item.id)
await asyncio.sleep(0.2) # Ensure cancellation is processed
if item.type == "show":
for season in item.seasons:
for episode in season.episodes:
request.app.program.em.cancel_job(episode.id)
await asyncio.sleep(0.2)
db_functions.delete_media_item_by_id(episode.id)
request.app.program.em.cancel_job(season.id)
await asyncio.sleep(0.2)
db_functions.delete_media_item_by_id(season.id)

db_functions.clear_streams_by_id(item.id)

symlink_service = request.app.program.services.get(Symlinker)
Expand Down

0 comments on commit 2096a4e

Please sign in to comment.