Skip to content

[Feature] Allow operator to disable stream types#593

Open
funkypenguin wants to merge 2 commits intoViren070:mainfrom
funkypenguin:disabled-stream-types-v2.19.0
Open

[Feature] Allow operator to disable stream types#593
funkypenguin wants to merge 2 commits intoViren070:mainfrom
funkypenguin:disabled-stream-types-v2.19.0

Conversation

@funkypenguin
Copy link
Contributor

@funkypenguin funkypenguin commented Dec 31, 2025

We've implemented this on the ElfHosted instance as of 1 Jan 2026, allowing us to apply our new policy of disabling non-debrid streams (P2P, live, HTTP) on our public instances. I've tried to make it as consistent as possible with the existing DISABLED_ options, and it adds a statistics entry if streams were disabled due to operator policy, like this:

Monosnap Image 2026-01-01 11-57-53

Summary by CodeRabbit

  • New Features
    • Added ability to disable specific stream types via configuration, preventing them from being served to clients. Supports comma-separated list format (e.g., p2p, http, live).

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

Signed-off-by: David Young <davidy@funkypenguin.co.nz>
Signed-off-by: David Young <davidy@funkypenguin.co.nz>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 31, 2025

Walkthrough

This pull request introduces configurable stream type filtering by adding a new environment variable DISABLED_STREAM_TYPES that allows administrators to exclude specific stream types from responses. The implementation filters streams during transformation, tracks counts of disabled streams by type, and updates statistics accordingly.

Changes

Cohort / File(s) Summary
Environment Configuration
.env.sample, packages/core/src/utils/env.ts
Introduces DISABLED_STREAM_TYPES environment variable documentation and validator configuration, enabling comma-separated list of stream types to exclude from client responses (e.g., p2p, http, live).
Stream Filtering Logic
packages/core/src/transformers/stremio.ts
Implements stream type filtering by reading disabled types from environment, filtering streams before transformation, tracking per-type counts of disabled streams, augmenting statistics with a new disabled-types entry, and appending filter summary to logs. Also adjusts convertParsedStreamToStream call with nullish coalescing fallback for provideStreamData.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hops through streams with careful grace,
Filtering types from every place,
With DISABLED_STREAM_TYPES in sight,
We keep the unwanted out of light,
Statistics tracked, the config's tight!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarises the primary change: adding operator configuration to disable specific stream types, which is directly reflected in the file changes across env config, transformer logic, and statistics tracking.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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: 1

🧹 Nitpick comments (2)
packages/core/src/transformers/stremio.ts (2)

289-289: Unrelated improvement: nullish coalescing for provideStreamData.

This change adds ?? false to ensure provideStreamData is always a boolean. While this is a good defensive programming practice, it appears unrelated to the disabled stream types feature.

Consider:

  • Documenting this change in the commit message
  • Verifying if this should be a separate commit/PR

244-301: Consider edge case: all streams filtered.

If all streams match DISABLED_STREAM_TYPES, users will receive an empty response with no explanation (unless statistics are enabled). This could be confusing.

Consider adding a helpful error stream when filteredStreams.length === 0 && streams.length > 0, informing users that all available streams were filtered by operator policy.

💡 Example implementation
 const filteredStreams = disabledStreamTypes.size
   ? streams.filter((stream) => {
       if (disabledStreamTypes.has(stream.type)) {
         filteredOutCounts[stream.type] =
           (filteredOutCounts[stream.type] || 0) + 1;
         return false;
       }
       return true;
     })
   : streams;
+
+// If all streams were filtered and statistics are disabled, show helpful message
+if (filteredStreams.length === 0 && streams.length > 0 && !this.userData.statistics?.enabled) {
+  return {
+    streams: [
+      StremioTransformer.createErrorStream({
+        errorTitle: '🚫 All Streams Filtered',
+        errorDescription: `All ${streams.length} available streams were removed by operator policy (disabled types: ${Array.from(disabledStreamTypes).join(', ')})`,
+      })
+    ]
+  };
+}
📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 878254c and 49843f2.

📒 Files selected for processing (3)
  • .env.sample
  • packages/core/src/transformers/stremio.ts
  • packages/core/src/utils/env.ts
🧰 Additional context used
🧬 Code graph analysis (1)
packages/core/src/transformers/stremio.ts (2)
packages/core/src/db/schemas.ts (2)
  • AIOStream (905-960)
  • AIOStream (962-962)
packages/core/src/utils/logger.ts (1)
  • getTimeTakenSincePoint (152-159)
🔇 Additional comments (4)
packages/core/src/transformers/stremio.ts (4)

244-260: LGTM! Efficient filtering implementation.

The filtering logic is well-structured:

  • Uses a Set for O(1) lookup performance
  • Only filters when necessary (checking disabledStreamTypes.size)
  • Correctly tracks counts per stream type
  • Preserves original array when no filtering is needed

261-276: Statistics tracking implemented correctly.

The implementation properly:

  • Creates a copy of the statistics array before modification
  • Only adds the disabled types statistic when appropriate
  • Provides clear per-type breakdown

The user-facing message "Streams of these types were removed by the operator" effectively communicates the filtering action.


295-301: Logging update enhances observability.

The filtered summary addition to the log message provides clear feedback about filtering actions, including correct pluralisation for singular/plural streams.


317-317: Correct use of augmented statistics list.

Properly uses statisticsList to include the disabled stream types statistic when applicable.

Comment on lines +364 to +367
DISABLED_STREAM_TYPES: str({
default: undefined,
desc: 'Comma separated list of stream types that should never be returned to clients (e.g., p2p,http,live).',
}),
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# First, examine the env.ts file around the DISABLED_STREAM_TYPES definition
echo "=== Examining env.ts around DISABLED_STREAM_TYPES ==="
sed -n '350,380p' packages/core/src/utils/env.ts

Repository: Viren070/AIOStreams

Length of output: 1365


🏁 Script executed:

#!/bin/bash
# Search for StreamTypes definition or constants
echo "=== Searching for StreamTypes definition ==="
rg -nP 'StreamTypes|stream.*type' --type=ts -i | head -30

Repository: Viren070/AIOStreams

Length of output: 3109


🏁 Script executed:

#!/bin/bash
# Search for how DISABLED_STREAM_TYPES is used in the codebase
echo "=== Searching for DISABLED_STREAM_TYPES usage ==="
rg -nP 'DISABLED_STREAM_TYPES' --type=ts -B2 -A2

Repository: Viren070/AIOStreams

Length of output: 933


🏁 Script executed:

#!/bin/bash
# Find the STREAM_TYPES constant definition
echo "=== STREAM_TYPES definition ==="
sed -n '50,80p' packages/frontend/src/components/menu/filters.tsx

Repository: Viren070/AIOStreams

Length of output: 981


🏁 Script executed:

#!/bin/bash
# See how disabledStreamTypes is used after parsing
echo "=== disabledStreamTypes usage context ==="
sed -n '240,270p' packages/core/src/transformers/stremio.ts

Repository: Viren070/AIOStreams

Length of output: 1154


🏁 Script executed:

#!/bin/bash
# Search for actual stream type values in the codebase
echo "=== Stream type values used ==="
rg -nP "type.*:.*['\"](?:p2p|http|live|debrid|usenet|statistic|error)" --type=ts | head -20

Repository: Viren070/AIOStreams

Length of output: 1804


🏁 Script executed:

#!/bin/bash
# Find the STREAM_TYPES constant in constants file
echo "=== STREAM_TYPES constant definition ==="
rg -nP 'export.*STREAM_TYPES' packages/core/src/utils/constants.ts -A10

Repository: Viren070/AIOStreams

Length of output: 587


🏁 Script executed:

#!/bin/bash
# Check all files in constants to find STREAM_TYPES
echo "=== Looking for STREAM_TYPES in constants ==="
cat packages/core/src/utils/constants.ts | grep -A20 "STREAM_TYPES"

Repository: Viren070/AIOStreams

Length of output: 1416


🏁 Script executed:

#!/bin/bash
# Search for stream type definitions or enums
echo "=== Searching for stream type enum or type definition ==="
rg -nP "type.*Stream.*Type|enum.*Stream" --type=ts -B2 -A5 | head -50

Repository: Viren070/AIOStreams

Length of output: 3733


🏁 Script executed:

#!/bin/bash
# Find the actual values of the stream type constants
echo "=== Stream type constant values ==="
grep -nP "(P2P|LIVE|USENET|ARCHIVE|DEBRID|HTTP|EXTERNAL|YOUTUBE|ERROR|STATISTIC)_STREAM_TYPE\s*=" packages/core/src/utils/constants.ts | head -20

Repository: Viren070/AIOStreams

Length of output: 750


Add validation and normalisation for stream types.

The configuration currently accepts any string without validating against known stream types (p2p, live, stremio-usenet, archive, usenet, debrid, http, external, youtube, error, statistic). Additionally, there is no case normalisation during parsing, making the matching case-sensitive. This could lead to silent failures if operators mistype stream types or use incorrect casing.

Consider:

  1. Validating parsed values against the STREAM_TYPES constant to reject invalid entries
  2. Normalising to lowercase during parsing (or during comparison) to prevent case-sensitivity issues
🤖 Prompt for AI Agents
In packages/core/src/utils/env.ts around lines 364-367, the
DISABLED_STREAM_TYPES config currently accepts any string and is case-sensitive;
update it to parse the comma-separated value into trimmed, lowercased tokens,
remove empties, validate each token against the STREAM_TYPES constant, and
reject (throw/raise a config validation error) if any unknown types are present;
normalize the stored value (or comparison path) to the validated lowercased
array so downstream checks are case-insensitive.

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