Skip to content

Feat/subdetect support#652

Open
worldInColors wants to merge 4 commits intoViren070:mainfrom
worldInColors:feat/subdetect-support
Open

Feat/subdetect support#652
worldInColors wants to merge 4 commits intoViren070:mainfrom
worldInColors:feat/subdetect-support

Conversation

@worldInColors
Copy link
Contributor

@worldInColors worldInColors commented Jan 25, 2026

  • Add optional SubDetect support
  • Only runs for scene releases
  • API key is generated client-side via the /generate-key endpoint

Summary by CodeRabbit

  • New Features

    • SubDetect integration: streams are automatically enriched with detected languages to improve metadata completeness.
    • Settings: SubDetect toggle and API key management (including key generation) available in Miscellaneous settings.
    • Parsing: Improved release-name parsing to recognise scene-style suffixes for better detection.
  • Chores

    • User profile now optionally stores SubDetect configuration (enabled status and API key).

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 25, 2026

Walkthrough

SubDetect language-detection is added end-to-end: user schema gains an optional subdetect field; a new SubDetectService calls an external API to detect languages for scene releases; parser regex updated; AIOStreams integrates enrichment into stream processing; frontend UI adds a SubDetect settings card with API-key handling.

Changes

Cohort / File(s) Summary
Schema & Data Model
packages/core/src/db/schemas.ts
Added optional subdetect object to UserDataSchema with enabled?: boolean and apiKey?: string
SubDetect service & utilities
packages/core/src/utils/subdetect.ts, packages/core/src/utils/index.ts
New SubDetect integration: SubDetectService (constructor, isEnabled, detectLanguages), processReleases() batching, isSceneRelease(), ISO-639-2 → language mapping, HTTP handling and logging; re-exported via utils/index.ts
Stream processing
packages/core/src/main.ts
AIOStreams now instantiates SubDetectService and adds _enrichWithSubDetectLanguages(); enrichment runs after deduplication and merges detected languages into ParsedStream metadata with guarded error handling and logging
Parser enhancements
packages/core/src/parser/regex.ts
Added sceneRelease RegExp (/-[a-zA-Z0-9]{2,}$/) to PARSE_REGEX for scene-style release suffix detection
Frontend configuration
packages/frontend/src/components/menu/miscellaneous.tsx
Added SubDetectCard component: toggle for subdetect.enabled, API-key generation POST, user-data updates, local loading/error state; rendered in pro-mode settings

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant Frontend as Frontend UI
    participant Backend as AIOStreams
    participant DB as User Data Store
    participant SubDetectAPI as SubDetect API

    User->>Frontend: Enable SubDetect
    alt API Key missing
        Frontend->>Backend: POST /generate-api-key
        Backend->>SubDetectAPI: Request key / register
        SubDetectAPI-->>Backend: API key
        Backend-->>Frontend: API key returned
    end
    Frontend->>DB: Save subdetect {enabled, apiKey}
    DB-->>Frontend: Persisted

    rect rgba(100, 150, 255, 0.5)
    Backend->>Backend: Collect streams grouped by release name
    Backend->>SubDetectAPI: POST releases (batched ≤20)
    SubDetectAPI-->>Backend: Results with language_codes
    Backend->>Backend: Convert ISO-639-2 → language names
    Backend->>Backend: Merge languages into stream.parsedFile.languages
    end

    Backend-->>Frontend: Enriched streams
    Frontend->>User: Display languages
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • Viren070

Poem

🐰 I found a key and hopped with glee,

Scene names whispered tongues to me,
Batches sent, codes turned to song,
Streams now speak where they belong,
A rabbit cheers — languages along!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.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 The title accurately summarises the main change—adding SubDetect integration support throughout the codebase across multiple files.

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

✨ Finishing touches
  • 📝 Generate docstrings

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

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 `@packages/core/src/main.ts`:
- Around line 2172-2230: The _enrichWithSubDetectLanguages method currently
calls this.subdetectService.detectLanguages which can throw and break the
pipeline; wrap the detectLanguages call in a try/catch and on any error log a
warning via logger.warn including the error and return the original streams
(i.e., fail open) so enrichment is optional; ensure subsequent logic only runs
when detectLanguages succeeds (e.g., skip enrichment if detectedLanguages is
undefined/null).

In `@packages/server/src/app.ts`:
- Around line 16-17: The import fails because subdetectApi is not exported from
the API barrel; open the module that should declare the route (the router or
handler named subdetectApi in packages/server/src/routes/api/index.ts or its
submodule) and either add a named export for subdetectApi (export const
subdetectApi = ... or export { subdetectApi } from './subdetect') or re-export
it from the barrel (export { subdetectApi } from './subdetect') so the import in
app.ts can resolve; confirm the route module exists and that the exported symbol
name exactly matches subdetectApi used in the import.
🧹 Nitpick comments (3)
packages/core/src/utils/subdetect.ts (2)

8-9: Consider making the SubDetect base URL configurable.

Hard-coding the API host makes self-hosting or staging environments awkward. A small Env-driven override would keep the default while enabling custom deployments.

♻️ Possible tweak
-import { makeRequest } from './http.js';
+import { makeRequest } from './http.js';
+import { Env } from './env.js';
 ...
-const SUBDETECT_API_URL = 'https://subdetect.chromeknight.dev';
+const SUBDETECT_API_URL =
+  Env.SUBDETECT_API_URL ?? 'https://subdetect.chromeknight.dev';

39-44: Avoid repeated linear scans for language lookups.

FULL_LANGUAGE_MAPPING.find(...) runs for every language code; a precomputed map is a low-cost optimisation when processing batches.

♻️ Suggested change
-export function convertISO6392ToLanguage(code: string): string | undefined {
-  const lang = FULL_LANGUAGE_MAPPING.find(
-    (language) => language.iso_639_2 === code.toLowerCase()
-  );
-  return lang?.english_name?.split('(')?.[0]?.trim();
-}
+const ISO6392_TO_NAME = new Map(
+  FULL_LANGUAGE_MAPPING.map((language) => [
+    language.iso_639_2?.toLowerCase(),
+    language.english_name?.split('(')?.[0]?.trim(),
+  ]).filter(
+    (entry): entry is [string, string] => Boolean(entry[0] && entry[1])
+  )
+);
+
+export function convertISO6392ToLanguage(code: string): string | undefined {
+  return ISO6392_TO_NAME.get(code.toLowerCase());
+}
packages/frontend/src/components/menu/miscellaneous.tsx (1)

451-459: Consider avoiding the hard-coded SubDetect host.

Using a fixed external URL makes the feature brittle for self-hosted or proxied deployments, and bypasses the new server route. It would be more flexible to call your own API route (or a configurable base URL) so deployments can override the host cleanly.

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