Skip to content

Add Kitsu-to-IMDB anime mapping infrastructure#461

Merged
g0ldyy merged 2 commits into
developmentfrom
feat/kitsu-offset
Jan 9, 2026
Merged

Add Kitsu-to-IMDB anime mapping infrastructure#461
g0ldyy merged 2 commits into
developmentfrom
feat/kitsu-offset

Conversation

@g0ldyy

@g0ldyy g0ldyy commented Jan 9, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Added Kitsu anime source for episode/season mapping and catalog matching
    • Automatic handling of multi-part anime episodes with episode offset adjustments
  • Improvements

    • More accurate anime-to-IMDB mapping and refreshed caching for faster lookups
    • Search and torrent matching use mapped episode/season values for better results

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 9, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

Walkthrough

Adds 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

Cohort / File(s) Summary
Database Schema
comet/core/database.py
Adds kitsu_imdb_mapping table (kitsu_id, imdb_id, title, from_season, from_episode) created during DB setup.
Anime Mapping Service
comet/services/anime.py
Adds in-memory _kitsu_mapping_cache, _kitsu_imdb_url, loader _load_kitsu_mapping_cache, persister _persist_kitsu_imdb_mapping(), refresh integration, and public get_kitsu_episode_mapping(kitsu_id) accessor.
Stream Endpoint
comet/api/endpoints/stream.py
Detects media_id starting with kitsu:, calls anime_mapper.get_kitsu_episode_mapping(), computes is_kitsu, search_episode, search_season, logs adjustments, and passes these into TorrentManager.
Torrent Orchestration
comet/services/orchestration.py
TorrentManager.__init__ signature extended to accept is_kitsu, search_episode, search_season; adds self.search_episode/self.search_season and uses them in scrape requests, caching queries, and Kitsu-specific filtering/row parsing.

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
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed Title check skipped as CodeRabbit has written the PR title.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4af9add and c7214f2.

📒 Files selected for processing (2)
  • comet/api/endpoints/stream.py
  • comet/services/anime.py

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot changed the title @coderabbitai Add Kitsu-to-IMDB anime mapping infrastructure Jan 9, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 67f7740 and 4af9add.

📒 Files selected for processing (4)
  • comet/api/endpoints/stream.py
  • comet/core/database.py
  • comet/services/anime.py
  • comet/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_mapping table schema is well-structured with appropriate column types and a primary key on kitsu_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 - 1 correctly 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 > 1 or custom from_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 CONFLICT for 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_episode and search_season parameters are well-integrated:

  • Sensible defaults that fall back to the original episode/season values
  • Maintains backward compatibility
  • Proper initialization as instance attributes

71-72: LGTM! Correct usage in scrape request.

The scrape request correctly uses search_season and search_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 season and episode values

This 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 season and episode values

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_episode for Kitsu content (the remapped value)
  • Uses episode for non-Kitsu content
  • Validates the target episode is actually in the parsed data

Comment thread comet/services/anime.py
Comment thread comet/services/anime.py Outdated
@g0ldyy g0ldyy merged commit 85de14d into development Jan 9, 2026
1 check was pending
@g0ldyy g0ldyy deleted the feat/kitsu-offset branch January 9, 2026 01:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant