Task 3: remove non-reentrant TMDB context in NFOService and mark task done
This commit is contained in:
@@ -98,6 +98,8 @@ If the TMDB API key is configured only via `config.json` (not the `TMDB_API_KEY`
|
|||||||
|
|
||||||
## Task 3 — Remove non-reentrant `async with self.tmdb_client:` from NFOService public methods
|
## Task 3 — Remove non-reentrant `async with self.tmdb_client:` from NFOService public methods
|
||||||
|
|
||||||
|
- [x] Completed
|
||||||
|
|
||||||
### Where
|
### Where
|
||||||
`src/core/services/nfo_service.py` — `create_tvshow_nfo` (~line 151) and `update_tvshow_nfo` (~line 265)
|
`src/core/services/nfo_service.py` — `create_tvshow_nfo` (~line 151) and `update_tvshow_nfo` (~line 265)
|
||||||
|
|
||||||
|
|||||||
@@ -146,7 +146,9 @@ class NFOService:
|
|||||||
logger.info("Creating series folder: %s", folder_path)
|
logger.info("Creating series folder: %s", folder_path)
|
||||||
folder_path.mkdir(parents=True, exist_ok=True)
|
folder_path.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
async with self.tmdb_client:
|
try:
|
||||||
|
await self.tmdb_client._ensure_session()
|
||||||
|
|
||||||
# Search for TV show with clean name (without year)
|
# Search for TV show with clean name (without year)
|
||||||
logger.debug("Searching TMDB for: %s", search_name)
|
logger.debug("Searching TMDB for: %s", search_name)
|
||||||
search_results = await self.tmdb_client.search_tv_show(search_name)
|
search_results = await self.tmdb_client.search_tv_show(search_name)
|
||||||
@@ -202,6 +204,8 @@ class NFOService:
|
|||||||
)
|
)
|
||||||
|
|
||||||
return nfo_path
|
return nfo_path
|
||||||
|
finally:
|
||||||
|
await self.tmdb_client.close()
|
||||||
|
|
||||||
async def update_tvshow_nfo(
|
async def update_tvshow_nfo(
|
||||||
self,
|
self,
|
||||||
@@ -260,8 +264,8 @@ class NFOService:
|
|||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
raise TMDBAPIError(f"Invalid TMDB ID format in NFO: {e}")
|
raise TMDBAPIError(f"Invalid TMDB ID format in NFO: {e}")
|
||||||
|
|
||||||
# Fetch fresh data from TMDB
|
try:
|
||||||
async with self.tmdb_client:
|
await self.tmdb_client._ensure_session()
|
||||||
logger.debug("Fetching fresh data for TMDB ID: %s", tmdb_id)
|
logger.debug("Fetching fresh data for TMDB ID: %s", tmdb_id)
|
||||||
details = await self.tmdb_client.get_tv_show_details(
|
details = await self.tmdb_client.get_tv_show_details(
|
||||||
tmdb_id,
|
tmdb_id,
|
||||||
@@ -299,6 +303,8 @@ class NFOService:
|
|||||||
)
|
)
|
||||||
|
|
||||||
return nfo_path
|
return nfo_path
|
||||||
|
finally:
|
||||||
|
await self.tmdb_client.close()
|
||||||
|
|
||||||
def parse_nfo_ids(self, nfo_path: Path) -> Dict[str, Optional[int]]:
|
def parse_nfo_ids(self, nfo_path: Path) -> Dict[str, Optional[int]]:
|
||||||
"""Parse TMDB ID and TVDB ID from an existing NFO file.
|
"""Parse TMDB ID and TVDB ID from an existing NFO file.
|
||||||
|
|||||||
Reference in New Issue
Block a user