Add Kitsu-to-IMDB anime mapping infrastructure#461
Conversation
|
Caution Review failedThe pull request is closed. WalkthroughAdds Kitsu-to-IMDB anime mapping support: new DB table, AnimeMapper caching and accessor, stream endpoint remapping for Kitsu media IDs, and TorrentManager constructor/behavior extended to accept and use remapped search_episode/search_season and is_kitsu flags. Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Client Request
participant Stream as Stream Endpoint
participant Mapper as AnimeMapper
participant DB as Database
participant TorrentMgr as TorrentManager
participant Scraper as Torrent Scraper
Client->>Stream: Request with media_id "kitsu:<id>" and episode
Stream->>Mapper: get_kitsu_episode_mapping(kitsu_id)
Mapper->>DB: read kitsu_imdb_mapping cache / table
DB-->>Mapper: return offset (from_season, from_episode)
Mapper-->>Stream: mapping (or None)
Stream->>Stream: compute is_kitsu, search_episode, search_season
Stream->>TorrentMgr: instantiate with is_kitsu + search_episode/search_season
TorrentMgr->>Scraper: scrape using search_season/search_episode
Scraper-->>TorrentMgr: return torrent candidates
TorrentMgr->>TorrentMgr: filter/compare using search_episode (Kitsu-aware)
TorrentMgr-->>Stream: filtered results
Stream-->>Client: respond with results
Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In @comet/services/anime.py:
- Line 282: The tuple unpacking captures an unused value `total_fribb`; change
the unpack to signal intentional unusedness by prefixing it (e.g.,
`total_entries, _total_fribb = await self._persist_mapping(...)`) or remove the
second target and only capture `total_entries` (e.g., assign the call result and
take index 0). Update the line where `total_entries, total_fribb = await
self._persist_mapping(...)` is used to avoid the unused variable warning while
keeping the call to `_persist_mapping`.
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
comet/api/endpoints/stream.pycomet/core/database.pycomet/services/anime.pycomet/services/orchestration.py
🧰 Additional context used
🧬 Code graph analysis (2)
comet/core/database.py (1)
comet/core/db_router.py (1)
execute(72-73)
comet/api/endpoints/stream.py (2)
comet/services/anime.py (1)
get_kitsu_episode_mapping(163-167)comet/utils/network_manager.py (1)
get(283-284)
🪛 Ruff (0.14.10)
comet/services/anime.py
228-228: Do not catch blind exception: Exception
(BLE001)
282-282: Unpacked variable total_fribb is never used
Prefix it with an underscore or any other dummy variable pattern
(RUF059)
500-500: Consider moving this statement to an else block
(TRY300)
501-501: Do not catch blind exception: Exception
(BLE001)
🔇 Additional comments (14)
comet/core/database.py (1)
373-383: LGTM! Clean table definition for Kitsu-IMDB mapping.The new
kitsu_imdb_mappingtable schema is well-structured with appropriate column types and a primary key onkitsu_id. The placement in the setup flow is logical.comet/api/endpoints/stream.py (2)
322-340: LGTM! Well-implemented Kitsu episode mapping logic.The mapping retrieval and episode/season adjustment logic is correct:
- Safe dictionary access with
.get()- Proper conditional checks before applying adjustments
- Episode calculation
from_episode + episode - 1correctly maps Kitsu episodes to the target numbering scheme- Helpful logging for debugging multi-part anime
355-357: LGTM! Proper parameter passing to TorrentManager.Correctly passes the new Kitsu-aware parameters to TorrentManager, enabling episode/season remapping for anime content.
comet/services/anime.py (6)
48-52: LGTM! Clean initialization of Kitsu mapping infrastructure.The in-memory cache and URL constant are well-placed and follow existing patterns.
64-82: LGTM! Proper integration of Kitsu cache loading.The refresh logic correctly handles both stale cache and missing Kitsu data scenarios. The updated log message accurately reflects the loaded data including Kitsu episode offsets.
163-167: LGTM! Clean accessor method.Properly checks loading state and handles the Kitsu ID lookup with appropriate type conversion.
208-229: LGTM! Efficient Kitsu episode cache loading.The filtering logic is smart - only caches entries with meaningful episode/season offsets (
from_episode > 1or customfrom_season). Error handling is appropriate for a non-critical cache operation.
307-314: LGTM! Proper reload sequence after persistence.The code correctly reloads both provider IDs and the Kitsu episode cache after persisting new data. The log message provides useful feedback about what was loaded.
449-503: LGTM! Well-implemented batch persistence with proper error handling.The method correctly:
- Uses batching for efficiency (1000 records per batch)
- Wraps operations in a transaction for atomicity
- Validates input data before insertion
- Uses
ON CONFLICTfor proper upsert behavior- Returns the total count for logging
The blind exception handling is acceptable for a persistence operation where any error should be caught and logged.
comet/services/orchestration.py (5)
31-48: LGTM! Clean parameter additions with proper defaults.The new
search_episodeandsearch_seasonparameters are well-integrated:
- Sensible defaults that fall back to the original
episode/seasonvalues- Maintains backward compatibility
- Proper initialization as instance attributes
71-72: LGTM! Correct usage in scrape request.The scrape request correctly uses
search_seasonandsearch_episode, ensuring that scrapers search for the remapped episode numbers when dealing with Kitsu content.
87-94: LGTM! Proper episode filtering for Kitsu content.The filtering logic correctly differentiates between Kitsu and non-Kitsu content:
- Kitsu: compares against
search_episode(the remapped value)- Non-Kitsu: uses original
seasonandepisodevaluesThis ensures torrents match the correct episode numbering scheme.
108-135: LGTM! Correct database queries for Kitsu content.The cached torrent retrieval properly distinguishes between Kitsu and non-Kitsu:
- Kitsu: queries using
search_episode(line 118) to find torrents matching the remapped episode- Non-Kitsu: queries using original
seasonandepisodevalues
142-145: LGTM! Smart handling of season packs.When the cached row doesn't specify an episode but the parsed data has episodes (season packs), the code correctly:
- Uses
search_episodefor Kitsu content (the remapped value)- Uses
episodefor non-Kitsu content- Validates the target episode is actually in the parsed data
Summary by CodeRabbit
New Features
Improvements
✏️ Tip: You can customize this high-level summary in your review settings.