mirror of
https://github.com/Viren070/AIOStreams.git
synced 2025-12-01 23:14:04 +01:00
Merge pull request #179 from Viren070/rewrite
This commit is contained in:
+386
-137
@@ -1,226 +1,475 @@
|
||||
# ==============================================================================
|
||||
# GENERAL ADDON CONFIGURATION
|
||||
# ESSENTIAL ADDON SETUP
|
||||
# ==============================================================================
|
||||
# These are the most important settings you'll need to configure.
|
||||
|
||||
# --- Addon Identification ---
|
||||
# Descriptive name for your addon instance.
|
||||
ADDON_NAME="AIOStreams"
|
||||
# Unique identifier for your addon.
|
||||
ADDON_ID="aiostreams.viren070.com"
|
||||
# Set to true to generate a deterministic addon ID based on the configuration, useful for apps like Vidi that require a different addon ID for multiple installations
|
||||
DETERMINISTIC_ADDON_ID=true
|
||||
# The port on which the addon will listen on
|
||||
|
||||
# --- Network Configuration ---
|
||||
# The port on which the addon will listen.
|
||||
# Default: 3000
|
||||
PORT=3000
|
||||
# The secret key used for encrypting the addon's configuration
|
||||
# You must use a 64 character **hex** string, use the following commands to generate one:
|
||||
# Linux: openssl rand -hex 32
|
||||
# Windows: [System.Guid]::NewGuid().ToString("N").Substring(0, 32) + [System.Guid]::NewGuid().ToString("N").Substring(0, 32)
|
||||
|
||||
# The base URL of your addon. Highly recommended for proper functioning.
|
||||
# Used for generating installation URLs and identifying self-scraping.
|
||||
# Example: https://aiostreams.yourdomain.com
|
||||
BASE_URL=
|
||||
|
||||
# --- Security ---
|
||||
# CRITICAL: Secret key for encrypting addon configuration.
|
||||
# MUST be a 64-character hex string.
|
||||
# Generate one using:
|
||||
# Linux/macOS: openssl rand -hex 32
|
||||
# Windows (PowerShell): -join ((0..31) | ForEach-Object { '{0:x2}' -f (Get-Random -Minimum 0 -Maximum 255) })
|
||||
# Or: [System.Guid]::NewGuid().ToString("N") + [System.Guid]::NewGuid().ToString("N") (ensure it's 64 chars)
|
||||
SECRET_KEY=
|
||||
# The API key used to install and use the addon, leave empty to disable API key requirement
|
||||
# Can be set to any string
|
||||
API_KEY=
|
||||
|
||||
# Controls whether the addon shows a dice emoji in its stream results
|
||||
SHOW_DIE=false
|
||||
# The log level of the addon, can be set to "debug", "info", "warn", "error"
|
||||
LOG_LEVEL=info
|
||||
# The log format of the addon, can be set to "json" or "text"
|
||||
# API key to protect your addon installation and usage.
|
||||
# Leave empty to disable password protection.
|
||||
# Can be any string.
|
||||
ADDON_PASSWORD=
|
||||
|
||||
# --- Database ---
|
||||
# REQUIRED: The database URI for storing addon configuration.
|
||||
# Supports SQLite (simplest) or PostgreSQL.
|
||||
#
|
||||
# SQLite example (stores data in a file):
|
||||
# DATABASE_URI=sqlite://./data/db.sqlite
|
||||
# (You can change './data/db.sqlite' to your preferred path)
|
||||
#
|
||||
# PostgreSQL example:
|
||||
# DATABASE_URI=postgresql://username:password@host:port/database_name
|
||||
# (e.g., postgresql://postgres:password@localhost:5432/aiostreams)
|
||||
DATABASE_URI=sqlite://./data/db.sqlite
|
||||
|
||||
|
||||
# ==============================================================================
|
||||
# DEBRID & OTHER SERVICE API KEYS
|
||||
# ==============================================================================
|
||||
|
||||
# Provide a default TMDB access token to be used for the Title Matching filter if a user does not provide any.
|
||||
TMDB_ACCESS_TOKEN=
|
||||
|
||||
# Configure API keys for debrid services and others you plan to use.
|
||||
# 'DEFAULT_' values are pre-filled in the user's config page.
|
||||
# 'FORCED_' values override user settings and hide the option.
|
||||
|
||||
# --- Real-Debrid ---
|
||||
DEFAULT_REALDEBRID_API_KEY=
|
||||
FORCED_REALDEBRID_API_KEY=
|
||||
|
||||
# --- AllDebrid ---
|
||||
DEFAULT_ALLDEBRID_API_KEY=
|
||||
FORCED_ALLDEBRID_API_KEY=
|
||||
|
||||
# --- Premiumize ---
|
||||
DEFAULT_PREMIUMIZE_API_KEY=
|
||||
FORCED_PREMIUMIZE_API_KEY=
|
||||
|
||||
# --- Debrid-Link ---
|
||||
DEFAULT_DEBRIDLINK_API_KEY=
|
||||
FORCED_DEBRIDLINK_API_KEY=
|
||||
|
||||
# --- Torbox ---
|
||||
DEFAULT_TORBOX_API_KEY=
|
||||
FORCED_TORBOX_API_KEY=
|
||||
|
||||
# --- OffCloud ---
|
||||
DEFAULT_OFFCLOUD_API_KEY=
|
||||
FORCED_OFFCLOUD_API_KEY=
|
||||
DEFAULT_OFFCLOUD_EMAIL=
|
||||
FORCED_OFFCLOUD_EMAIL=
|
||||
DEFAULT_OFFCLOUD_PASSWORD=
|
||||
FORCED_OFFCLOUD_PASSWORD=
|
||||
|
||||
# --- Put.io ---
|
||||
DEFAULT_PUTIO_CLIENT_ID=
|
||||
FORCED_PUTIO_CLIENT_ID=
|
||||
DEFAULT_PUTIO_CLIENT_SECRET=
|
||||
FORCED_PUTIO_CLIENT_SECRET=
|
||||
|
||||
# --- EasyNews ---
|
||||
DEFAULT_EASYNEWS_USERNAME=
|
||||
FORCED_EASYNEWS_USERNAME=
|
||||
DEFAULT_EASYNEWS_PASSWORD=
|
||||
FORCED_EASYNEWS_PASSWORD=
|
||||
|
||||
# --- EasyDebrid ---
|
||||
DEFAULT_EASYDEBRID_API_KEY=
|
||||
FORCED_EASYDEBRID_API_KEY=
|
||||
|
||||
# --- PikPak ---
|
||||
DEFAULT_PIKPAK_EMAIL=
|
||||
FORCED_PIKPAK_EMAIL=
|
||||
DEFAULT_PIKPAK_PASSWORD=
|
||||
FORCED_PIKPAK_PASSWORD=
|
||||
|
||||
# --- Seedr ---
|
||||
DEFAULT_SEEDR_ENCODED_TOKEN=
|
||||
FORCED_SEEDR_ENCODED_TOKEN=
|
||||
|
||||
|
||||
# ==============================================================================
|
||||
# CUSTOMIZATION & ACCESS CONTROL
|
||||
# ==============================================================================
|
||||
|
||||
# --- Custom HTML ---
|
||||
# Display custom HTML at the top of the addon's configuration page.
|
||||
# Example: CUSTOM_HTML="<div>Welcome to my AIOStreams!</div>"
|
||||
CUSTOM_HTML=
|
||||
|
||||
# --- Trusted Users ---
|
||||
# Comma-separated list of trusted UUIDs.
|
||||
# Trusted users can access features like regex filters if REGEX_FILTER_ACCESS is 'trusted'.
|
||||
# Example: TRUSTED_UUIDS=ae32f456-1234-5678-9012-345678901234,another-uuid-here
|
||||
# TRUSTED_UUIDS=
|
||||
|
||||
# --- Regex Filter Access ---
|
||||
# Controls who can use regex filters.
|
||||
# 'none': No one can use regex filters.
|
||||
# 'trusted': Only users listed in TRUSTED_UUIDS.
|
||||
# 'all': All users (only recommended if ADDON_PASSWORD is set).
|
||||
# Default: trusted
|
||||
REGEX_FILTER_ACCESS=trusted
|
||||
|
||||
# --- Aliased Configurations (Vanity URLs) ---
|
||||
# Create shorter, memorable installation URLs.
|
||||
# Format: aliasName1:uuid1:encryptedPassword1,aliasName2:uuid2:encryptedPassword2
|
||||
# Users can then access the addon via /stremio/u/aliasName/manifest.json
|
||||
# ALIASED_CONFIGURATIONS=
|
||||
|
||||
|
||||
# ==============================================================================
|
||||
# FEATURE CONTROL
|
||||
# ==============================================================================
|
||||
# Enable or disable specific addon features.
|
||||
|
||||
# --- Self-Scraping ---
|
||||
# Prevent this AIOStreams instance from being added as an addon to itself.
|
||||
# Default: true
|
||||
DISABLE_SELF_SCRAPING=true
|
||||
|
||||
# --- Disabled Hosts ---
|
||||
# Prevent certain hostnames from being added as addons.
|
||||
# Format: host1:reason1,host2:reason2
|
||||
# Example: DISABLED_HOSTS=torrentio.strem.fun:Blocked by Torrentio
|
||||
# DISABLED_HOSTS=
|
||||
|
||||
# --- Disabled Addons (Marketplace) ---
|
||||
# Disable specific addons from appearing in the marketplace.
|
||||
# See https://github.com/Viren070/AIOStreams/blob/main/packages/core/src/utils/marketplace.ts for IDs.
|
||||
# Format: addonID1:reason1,addonID2:reason2
|
||||
# Example: DISABLED_ADDONS=torrentio:Blocked by Torrentio
|
||||
# DISABLED_ADDONS=
|
||||
|
||||
# --- Disabled Services (Configuration Page) ---
|
||||
# Hide certain services (e.g., debrid services) from the configuration page.
|
||||
# Format: service1:reason1,service2:reason2
|
||||
# Example: DISABLED_SERVICES=realdebrid:Not available on this instance
|
||||
# DISABLED_SERVICES=
|
||||
|
||||
|
||||
# ==============================================================================
|
||||
# LOGGING
|
||||
# ==============================================================================
|
||||
|
||||
# --- Log Level ---
|
||||
# Set the verbosity of logs. Options: "error", "warn", "info", "http", "verbose","debug", "silly"
|
||||
# Default: info
|
||||
LOG_LEVEL=http
|
||||
|
||||
# --- Log Format ---
|
||||
# Output logs in "json" or "text" format.
|
||||
# Default: text
|
||||
LOG_FORMAT=text
|
||||
# Whether to log sensitive information like API keys
|
||||
|
||||
# --- Log Sensitive Information ---
|
||||
# Whether to include potentially sensitive info (like API keys) in logs.
|
||||
# Useful for debugging, but disable for production if concerned.
|
||||
# Default: true
|
||||
LOG_SENSITIVE_INFO=true
|
||||
# ==============================================================================
|
||||
|
||||
|
||||
# ==============================================================================
|
||||
# PROXY CONFIGURATION
|
||||
# PROXY FOR OUTGOING ADDON REQUESTS (Torrentio, etc.)
|
||||
# ==============================================================================
|
||||
# The proxy URL to use for all requests made to upstream addons
|
||||
# You only need to configure this if the server you are hosting the addon on
|
||||
# is blocked by Torrentio.
|
||||
# e.g. http://warp:1080
|
||||
# from https://github.com/cmj2002/warp-docker
|
||||
# Configure a proxy for requests made *by* this AIOStreams instance *to* other addons (e.g., Torrentio).
|
||||
# Useful if your server's IP is blocked by an upstream service.
|
||||
|
||||
# --- Addon Proxy URL ---
|
||||
# The proxy URL to use for all requests to upstream addons.
|
||||
# Example: ADDON_PROXY=http://warp:1080 (using https://github.com/cmj2002/warp-docker)
|
||||
# ADDON_PROXY=
|
||||
# Optionally, configure what domains to proxy
|
||||
# Use a comma separated list of rules in the format string:boolean.
|
||||
# The later in the list, the higher the priority.
|
||||
# You can use wildcards (*) to match multiple domains
|
||||
# e.g. ADDON_PROXY_CONFIG="*:false,*.strem.fun:true"
|
||||
# This would only proxy requests to the strem.fun domain and any subdomains of it
|
||||
|
||||
# --- Addon Proxy Configuration ---
|
||||
# Optionally, specify which domains to proxy.
|
||||
# Comma-separated list of rules: domain_pattern:boolean. Later rules have higher priority.
|
||||
# Wildcards (*) can be used.
|
||||
# Example: ADDON_PROXY_CONFIG="*:false,*.strem.fun:true" (only proxy *.strem.fun domains)
|
||||
# ADDON_PROXY_CONFIG=
|
||||
|
||||
|
||||
# ==============================================================================
|
||||
# CONFIGURATION LIMITS
|
||||
# ==============================================================================
|
||||
# The max number of addons that are allowed to be used through a single instance of the addon
|
||||
MAX_ADDONS=15
|
||||
# The maximum number of keyword filters that can be used in a single instance of the addon
|
||||
MAX_KEYWORD_FILTERS=30
|
||||
# The maximum number of regexes that can be used for sorting in a single instance of the addon
|
||||
MAX_REGEX_SORT_PATTERNS=30
|
||||
# To control the maximum size the size filter sliders can go up to in bytes
|
||||
MAX_MOVIE_SIZE=161061273600
|
||||
MAX_EPISODE_SIZE=161061273600
|
||||
# The maximum timeout that can be set for an addon through the override option
|
||||
MAX_TIMEOUT=50000
|
||||
MIN_TIMEOUT=1000
|
||||
# DEFAULT/FORCED STREAM PROXY (MediaFlow, StremThru)
|
||||
# ==============================================================================
|
||||
# Configure how AIOStreams handles stream proxies like MediaFlow or StremThru for playback.
|
||||
# 'DEFAULT_' values are pre-filled. 'FORCE_' values override user settings.
|
||||
|
||||
# ==============================================================================
|
||||
# MEDIAFLOW CONFIGURATION
|
||||
# ==============================================================================
|
||||
# The timeout for requesting the IP from MediaFlow
|
||||
# When we fail to get the IP from MediaFlow, no streams will be fetched and only an error message will be shown
|
||||
MEDIAFLOW_IP_TIMEOUT=30000
|
||||
# If you set a default mediaflow configuration, it will force the addon to use MediaFlow for all instances
|
||||
# A user can override the mediaflow instance to use a different one
|
||||
# DEFAULT_MEDIAFLOW_URL=
|
||||
# DEFAULT_MEDIAFLOW_API_PASSWORD=
|
||||
# DEFAULT_MEDIAFLOW_PUBLIC_IP=
|
||||
# Whether to encrypt each mediaflow URL. Improves compatability with external players.
|
||||
# --- Stream Proxy Enabled ---
|
||||
# DEFAULT_PROXY_ENABLED=true # Default state for enabling a stream proxy.
|
||||
# FORCE_PROXY_ENABLED=false # Force stream proxy on/off for all users.
|
||||
|
||||
# --- Stream Proxy ID ---
|
||||
# 'mediaflow' or 'stremthru'
|
||||
DEFAULT_PROXY_ID=mediaflow
|
||||
# FORCE_PROXY_ID=
|
||||
|
||||
# --- Stream Proxy URL ---
|
||||
# URL of your MediaFlow or StremThru instance.
|
||||
# DEFAULT_PROXY_URL=
|
||||
# FORCE_PROXY_URL=
|
||||
|
||||
# --- Stream Proxy Credentials ---
|
||||
# Format: username:password
|
||||
# DEFAULT_PROXY_CREDENTIALS=
|
||||
# FORCE_PROXY_CREDENTIALS=
|
||||
|
||||
# --- Stream Proxy Public IP ---
|
||||
# Public IP for the proxy, if needed.
|
||||
# DEFAULT_PROXY_PUBLIC_IP=
|
||||
# FORCE_PROXY_PUBLIC_IP=
|
||||
|
||||
# --- Proxied Services ---
|
||||
# Comma-separated list of services whose streams should be proxied (e.g., realdebrid,alldebrid).
|
||||
# DEFAULT_PROXY_PROXIED_SERVICES=
|
||||
# FORCE_PROXY_PROXIED_SERVICES=
|
||||
|
||||
# --- Disable Proxied Addons Feature ---
|
||||
# If true, proxied addons (like MediaFlow itself) won't be added as an addon.
|
||||
FORCE_PROXY_DISABLE_PROXIED_ADDONS=false
|
||||
|
||||
# --- Encrypt Streaming URLs ---
|
||||
# Encrypt MediaFlow/StremThru URLs for better compatibility with external players.
|
||||
ENCRYPT_MEDIAFLOW_URLS=true
|
||||
# ==============================================================================
|
||||
|
||||
|
||||
# ==============================================================================
|
||||
# STREMTHRU (PROXY) CONFIGURATION
|
||||
# ==============================================================================
|
||||
# The timeout for requests to the StremThru instance
|
||||
STREMTHRU_TIMEOUT=30000
|
||||
# If you set a default stremthru configuration, it will force the addon to use StremThru for all instances
|
||||
# A user can override the stremthru instance to use a different one
|
||||
# DEFAULT_STREMTHRU_URL=
|
||||
# The default credential used (either plain-text or base64 encoded of a username:password pair)
|
||||
# DEFAULT_STREMTHRU_CREDENTIAL=
|
||||
# Whether to optionally use a default public IP for the stremthru instance
|
||||
# DEFAULT_STREMTHRU_PUBLIC_IP=
|
||||
# Whether to encrypt each StremThru proxy URL.
|
||||
ENCRYPT_STREMTHRU_URLS=true
|
||||
|
||||
|
||||
# ==============================================================================
|
||||
# ADDON CONSTANTS
|
||||
# ADVANCED CONFIGURATION & LIMITS
|
||||
# ==============================================================================
|
||||
|
||||
# Default regex patterns for filtering and sorting
|
||||
# These are used as defaults, and can be overridden in the addon configuration page
|
||||
#
|
||||
# NOTE: You MUST provide the regex between 2 single quotes ('), not double quotes or no quotes, otherwise it will NOT work.
|
||||
#
|
||||
# Example Exclude Pattern: `/b(0neshot)\b` will exclude streams with the word "0neshot" in them
|
||||
# DEFAULT_REGEX_EXCLUDE_PATTERN=''
|
||||
# Example Include Pattern: `/b(3L)\b` will include only streams with the word "3L" in them
|
||||
# DEFAULT_REGEX_INCLUDE_PATTERN=''
|
||||
# Example Sort Patterns: `/b(3L|BiZKiT)\b \b(FraMeSToR)\b \b(TRiToN)\b` will sort streams with the word "3L" or "BiZKiT" in them, followed by "FraMeSToR", followed by "TRiToN"
|
||||
# DEFAULT_REGEX_SORT_PATTERNS=''
|
||||
|
||||
# The default timeout for all requests. If other timeouts are not set, this will be used
|
||||
# --- General Default Timeout ---
|
||||
# Default timeout in milliseconds for all requests if not overridden by a specific timeout.
|
||||
# Default: 15000 (15 seconds)
|
||||
DEFAULT_TIMEOUT=15000
|
||||
|
||||
# Note: all URLs must end in a trailing slash
|
||||
# --- Configuration Limits ---
|
||||
# Maximum number of addons allowed per AIOStreams configuration.
|
||||
MAX_ADDONS=15
|
||||
# Maximum number of keyword filters per AIOStreams configuration.
|
||||
MAX_KEYWORD_FILTERS=30
|
||||
# Maximum timeout (ms) an addon can be set to via override.
|
||||
MAX_TIMEOUT=50000
|
||||
# Minimum timeout (ms) an addon can be set to via override.
|
||||
MIN_TIMEOUT=1000
|
||||
|
||||
|
||||
# ==============================================================================
|
||||
# RATE LIMIT CONFIGURATION
|
||||
# ==============================================================================
|
||||
# Configure rate limits to prevent abuse. Typically, defaults are fine.
|
||||
|
||||
# --- Disable Rate Limits ---
|
||||
# Set to true to disable all rate limits (NOT RECOMMENDED).
|
||||
# Default: false
|
||||
DISABLE_RATE_LIMITS=false
|
||||
|
||||
# Window and Max requests refer to the maximum number of requests a user can make within a specific timeframe
|
||||
|
||||
# --- Static File Serving ---
|
||||
STATIC_RATE_LIMIT_WINDOW=5
|
||||
STATIC_RATE_LIMIT_MAX_REQUESTS=100
|
||||
|
||||
# --- User API ---
|
||||
USER_API_RATE_LIMIT_WINDOW=5
|
||||
USER_API_RATE_LIMIT_MAX_REQUESTS=10
|
||||
|
||||
# --- Stream API ---
|
||||
STREAM_API_RATE_LIMIT_WINDOW=5
|
||||
STREAM_API_RATE_LIMIT_MAX_REQUESTS=10
|
||||
|
||||
# --- Format API ---
|
||||
FORMAT_API_RATE_LIMIT_WINDOW=5
|
||||
FORMAT_API_RATE_LIMIT_MAX_REQUESTS=15
|
||||
|
||||
# --- Catalog API ---
|
||||
CATALOG_API_RATE_LIMIT_WINDOW=5
|
||||
CATALOG_API_RATE_LIMIT_MAX_REQUESTS=5
|
||||
|
||||
# --- Stremio Stream ---
|
||||
STREMIO_STREAM_RATE_LIMIT_WINDOW=5
|
||||
STREMIO_STREAM_RATE_LIMIT_MAX_REQUESTS=10
|
||||
|
||||
# --- Stremio Catalog ---
|
||||
STREMIO_CATALOG_RATE_LIMIT_WINDOW=5
|
||||
STREMIO_CATALOG_RATE_LIMIT_MAX_REQUESTS=10
|
||||
|
||||
|
||||
# ==============================================================================
|
||||
# INACTIVE USER PRUNING
|
||||
# ==============================================================================
|
||||
# Automatically prune (delete) inactive user configurations.
|
||||
|
||||
# --- Prune Interval ---
|
||||
# How often to check for inactive users, in seconds.
|
||||
# Default: 86400 (1 day)
|
||||
PRUNE_INTERVAL=86400
|
||||
|
||||
# --- Prune Max Inactivity Days ---
|
||||
# Maximum days of inactivity before a user's configuration is pruned.
|
||||
# Default: 30
|
||||
PRUNE_MAX_DAYS=30
|
||||
|
||||
|
||||
# ==============================================================================
|
||||
# EXTERNAL ADDON SERVICE URLs & TIMEOUTS
|
||||
# ==============================================================================
|
||||
# URLs and default timeouts for various external Stremio addons that AIOStreams can integrate with.
|
||||
# Change these if you use self-hosted versions or if defaults become outdated.
|
||||
|
||||
# ----------- COMET ------------
|
||||
COMET_URL=https://comet.elfhosted.com/
|
||||
# The default timeout for all requests to the Comet API. If left empty, either the DEFAULT_TIMEOUT or the overriden timeout will be used
|
||||
# DEFAULT_COMET_TIMOUT=
|
||||
# The following environment variables should only be set if you are using an internal URL for 'COMET_URL' e.g. http://comet:3000/
|
||||
# and want the comet streams to be accessible from outside the network
|
||||
# i.e. you would set these to the public URL of the comet instance
|
||||
# Do not uncomment these if you don't want to use them, as these accept empty strings and your comet streams will NOT work
|
||||
|
||||
# Example scenarios:
|
||||
# 1. Your COMET_URL is an internal URL (e.g. http://comet:3000), you would need to set FORCE_COMET_HOSTNAME to your publicly accessible host, set FORCE_COMET_PROTOCOL as needed
|
||||
# and make sure to set FORCE_COMET_PROTOCOL to an empty value
|
||||
# 2. Same as scenario 1, but you are using mediaflow proxy on the same docker network. In this case, it is better for MediaFlow proxy to use the internal URL so leave these
|
||||
# commented out.
|
||||
# 3. You set COMET_URL to a publicly accessible URL. No further actions are required.
|
||||
# DEFAULT_COMET_TIMEOUT=
|
||||
# Advanced: Override Comet hostname/port/protocol if COMET_URL is internal but needs to be public-facing.
|
||||
# Only uncomment and set if needed. Usually, leave these commented.
|
||||
# FORCE_COMET_HOSTNAME=
|
||||
# FORCE_COMET_PORT=
|
||||
# FORCE_COMET_PROTOCOL=
|
||||
# -------------------------------------
|
||||
# FORCE_COMET_PROTOCOL= # e.g., https
|
||||
|
||||
# ----------- MEDIAFUSION ------------
|
||||
MEDIAFUSION_URL=https://mediafusion.elfhosted.com/
|
||||
# DEFAULT_MEDIAFUSION_TIMEOUT=
|
||||
# The timeout applied to the /encrypt-user-data endpoint of MediaFusion when auto generating the configuration
|
||||
MEDIAFUSION_CONFIG_TIMEOUT=5000
|
||||
# If you are using a self hosted instance of MediaFusion protected with a 'API_PASSWORD', you must provide it here
|
||||
# If you want to be able to make use of the auto configuration. If you are planning on overriding the URL at the config page, you can leave this empty
|
||||
MEDIAFUSION_CONFIG_TIMEOUT=5000 # Timeout (ms) for /encrypt-user-data endpoint.
|
||||
# API Password for self-hosted MediaFusion (for auto-configuration).
|
||||
# MEDIAFUSION_API_PASSWORD=
|
||||
# -------------------------------------
|
||||
|
||||
# ----------- JACKETTIO -------------
|
||||
JACKETTIO_URL=https://jackettio.elfhosted.com/
|
||||
# The default indexers used when auto generating the configuration. Change if using a custom Jackettio instance, and you have different indexers
|
||||
DEFAULT_JACKETTIO_INDEXERS=["bitsearch", "eztv", "thepiratebay", "therarbg", "yts"]
|
||||
# DEFAULT_JACKETTIO_TIMEOUT=
|
||||
# The default URL used for the stremthru instance.
|
||||
# Default indexers for auto-configuration with Jackettio.
|
||||
DEFAULT_JACKETTIO_INDEXERS='["bitsearch", "eztv", "thepiratebay", "therarbg", "yts"]'
|
||||
# Default StremThru URL used by Jackettio.
|
||||
DEFAULT_JACKETTIO_STREMTHRU_URL=https://stremthru.13377001.xyz
|
||||
# You may also provide a selfhosted instance of StremThru here.
|
||||
# Self-hosted StremThru for Jackettio:
|
||||
# DEFAULT_JACKETTIO_STREMTHRU_URL=http://stremthru:8080
|
||||
|
||||
# These values work the same as the comet ones, but for Jackettio
|
||||
# Advanced: Override Jackettio hostname/port/protocol (similar to Comet).
|
||||
# FORCE_JACKETTIO_HOSTNAME=
|
||||
# FORCE_JACKETTIO_PORT=
|
||||
# FORCE_JACKETTIO_PROTOCOL=
|
||||
# -------------------------------------
|
||||
|
||||
# ---------- STREMIO-JACKETT ----------
|
||||
STREMIO_JACKETT_URL=https://stremio-jackett.elfhosted.com/
|
||||
# If using a self hosted instance, provide the Jackett URL and API key here
|
||||
# DEFAULT_STREMIO_JACKETT_JACKETT_URL=
|
||||
# DEFAULT_STREMIO_JACKETT_JACKETT_API_KEY=
|
||||
# The default API key used in Stremio Jackett configurations.
|
||||
# DEFAULT_STREMIO_JACKETT_TMDB_API_KEY=
|
||||
# DEFAULT_STREMIO_JACKETT_TIMEOUT=
|
||||
# -------------------------------------
|
||||
|
||||
|
||||
# --------- STREMTHRU-STORE ---------
|
||||
STREMTHRU_STORE_URL=https://stremthru.elfhosted.com/stremio/store/
|
||||
# DEFAULT_STREMTHRU_STORE_TIMEOUT=
|
||||
# --------------------------------------
|
||||
|
||||
# --------- STREMTHRU-TORZ -----
|
||||
STREMTHRU_TORZ_URL=https://stremthru.elfhosted.com/stremio/torz/
|
||||
# DEFAULT_STREMTHRU_TORZ_TIMEOUT=
|
||||
|
||||
# --------- EASYNEWS+ ADDON ---------
|
||||
EASYNEWS_PLUS_URL=https://b89262c192b0-stremio-easynews-addon.baby-beamup.club/
|
||||
# DEFAULT_EASYNEWS_PLUS_TIMEOUT=
|
||||
# -------------------------------------
|
||||
|
||||
# -------- EASYNEWS++ ADDON ---------
|
||||
EASYNEWS_PLUS_PLUS_URL=https://easynews-cloudflare-worker.jqrw92fchz.workers.dev/
|
||||
# DEFAULT_EASYNEWS_PLUS_PLUS_TIMEOUT=
|
||||
# -------------------------------------
|
||||
|
||||
# --------- STREAMFUSION ---------
|
||||
STREAMFUSION_URL=https://stream-fusion.stremiofr.com/
|
||||
# DEFAULT_STREAMFUSION_TIMEOUT=
|
||||
|
||||
# --------- MARVEL UNIVERSE ---------
|
||||
MARVEL_UNIVERSE_URL=https://addon-marvel.onrender.com/
|
||||
# DEFAULT_MARVEL_UNIVERSE_TIMEOUT=
|
||||
|
||||
# --------- DC UNIVERSE ---------
|
||||
DC_UNIVERSE_URL=https://addon-dc-cq85.onrender.com/
|
||||
# DEFAULT_DC_UNIVERSE_TIMEOUT=
|
||||
|
||||
# --------- STAR WARS UNIVERSE ---------
|
||||
STAR_WARS_UNIVERSE_URL=https://addon-star-wars-u9e3.onrender.com/
|
||||
# DEFAULT_STAR_WARS_UNIVERSE_TIMEOUT=
|
||||
|
||||
# --------- ANIME KITSU ---------
|
||||
ANIME_KITSU_URL=https://anime-kitsu.strem.fun/
|
||||
# DEFAULT_ANIME_KITSU_TIMEOUT=
|
||||
|
||||
# --------- NUVIOSTREAMS ---------
|
||||
NUVIOSTREAMS_URL=https://nuviostreams.hayd.uk/
|
||||
# DEFAULT_NUVIOSTREAMS_TIMEOUT=
|
||||
|
||||
# --------- TMDB COLLECTIONS ---------
|
||||
TMDB_COLLECTIONS_URL=https://61ab9c85a149-tmdb-collections.baby-beamup.club/
|
||||
# DEFAULT_TMDB_COLLECTIONS_TIMEOUT=
|
||||
|
||||
# ----------- TORRENTIO -------------
|
||||
TORRENTIO_URL=https://torrentio.strem.fun/
|
||||
# DEFAULT_TORRENTIO_TIMEOUT=
|
||||
# -------------------------------------
|
||||
|
||||
# -------- ORION STREMIO ADDON --------
|
||||
ORION_STREMIO_ADDON_URL=https://5a0d1888fa64-orion.baby-beamup.club/
|
||||
# DEFAULT_ORION_STREMIO_ADDON_TIMEOUT=
|
||||
# -------------------------------------
|
||||
|
||||
# ------------ PEERFLIX --------------
|
||||
PEERFLIX_URL=https://peerflix-addon.onrender.com/
|
||||
# DEFAULT_PEERFLIX_TIMEOUT=
|
||||
# -------------------------------------
|
||||
|
||||
# -------- TORBOX STREMIO ADDON --------
|
||||
TORBOX_STREMIO_URL=https://stremio.torbox.app/
|
||||
# DEFAULT_TORBOX_STREMIO_TIMEOUT=
|
||||
# --------------------------------------
|
||||
|
||||
# -------- EASYNEWS ADDON --------
|
||||
# -------- EASYNEWS ADDON (Standalone) --------
|
||||
EASYNEWS_URL=https://ea627ddf0ee7-easynews.baby-beamup.club/
|
||||
# DEFAULT_EASYNEWS_TIMEOUT=
|
||||
# --------------------------------------
|
||||
|
||||
# ------------ DEBRIDIO -----------
|
||||
DEBRIDIO_URL=https://debridio.adobotec.com/
|
||||
# DEFAULT_DEBRIDIO_TIMEOUT=
|
||||
# --------------------------------------
|
||||
|
||||
# ------------ DEBRIDIO TVDB ------------
|
||||
DEBRIDIO_TVDB_URL=https://tvdb-addon.debridio.com/
|
||||
# DEFAULT_DEBRIDIO_TVDB_TIMEOUT=
|
||||
|
||||
# ------------ DEBRIDIO TMDB ------------
|
||||
DEBRIDIO_TMDB_URL=https://tmdb-addon.debridio.com/
|
||||
# DEFAULT_DEBRIDIO_TMDB_TIMEOUT=
|
||||
|
||||
# ------------ DEBRIDIO TV ------------
|
||||
DEBRIDIO_TV_URL=https://tv-addon.debridio.com/
|
||||
# DEFAULT_DEBRIDIO_TV_TIMEOUT=
|
||||
|
||||
# ------------ DEBRIDIO WATCHTOWER ------------
|
||||
DEBRIDIO_WATCHTOWER_URL=https://wt-addon.debridio.com/
|
||||
# DEFAULT_DEBRIDIO_WATCHTOWER_TIMEOUT=
|
||||
|
||||
# ------------ OPENSUBTITLES V3 ------------
|
||||
OPENSUBTITLES_URL=https://opensubtitles-v3.strem.io/
|
||||
# DEFAULT_OPENSUBTITLES_TIMEOUT=
|
||||
|
||||
# ------------ TORRENT CATALOGS ------------
|
||||
TORRENT_CATALOGS_URL=https://torrent-catalogs.strem.fun/
|
||||
# DEFAULT_TORRENT_CATALOGS_TIMEOUT=
|
||||
|
||||
# ------------ RPDB CATALOGS ------------
|
||||
RPDB_CATALOGS_URL=https://1fe84bc728af-rpdb.baby-beamup.club/
|
||||
# DEFAULT_RPDB_CATALOGS_TIMEOUT=
|
||||
|
||||
# ------------- DMM Cast ----------------
|
||||
# DEFAULT_DMM_CAST_TIMEOUT=
|
||||
# --------------------------------------
|
||||
|
||||
# -------------- STREMIO GDRIVE ----------------
|
||||
# DEFAULT_STREMIO_GDRIVE_TIMEOUT=
|
||||
# --------------------------------------
|
||||
# ==============================================================================
|
||||
@@ -53,9 +53,11 @@ jobs:
|
||||
if [[ "$(git rev-parse origin/main)" = "$(git rev-parse "${INPUT_REF}")" ]]; then
|
||||
TAGS="${TAGS} latest"
|
||||
fi
|
||||
CHANNEL="stable"
|
||||
;;
|
||||
[0-9]*.[0-9]*.[0-9]*-nightly)
|
||||
TAGS="${INPUT_REF} nightly"
|
||||
CHANNEL="nightly"
|
||||
;;
|
||||
*)
|
||||
echo "Invalid Input Ref: ${INPUT_REF}"
|
||||
@@ -76,8 +78,19 @@ jobs:
|
||||
echo EOF
|
||||
} >> "${GITHUB_ENV}"
|
||||
|
||||
echo "CHANNEL=${CHANNEL}" >> "${GITHUB_ENV}"
|
||||
|
||||
cat "${GITHUB_ENV}"
|
||||
|
||||
- name: Node
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
|
||||
- name: Generate metadata
|
||||
run: |
|
||||
node scripts/generateMetadata.js --channel=${{env.CHANNEL}}
|
||||
|
||||
- name: Build & Push
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
|
||||
+3
-1
@@ -5,4 +5,6 @@ out/
|
||||
.next/
|
||||
next-env.d.ts
|
||||
.wrangler/
|
||||
.env
|
||||
.env
|
||||
metadata.json
|
||||
data/
|
||||
+18
-27
@@ -7,13 +7,9 @@ COPY LICENSE ./
|
||||
|
||||
# Copy the relevant package.json and package-lock.json files.
|
||||
COPY package*.json ./
|
||||
COPY packages/formatters/package*.json ./packages/formatters/
|
||||
COPY packages/parser/package*.json ./packages/parser/
|
||||
COPY packages/types/package*.json ./packages/types/
|
||||
COPY packages/wrappers/package*.json ./packages/wrappers/
|
||||
COPY packages/addon/package*.json ./packages/addon/
|
||||
COPY packages/server/package*.json ./packages/server/
|
||||
COPY packages/core/package*.json ./packages/core/
|
||||
COPY packages/frontend/package*.json ./packages/frontend/
|
||||
COPY packages/utils/package*.json ./packages/utils/
|
||||
|
||||
# Install dependencies.
|
||||
RUN npm install
|
||||
@@ -21,13 +17,12 @@ RUN npm install
|
||||
# Copy source files.
|
||||
COPY tsconfig.*json ./
|
||||
|
||||
COPY packages/addon ./packages/addon
|
||||
COPY packages/formatters ./packages/formatters
|
||||
COPY packages/parser ./packages/parser
|
||||
COPY packages/types ./packages/types
|
||||
COPY packages/wrappers ./packages/wrappers
|
||||
COPY packages/server ./packages/server
|
||||
COPY packages/core ./packages/core
|
||||
COPY packages/frontend ./packages/frontend
|
||||
COPY packages/utils ./packages/utils
|
||||
COPY scripts ./scripts
|
||||
COPY resources ./resources
|
||||
|
||||
|
||||
# Build the project.
|
||||
RUN npm run build
|
||||
@@ -43,25 +38,21 @@ WORKDIR /app
|
||||
# The package.json files must be copied as well for NPM workspace symlinks between local packages to work.
|
||||
COPY --from=builder /build/package*.json /build/LICENSE ./
|
||||
|
||||
COPY --from=builder /build/packages/addon/package.*json ./packages/addon/
|
||||
COPY --from=builder /build/packages/core/package.*json ./packages/core/
|
||||
COPY --from=builder /build/packages/frontend/package.*json ./packages/frontend/
|
||||
COPY --from=builder /build/packages/formatters/package.*json ./packages/formatters/
|
||||
COPY --from=builder /build/packages/parser/package.*json ./packages/parser/
|
||||
COPY --from=builder /build/packages/types/package.*json ./packages/types/
|
||||
COPY --from=builder /build/packages/wrappers/package.*json ./packages/wrappers/
|
||||
COPY --from=builder /build/packages/utils/package.*json ./packages/utils/
|
||||
COPY --from=builder /build/packages/server/package.*json ./packages/server/
|
||||
|
||||
|
||||
COPY --from=builder /build/packages/addon/dist ./packages/addon/dist
|
||||
COPY --from=builder /build/packages/core/dist ./packages/core/dist
|
||||
COPY --from=builder /build/packages/frontend/out ./packages/frontend/out
|
||||
COPY --from=builder /build/packages/formatters/dist ./packages/formatters/dist
|
||||
COPY --from=builder /build/packages/parser/dist ./packages/parser/dist
|
||||
COPY --from=builder /build/packages/types/dist ./packages/types/dist
|
||||
COPY --from=builder /build/packages/wrappers/dist ./packages/wrappers/dist
|
||||
COPY --from=builder /build/packages/utils/dist ./packages/utils/dist
|
||||
COPY --from=builder /build/packages/server/dist ./packages/server/dist
|
||||
|
||||
COPY --from=builder /build/resources ./resources
|
||||
|
||||
COPY --from=builder /build/node_modules ./node_modules
|
||||
|
||||
EXPOSE 3000
|
||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
|
||||
CMD wget --no-verbose --tries=1 --spider http://localhost:$PORT/api/v1/status || exit 1
|
||||
|
||||
ENTRYPOINT ["npm", "run", "start:addon"]
|
||||
EXPOSE $PORT
|
||||
|
||||
ENTRYPOINT ["npm", "run", "start"]
|
||||
+3
-1
@@ -7,8 +7,10 @@ services:
|
||||
- 3000:3000
|
||||
env_file:
|
||||
- .env
|
||||
volumes:
|
||||
- ./data:/app/data
|
||||
healthcheck:
|
||||
test: wget -qO- http://localhost:3000/health
|
||||
test: wget -qO- http://localhost:3000/api/v1/status
|
||||
interval: 1m
|
||||
timeout: 10s
|
||||
retries: 5
|
||||
|
||||
Generated
+6744
-5338
File diff suppressed because it is too large
Load Diff
+12
-19
@@ -1,21 +1,20 @@
|
||||
{
|
||||
"name": "aiostreams",
|
||||
"version": "1.22.0",
|
||||
"description": "Stremio addon to combine streams into one addon",
|
||||
"main": "dist/server.js",
|
||||
"description": "AIOStreams consolidates multiple Stremio addons and debrid services into a single, easily configurable addon. It allows highly customisable filtering, sorting, and formatting of results and supports proxying all your streams through MediaFlow Proxy or StremThru for improved compatibility and IP restriction bypassing.",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"test": "npm run test --workspaces",
|
||||
"release": "commit-and-tag-version",
|
||||
"format": "prettier --write .",
|
||||
"build": "npm -w packages/types run build && npm -w packages/utils run build && npm -w packages/parser run build && npm -w packages/formatters run build && npm -w packages/wrappers run build && npm -w packages/addon run build && npm -w packages/frontend run build",
|
||||
"metadata": "node scripts/generateMetadata.js",
|
||||
"build": "npm -w packages/core run build && npm -w packages/server run build && npm -w packages/frontend run build",
|
||||
"build:watch": "tsc --build --watch",
|
||||
"start": "npm -w packages/addon start",
|
||||
"start:addon": "npm -w packages/addon start",
|
||||
"start:addon:dev": "npm -w packages/addon run start:dev",
|
||||
"start:frontend:dev": "npm -w packages/frontend run dev",
|
||||
"start:cloudflare-worker:dev": "npm -w packages/cloudflare-worker run dev",
|
||||
"deploy:beamup": "beamup",
|
||||
"deploy:cloudflare-worker": "npm -w packages/cloudflare-worker run deploy"
|
||||
"start": "node packages/server/dist/server",
|
||||
"start:addon": "npm run start",
|
||||
"start:dev": "cross-env NODE_ENV=development tsx watch packages/server/src/server.ts",
|
||||
"start:addon:dev": "npm run start:dev",
|
||||
"start:frontend:dev": "npm -w packages/frontend run dev"
|
||||
},
|
||||
"author": "Viren070",
|
||||
"license": "MIT",
|
||||
@@ -23,20 +22,14 @@
|
||||
"packages/*"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.14.10",
|
||||
"beamup-cli": "^1.3.0",
|
||||
"commit-and-tag-version": "^12.5.0",
|
||||
"cross-env": "^7.0.3",
|
||||
"prettier": "^3.3.2",
|
||||
"tsx": "^4.16.2",
|
||||
"typescript": "^5.5.3",
|
||||
"vitest": "^2.1.5"
|
||||
"vitest": "^2.1.5",
|
||||
"ts-node": "^10.9.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"super-regex": "^1.0.0",
|
||||
"undici": "^7.2.3"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
{
|
||||
"name": "@aiostreams/addon",
|
||||
"version": "1.21.1",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"test": "vitest run --passWithNoTests",
|
||||
"test:watch": "vitest watch",
|
||||
"build": "tsc",
|
||||
"prepublish": "npm run build",
|
||||
"start": "node dist/server.js",
|
||||
"start:dev": "cross-env NODE_ENV=dev tsx watch src/server.ts"
|
||||
},
|
||||
"description": "Combine all your streams into one addon and display them with consistent formatting, sorting, and filtering.",
|
||||
"dependencies": {
|
||||
"@aiostreams/formatters": "^1.0.0",
|
||||
"@aiostreams/types": "^1.0.0",
|
||||
"@aiostreams/utils": "^1.0.0",
|
||||
"@aiostreams/wrappers": "^1.0.0",
|
||||
"dotenv": "^16.4.7",
|
||||
"express": "^4.21.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/express": "^5.0.0"
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,537 +0,0 @@
|
||||
import { AddonDetail, Config } from '@aiostreams/types';
|
||||
import {
|
||||
addonDetails,
|
||||
isValueEncrypted,
|
||||
parseAndDecryptString,
|
||||
serviceDetails,
|
||||
Settings,
|
||||
unminifyConfig,
|
||||
} from '@aiostreams/utils';
|
||||
|
||||
export const allowedFormatters = [
|
||||
'gdrive',
|
||||
'minimalistic-gdrive',
|
||||
'torrentio',
|
||||
'torbox',
|
||||
'imposter',
|
||||
'custom',
|
||||
];
|
||||
|
||||
export const allowedLanguages = [
|
||||
'Multi',
|
||||
'English',
|
||||
'Japanese',
|
||||
'Chinese',
|
||||
'Russian',
|
||||
'Arabic',
|
||||
'Portuguese',
|
||||
'Spanish',
|
||||
'French',
|
||||
'German',
|
||||
'Italian',
|
||||
'Korean',
|
||||
'Hindi',
|
||||
'Bengali',
|
||||
'Punjabi',
|
||||
'Marathi',
|
||||
'Gujarati',
|
||||
'Tamil',
|
||||
'Telugu',
|
||||
'Kannada',
|
||||
'Malayalam',
|
||||
'Thai',
|
||||
'Vietnamese',
|
||||
'Indonesian',
|
||||
'Turkish',
|
||||
'Hebrew',
|
||||
'Persian',
|
||||
'Ukrainian',
|
||||
'Greek',
|
||||
'Lithuanian',
|
||||
'Latvian',
|
||||
'Estonian',
|
||||
'Polish',
|
||||
'Czech',
|
||||
'Slovak',
|
||||
'Hungarian',
|
||||
'Romanian',
|
||||
'Bulgarian',
|
||||
'Serbian',
|
||||
'Croatian',
|
||||
'Slovenian',
|
||||
'Dutch',
|
||||
'Danish',
|
||||
'Finnish',
|
||||
'Swedish',
|
||||
'Norwegian',
|
||||
'Malay',
|
||||
'Latino',
|
||||
'Unknown',
|
||||
'Dual Audio',
|
||||
'Dubbed',
|
||||
];
|
||||
|
||||
export function validateConfig(
|
||||
config: Config,
|
||||
environment: 'client' | 'server' = 'server'
|
||||
): {
|
||||
valid: boolean;
|
||||
errorCode: string | null;
|
||||
errorMessage: string | null;
|
||||
} {
|
||||
config = unminifyConfig(config);
|
||||
const createResponse = (
|
||||
valid: boolean,
|
||||
errorCode: string | null,
|
||||
errorMessage: string | null
|
||||
) => {
|
||||
return { valid, errorCode, errorMessage };
|
||||
};
|
||||
|
||||
if (config.addons.length < 1) {
|
||||
return createResponse(
|
||||
false,
|
||||
'noAddons',
|
||||
'At least one addon must be selected'
|
||||
);
|
||||
}
|
||||
|
||||
if (config.addons.length > Settings.MAX_ADDONS) {
|
||||
return createResponse(
|
||||
false,
|
||||
'tooManyAddons',
|
||||
`You can only select a maximum of ${Settings.MAX_ADDONS} addons`
|
||||
);
|
||||
}
|
||||
// check for apiKey if Settings.API_KEY is set
|
||||
if (environment === 'server' && Settings.API_KEY) {
|
||||
const { apiKey } = config;
|
||||
if (!apiKey) {
|
||||
return createResponse(
|
||||
false,
|
||||
'missingApiKey',
|
||||
'The AIOStreams API key is required'
|
||||
);
|
||||
}
|
||||
let decryptedApiKey = apiKey;
|
||||
if (isValueEncrypted(apiKey)) {
|
||||
const decryptionResult = parseAndDecryptString(apiKey);
|
||||
if (decryptionResult === null) {
|
||||
return createResponse(
|
||||
false,
|
||||
'decryptionFailed',
|
||||
'Failed to decrypt the AIOStreams API key'
|
||||
);
|
||||
} else if (decryptionResult === '') {
|
||||
return createResponse(
|
||||
false,
|
||||
'emptyDecryption',
|
||||
'Decrypted API key is empty'
|
||||
);
|
||||
}
|
||||
decryptedApiKey = decryptionResult;
|
||||
}
|
||||
if (decryptedApiKey !== Settings.API_KEY) {
|
||||
return createResponse(
|
||||
false,
|
||||
'invalidApiKey',
|
||||
'Invalid AIOStreams API key. Please use the one defined in your environment variables'
|
||||
);
|
||||
}
|
||||
}
|
||||
const duplicateAddons = config.addons.filter(
|
||||
(addon, index) =>
|
||||
config.addons.findIndex(
|
||||
(a) =>
|
||||
a.id === addon.id &&
|
||||
JSON.stringify(a.options) === JSON.stringify(addon.options)
|
||||
) !== index
|
||||
);
|
||||
|
||||
if (duplicateAddons.length > 0) {
|
||||
return createResponse(
|
||||
false,
|
||||
'duplicateAddons',
|
||||
'Duplicate addons found. Please remove any duplicates'
|
||||
);
|
||||
}
|
||||
|
||||
for (const addon of config.addons) {
|
||||
if (Settings.DISABLE_TORRENTIO && addon.id === 'torrentio') {
|
||||
return createResponse(
|
||||
false,
|
||||
'torrentioDisabled',
|
||||
Settings.DISABLE_TORRENTIO_MESSAGE
|
||||
);
|
||||
}
|
||||
|
||||
const details = addonDetails.find(
|
||||
(detail: AddonDetail) => detail.id === addon.id
|
||||
);
|
||||
if (!details) {
|
||||
return createResponse(
|
||||
false,
|
||||
'invalidAddon',
|
||||
`Invalid addon: ${addon.id}`
|
||||
);
|
||||
}
|
||||
if (details.requiresService) {
|
||||
const supportedServices = details.supportedServices;
|
||||
const isAtLeastOneServiceEnabled = config.services.some(
|
||||
(service) => supportedServices.includes(service.id) && service.enabled
|
||||
);
|
||||
const isOverrideUrlSet = addon.options?.overrideUrl;
|
||||
if (!isAtLeastOneServiceEnabled && !isOverrideUrlSet) {
|
||||
return createResponse(
|
||||
false,
|
||||
'missingService',
|
||||
`${addon.options?.name || details.name} requires at least one of the following services to be enabled: ${supportedServices
|
||||
.map(
|
||||
(service) =>
|
||||
serviceDetails.find((detail) => detail.id === service)?.name ||
|
||||
service
|
||||
)
|
||||
.join(', ')}`
|
||||
);
|
||||
}
|
||||
}
|
||||
if (details.options) {
|
||||
for (const option of details.options) {
|
||||
if (option.required && !addon.options[option.id]) {
|
||||
return createResponse(
|
||||
false,
|
||||
'missingRequiredOption',
|
||||
`Option ${option.label} is required for addon ${addon.id}`
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
option.id.toLowerCase().includes('url') &&
|
||||
addon.options[option.id] &&
|
||||
((isValueEncrypted(addon.options[option.id]) &&
|
||||
environment === 'server') ||
|
||||
!isValueEncrypted(addon.options[option.id]))
|
||||
) {
|
||||
const url = parseAndDecryptString(addon.options[option.id] ?? '');
|
||||
if (url === null) {
|
||||
return createResponse(
|
||||
false,
|
||||
'decryptionFailed',
|
||||
`Failed to decrypt URL for ${option.label}`
|
||||
);
|
||||
} else if (url === '') {
|
||||
return createResponse(
|
||||
false,
|
||||
'emptyDecryption',
|
||||
`Decrypted URL for ${option.label} is empty`
|
||||
);
|
||||
}
|
||||
if (
|
||||
Settings.DISABLE_TORRENTIO &&
|
||||
url.match(/torrentio\.strem\.fun/) !== null
|
||||
) {
|
||||
// if torrentio is disabled, don't allow the user to set URLs with torrentio.strem.fun
|
||||
return createResponse(
|
||||
false,
|
||||
'torrentioDisabled',
|
||||
Settings.DISABLE_TORRENTIO_MESSAGE
|
||||
);
|
||||
} else if (
|
||||
Settings.DISABLE_TORRENTIO &&
|
||||
url.match(/stremthru\.elfhosted\.com/) !== null
|
||||
) {
|
||||
// if torrentio is disabled, we need to inspect the stremthru URL to see if it's using torrentio
|
||||
try {
|
||||
const parsedUrl = new URL(url);
|
||||
// get the component before manifest.json
|
||||
const pathComponents = parsedUrl.pathname.split('/');
|
||||
if (pathComponents.includes('manifest.json')) {
|
||||
const index = pathComponents.indexOf('manifest.json');
|
||||
const componentBeforeManifest = pathComponents[index - 1];
|
||||
// base64 decode the component before manifest.json
|
||||
const decodedComponent = atob(componentBeforeManifest);
|
||||
const stremthruData = JSON.parse(decodedComponent);
|
||||
if (stremthruData?.manifest_url?.match(/torrentio.strem.fun/)) {
|
||||
return createResponse(
|
||||
false,
|
||||
'torrentioDisabled',
|
||||
Settings.DISABLE_TORRENTIO_MESSAGE
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (_) {
|
||||
// ignore
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
new URL(url);
|
||||
} catch (_) {
|
||||
return createResponse(
|
||||
false,
|
||||
'invalidUrl',
|
||||
` Invalid URL for ${option.label}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (option.type === 'number' && addon.options[option.id]) {
|
||||
const input = addon.options[option.id];
|
||||
if (input !== undefined && !parseInt(input)) {
|
||||
return createResponse(
|
||||
false,
|
||||
'invalidNumber',
|
||||
`${option.label} must be a number`
|
||||
);
|
||||
} else if (input !== undefined) {
|
||||
const value = parseInt(input);
|
||||
const { min, max } = option.constraints || {};
|
||||
if (
|
||||
(min !== undefined && value < min) ||
|
||||
(max !== undefined && value > max)
|
||||
) {
|
||||
return createResponse(
|
||||
false,
|
||||
'invalidNumber',
|
||||
`${option.label} must be between ${min} and ${max}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!allowedFormatters.includes(config.formatter)) {
|
||||
if (config.formatter.startsWith('custom') && config.formatter.length > 7) {
|
||||
const jsonString = config.formatter.slice(7);
|
||||
const data = JSON.parse(jsonString);
|
||||
if (!data.name || !data.description) {
|
||||
return createResponse(
|
||||
false,
|
||||
'invalidCustomFormatter',
|
||||
'Invalid custom formatter: name and description are required'
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return createResponse(
|
||||
false,
|
||||
'invalidFormatter',
|
||||
`Invalid formatter: ${config.formatter}`
|
||||
);
|
||||
}
|
||||
}
|
||||
for (const service of config.services) {
|
||||
if (service.enabled) {
|
||||
const serviceDetail = serviceDetails.find(
|
||||
(detail) => detail.id === service.id
|
||||
);
|
||||
if (!serviceDetail) {
|
||||
return createResponse(
|
||||
false,
|
||||
'invalidService',
|
||||
`Invalid service: ${service.id}`
|
||||
);
|
||||
}
|
||||
for (const credential of serviceDetail.credentials) {
|
||||
if (!service.credentials[credential.id]) {
|
||||
return createResponse(
|
||||
false,
|
||||
'missingCredential',
|
||||
`${credential.label} is required for ${service.name}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// need at least one visual tag, resolution, quality
|
||||
|
||||
if (
|
||||
!config.visualTags.some((tag) => Object.values(tag)[0]) ||
|
||||
!config.resolutions.some((resolution) => Object.values(resolution)[0]) ||
|
||||
!config.qualities.some((quality) => Object.values(quality)[0])
|
||||
) {
|
||||
return createResponse(
|
||||
false,
|
||||
'noFilters',
|
||||
'At least one visual tag, resolution, and quality must be selected'
|
||||
);
|
||||
}
|
||||
|
||||
for (const [min, max] of [
|
||||
[config.minMovieSize, config.maxMovieSize],
|
||||
[config.minEpisodeSize, config.maxEpisodeSize],
|
||||
[config.minSize, config.maxSize],
|
||||
]) {
|
||||
if (min && max) {
|
||||
if (min >= max) {
|
||||
return createResponse(
|
||||
false,
|
||||
'invalidSizeRange',
|
||||
"Your minimum size limit can't be greater than or equal to your maximum size limit"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (config.maxResultsPerResolution && config.maxResultsPerResolution < 1) {
|
||||
return createResponse(
|
||||
false,
|
||||
'invalidMaxResultsPerResolution',
|
||||
'Max results per resolution must be greater than 0'
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
config.mediaFlowConfig?.mediaFlowEnabled &&
|
||||
config.stremThruConfig?.stremThruEnabled
|
||||
) {
|
||||
return createResponse(
|
||||
false,
|
||||
'multipleProxyServices',
|
||||
'Multiple proxy services are not allowed'
|
||||
);
|
||||
}
|
||||
if (config.mediaFlowConfig?.mediaFlowEnabled) {
|
||||
if (!config.mediaFlowConfig.proxyUrl) {
|
||||
return createResponse(
|
||||
false,
|
||||
'missingProxyUrl',
|
||||
'Proxy URL is required if MediaFlow is enabled'
|
||||
);
|
||||
}
|
||||
if (!config.mediaFlowConfig.apiPassword) {
|
||||
return createResponse(
|
||||
false,
|
||||
'missingApiPassword',
|
||||
'API Password is required if MediaFlow is enabled'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (config.stremThruConfig?.stremThruEnabled) {
|
||||
if (!config.stremThruConfig.url) {
|
||||
return createResponse(
|
||||
false,
|
||||
'missingUrl',
|
||||
'URL is required if Stremthru is enabled'
|
||||
);
|
||||
}
|
||||
if (!config.stremThruConfig.credential) {
|
||||
return createResponse(
|
||||
false,
|
||||
'missingCredential',
|
||||
'Credential is required if StremThru is enabled'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
(config.excludeFilters?.length ?? 0) > Settings.MAX_KEYWORD_FILTERS ||
|
||||
(config.strictIncludeFilters?.length ?? 0) > Settings.MAX_KEYWORD_FILTERS
|
||||
) {
|
||||
return createResponse(
|
||||
false,
|
||||
'tooManyFilters',
|
||||
`You can only have a maximum of ${Settings.MAX_KEYWORD_FILTERS} filters`
|
||||
);
|
||||
}
|
||||
|
||||
const filters = [
|
||||
...(config.excludeFilters || []),
|
||||
...(config.strictIncludeFilters || []),
|
||||
];
|
||||
filters.forEach((filter) => {
|
||||
if (filter.length > 20) {
|
||||
return createResponse(
|
||||
false,
|
||||
'invalidFilter',
|
||||
'One of your filters is too long'
|
||||
);
|
||||
}
|
||||
if (!filter) {
|
||||
return createResponse(
|
||||
false,
|
||||
'invalidFilter',
|
||||
'Filters must not be empty'
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
if (config.regexFilters) {
|
||||
if (!config.apiKey) {
|
||||
return createResponse(
|
||||
false,
|
||||
'missingApiKey',
|
||||
'Regex filtering requires an API key to be set'
|
||||
);
|
||||
}
|
||||
|
||||
if (config.regexFilters.excludePattern) {
|
||||
try {
|
||||
new RegExp(config.regexFilters.excludePattern);
|
||||
} catch (e) {
|
||||
return createResponse(
|
||||
false,
|
||||
'invalidExcludeRegex',
|
||||
'Invalid exclude regex pattern'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (config.regexFilters.includePattern) {
|
||||
try {
|
||||
new RegExp(config.regexFilters.includePattern);
|
||||
} catch (e) {
|
||||
return createResponse(
|
||||
false,
|
||||
'invalidIncludeRegex',
|
||||
'Invalid include regex pattern'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (config.regexSortPatterns) {
|
||||
if (!config.apiKey) {
|
||||
return createResponse(
|
||||
false,
|
||||
'missingApiKey',
|
||||
'Regex sorting requires an API key to be set'
|
||||
);
|
||||
}
|
||||
|
||||
// Split the pattern by spaces and validate each one
|
||||
const patterns = config.regexSortPatterns.split(/\s+/).filter(Boolean);
|
||||
// Enforce an upper bound on the number of patterns
|
||||
if (patterns.length > Settings.MAX_REGEX_SORT_PATTERNS) {
|
||||
return createResponse(
|
||||
false,
|
||||
'tooManyRegexSortPatterns',
|
||||
`You can specify at most ${Settings.MAX_REGEX_SORT_PATTERNS} regex sort patterns`
|
||||
);
|
||||
}
|
||||
|
||||
for (const pattern of patterns) {
|
||||
const delimiter = '<::>';
|
||||
const delimiterIndex = pattern.indexOf(delimiter);
|
||||
let name: string = 'Unamed';
|
||||
let regexPattern = pattern;
|
||||
if (delimiterIndex !== -1) {
|
||||
name = pattern.slice(0, delimiterIndex).replace(/_/g, ' ');
|
||||
regexPattern = pattern.slice(delimiterIndex + delimiter.length);
|
||||
}
|
||||
try {
|
||||
new RegExp(regexPattern);
|
||||
} catch (e) {
|
||||
return createResponse(
|
||||
false,
|
||||
'invalidRegexSortPattern',
|
||||
`Invalid regex sort pattern: ${name ? `"${name}" ` : ''}${regexPattern}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return createResponse(true, null, null);
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
export * from './addon';
|
||||
export * from './config';
|
||||
export * from './manifest';
|
||||
export * from './responses';
|
||||
@@ -1,37 +0,0 @@
|
||||
import { Config } from '@aiostreams/types';
|
||||
import { version, description } from '../../../package.json';
|
||||
import { getTextHash, Settings } from '@aiostreams/utils';
|
||||
|
||||
const manifest = (config?: Config, configPresent?: boolean) => {
|
||||
let addonId = Settings.ADDON_ID;
|
||||
if (config && Settings.DETERMINISTIC_ADDON_ID) {
|
||||
addonId =
|
||||
addonId += `.${getTextHash(JSON.stringify(config)).substring(0, 12)}`;
|
||||
}
|
||||
return {
|
||||
name: config?.overrideName || Settings.ADDON_NAME,
|
||||
id: addonId,
|
||||
version: version,
|
||||
description: description,
|
||||
catalogs: [],
|
||||
resources: ['stream'],
|
||||
background:
|
||||
'https://raw.githubusercontent.com/Viren070/AIOStreams/refs/heads/main/packages/frontend/public/assets/background.png',
|
||||
logo: 'https://raw.githubusercontent.com/Viren070/AIOStreams/refs/heads/main/packages/frontend/public/assets/logo.png',
|
||||
types: ['movie', 'series'],
|
||||
behaviorHints: {
|
||||
configurable: true,
|
||||
configurationRequired: config || configPresent ? false : true,
|
||||
},
|
||||
stremioAddonsConfig:
|
||||
Settings.STREMIO_ADDONS_CONFIG_ISSUER &&
|
||||
Settings.STREMIO_ADDONS_CONFIG_SIGNATURE
|
||||
? {
|
||||
issuer: Settings.STREMIO_ADDONS_CONFIG_ISSUER,
|
||||
signature: Settings.STREMIO_ADDONS_CONFIG_SIGNATURE,
|
||||
}
|
||||
: undefined,
|
||||
};
|
||||
};
|
||||
|
||||
export default manifest;
|
||||
@@ -1,29 +0,0 @@
|
||||
import { Settings } from '@aiostreams/utils';
|
||||
|
||||
export const errorResponse = (
|
||||
errorMessage: string,
|
||||
origin?: string,
|
||||
path?: string,
|
||||
externalUrl?: string
|
||||
) => {
|
||||
return {
|
||||
streams: [errorStream(errorMessage, 'Error', origin, path, externalUrl)],
|
||||
};
|
||||
};
|
||||
|
||||
export const errorStream = (
|
||||
errorMessage: string,
|
||||
errorTitle?: string,
|
||||
origin?: string,
|
||||
path?: string,
|
||||
externalUrl?: string
|
||||
) => {
|
||||
return {
|
||||
externalUrl:
|
||||
(origin && path ? origin + path : undefined) ||
|
||||
externalUrl ||
|
||||
'https://github.com/Viren070/AIOStreams',
|
||||
name: `[❌] ${Settings.ADDON_NAME}\n${errorTitle || 'Error'}`,
|
||||
description: errorMessage,
|
||||
};
|
||||
};
|
||||
@@ -1,645 +0,0 @@
|
||||
import express, { Request, Response } from 'express';
|
||||
|
||||
import path from 'path';
|
||||
import { AIOStreams } from './addon';
|
||||
import { Config, StreamRequest } from '@aiostreams/types';
|
||||
import { validateConfig } from './config';
|
||||
import manifest from './manifest';
|
||||
import { errorResponse } from './responses';
|
||||
import {
|
||||
Settings,
|
||||
addonDetails,
|
||||
parseAndDecryptString,
|
||||
Cache,
|
||||
unminifyConfig,
|
||||
minifyConfig,
|
||||
crushJson,
|
||||
compressData,
|
||||
encryptData,
|
||||
decompressData,
|
||||
decryptData,
|
||||
uncrushJson,
|
||||
loadSecretKey,
|
||||
createLogger,
|
||||
getTimeTakenSincePoint,
|
||||
isValueEncrypted,
|
||||
maskSensitiveInfo,
|
||||
} from '@aiostreams/utils';
|
||||
|
||||
const logger = createLogger('server');
|
||||
|
||||
const app = express();
|
||||
//logger.info(`Starting server and loading settings...`);
|
||||
logger.info('Starting server and loading settings...', { func: 'init' });
|
||||
Object.entries(Settings).forEach(([key, value]) => {
|
||||
switch (key) {
|
||||
case 'SECRET_KEY':
|
||||
if (value) {
|
||||
logger.info(`${key} = ${value.replace(/./g, '*').slice(0, 64)}`);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'BRANDING':
|
||||
case 'CUSTOM_CONFIGS':
|
||||
// Skip CUSTOM_CONFIGS processing here, handled later
|
||||
break;
|
||||
|
||||
default:
|
||||
logger.info(`${key} = ${value}`);
|
||||
}
|
||||
});
|
||||
|
||||
// attempt to load the secret key
|
||||
try {
|
||||
if (Settings.SECRET_KEY) loadSecretKey(true);
|
||||
} catch (error: any) {
|
||||
// determine command to run based on system OS
|
||||
const command =
|
||||
process.platform === 'win32'
|
||||
? '[System.Guid]::NewGuid().ToString("N").Substring(0, 32) + [System.Guid]::NewGuid().ToString("N").Substring(0, 32)'
|
||||
: 'openssl rand -hex 32';
|
||||
logger.error(
|
||||
`The secret key is invalid. You will not be able to generate configurations. You can generate a new secret key by running the following command\n${command}`
|
||||
);
|
||||
}
|
||||
|
||||
// Built-in middleware for parsing JSON
|
||||
app.use(express.json());
|
||||
// Built-in middleware for parsing URL-encoded data
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
|
||||
// unhandled errors
|
||||
app.use((err: any, req: Request, res: Response, next: any) => {
|
||||
logger.error(`${err.message}`);
|
||||
res.status(500).send('Internal server error');
|
||||
});
|
||||
|
||||
app.use((req, res, next) => {
|
||||
res.append('Access-Control-Allow-Origin', '*');
|
||||
res.append('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
|
||||
const start = Date.now();
|
||||
res.on('finish', () => {
|
||||
logger.info(
|
||||
`${req.method} ${req.path
|
||||
.replace(/\/ey[JI][\w\=]+/g, '/*******')
|
||||
.replace(
|
||||
/\/(E2?|B)?-[\w-\%]+/g,
|
||||
'/*******'
|
||||
)} - ${getIp(req) ? maskSensitiveInfo(getIp(req)!) : 'Unknown IP'} - ${res.statusCode} - ${getTimeTakenSincePoint(start)}`
|
||||
);
|
||||
});
|
||||
next();
|
||||
});
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
res.redirect('/configure');
|
||||
});
|
||||
|
||||
app.get(
|
||||
['/_next/*', '/assets/*', '/icon.ico', '/configure.txt'],
|
||||
(req, res) => {
|
||||
res.sendFile(path.join(__dirname, '../../frontend/out', req.path));
|
||||
}
|
||||
);
|
||||
|
||||
if (!Settings.DISABLE_CUSTOM_CONFIG_GENERATOR_ROUTE) {
|
||||
app.get('/custom-config-generator', (req, res) => {
|
||||
res.sendFile(
|
||||
path.join(__dirname, '../../frontend/out/custom-config-generator.html')
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
app.get('/configure', (req, res) => {
|
||||
res.sendFile(path.join(__dirname, '../../frontend/out/configure.html'));
|
||||
});
|
||||
|
||||
app.get('/:config/configure', (req, res) => {
|
||||
const config = req.params.config;
|
||||
if (config.startsWith('eyJ') || config.startsWith('eyI')) {
|
||||
return res.sendFile(
|
||||
path.join(__dirname, '../../frontend/out/configure.html')
|
||||
);
|
||||
}
|
||||
try {
|
||||
let configJson = extractJsonConfig(config);
|
||||
let configString = config;
|
||||
if (Settings.CUSTOM_CONFIGS) {
|
||||
const customConfig = extractCustomConfig(config);
|
||||
if (customConfig) {
|
||||
configJson = customConfig;
|
||||
configString = decodeURIComponent(Settings.CUSTOM_CONFIGS[config]);
|
||||
}
|
||||
}
|
||||
if (isValueEncrypted(configString)) {
|
||||
logger.info(`Encrypted config detected, encrypting credentials`);
|
||||
configJson = encryptInfoInConfig(configJson);
|
||||
}
|
||||
const base64Config = Buffer.from(JSON.stringify(configJson)).toString(
|
||||
'base64'
|
||||
);
|
||||
res.redirect(`/${encodeURIComponent(base64Config)}/configure`);
|
||||
} catch (error: any) {
|
||||
logger.error(`Failed to extract config: ${error.message}`);
|
||||
res.status(400).send('Invalid config');
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/manifest.json', (req, res) => {
|
||||
res.status(200).json(manifest());
|
||||
});
|
||||
|
||||
app.get('/:config/manifest.json', (req, res) => {
|
||||
const config = decodeURIComponent(req.params.config);
|
||||
let configJson: Config;
|
||||
try {
|
||||
configJson = extractJsonConfig(config);
|
||||
logger.info(`Extracted config for manifest request`);
|
||||
configJson = decryptEncryptedInfoFromConfig(configJson);
|
||||
if (Settings.LOG_SENSITIVE_INFO) {
|
||||
logger.info(`Final config: ${JSON.stringify(configJson)}`);
|
||||
}
|
||||
logger.info(`Successfully removed or decrypted sensitive info`);
|
||||
const { valid, errorMessage } = validateConfig(configJson);
|
||||
if (!valid) {
|
||||
logger.error(
|
||||
`Received invalid config for manifest request: ${errorMessage}`
|
||||
);
|
||||
res.status(400).json({ error: 'Invalid config', message: errorMessage });
|
||||
return;
|
||||
}
|
||||
} catch (error: any) {
|
||||
logger.error(`Failed to extract config: ${error.message}`);
|
||||
res.status(400).json({ error: 'Invalid config' });
|
||||
return;
|
||||
}
|
||||
res.status(200).json(manifest(configJson));
|
||||
});
|
||||
|
||||
// Route for /stream
|
||||
app.get('/stream/:type/:id', (req: Request, res: Response) => {
|
||||
res
|
||||
.status(200)
|
||||
.json(
|
||||
errorResponse(
|
||||
'You must configure this addon to use it',
|
||||
rootUrl(req),
|
||||
'/configure'
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
app.get('/:config/stream/:type/:id.json', (req, res: Response): void => {
|
||||
const { config, type, id } = req.params;
|
||||
let configJson: Config;
|
||||
try {
|
||||
configJson = extractJsonConfig(config);
|
||||
logger.info(`Extracted config for stream request`);
|
||||
configJson = decryptEncryptedInfoFromConfig(configJson);
|
||||
if (Settings.LOG_SENSITIVE_INFO) {
|
||||
logger.info(`Final config: ${JSON.stringify(configJson)}`);
|
||||
}
|
||||
logger.info(`Successfully removed or decrypted sensitive info`);
|
||||
} catch (error: any) {
|
||||
logger.error(`Failed to extract config: ${error.message}`);
|
||||
res.json(
|
||||
errorResponse(
|
||||
`${error.message}, please check the logs or click this stream to create an issue on GitHub`,
|
||||
rootUrl(req),
|
||||
undefined,
|
||||
'https://github.com/Viren070/AIOStreams/issues/new?template=bug_report.yml'
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info(`Requesting streams for ${type} ${id}`);
|
||||
|
||||
if (type !== 'movie' && type !== 'series') {
|
||||
logger.error(`Invalid type for stream request`);
|
||||
res.json(
|
||||
errorResponse(
|
||||
'Invalid type for stream request, must be movie or series',
|
||||
rootUrl(req),
|
||||
'/'
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
let streamRequest: StreamRequest = { id, type };
|
||||
|
||||
try {
|
||||
const { valid, errorCode, errorMessage } = validateConfig(configJson);
|
||||
if (!valid) {
|
||||
logger.error(`Received invalid config: ${errorCode} - ${errorMessage}`);
|
||||
res.json(
|
||||
errorResponse(errorMessage ?? 'Unknown', rootUrl(req), '/configure')
|
||||
);
|
||||
return;
|
||||
}
|
||||
configJson.requestingIp = getIp(req);
|
||||
const aioStreams = new AIOStreams(configJson);
|
||||
aioStreams
|
||||
.getStreams(streamRequest)
|
||||
.then((streams) => {
|
||||
res.json({ streams: streams });
|
||||
})
|
||||
.catch((error: any) => {
|
||||
logger.error(`Internal addon error: ${error.message}`);
|
||||
res.json(
|
||||
errorResponse(
|
||||
'An unexpected error occurred, please check the logs or create an issue on GitHub',
|
||||
rootUrl(req),
|
||||
undefined,
|
||||
'https://github.com/Viren070/AIOStreams/issues/new?template=bug_report.yml'
|
||||
)
|
||||
);
|
||||
});
|
||||
} catch (error: any) {
|
||||
logger.error(`Internal addon error: ${error.message}`);
|
||||
res.json(
|
||||
errorResponse(
|
||||
'An unexpected error occurred, please check the logs or create an issue on GitHub',
|
||||
rootUrl(req),
|
||||
undefined,
|
||||
'https://github.com/Viren070/AIOStreams/issues/new?template=bug_report.yml'
|
||||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
app.post('/encrypt-user-data', (req, res) => {
|
||||
const { data } = req.body;
|
||||
let finalString: string = '';
|
||||
if (!data) {
|
||||
logger.error('/encrypt-user-data: No data provided');
|
||||
res.json({ success: false, message: 'No data provided' });
|
||||
return;
|
||||
}
|
||||
// First, validate the config
|
||||
try {
|
||||
const config = JSON.parse(data);
|
||||
const { valid, errorCode, errorMessage } = validateConfig(config);
|
||||
if (!valid) {
|
||||
logger.error(
|
||||
`generateConfig: Invalid config: ${errorCode} - ${errorMessage}`
|
||||
);
|
||||
res.json({ success: false, message: errorMessage, error: errorMessage });
|
||||
return;
|
||||
}
|
||||
} catch (error: any) {
|
||||
logger.error(`/encrypt-user-data: Invalid JSON: ${error.message}`);
|
||||
res.json({ success: false, message: 'Malformed configuration' });
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const minified = minifyConfig(JSON.parse(data));
|
||||
const crushed = crushJson(JSON.stringify(minified));
|
||||
const compressed = compressData(crushed);
|
||||
if (!Settings.SECRET_KEY) {
|
||||
// use base64 encoding if no secret key is set
|
||||
finalString = `B-${encodeURIComponent(compressed.toString('base64'))}`;
|
||||
} else {
|
||||
const { iv, data } = encryptData(compressed);
|
||||
finalString = `E2-${encodeURIComponent(iv)}-${encodeURIComponent(data)}`;
|
||||
}
|
||||
|
||||
logger.info(
|
||||
`|INF| server > /encrypt-user-data: Encrypted user data, compression report:`
|
||||
);
|
||||
logger.info(`+--------------------------------------------+`);
|
||||
logger.info(`| Original: ${data.length} bytes`);
|
||||
logger.info(`| URL Encoded: ${encodeURIComponent(data).length} bytes`);
|
||||
logger.info(`| Minified: ${JSON.stringify(minified).length} bytes`);
|
||||
logger.info(`| Crushed: ${crushed.length} bytes`);
|
||||
logger.info(`| Compressed: ${compressed.length} bytes`);
|
||||
logger.info(`| Final String: ${finalString.length} bytes`);
|
||||
logger.info(
|
||||
`| Ratio: ${((finalString.length / data.length) * 100).toFixed(2)}%`
|
||||
);
|
||||
logger.info(
|
||||
`| Reduction: ${data.length - finalString.length} bytes (${(((data.length - finalString.length) / data.length) * 100).toFixed(2)}%)`
|
||||
);
|
||||
logger.info(`+--------------------------------------------+`);
|
||||
|
||||
res.json({ success: true, data: finalString });
|
||||
} catch (error: any) {
|
||||
logger.error(`/encrypt-user-data: ${error.message}`);
|
||||
logger.error(error);
|
||||
res.json({ success: false, message: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/get-addon-config', (req, res) => {
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
maxMovieSize: Settings.MAX_MOVIE_SIZE,
|
||||
maxEpisodeSize: Settings.MAX_EPISODE_SIZE,
|
||||
torrentioDisabled: Settings.DISABLE_TORRENTIO,
|
||||
apiKeyRequired: !!Settings.API_KEY,
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/health', (req, res) => {
|
||||
res.status(200).json({ status: 'ok' });
|
||||
});
|
||||
|
||||
// define 404
|
||||
app.use((req, res) => {
|
||||
res.status(404).sendFile(path.join(__dirname, '../../frontend/out/404.html'));
|
||||
});
|
||||
|
||||
app.listen(Settings.PORT, () => {
|
||||
logger.info(`Listening on port ${Settings.PORT}`);
|
||||
});
|
||||
|
||||
function getIp(req: Request): string | undefined {
|
||||
return (
|
||||
req.get('X-Client-IP') ||
|
||||
req.get('X-Forwarded-For')?.split(',')[0].trim() ||
|
||||
req.get('X-Real-IP') ||
|
||||
req.get('CF-Connecting-IP') ||
|
||||
req.get('True-Client-IP') ||
|
||||
req.get('X-Forwarded')?.split(',')[0].trim() ||
|
||||
req.get('Forwarded-For')?.split(',')[0].trim() ||
|
||||
req.ip
|
||||
);
|
||||
}
|
||||
function extractJsonConfig(config: string): Config {
|
||||
if (
|
||||
config.startsWith('eyJ') ||
|
||||
config.startsWith('eyI') ||
|
||||
config.startsWith('B-') ||
|
||||
isValueEncrypted(config)
|
||||
) {
|
||||
return extractEncryptedOrEncodedConfig(config, 'Config');
|
||||
}
|
||||
if (Settings.CUSTOM_CONFIGS) {
|
||||
const customConfig = extractCustomConfig(config);
|
||||
if (customConfig) return customConfig;
|
||||
}
|
||||
throw new Error('Config was in an unexpected format');
|
||||
}
|
||||
|
||||
function extractCustomConfig(config: string): Config | undefined {
|
||||
const customConfig = Settings.CUSTOM_CONFIGS[config];
|
||||
if (!customConfig) return undefined;
|
||||
logger.info(
|
||||
`Found custom config for alias ${config}, attempting to extract config`
|
||||
);
|
||||
return extractEncryptedOrEncodedConfig(
|
||||
decodeURIComponent(customConfig),
|
||||
`CustomConfig ${config}`
|
||||
);
|
||||
}
|
||||
|
||||
function extractEncryptedOrEncodedConfig(
|
||||
config: string,
|
||||
label: string
|
||||
): Config {
|
||||
let decodedConfig: Config;
|
||||
try {
|
||||
if (config.startsWith('E-')) {
|
||||
// compressed and encrypted (hex)
|
||||
logger.info(`Extracting encrypted (v1) config`);
|
||||
const parts = config.split('-');
|
||||
if (parts.length !== 3) {
|
||||
throw new Error('Invalid encrypted config format');
|
||||
}
|
||||
const iv = Buffer.from(decodeURIComponent(parts[1]), 'hex');
|
||||
const data = Buffer.from(decodeURIComponent(parts[2]), 'hex');
|
||||
decodedConfig = JSON.parse(decompressData(decryptData(data, iv)));
|
||||
} else if (config.startsWith('E2-')) {
|
||||
// minified, crushed, compressed and encrypted (base64)
|
||||
logger.info(`Extracting encrypted (v2) config`);
|
||||
const parts = config.split('-');
|
||||
if (parts.length !== 3) {
|
||||
throw new Error('Invalid encrypted config format');
|
||||
}
|
||||
const iv = Buffer.from(decodeURIComponent(parts[1]), 'base64');
|
||||
const data = Buffer.from(decodeURIComponent(parts[2]), 'base64');
|
||||
const compressedCrushedJson = decryptData(data, iv);
|
||||
const crushedJson = decompressData(compressedCrushedJson);
|
||||
const minifiedConfig = uncrushJson(crushedJson);
|
||||
decodedConfig = unminifyConfig(JSON.parse(minifiedConfig));
|
||||
} else if (config.startsWith('B-')) {
|
||||
// minifed, crushed, compressed, base64 encoded
|
||||
logger.info(`Extracting base64 encoded and compressed config`);
|
||||
decodedConfig = unminifyConfig(
|
||||
JSON.parse(
|
||||
uncrushJson(decompressData(Buffer.from(config.slice(2), 'base64')))
|
||||
)
|
||||
);
|
||||
} else {
|
||||
// plain base64 encoded
|
||||
logger.info(`Extracting plain base64 encoded config`);
|
||||
decodedConfig = JSON.parse(
|
||||
Buffer.from(config, 'base64').toString('utf-8')
|
||||
);
|
||||
}
|
||||
return decodedConfig;
|
||||
} catch (error: any) {
|
||||
logger.error(`Failed to parse ${label}: ${error.message}`, {
|
||||
func: 'extractJsonConfig',
|
||||
});
|
||||
logger.error(error, { func: 'extractJsonConfig' });
|
||||
throw new Error(`Failed to parse ${label}`);
|
||||
}
|
||||
}
|
||||
|
||||
function decryptEncryptedInfoFromConfig(config: Config): Config {
|
||||
if (config.services) {
|
||||
config.services.forEach(
|
||||
(service) =>
|
||||
service.credentials &&
|
||||
processObjectValues(
|
||||
service.credentials,
|
||||
`service ${service.id}`,
|
||||
true,
|
||||
(key, value) => isValueEncrypted(value)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (config.mediaFlowConfig) {
|
||||
decryptMediaFlowConfig(config.mediaFlowConfig);
|
||||
}
|
||||
if (config.stremThruConfig) {
|
||||
decryptStremThruConfig(config.stremThruConfig);
|
||||
}
|
||||
|
||||
if (config.apiKey) {
|
||||
config.apiKey = decryptValue(config.apiKey, 'aioStreams apiKey');
|
||||
}
|
||||
|
||||
if (config.addons) {
|
||||
config.addons.forEach((addon) => {
|
||||
if (addon.options) {
|
||||
processObjectValues(
|
||||
addon.options,
|
||||
`addon ${addon.id}`,
|
||||
true,
|
||||
(key, value) =>
|
||||
isValueEncrypted(value) &&
|
||||
// Decrypt only if the option is secret
|
||||
(
|
||||
addonDetails.find((addonDetail) => addonDetail.id === addon.id)
|
||||
?.options ?? []
|
||||
).some((option) => option.id === key && option.secret)
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
function decryptMediaFlowConfig(mediaFlowConfig: {
|
||||
apiPassword: string;
|
||||
proxyUrl: string;
|
||||
publicIp: string;
|
||||
}): void {
|
||||
const { apiPassword, proxyUrl, publicIp } = mediaFlowConfig;
|
||||
mediaFlowConfig.apiPassword = decryptValue(
|
||||
apiPassword,
|
||||
'MediaFlow apiPassword'
|
||||
);
|
||||
mediaFlowConfig.proxyUrl = decryptValue(proxyUrl, 'MediaFlow proxyUrl');
|
||||
mediaFlowConfig.publicIp = decryptValue(publicIp, 'MediaFlow publicIp');
|
||||
}
|
||||
|
||||
function decryptStremThruConfig(
|
||||
stremThruConfig: Config['stremThruConfig']
|
||||
): void {
|
||||
if (!stremThruConfig) return;
|
||||
const { url, credential, publicIp } = stremThruConfig;
|
||||
stremThruConfig.url = decryptValue(url, 'StremThru url');
|
||||
stremThruConfig.credential = decryptValue(credential, 'StremThru credential');
|
||||
stremThruConfig.publicIp = decryptValue(publicIp, 'StremThru publicIp');
|
||||
}
|
||||
|
||||
function encryptInfoInConfig(config: Config): Config {
|
||||
if (config.services) {
|
||||
config.services.forEach(
|
||||
(service) =>
|
||||
service.credentials &&
|
||||
processObjectValues(
|
||||
service.credentials,
|
||||
`service ${service.id}`,
|
||||
false,
|
||||
() => true
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (config.mediaFlowConfig) {
|
||||
encryptMediaFlowConfig(config.mediaFlowConfig);
|
||||
}
|
||||
|
||||
if (config.stremThruConfig) {
|
||||
encryptStremThruConfig(config.stremThruConfig);
|
||||
}
|
||||
|
||||
if (config.apiKey) {
|
||||
// we can either remove the api key for better security or encrypt it for usability
|
||||
// removing it means the user has to enter it every time upon reconfiguration.
|
||||
config.apiKey = encryptValue(config.apiKey, 'aioStreams apiKey');
|
||||
}
|
||||
|
||||
if (config.addons) {
|
||||
config.addons.forEach((addon) => {
|
||||
if (addon.options) {
|
||||
processObjectValues(
|
||||
addon.options,
|
||||
`addon ${addon.id}`,
|
||||
false,
|
||||
(key) => {
|
||||
const addonDetail = addonDetails.find(
|
||||
(addonDetail) => addonDetail.id === addon.id
|
||||
);
|
||||
if (!addonDetail) return false;
|
||||
const optionDetail = addonDetail.options?.find(
|
||||
(option) => option.id === key
|
||||
);
|
||||
// Encrypt only if the option is secret
|
||||
return optionDetail?.secret ?? false;
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
function encryptMediaFlowConfig(mediaFlowConfig: {
|
||||
apiPassword: string;
|
||||
proxyUrl: string;
|
||||
publicIp: string;
|
||||
}): void {
|
||||
const { apiPassword, proxyUrl, publicIp } = mediaFlowConfig;
|
||||
mediaFlowConfig.apiPassword = encryptValue(
|
||||
apiPassword,
|
||||
'MediaFlow apiPassword'
|
||||
);
|
||||
mediaFlowConfig.proxyUrl = encryptValue(proxyUrl, 'MediaFlow proxyUrl');
|
||||
mediaFlowConfig.publicIp = encryptValue(publicIp, 'MediaFlow publicIp');
|
||||
}
|
||||
|
||||
function encryptStremThruConfig(
|
||||
stremThruConfig: Config['stremThruConfig']
|
||||
): void {
|
||||
if (!stremThruConfig) return;
|
||||
const { url, credential, publicIp } = stremThruConfig;
|
||||
stremThruConfig.url = encryptValue(url, 'StremThru url');
|
||||
stremThruConfig.credential = encryptValue(credential, 'StremThru credential');
|
||||
stremThruConfig.publicIp = encryptValue(publicIp, 'StremThru publicIp');
|
||||
}
|
||||
|
||||
function processObjectValues(
|
||||
obj: Record<string, any>,
|
||||
labelPrefix: string,
|
||||
decrypt: boolean,
|
||||
condition: (key: string, value: any) => boolean
|
||||
): void {
|
||||
Object.keys(obj).forEach((key) => {
|
||||
const value = obj[key];
|
||||
if (condition(key, value)) {
|
||||
logger.debug(`Processing ${labelPrefix} ${key}`);
|
||||
obj[key] = decrypt
|
||||
? decryptValue(value, `${labelPrefix} ${key}`)
|
||||
: encryptValue(value, `${labelPrefix} ${key}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function encryptValue(value: any, label: string): any {
|
||||
if (value && !isValueEncrypted(value)) {
|
||||
try {
|
||||
const { iv, data } = encryptData(compressData(value));
|
||||
return `E2-${iv}-${data}`;
|
||||
} catch (error: any) {
|
||||
logger.error(`Failed to encrypt ${label}`, { func: 'encryptValue' });
|
||||
logger.error(error, { func: 'encryptValue' });
|
||||
return '';
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function decryptValue(value: any, label: string): any {
|
||||
try {
|
||||
if (!isValueEncrypted(value)) return value;
|
||||
const decrypted = parseAndDecryptString(value);
|
||||
if (decrypted === null) throw new Error('Decryption failed');
|
||||
return decrypted;
|
||||
} catch (error: any) {
|
||||
logger.error(`Failed to decrypt ${label}: ${error.message}`, {
|
||||
func: 'decryptValue',
|
||||
});
|
||||
logger.error(error, { func: 'decryptValue' });
|
||||
throw new Error('Failed to decrypt config');
|
||||
}
|
||||
}
|
||||
|
||||
const rootUrl = (req: Request) =>
|
||||
`${req.protocol}://${req.hostname}${req.hostname === 'localhost' ? `:${Settings.PORT}` : ''}`;
|
||||
@@ -1,22 +0,0 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "src",
|
||||
"outDir": "dist",
|
||||
"resolveJsonModule": true
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"path": "../wrappers"
|
||||
},
|
||||
{
|
||||
"path": "../formatters"
|
||||
},
|
||||
{
|
||||
"path": "../types"
|
||||
},
|
||||
{
|
||||
"path": "../utils"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
{
|
||||
"name": "@aiostreams/cloudflare-worker",
|
||||
"version": "1.21.1",
|
||||
"scripts": {
|
||||
"deploy": "wrangler deploy",
|
||||
"dev": "wrangler dev",
|
||||
"start": "wrangler dev",
|
||||
"test": "vitest",
|
||||
"cf-typegen": "wrangler types"
|
||||
},
|
||||
"dependencies": {
|
||||
"@aiostreams/addon": "^1.0.0",
|
||||
"@aiostreams/types": "^1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@cloudflare/workers-types": "^4.20241224.0",
|
||||
"typescript": "^5.5.2",
|
||||
"wrangler": "^3.99.0"
|
||||
}
|
||||
}
|
||||
@@ -1,171 +0,0 @@
|
||||
import { AIOStreams, errorResponse, validateConfig } from '@aiostreams/addon';
|
||||
import manifest from '@aiostreams/addon/src/manifest';
|
||||
import { Config, StreamRequest } from '@aiostreams/types';
|
||||
import { Cache, unminifyConfig } from '@aiostreams/utils';
|
||||
|
||||
const HEADERS = {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'GET,HEAD,POST,OPTIONS',
|
||||
};
|
||||
|
||||
function createJsonResponse(data: any): Response {
|
||||
return new Response(JSON.stringify(data, null, 4), {
|
||||
headers: HEADERS,
|
||||
});
|
||||
}
|
||||
|
||||
function createResponse(message: string, status: number): Response {
|
||||
return new Response(message, {
|
||||
status,
|
||||
headers: HEADERS,
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
async fetch(request, env, ctx): Promise<Response> {
|
||||
try {
|
||||
const url = new URL(decodeURIComponent(request.url));
|
||||
const components = url.pathname.split('/').splice(1);
|
||||
|
||||
// handle static asset requests
|
||||
if (components.includes('_next') || components.includes('assets')) {
|
||||
return env.ASSETS.fetch(request);
|
||||
}
|
||||
|
||||
if (url.pathname === '/icon.ico') {
|
||||
return env.ASSETS.fetch(request);
|
||||
}
|
||||
|
||||
// redirect to /configure if root path is requested
|
||||
if (url.pathname === '/') {
|
||||
return Response.redirect(url.origin + '/configure', 301);
|
||||
}
|
||||
|
||||
// handle /encrypt-user-data POST requests
|
||||
if (components.includes('encrypt-user-data')) {
|
||||
const data = (await request.json()) as { data: string };
|
||||
if (!data) {
|
||||
return createResponse('Invalid Request', 400);
|
||||
}
|
||||
const dataToEncode = data.data;
|
||||
try {
|
||||
console.log(
|
||||
`Received /encrypt-user-data request with Data: ${dataToEncode}`
|
||||
);
|
||||
const encodedData = Buffer.from(dataToEncode).toString('base64');
|
||||
return createJsonResponse({ data: encodedData, success: true });
|
||||
} catch (error: any) {
|
||||
console.error(error);
|
||||
return createJsonResponse({ error: error.message, success: false });
|
||||
}
|
||||
}
|
||||
// handle /configure and /:config/configure requests
|
||||
if (components.includes('configure')) {
|
||||
if (components.length === 1) {
|
||||
return env.ASSETS.fetch(request);
|
||||
} else {
|
||||
// display configure page with config still in url
|
||||
return env.ASSETS.fetch(
|
||||
new Request(url.origin + '/configure', request)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// handle /manifest.json and /:config/manifest.json requests
|
||||
if (components.includes('manifest.json')) {
|
||||
if (components.length === 1) {
|
||||
return createJsonResponse(manifest());
|
||||
} else {
|
||||
return createJsonResponse(manifest(undefined, true));
|
||||
}
|
||||
}
|
||||
|
||||
if (components.includes('stream')) {
|
||||
// when /stream is requested without config
|
||||
let config = decodeURIComponent(components[0]);
|
||||
console.log(`components: ${components}`);
|
||||
if (components.length < 4) {
|
||||
return createJsonResponse(
|
||||
errorResponse(
|
||||
'You must configure this addon first',
|
||||
url.origin,
|
||||
'/configure'
|
||||
)
|
||||
);
|
||||
}
|
||||
console.log(`Received /stream request with Config: ${config}`);
|
||||
const decodedPath = decodeURIComponent(url.pathname);
|
||||
|
||||
const streamMatch = /stream\/(movie|series)\/([^/]+)\.json/.exec(
|
||||
decodedPath
|
||||
);
|
||||
if (!streamMatch) {
|
||||
let path = decodedPath.replace(`/${config}`, '');
|
||||
console.error(`Invalid request: ${path}`);
|
||||
return createResponse('Invalid request', 400);
|
||||
}
|
||||
|
||||
const [type, id] = streamMatch.slice(1);
|
||||
console.log(`Received /stream request with Type: ${type}, ID: ${id}`);
|
||||
|
||||
let decodedConfig: Config;
|
||||
|
||||
if (config.startsWith('E-') || config.startsWith('E2-')) {
|
||||
return createResponse('Encrypted Config Not Supported', 400);
|
||||
}
|
||||
try {
|
||||
decodedConfig = unminifyConfig(
|
||||
JSON.parse(Buffer.from(config, 'base64').toString('utf-8'))
|
||||
);
|
||||
} catch (error: any) {
|
||||
console.error(error);
|
||||
return createJsonResponse(
|
||||
errorResponse(
|
||||
'Unable to parse config, please reconfigure or create an issue on GitHub',
|
||||
url.origin,
|
||||
'/configure'
|
||||
)
|
||||
);
|
||||
}
|
||||
const { valid, errorMessage, errorCode } =
|
||||
validateConfig(decodedConfig);
|
||||
if (!valid) {
|
||||
console.error(`Invalid config: ${errorMessage}`);
|
||||
return createJsonResponse(
|
||||
errorResponse(errorMessage ?? 'Unknown', url.origin, '/configure')
|
||||
);
|
||||
}
|
||||
|
||||
if (type !== 'movie' && type !== 'series') {
|
||||
return createResponse('Invalid Request', 400);
|
||||
}
|
||||
|
||||
let streamRequest: StreamRequest = { id, type };
|
||||
|
||||
decodedConfig.requestingIp =
|
||||
request.headers.get('X-Forwarded-For') ||
|
||||
request.headers.get('X-Real-IP') ||
|
||||
request.headers.get('CF-Connecting-IP') ||
|
||||
request.headers.get('X-Client-IP') ||
|
||||
undefined;
|
||||
|
||||
const aioStreams = new AIOStreams(decodedConfig);
|
||||
const streams = await aioStreams.getStreams(streamRequest);
|
||||
return createJsonResponse({ streams });
|
||||
}
|
||||
|
||||
const notFound = await env.ASSETS.fetch(
|
||||
new Request(url.origin + '/404', request)
|
||||
);
|
||||
return new Response(notFound.body, { ...notFound, status: 404 });
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return new Response('Internal Server Error', {
|
||||
status: 500,
|
||||
headers: {
|
||||
'Content-Type': 'text/plain',
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
} satisfies ExportedHandler<Env>;
|
||||
@@ -1,48 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2021",
|
||||
"lib": ["es2021"],
|
||||
/* Specify what JSX code is generated. */
|
||||
"jsx": "react-jsx",
|
||||
|
||||
/* Specify what module code is generated. */
|
||||
"module": "es2022",
|
||||
/* Specify how TypeScript looks up a file from a given module specifier. */
|
||||
"moduleResolution": "Bundler",
|
||||
/* Specify type package names to be included without being referenced in a source file. */
|
||||
"types": ["@cloudflare/workers-types"],
|
||||
/* Enable importing .json files */
|
||||
"resolveJsonModule": true,
|
||||
|
||||
/* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */
|
||||
"allowJs": true,
|
||||
/* Enable error reporting in type-checked JavaScript files. */
|
||||
"checkJs": false,
|
||||
|
||||
/* Disable emitting files from a compilation. */
|
||||
"noEmit": true,
|
||||
|
||||
/* Ensure that each file can be safely transpiled without relying on other imports. */
|
||||
"isolatedModules": true,
|
||||
/* Allow 'import x from y' when a module doesn't have a default export. */
|
||||
"allowSyntheticDefaultImports": true,
|
||||
/* Ensure that casing is correct in imports. */
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
|
||||
/* Enable all strict type-checking options. */
|
||||
"strict": true,
|
||||
|
||||
/* Skip type checking all .d.ts files. */
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"path": "../addon"
|
||||
},
|
||||
{
|
||||
"path": "../types"
|
||||
}
|
||||
],
|
||||
"exclude": ["test"],
|
||||
"include": ["worker-configuration.d.ts", "src/**/*.ts"]
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
// Generated by Wrangler by running `wrangler types`
|
||||
|
||||
interface Env {
|
||||
ASSETS: Fetcher;
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
#:schema node_modules/wrangler/config-schema.json
|
||||
name = "aiostreams"
|
||||
main = "src/index.ts"
|
||||
compatibility_date = "2024-12-24"
|
||||
compatibility_flags = ["nodejs_compat"]
|
||||
assets = { directory = "../frontend/out", binding = "ASSETS", experimental_serve_directly = false}
|
||||
|
||||
# Workers Logs
|
||||
# Docs: https://developers.cloudflare.com/workers/observability/logs/workers-logs/
|
||||
# Configuration: https://developers.cloudflare.com/workers/observability/logs/workers-logs/#enable-workers-logs
|
||||
[observability]
|
||||
enabled = true
|
||||
|
||||
# Automatically place your workloads in an optimal location to minimize latency.
|
||||
# If you are running back-end logic in a Worker, running it closer to your back-end infrastructure
|
||||
# rather than the end user may result in better performance.
|
||||
# Docs: https://developers.cloudflare.com/workers/configuration/smart-placement/#smart-placement
|
||||
# [placement]
|
||||
# mode = "smart"
|
||||
|
||||
# Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
|
||||
# Docs:
|
||||
# - https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
|
||||
# Note: Use secrets to store sensitive data.
|
||||
# - https://developers.cloudflare.com/workers/configuration/secrets/
|
||||
# [vars]
|
||||
# MY_VARIABLE = "production_value"
|
||||
|
||||
# Bind the Workers AI model catalog. Run machine learning models, powered by serverless GPUs, on Cloudflare’s global network
|
||||
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#workers-ai
|
||||
# [ai]
|
||||
# binding = "AI"
|
||||
|
||||
# Bind an Analytics Engine dataset. Use Analytics Engine to write analytics within your Pages Function.
|
||||
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#analytics-engine-datasets
|
||||
# [[analytics_engine_datasets]]
|
||||
# binding = "MY_DATASET"
|
||||
|
||||
# Bind a headless browser instance running on Cloudflare's global network.
|
||||
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#browser-rendering
|
||||
# [browser]
|
||||
# binding = "MY_BROWSER"
|
||||
|
||||
# Bind a D1 database. D1 is Cloudflare’s native serverless SQL database.
|
||||
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#d1-databases
|
||||
# [[d1_databases]]
|
||||
# binding = "MY_DB"
|
||||
# database_name = "my-database"
|
||||
# database_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
||||
|
||||
# Bind a dispatch namespace. Use Workers for Platforms to deploy serverless functions programmatically on behalf of your customers.
|
||||
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#dispatch-namespace-bindings-workers-for-platforms
|
||||
# [[dispatch_namespaces]]
|
||||
# binding = "MY_DISPATCHER"
|
||||
# namespace = "my-namespace"
|
||||
|
||||
# Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model.
|
||||
# Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps.
|
||||
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects
|
||||
# [[durable_objects.bindings]]
|
||||
# name = "MY_DURABLE_OBJECT"
|
||||
# class_name = "MyDurableObject"
|
||||
|
||||
# Durable Object migrations.
|
||||
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#migrations
|
||||
# [[migrations]]
|
||||
# tag = "v1"
|
||||
# new_classes = ["MyDurableObject"]
|
||||
|
||||
# Bind a Hyperdrive configuration. Use to accelerate access to your existing databases from Cloudflare Workers.
|
||||
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#hyperdrive
|
||||
# [[hyperdrive]]
|
||||
# binding = "MY_HYPERDRIVE"
|
||||
# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
|
||||
# Bind a KV Namespace. Use KV as persistent storage for small key-value pairs.
|
||||
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#kv-namespaces
|
||||
# [[kv_namespaces]]
|
||||
# binding = "MY_KV_NAMESPACE"
|
||||
# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
|
||||
# Bind an mTLS certificate. Use to present a client certificate when communicating with another service.
|
||||
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#mtls-certificates
|
||||
# [[mtls_certificates]]
|
||||
# binding = "MY_CERTIFICATE"
|
||||
# certificate_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
||||
|
||||
# Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer.
|
||||
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#queues
|
||||
# [[queues.producers]]
|
||||
# binding = "MY_QUEUE"
|
||||
# queue = "my-queue"
|
||||
|
||||
# Bind a Queue consumer. Queue Consumers can retrieve tasks scheduled by Producers to act on them.
|
||||
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#queues
|
||||
# [[queues.consumers]]
|
||||
# queue = "my-queue"
|
||||
|
||||
# Bind an R2 Bucket. Use R2 to store arbitrarily large blobs of data, such as files.
|
||||
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#r2-buckets
|
||||
# [[r2_buckets]]
|
||||
# binding = "MY_BUCKET"
|
||||
# bucket_name = "my-bucket"
|
||||
|
||||
# Bind another Worker service. Use this binding to call another Worker without network overhead.
|
||||
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#service-bindings
|
||||
# [[services]]
|
||||
# binding = "MY_SERVICE"
|
||||
# service = "my-service"
|
||||
|
||||
# Bind a Vectorize index. Use to store and query vector embeddings for semantic search, classification and other vector search use-cases.
|
||||
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#vectorize-indexes
|
||||
# [[vectorize]]
|
||||
# binding = "MY_INDEX"
|
||||
# index_name = "my-index"
|
||||
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"name": "@aiostreams/core",
|
||||
"version": "0.0.0",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"test": "vitest run --passWithNoTests",
|
||||
"test:watch": "vitest watch",
|
||||
"build": "tsc"
|
||||
},
|
||||
"description": "Combine all your streams into one addon and display them with consistent formatting, sorting, and filtering.",
|
||||
"dependencies": {
|
||||
"bcrypt": "^6.0.0",
|
||||
"dotenv": "^16.4.7",
|
||||
"envalid": "^8.0.0",
|
||||
"expr-eval": "^2.0.2",
|
||||
"moment-timezone": "^0.5.48",
|
||||
"parse-torrent-title": "github:TheBeastLT/parse-torrent-title",
|
||||
"pg": "^8.16.0",
|
||||
"sqlite": "^5.1.1",
|
||||
"sqlite3": "^5.1.7",
|
||||
"super-regex": "^1.0.0",
|
||||
"undici": "^7.2.3",
|
||||
"winston": "^3.17.0",
|
||||
"zod": "^3.24.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/bcrypt": "^5.0.2",
|
||||
"@types/node": "^20.14.10",
|
||||
"@types/pg": "^8.15.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,230 @@
|
||||
import { TABLES } from './schemas';
|
||||
import { createLogger } from '../utils';
|
||||
import { parseConnectionURI, adaptQuery, ConnectionURI } from './utils';
|
||||
|
||||
const logger = createLogger('database');
|
||||
|
||||
import { Pool, Client, QueryResult } from 'pg';
|
||||
import sqlite3 from 'sqlite3';
|
||||
import { open, Database } from 'sqlite';
|
||||
import { URL } from 'url';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
|
||||
type QueryResultRow = Record<string, any>;
|
||||
|
||||
interface UnifiedQueryResult<T = QueryResultRow> {
|
||||
rows: T[];
|
||||
rowCount: number;
|
||||
command?: string;
|
||||
}
|
||||
|
||||
type DBDialect = 'postgres' | 'sqlite';
|
||||
|
||||
type DSNModifier = (url: URL, query: URLSearchParams) => void;
|
||||
|
||||
type Transaction = {
|
||||
commit: () => Promise<void>;
|
||||
rollback: () => Promise<void>;
|
||||
execute: (query: string, params?: any[]) => Promise<UnifiedQueryResult<any>>;
|
||||
};
|
||||
|
||||
export class DB {
|
||||
private static instance: DB;
|
||||
private db!: Pool | Database<any>;
|
||||
private static initialised: boolean = false;
|
||||
private static dialect: DBDialect;
|
||||
private uri!: ConnectionURI;
|
||||
private dsnModifiers: DSNModifier[] = [];
|
||||
|
||||
private constructor() {}
|
||||
|
||||
static getInstance(): DB {
|
||||
if (!this.instance) {
|
||||
this.instance = new DB();
|
||||
}
|
||||
return this.instance;
|
||||
}
|
||||
isInitialised(): boolean {
|
||||
return DB.initialised;
|
||||
}
|
||||
|
||||
getDialect(): DBDialect {
|
||||
return DB.dialect;
|
||||
}
|
||||
|
||||
async initialise(
|
||||
uri: string,
|
||||
dsnModifiers: DSNModifier[] = []
|
||||
): Promise<void> {
|
||||
if (DB.initialised) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
this.uri = parseConnectionURI(uri);
|
||||
this.dsnModifiers = dsnModifiers;
|
||||
await this.open();
|
||||
await this.ping();
|
||||
|
||||
// create tables
|
||||
for (const [name, schema] of Object.entries(TABLES)) {
|
||||
const createTableQuery = `CREATE TABLE IF NOT EXISTS ${name} (${schema})`;
|
||||
await this.execute(createTableQuery);
|
||||
}
|
||||
|
||||
if (this.uri.dialect === 'sqlite') {
|
||||
await this.execute('PRAGMA busy_timeout = 5000');
|
||||
await this.execute('PRAGMA foreign_keys = ON');
|
||||
await this.execute('PRAGMA synchronous = OFF');
|
||||
await this.execute('PRAGMA journal_mode = WAL');
|
||||
await this.execute('PRAGMA locking_mode = IMMEDIATE');
|
||||
}
|
||||
|
||||
DB.initialised = true;
|
||||
DB.dialect = this.uri.dialect;
|
||||
} catch (error) {
|
||||
logger.error('Failed to initialize database:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async open(): Promise<void> {
|
||||
if (this.uri.dialect === 'postgres') {
|
||||
const pool = new Pool({
|
||||
connectionString: this.uri.url.toString(),
|
||||
idleTimeoutMillis: 30000,
|
||||
connectionTimeoutMillis: 2000,
|
||||
});
|
||||
this.db = pool;
|
||||
this.uri.dialect = 'postgres';
|
||||
} else if (this.uri.dialect === 'sqlite') {
|
||||
// make parent directory if it does not exist
|
||||
const parentDir = path.dirname(this.uri.filename);
|
||||
if (!parentDir) {
|
||||
throw new Error('Invalid SQLite path');
|
||||
}
|
||||
if (!fs.existsSync(parentDir)) {
|
||||
fs.mkdirSync(parentDir, { recursive: true });
|
||||
}
|
||||
logger.debug(`Opening SQLite database: ${this.uri.filename}`);
|
||||
|
||||
this.db = await open({
|
||||
filename: this.uri.filename,
|
||||
driver: sqlite3.Database,
|
||||
});
|
||||
this.uri.dialect = 'sqlite';
|
||||
}
|
||||
}
|
||||
|
||||
async close(): Promise<void> {
|
||||
if (this.uri.dialect === 'postgres') {
|
||||
await (this.db as Pool).end();
|
||||
} else if (this.uri.dialect === 'sqlite') {
|
||||
await (this.db as Database<any>).close();
|
||||
}
|
||||
}
|
||||
|
||||
async ping(): Promise<void> {
|
||||
if (this.uri.dialect === 'postgres') {
|
||||
await (this.db as Pool).query('SELECT 1');
|
||||
} else if (this.uri.dialect === 'sqlite') {
|
||||
await (this.db as Database<any>).get('SELECT 1');
|
||||
}
|
||||
}
|
||||
|
||||
async execute(query: string, params?: any[]): Promise<any> {
|
||||
if (this.uri.dialect === 'postgres') {
|
||||
return (this.db as Pool).query(
|
||||
adaptQuery(query, this.uri.dialect),
|
||||
params
|
||||
);
|
||||
} else if (this.uri.dialect === 'sqlite') {
|
||||
return (this.db as Database<any>).run(
|
||||
adaptQuery(query, this.uri.dialect),
|
||||
params
|
||||
);
|
||||
}
|
||||
throw new Error('Unsupported dialect');
|
||||
}
|
||||
|
||||
async query(query: string, params?: any[]): Promise<any[]> {
|
||||
const adaptedQuery = adaptQuery(query, this.uri.dialect);
|
||||
if (this.uri.dialect === 'postgres') {
|
||||
const result = await (this.db as Pool).query(adaptedQuery, params);
|
||||
return result.rows;
|
||||
} else if (this.uri.dialect === 'sqlite') {
|
||||
return (this.db as Database<any>).all(adaptedQuery, params);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
async begin(): Promise<Transaction> {
|
||||
if (this.uri.dialect === 'postgres') {
|
||||
const client = await (this.db as Pool).connect();
|
||||
await client.query('BEGIN');
|
||||
|
||||
let finalised = false;
|
||||
|
||||
const finalise = () => {
|
||||
if (!finalised) {
|
||||
finalised = true;
|
||||
client.release();
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
commit: async () => {
|
||||
try {
|
||||
await client.query('COMMIT');
|
||||
} finally {
|
||||
finalise();
|
||||
}
|
||||
},
|
||||
rollback: async () => {
|
||||
try {
|
||||
await client.query('ROLLBACK');
|
||||
} finally {
|
||||
finalise();
|
||||
}
|
||||
},
|
||||
execute: async (
|
||||
query: string,
|
||||
params?: any[]
|
||||
): Promise<UnifiedQueryResult> => {
|
||||
const result = await client.query(
|
||||
adaptQuery(query, 'postgres'),
|
||||
params
|
||||
);
|
||||
return {
|
||||
rows: result.rows,
|
||||
rowCount: result.rowCount || 0,
|
||||
command: result.command,
|
||||
};
|
||||
},
|
||||
};
|
||||
} else if (this.uri.dialect === 'sqlite') {
|
||||
const db = this.db as Database<any>;
|
||||
await db.run('BEGIN');
|
||||
return {
|
||||
commit: async () => {
|
||||
await db.run('COMMIT');
|
||||
},
|
||||
rollback: async () => {
|
||||
await db.run('ROLLBACK');
|
||||
},
|
||||
execute: async (
|
||||
query: string,
|
||||
params?: any[]
|
||||
): Promise<UnifiedQueryResult> => {
|
||||
const result = await db.all(adaptQuery(query, 'sqlite'), params);
|
||||
return {
|
||||
rows: result,
|
||||
rowCount: result.length || 0,
|
||||
command: 'SELECT',
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
throw new Error('Unsupported transaction dialect');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
export * from './db';
|
||||
export * from './users';
|
||||
export * from './schemas';
|
||||
export * from './queue';
|
||||
@@ -0,0 +1,58 @@
|
||||
import { createLogger } from '../utils';
|
||||
import { DB } from './db';
|
||||
const logger = createLogger('db');
|
||||
const db = DB.getInstance();
|
||||
|
||||
// Queue for SQLite transactions
|
||||
|
||||
export class TransactionQueue {
|
||||
private queue: Array<() => Promise<any>> = [];
|
||||
private processing = false;
|
||||
private static instance: TransactionQueue;
|
||||
|
||||
private constructor() {}
|
||||
|
||||
static getInstance(): TransactionQueue {
|
||||
if (!this.instance) {
|
||||
this.instance = new TransactionQueue();
|
||||
}
|
||||
return this.instance;
|
||||
}
|
||||
|
||||
async enqueue<T>(operation: () => Promise<T>): Promise<T> {
|
||||
// If using PostgreSQL, execute directly without queuing
|
||||
if (db['uri']?.dialect === 'postgres') {
|
||||
return operation();
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.queue.push(async () => {
|
||||
try {
|
||||
const result = await operation();
|
||||
resolve(result);
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
this.processQueue();
|
||||
});
|
||||
}
|
||||
|
||||
private async processQueue() {
|
||||
if (this.processing || this.queue.length === 0) return;
|
||||
this.processing = true;
|
||||
|
||||
while (this.queue.length > 0) {
|
||||
const operation = this.queue.shift();
|
||||
if (operation) {
|
||||
try {
|
||||
await operation();
|
||||
} catch (error) {
|
||||
logger.error('Error processing queued operation:', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.processing = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,777 @@
|
||||
import { z } from 'zod';
|
||||
import * as constants from '../utils/constants';
|
||||
|
||||
const ServiceIds = z.enum(constants.SERVICES);
|
||||
|
||||
const Resolutions = z.enum(constants.RESOLUTIONS);
|
||||
|
||||
const Qualities = z.enum(constants.QUALITIES);
|
||||
|
||||
const VisualTags = z.enum(constants.VISUAL_TAGS);
|
||||
|
||||
const AudioTags = z.enum(constants.AUDIO_TAGS);
|
||||
|
||||
const AudioChannels = z.enum(constants.AUDIO_CHANNELS);
|
||||
|
||||
const Encodes = z.enum(constants.ENCODES);
|
||||
|
||||
// const SortCriteria = z.enum(constants.SORT_CRITERIA);
|
||||
|
||||
// const SortDirections = z.enum(constants.SORT_DIRECTIONS);
|
||||
|
||||
const SortCriterion = z.object({
|
||||
key: z.enum(constants.SORT_CRITERIA),
|
||||
direction: z.enum(constants.SORT_DIRECTIONS),
|
||||
});
|
||||
|
||||
export type SortCriterion = z.infer<typeof SortCriterion>;
|
||||
|
||||
const StreamTypes = z.enum(constants.STREAM_TYPES);
|
||||
const Languages = z.enum(constants.LANGUAGES);
|
||||
|
||||
const Formatter = z.object({
|
||||
id: z.enum(constants.FORMATTERS),
|
||||
definition: z
|
||||
.object({
|
||||
name: z.string().min(1),
|
||||
description: z.string().min(1),
|
||||
})
|
||||
.optional(),
|
||||
});
|
||||
|
||||
const StreamProxyConfig = z.object({
|
||||
enabled: z.boolean().optional(),
|
||||
id: z.enum(constants.PROXY_SERVICES).optional(),
|
||||
url: z.string().optional(),
|
||||
credentials: z.string().min(1).optional(),
|
||||
publicIp: z.string().ip().optional(),
|
||||
proxiedAddons: z.array(z.string().min(1)).optional(),
|
||||
proxiedServices: z.array(z.string().min(1)).optional(),
|
||||
});
|
||||
|
||||
export type StreamProxyConfig = z.infer<typeof StreamProxyConfig>;
|
||||
|
||||
const ResultLimitOptions = z.object({
|
||||
global: z.number().min(1).optional(),
|
||||
service: z.number().min(1).optional(),
|
||||
addon: z.number().min(1).optional(),
|
||||
resolution: z.number().min(1).optional(),
|
||||
quality: z.number().min(1).optional(),
|
||||
streamType: z.number().min(1).optional(),
|
||||
indexer: z.number().min(1).optional(),
|
||||
releaseGroup: z.number().min(1).optional(),
|
||||
});
|
||||
|
||||
// const SizeFilter = z.object({
|
||||
// min: z.number().min(1).optional(),
|
||||
// max: z.number().min(1).optional(),
|
||||
// });
|
||||
const SizeFilter = z.object({
|
||||
movies: z
|
||||
.tuple([z.number().min(0), z.number().min(0)])
|
||||
// .object({
|
||||
// min: z.number().min(1).optional(),
|
||||
// max: z.number().min(1).optional(),
|
||||
// })
|
||||
.optional(),
|
||||
series: z
|
||||
.tuple([z.number().min(0), z.number().min(0)])
|
||||
// .object({
|
||||
// min: z.number().min(1).optional(),
|
||||
// max: z.number().min(1).optional(),
|
||||
// })
|
||||
.optional(),
|
||||
});
|
||||
|
||||
const SizeFilterOptions = z.object({
|
||||
global: SizeFilter,
|
||||
resolution: z.record(Resolutions, SizeFilter).optional(),
|
||||
});
|
||||
|
||||
const ServiceSchema = z.object({
|
||||
id: ServiceIds,
|
||||
enabled: z.boolean().optional(),
|
||||
credentials: z.record(z.string().min(1), z.string().min(1)),
|
||||
});
|
||||
|
||||
export type Service = z.infer<typeof ServiceSchema>;
|
||||
|
||||
const ServiceList = z.array(ServiceSchema);
|
||||
|
||||
const ResourceSchema = z.enum(constants.RESOURCES);
|
||||
|
||||
export type Resource = z.infer<typeof ResourceSchema>;
|
||||
|
||||
const ResourceList = z.array(ResourceSchema);
|
||||
|
||||
const AddonSchema = z.object({
|
||||
id: z.string().min(1).optional(),
|
||||
manifestUrl: z.string().url(),
|
||||
enabled: z.boolean(),
|
||||
resources: ResourceList.optional(),
|
||||
name: z.string().min(1),
|
||||
identifyingName: z.string().min(1),
|
||||
timeout: z.number().min(1),
|
||||
library: z.boolean().optional(),
|
||||
streamPassthrough: z.boolean().optional(),
|
||||
fromPresetId: z.string().min(1).optional(),
|
||||
headers: z.record(z.string().min(1), z.string().min(1)).optional(),
|
||||
ip: z.string().ip().optional(),
|
||||
});
|
||||
|
||||
// preset objects are transformed into addons by a preset transformer.
|
||||
const PresetSchema = z.object({
|
||||
id: z.string().min(1),
|
||||
enabled: z.boolean(),
|
||||
options: z.record(z.string().min(1), z.any()),
|
||||
});
|
||||
|
||||
export type PresetObject = z.infer<typeof PresetSchema>;
|
||||
|
||||
const AddonList = z.array(AddonSchema);
|
||||
const PresetList = z.array(PresetSchema);
|
||||
|
||||
export type Addon = z.infer<typeof AddonSchema>;
|
||||
export type Preset = z.infer<typeof PresetSchema>;
|
||||
|
||||
const DeduplicatorKey = z.enum(constants.DEDUPLICATOR_KEYS);
|
||||
|
||||
// deduplicator options.
|
||||
// can choose what keys to use for identifying duplicates.
|
||||
// can choose how duplicates are removed specifically.
|
||||
// we can either
|
||||
// - keep only 1 result from the highest priority service from the highest priority addon (single_result)
|
||||
// - keep 1 result for each enabled service from the higest priority addon (per_service)
|
||||
// - keep 1 result from the highest priority service from each enabled addon (per_addon)
|
||||
const DeduplicatorMode = z.enum([
|
||||
'single_result',
|
||||
'per_service',
|
||||
'per_addon',
|
||||
'disabled',
|
||||
]);
|
||||
|
||||
const DeduplicatorOptions = z.object({
|
||||
enabled: z.boolean().optional(),
|
||||
keys: z.array(DeduplicatorKey).optional(),
|
||||
cached: DeduplicatorMode.optional(),
|
||||
uncached: DeduplicatorMode.optional(),
|
||||
p2p: DeduplicatorMode.optional(),
|
||||
http: DeduplicatorMode.optional(),
|
||||
live: DeduplicatorMode.optional(),
|
||||
youtube: DeduplicatorMode.optional(),
|
||||
external: DeduplicatorMode.optional(),
|
||||
});
|
||||
|
||||
const OptionDefinition = z.object({
|
||||
id: z.string().min(1),
|
||||
name: z.string().min(1),
|
||||
description: z.string().min(1),
|
||||
emptyIsUndefined: z.boolean().optional(),
|
||||
type: z.enum([
|
||||
'string',
|
||||
'password',
|
||||
'number',
|
||||
'boolean',
|
||||
'select',
|
||||
'multi-select',
|
||||
'url',
|
||||
]),
|
||||
required: z.boolean().optional(),
|
||||
default: z.any().optional(),
|
||||
// sensitive: z.boolean().optional(),
|
||||
forced: z.any().optional(),
|
||||
options: z
|
||||
.array(
|
||||
z.object({
|
||||
value: z.any(),
|
||||
label: z.string().min(1),
|
||||
})
|
||||
)
|
||||
.optional(),
|
||||
constraints: z
|
||||
.object({
|
||||
min: z.number().min(1).optional(), // for string inputs, consider this the minimum length.
|
||||
max: z.number().min(1).optional(), // and for number inputs, consider this the minimum and maximum value.
|
||||
})
|
||||
.optional(),
|
||||
});
|
||||
|
||||
export type Option = z.infer<typeof OptionDefinition>;
|
||||
|
||||
const NameableRegex = z.object({
|
||||
name: z.string().min(0),
|
||||
pattern: z.string().min(1),
|
||||
});
|
||||
|
||||
const Group = z.object({
|
||||
addons: z.array(z.string().min(1)).min(1),
|
||||
condition: z.string().min(1).max(200),
|
||||
});
|
||||
|
||||
export type Group = z.infer<typeof Group>;
|
||||
|
||||
// Resolution, Quality, Encode, Visual Tag, Audio Tag, Stream Type, Keyword, Regex, Cached, Uncached, Size
|
||||
|
||||
const CatalogModification = z.object({
|
||||
id: z.string().min(1), // an id that maps to an actual catalog ID
|
||||
type: z.string().min(1), // the type of catalog modification
|
||||
name: z.string().min(1).optional(), // override the name of the catalog
|
||||
shuffle: z.boolean().optional(), // shuffle the catalog
|
||||
onlyOnDiscover: z.boolean().optional(), // only show the catalog on the discover page
|
||||
enabled: z.boolean().optional(), // enable or disable the catalog
|
||||
rpdb: z.boolean().optional(), // use rpdb for posters if supported
|
||||
hideable: z.boolean().optional(), // hide the catalog from the home page
|
||||
addonName: z.string().min(1).optional(), // the name of the addon that provides the catalog
|
||||
});
|
||||
|
||||
export const UserDataSchema = z.object({
|
||||
uuid: z.string().uuid().optional(),
|
||||
encryptedPassword: z.string().min(1).optional(),
|
||||
trusted: z.boolean().optional(),
|
||||
addonPassword: z.string().min(1).optional(),
|
||||
ip: z.string().ip().optional(),
|
||||
addonName: z.string().min(1).optional(),
|
||||
addonLogo: z.string().url().optional(),
|
||||
addonBackground: z.string().url().optional(),
|
||||
addonDescription: z.string().min(1).optional(),
|
||||
excludedResolutions: z.array(Resolutions).optional(),
|
||||
includedResolutions: z.array(Resolutions).optional(),
|
||||
requiredResolutions: z.array(Resolutions).optional(),
|
||||
preferredResolutions: z.array(Resolutions).optional(),
|
||||
excludedQualities: z.array(Qualities).optional(),
|
||||
includedQualities: z.array(Qualities).optional(),
|
||||
requiredQualities: z.array(Qualities).optional(),
|
||||
preferredQualities: z.array(Qualities).optional(),
|
||||
excludedLanguages: z.array(Languages).optional(),
|
||||
includedLanguages: z.array(Languages).optional(),
|
||||
requiredLanguages: z.array(Languages).optional(),
|
||||
preferredLanguages: z.array(Languages).optional(),
|
||||
excludedVisualTags: z.array(VisualTags).optional(),
|
||||
includedVisualTags: z.array(VisualTags).optional(),
|
||||
requiredVisualTags: z.array(VisualTags).optional(),
|
||||
preferredVisualTags: z.array(VisualTags).optional(),
|
||||
excludedAudioTags: z.array(AudioTags).optional(),
|
||||
includedAudioTags: z.array(AudioTags).optional(),
|
||||
requiredAudioTags: z.array(AudioTags).optional(),
|
||||
preferredAudioTags: z.array(AudioTags).optional(),
|
||||
excludedAudioChannels: z.array(AudioChannels).optional(),
|
||||
includedAudioChannels: z.array(AudioChannels).optional(),
|
||||
requiredAudioChannels: z.array(AudioChannels).optional(),
|
||||
preferredAudioChannels: z.array(AudioChannels).optional(),
|
||||
excludedStreamTypes: z.array(StreamTypes).optional(),
|
||||
includedStreamTypes: z.array(StreamTypes).optional(),
|
||||
requiredStreamTypes: z.array(StreamTypes).optional(),
|
||||
preferredStreamTypes: z.array(StreamTypes).optional(),
|
||||
excludedEncodes: z.array(Encodes).optional(),
|
||||
includedEncodes: z.array(Encodes).optional(),
|
||||
requiredEncodes: z.array(Encodes).optional(),
|
||||
preferredEncodes: z.array(Encodes).optional(),
|
||||
excludedRegexPatterns: z.array(z.string().min(1)).optional(),
|
||||
includedRegexPatterns: z.array(z.string().min(1)).optional(),
|
||||
requiredRegexPatterns: z.array(z.string().min(1)).optional(),
|
||||
preferredRegexPatterns: z.array(NameableRegex).optional(),
|
||||
requiredKeywords: z.array(z.string().min(1)).optional(),
|
||||
includedKeywords: z.array(z.string().min(1)).optional(),
|
||||
excludedKeywords: z.array(z.string().min(1)).optional(),
|
||||
preferredKeywords: z.array(z.string().min(1)).optional(),
|
||||
|
||||
randomiseResults: z.boolean().optional(),
|
||||
enhanceResults: z.boolean().optional(),
|
||||
enhancePosters: z.boolean().optional(),
|
||||
|
||||
excludeSeederRange: z
|
||||
.tuple([z.number().min(0), z.number().min(0)])
|
||||
.optional(),
|
||||
includeSeederRange: z
|
||||
.tuple([z.number().min(0), z.number().min(0)])
|
||||
.optional(),
|
||||
requiredSeederRange: z
|
||||
.tuple([z.number().min(0), z.number().min(0)])
|
||||
.optional(),
|
||||
seederRangeTypes: z.array(z.enum(['p2p', 'cached', 'uncached'])).optional(),
|
||||
excludeCached: z.boolean().optional(),
|
||||
excludeCachedFromAddons: z.array(z.string().min(1)).optional(),
|
||||
excludeCachedFromServices: z.array(z.string().min(1)).optional(),
|
||||
excludeCachedFromStreamTypes: z.array(StreamTypes).optional(),
|
||||
excludeCachedMode: z.enum(['or', 'and']).optional(),
|
||||
excludeUncached: z.boolean().optional(),
|
||||
excludeUncachedFromAddons: z.array(z.string().min(1)).optional(),
|
||||
excludeUncachedFromServices: z.array(z.string().min(1)).optional(),
|
||||
excludeUncachedFromStreamTypes: z.array(StreamTypes).optional(),
|
||||
excludeUncachedMode: z.enum(['or', 'and']).optional(),
|
||||
groups: z
|
||||
.array(
|
||||
z.object({
|
||||
addons: z.array(z.string().min(1)),
|
||||
condition: z.string().min(1).max(200),
|
||||
})
|
||||
)
|
||||
.optional(),
|
||||
sortCriteria: z.object({
|
||||
// global must be defined.
|
||||
global: z.array(SortCriterion),
|
||||
// results must be from either a movie or series search, so we can safely apply different sort criteria.
|
||||
movies: z.array(SortCriterion).optional(),
|
||||
series: z.array(SortCriterion).optional(),
|
||||
// cached and uncached results are a sort criteria themselves, so this can only be applied when cache is high enough in the global
|
||||
// sort criteria, and we would have to split the results into two (cached and uncached) lists, and then apply both sort criteria below
|
||||
// and then merge the results.
|
||||
cached: z.array(SortCriterion).optional(),
|
||||
uncached: z.array(SortCriterion).optional(),
|
||||
cachedMovies: z.array(SortCriterion).optional(),
|
||||
uncachedMovies: z.array(SortCriterion).optional(),
|
||||
cachedSeries: z.array(SortCriterion).optional(),
|
||||
uncachedSeries: z.array(SortCriterion).optional(),
|
||||
}),
|
||||
rpdbApiKey: z.string().optional(),
|
||||
formatter: Formatter,
|
||||
proxy: StreamProxyConfig.optional(),
|
||||
resultLimits: ResultLimitOptions.optional(),
|
||||
size: SizeFilterOptions.optional(),
|
||||
hideErrors: z.boolean().optional(),
|
||||
hideErrorsForResources: z.array(ResourceSchema).optional(),
|
||||
tmdbAccessToken: z.string().optional(),
|
||||
titleMatching: z
|
||||
.object({
|
||||
mode: z.enum(['exact', 'contains']).optional(),
|
||||
enabled: z.boolean().optional(),
|
||||
requestTypes: z.array(z.string()).optional(),
|
||||
addons: z.array(z.string()).optional(),
|
||||
})
|
||||
.optional(),
|
||||
seasonEpisodeMatching: z
|
||||
.object({
|
||||
enabled: z.boolean().optional(),
|
||||
requestTypes: z.array(z.string()).optional(),
|
||||
addons: z.array(z.string()).optional(),
|
||||
})
|
||||
.optional(),
|
||||
deduplicator: DeduplicatorOptions.optional(),
|
||||
precacheNextEpisode: z.boolean().optional(),
|
||||
services: ServiceList.optional(),
|
||||
presets: PresetList,
|
||||
catalogModifications: z.array(CatalogModification).optional(),
|
||||
});
|
||||
|
||||
export type UserData = z.infer<typeof UserDataSchema>;
|
||||
|
||||
export const TABLES = {
|
||||
USERS: `
|
||||
uuid TEXT PRIMARY KEY,
|
||||
password_hash TEXT NOT NULL,
|
||||
config TEXT NOT NULL,
|
||||
config_salt TEXT NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP),
|
||||
updated_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP),
|
||||
accessed_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP)
|
||||
`,
|
||||
};
|
||||
|
||||
const strictManifestResourceSchema = z.object({
|
||||
name: z.enum(constants.RESOURCES),
|
||||
types: z.array(z.string()),
|
||||
idPrefixes: z.array(z.string().min(1)).optional(),
|
||||
});
|
||||
|
||||
export type StrictManifestResource = z.infer<
|
||||
typeof strictManifestResourceSchema
|
||||
>;
|
||||
|
||||
const ManifestResourceSchema = z.union([
|
||||
z.string(),
|
||||
strictManifestResourceSchema,
|
||||
]);
|
||||
|
||||
const ManifestExtraSchema = z.object({
|
||||
name: z.string().min(1),
|
||||
isRequired: z.boolean().optional(),
|
||||
options: z.array(z.string()).optional(),
|
||||
optionsLimit: z.number().min(1).optional(),
|
||||
});
|
||||
const ManifestCatalogSchema = z.object({
|
||||
type: z.string(),
|
||||
id: z.string().min(1),
|
||||
name: z.string().min(1),
|
||||
extra: z.array(ManifestExtraSchema).optional(),
|
||||
});
|
||||
|
||||
const AddonCatalogDefinitionSchema = z.object({
|
||||
type: z.string(),
|
||||
id: z.string().min(1),
|
||||
name: z.string().min(1),
|
||||
});
|
||||
|
||||
export const ManifestSchema = z.object({
|
||||
id: z.string().min(1),
|
||||
name: z.string().min(1),
|
||||
description: z.string().min(1),
|
||||
version: z.string().min(1),
|
||||
types: z.array(z.string()),
|
||||
idPrefixes: z.array(z.string().min(1)).optional(),
|
||||
resources: z.array(ManifestResourceSchema),
|
||||
catalogs: z.array(ManifestCatalogSchema),
|
||||
addonCatalogs: z.array(AddonCatalogDefinitionSchema).optional(),
|
||||
background: z.string().min(1).optional(),
|
||||
logo: z.string().optional(),
|
||||
contactEmail: z.string().min(1).optional(),
|
||||
behaviorHints: z
|
||||
.object({
|
||||
adult: z.boolean().optional(),
|
||||
p2p: z.boolean().optional(),
|
||||
configurable: z.boolean().optional(),
|
||||
configurationRequired: z.boolean().optional(),
|
||||
})
|
||||
.optional(),
|
||||
// not part of the manifest scheme, but needed for stremio-addons.net
|
||||
stremioAddonsConfig: z
|
||||
.object({
|
||||
issuer: z.string().min(1),
|
||||
signature: z.string().min(1),
|
||||
})
|
||||
.optional(),
|
||||
});
|
||||
|
||||
export type Manifest = z.infer<typeof ManifestSchema>;
|
||||
|
||||
export const SubtitleSchema = z
|
||||
.object({
|
||||
id: z.string().min(1),
|
||||
url: z.string().url(),
|
||||
lang: z.string().min(1),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
export const SubtitleResponseSchema = z.object({
|
||||
subtitles: z.array(SubtitleSchema),
|
||||
});
|
||||
export type SubtitleResponse = z.infer<typeof SubtitleResponseSchema>;
|
||||
export type Subtitle = z.infer<typeof SubtitleSchema>;
|
||||
|
||||
export const StreamSchema = z
|
||||
.object({
|
||||
url: z.string().url().optional(),
|
||||
ytId: z.string().min(1).optional(),
|
||||
infoHash: z.string().min(1).or(z.null()).optional(),
|
||||
fileIdx: z.number().or(z.null()).optional(),
|
||||
externalUrl: z.string().min(1).optional(),
|
||||
name: z.string().min(1).optional(),
|
||||
title: z.string().min(1).optional(),
|
||||
description: z.string().min(1).optional(),
|
||||
subtitles: z.array(SubtitleSchema).optional(),
|
||||
sources: z.array(z.string().min(1)).optional(),
|
||||
behaviorHints: z
|
||||
.object({
|
||||
countryWhitelist: z.array(z.string().length(3)).optional(),
|
||||
notWebReady: z.boolean().optional(),
|
||||
bingeGroup: z.string().min(1).optional(),
|
||||
proxyHeaders: z
|
||||
.object({
|
||||
request: z.record(z.string().min(1), z.string().min(1)).optional(),
|
||||
response: z.record(z.string().min(1), z.string().min(1)).optional(),
|
||||
})
|
||||
.optional(),
|
||||
videoHash: z.string().min(1).optional(),
|
||||
videoSize: z.number().optional(),
|
||||
filename: z.string().min(1).optional(),
|
||||
})
|
||||
.optional(),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
export const StreamResponseSchema = z.object({
|
||||
streams: z.array(StreamSchema),
|
||||
});
|
||||
|
||||
export type StreamResponse = z.infer<typeof StreamResponseSchema>;
|
||||
|
||||
export type Stream = z.infer<typeof StreamSchema>;
|
||||
|
||||
const TrailerSchema = z.object({
|
||||
source: z.string().min(1),
|
||||
type: z.enum(['Trailer']),
|
||||
});
|
||||
|
||||
const MetaLinkSchema = z.object({
|
||||
name: z.string().min(1),
|
||||
category: z.string().min(1),
|
||||
url: z.string().url().or(z.string().startsWith('stremio:///')),
|
||||
});
|
||||
|
||||
const MetaVideoSchema = z.object({
|
||||
id: z.string().min(1),
|
||||
title: z.string().optional(),
|
||||
released: z.string().datetime().optional(),
|
||||
thumbnail: z.string().url().or(z.null()).optional(),
|
||||
streams: z.array(StreamSchema).optional(),
|
||||
available: z.boolean().optional(),
|
||||
episode: z.number().optional(),
|
||||
season: z.number().optional(),
|
||||
trailers: z.array(TrailerSchema).optional(),
|
||||
overview: z.string().optional(),
|
||||
});
|
||||
|
||||
export const MetaPreviewSchema = z.object({
|
||||
id: z.string().min(1),
|
||||
type: z.string().min(1),
|
||||
name: z.string().optional(),
|
||||
poster: z.string().optional(),
|
||||
posterShape: z.enum(['square', 'poster', 'landscape', 'regular']).optional(),
|
||||
// discover sidebar
|
||||
//@deprecated use links instead
|
||||
genres: z.array(z.string()).optional(),
|
||||
imdbRating: z.string().or(z.null()).or(z.number()).optional(),
|
||||
releaseInfo: z.string().or(z.number()).or(z.null()).optional(),
|
||||
//@deprecated
|
||||
director: z.array(z.string()).or(z.null()).optional(),
|
||||
//@deprecated
|
||||
cast: z.array(z.string()).or(z.null()).optional(),
|
||||
// background: z.string().min(1).optional(),
|
||||
// logo: z.string().min(1).optional(),
|
||||
description: z.string().or(z.null()).optional(),
|
||||
trailers: z.array(TrailerSchema).optional(),
|
||||
links: z.array(MetaLinkSchema).optional(),
|
||||
// released: z.string().datetime().optional(),
|
||||
});
|
||||
|
||||
export const MetaSchema = MetaPreviewSchema.extend({
|
||||
poster: z.string().min(1).optional(),
|
||||
background: z.string().min(1).optional(),
|
||||
logo: z.string().optional(),
|
||||
videos: z.array(MetaVideoSchema).optional(),
|
||||
runtime: z.string().optional(),
|
||||
language: z.string().min(1).optional(),
|
||||
country: z.string().optional(),
|
||||
awards: z.string().min(1).optional(),
|
||||
website: z.string().url().optional(),
|
||||
behaviorHints: z
|
||||
.object({
|
||||
defaultVideoId: z.string().or(z.null()).optional(),
|
||||
})
|
||||
.optional(),
|
||||
});
|
||||
|
||||
export const MetaResponseSchema = z.object({
|
||||
meta: MetaSchema,
|
||||
});
|
||||
export const CatalogResponseSchema = z.object({
|
||||
metas: z.array(MetaPreviewSchema),
|
||||
});
|
||||
export type MetaResponse = z.infer<typeof MetaResponseSchema>;
|
||||
export type CatalogResponse = z.infer<typeof CatalogResponseSchema>;
|
||||
export type Meta = z.infer<typeof MetaSchema>;
|
||||
export type MetaPreview = z.infer<typeof MetaPreviewSchema>;
|
||||
|
||||
export const AddonCatalogSchema = z.object({
|
||||
transportName: z.literal('http'),
|
||||
transportUrl: z.string().url(),
|
||||
manifest: ManifestSchema,
|
||||
});
|
||||
export const AddonCatalogResponseSchema = z.object({
|
||||
addons: z.array(AddonCatalogSchema),
|
||||
});
|
||||
export type AddonCatalogResponse = z.infer<typeof AddonCatalogResponseSchema>;
|
||||
export type AddonCatalog = z.infer<typeof AddonCatalogSchema>;
|
||||
|
||||
const ParsedFileSchema = z.object({
|
||||
releaseGroup: z.string().optional(),
|
||||
resolution: z.string().optional(),
|
||||
quality: z.string().optional(),
|
||||
encode: z.string().optional(),
|
||||
audioChannels: z.array(z.string()),
|
||||
visualTags: z.array(z.string()),
|
||||
audioTags: z.array(z.string()),
|
||||
languages: z.array(z.string()),
|
||||
title: z.string().optional(),
|
||||
year: z.string().optional(),
|
||||
season: z.number().optional(),
|
||||
seasons: z.array(z.number()).optional(),
|
||||
episode: z.number().optional(),
|
||||
seasonEpisode: z.array(z.string()).optional(),
|
||||
});
|
||||
|
||||
export type ParsedFile = z.infer<typeof ParsedFileSchema>;
|
||||
|
||||
export const ParsedStreamSchema = z.object({
|
||||
proxied: z.boolean().optional(),
|
||||
addon: AddonSchema,
|
||||
parsedFile: ParsedFileSchema.optional(),
|
||||
message: z.string().max(1000).optional(),
|
||||
regexMatched: z
|
||||
.object({
|
||||
name: z.string().min(1).optional(),
|
||||
pattern: z.string().min(1).optional(),
|
||||
index: z.number(),
|
||||
})
|
||||
.optional(),
|
||||
keywordMatched: z.boolean().optional(),
|
||||
size: z.number().optional(),
|
||||
folderSize: z.number().optional(),
|
||||
type: StreamTypes,
|
||||
indexer: z.string().optional(),
|
||||
age: z.string().optional(),
|
||||
torrent: z
|
||||
.object({
|
||||
infoHash: z.string().min(1).or(z.null()).optional(),
|
||||
fileIdx: z.number().or(z.null()).optional(),
|
||||
seeders: z.number().optional(),
|
||||
sources: z.array(z.string().min(1)).optional(), // array of tracker urls and DHT nodes
|
||||
})
|
||||
.optional(),
|
||||
countryWhitelist: z.array(z.string().length(3)).optional(),
|
||||
notWebReady: z.boolean().optional(),
|
||||
bingeGroup: z.string().min(1).optional(),
|
||||
requestHeaders: z.record(z.string().min(1), z.string().min(1)).optional(),
|
||||
responseHeaders: z.record(z.string().min(1), z.string().min(1)).optional(),
|
||||
videoHash: z.string().min(1).optional(),
|
||||
subtitles: z.array(SubtitleSchema).optional(),
|
||||
filename: z.string().optional(),
|
||||
folderName: z.string().optional(),
|
||||
service: z
|
||||
.object({
|
||||
id: z.enum(constants.SERVICES),
|
||||
cached: z.boolean(),
|
||||
})
|
||||
.optional(),
|
||||
duration: z.number().optional(),
|
||||
library: z.boolean().optional(),
|
||||
url: z.string().url().optional(),
|
||||
ytId: z.string().min(1).optional(),
|
||||
externalUrl: z.string().min(1).optional(),
|
||||
error: z
|
||||
.object({
|
||||
title: z.string().min(1),
|
||||
description: z.string().min(1),
|
||||
})
|
||||
.optional(),
|
||||
originalName: z.string().optional(),
|
||||
originalDescription: z.string().optional(),
|
||||
});
|
||||
|
||||
export type ParsedStream = z.infer<typeof ParsedStreamSchema>;
|
||||
|
||||
export const AIOStream = StreamSchema.extend({
|
||||
streamData: z.object({
|
||||
error: z
|
||||
.object({
|
||||
title: z.string().min(1),
|
||||
description: z.string().min(1),
|
||||
})
|
||||
.optional(),
|
||||
proxied: z.boolean().optional(),
|
||||
addon: z.string().optional(),
|
||||
filename: z.string().optional(),
|
||||
folderName: z.string().optional(),
|
||||
service: z
|
||||
.object({
|
||||
id: z.enum(constants.SERVICES),
|
||||
cached: z.boolean(),
|
||||
})
|
||||
.optional(),
|
||||
parsedFile: ParsedFileSchema.optional(),
|
||||
message: z.string().max(1000).optional(),
|
||||
regexMatched: z
|
||||
.object({
|
||||
name: z.string().min(1).optional(),
|
||||
pattern: z.string().min(1).optional(),
|
||||
index: z.number(),
|
||||
})
|
||||
.optional(),
|
||||
keywordMatched: z.boolean().optional(),
|
||||
size: z.number().optional(),
|
||||
folderSize: z.number().optional(),
|
||||
type: StreamTypes.optional(),
|
||||
indexer: z.string().optional(),
|
||||
age: z.string().optional(),
|
||||
torrent: z
|
||||
.object({
|
||||
infoHash: z.string().min(1).or(z.null()).optional(),
|
||||
fileIdx: z.number().or(z.null()).optional(),
|
||||
seeders: z.number().optional(),
|
||||
sources: z.array(z.string().min(1)).optional(), // array of tracker urls and DHT nodes
|
||||
})
|
||||
.optional(),
|
||||
duration: z.number().optional(),
|
||||
library: z.boolean().optional(),
|
||||
}),
|
||||
});
|
||||
|
||||
export type AIOStream = z.infer<typeof AIOStream>;
|
||||
|
||||
const AIOStreamResponseSchema = z.object({
|
||||
streams: z.array(AIOStream),
|
||||
});
|
||||
export type AIOStreamResponse = z.infer<typeof AIOStreamResponseSchema>;
|
||||
|
||||
const PresetMetadataSchema = z.object({
|
||||
ID: z.string(),
|
||||
NAME: z.string(),
|
||||
DISABLED: z
|
||||
.object({
|
||||
reason: z.string(),
|
||||
disabled: z.boolean(),
|
||||
})
|
||||
.optional(),
|
||||
LOGO: z.string(),
|
||||
DESCRIPTION: z.string(),
|
||||
URL: z.string(),
|
||||
TIMEOUT: z.number(),
|
||||
USER_AGENT: z.string(),
|
||||
SUPPORTED_SERVICES: z.array(z.string()),
|
||||
OPTIONS: z.array(OptionDefinition),
|
||||
SUPPORTED_STREAM_TYPES: z.array(StreamTypes),
|
||||
SUPPORTED_RESOURCES: z.array(ResourceSchema),
|
||||
});
|
||||
|
||||
const StatusResponseSchema = z.object({
|
||||
version: z.string(),
|
||||
tag: z.string(),
|
||||
commit: z.string(),
|
||||
buildTime: z.string(),
|
||||
commitTime: z.string(),
|
||||
users: z.number(),
|
||||
settings: z.object({
|
||||
baseUrl: z.string().url().optional(),
|
||||
addonName: z.string(),
|
||||
customHtml: z.string().optional(),
|
||||
protected: z.boolean(),
|
||||
regexFilterAccess: z.enum(['none', 'trusted', 'all']),
|
||||
tmdbApiAvailable: z.boolean(),
|
||||
forced: z.object({
|
||||
proxy: z.object({
|
||||
enabled: z.boolean().or(z.null()),
|
||||
id: z.string().or(z.null()),
|
||||
url: z.string().or(z.null()),
|
||||
publicIp: z.string().or(z.null()),
|
||||
credentials: z.string().or(z.null()),
|
||||
disableProxiedAddons: z.boolean(),
|
||||
proxiedServices: z.array(z.string()).or(z.null()),
|
||||
}),
|
||||
}),
|
||||
defaults: z.object({
|
||||
proxy: z.object({
|
||||
enabled: z.boolean().or(z.null()),
|
||||
id: z.string().or(z.null()),
|
||||
url: z.string().or(z.null()),
|
||||
publicIp: z.string().or(z.null()),
|
||||
credentials: z.string().or(z.null()),
|
||||
proxiedServices: z.array(z.string()).or(z.null()),
|
||||
}),
|
||||
timeout: z.number().or(z.null()),
|
||||
}),
|
||||
presets: z.array(PresetMetadataSchema),
|
||||
services: z.record(
|
||||
z.enum(constants.SERVICES),
|
||||
z.object({
|
||||
id: z.enum(constants.SERVICES),
|
||||
name: z.string(),
|
||||
shortName: z.string(),
|
||||
knownNames: z.array(z.string()),
|
||||
signUpText: z.string(),
|
||||
credentials: z.array(OptionDefinition),
|
||||
})
|
||||
),
|
||||
}),
|
||||
});
|
||||
|
||||
export type StatusResponse = z.infer<typeof StatusResponseSchema>;
|
||||
export type PresetMetadata = z.infer<typeof PresetMetadataSchema>;
|
||||
@@ -0,0 +1,383 @@
|
||||
// import { UserDataSchema, UserData, DB } from '../db';
|
||||
import { UserDataSchema, UserData } from './schemas';
|
||||
import { TransactionQueue } from './queue';
|
||||
import { DB } from './db';
|
||||
import {
|
||||
decryptString,
|
||||
deriveKey,
|
||||
encryptString,
|
||||
generateUUID,
|
||||
getTextHash,
|
||||
maskSensitiveInfo,
|
||||
createLogger,
|
||||
constants,
|
||||
Env,
|
||||
verifyHash,
|
||||
validateConfig,
|
||||
formatZodError,
|
||||
} from '../utils';
|
||||
|
||||
const APIError = constants.APIError;
|
||||
const logger = createLogger('users');
|
||||
const db = DB.getInstance();
|
||||
const txQueue = TransactionQueue.getInstance();
|
||||
|
||||
export class UserRepository {
|
||||
static async createUser(
|
||||
config: UserData,
|
||||
password: string
|
||||
): Promise<{ uuid: string; encryptedPassword: string }> {
|
||||
return txQueue.enqueue(async () => {
|
||||
if (password.length < 8) {
|
||||
return Promise.reject(
|
||||
new APIError(constants.ErrorCode.USER_NEW_PASSWORD_TOO_SHORT)
|
||||
);
|
||||
}
|
||||
|
||||
// require at least one uppercase, one lowercase, one number, and one special character
|
||||
// [@$!%*?&\-\._#~^()+=<>,;:'"`{}[\]|\\]
|
||||
if (
|
||||
!/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&\-\._#~^()+=<>,;:'"`{}[\]|\\])[A-Za-z\d@$!%*?&\-\._#~^()+=<>,;:'"`{}[\]|\\]{8,}$/.test(
|
||||
password
|
||||
)
|
||||
) {
|
||||
return Promise.reject(
|
||||
new APIError(constants.ErrorCode.USER_NEW_PASSWORD_TOO_SIMPLE)
|
||||
);
|
||||
}
|
||||
|
||||
let validatedConfig: UserData;
|
||||
try {
|
||||
// don't skip errors, but don't decrypt credentials
|
||||
// as we need to store the encrypted version
|
||||
validatedConfig = await validateConfig(config, false, false);
|
||||
} catch (error: any) {
|
||||
logger.error(`Invalid config for new user: ${error.message}`);
|
||||
return Promise.reject(
|
||||
new APIError(
|
||||
constants.ErrorCode.USER_INVALID_CONFIG,
|
||||
undefined,
|
||||
error.message
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
const uuid = await this.generateUUID();
|
||||
|
||||
const { encryptedConfig, salt: configSalt } = await this.encryptConfig(
|
||||
validatedConfig,
|
||||
password
|
||||
);
|
||||
const hashedPassword = await getTextHash(password);
|
||||
|
||||
const { success, data } = encryptString(password);
|
||||
if (success === false) {
|
||||
return Promise.reject(constants.ErrorCode.USER_ERROR);
|
||||
}
|
||||
|
||||
const encryptedPassword = data;
|
||||
let tx;
|
||||
let committed = false;
|
||||
try {
|
||||
tx = await db.begin();
|
||||
await tx.execute(
|
||||
'INSERT INTO users (uuid, password_hash, config, config_salt) VALUES (?, ?, ?, ?)',
|
||||
[uuid, hashedPassword, encryptedConfig, configSalt]
|
||||
);
|
||||
await tx.commit();
|
||||
committed = true;
|
||||
logger.info(`Created a new user with UUID: ${uuid}`);
|
||||
return { uuid, encryptedPassword };
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
`Failed to create user: ${error instanceof Error ? error.message : String(error)}`
|
||||
);
|
||||
if (error instanceof APIError) {
|
||||
throw error;
|
||||
}
|
||||
throw new APIError(constants.ErrorCode.INTERNAL_SERVER_ERROR);
|
||||
} finally {
|
||||
if (tx && !committed) {
|
||||
await tx.rollback();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static async checkUserExists(uuid: string): Promise<boolean> {
|
||||
try {
|
||||
const result = await db.query('SELECT uuid FROM users WHERE uuid = ?', [
|
||||
uuid,
|
||||
]);
|
||||
return result.length > 0;
|
||||
} catch (error) {
|
||||
logger.error(`Error checking user existence: ${error}`);
|
||||
return Promise.reject(constants.ErrorCode.USER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
// with stremio auth, we are given the encrypted password
|
||||
// with api use, we are given the password
|
||||
// GET /user should also return
|
||||
|
||||
static async getUser(
|
||||
uuid: string,
|
||||
password: string
|
||||
): Promise<UserData | null> {
|
||||
try {
|
||||
const result = await db.query(
|
||||
'SELECT config, config_salt, password_hash FROM users WHERE uuid = ?',
|
||||
[uuid]
|
||||
);
|
||||
|
||||
if (!result.length || !result[0].config) {
|
||||
return Promise.reject(new APIError(constants.ErrorCode.USER_NOT_FOUND));
|
||||
}
|
||||
|
||||
await db.execute(
|
||||
'UPDATE users SET accessed_at = CURRENT_TIMESTAMP WHERE uuid = ?',
|
||||
[uuid]
|
||||
);
|
||||
|
||||
const isValid = await this.verifyUserPassword(
|
||||
password,
|
||||
result[0].password_hash
|
||||
);
|
||||
if (!isValid) {
|
||||
return Promise.reject(
|
||||
new APIError(constants.ErrorCode.USER_INVALID_PASSWORD)
|
||||
);
|
||||
}
|
||||
|
||||
const decryptedConfig = await this.decryptConfig(
|
||||
result[0].config,
|
||||
password,
|
||||
result[0].config_salt
|
||||
);
|
||||
|
||||
// try {
|
||||
// // skip errors, and dont decrypt credentials either, as this would make
|
||||
// // encryption pointless
|
||||
// validatedConfig = await validateConfig(decryptedConfig, true, false);
|
||||
// } catch (error: any) {
|
||||
// return Promise.reject(
|
||||
// new APIError(
|
||||
// constants.ErrorCode.USER_INVALID_CONFIG,
|
||||
// undefined,
|
||||
// error.message
|
||||
// )
|
||||
// );
|
||||
// }
|
||||
// const {
|
||||
// success,
|
||||
// data: validatedConfig,
|
||||
// error,
|
||||
// } = UserDataSchema.safeParse(decryptedConfig);
|
||||
// if (!success) {
|
||||
// return Promise.reject(
|
||||
// new APIError(
|
||||
// constants.ErrorCode.USER_INVALID_CONFIG,
|
||||
// undefined,
|
||||
// formatZodError(error)
|
||||
// )
|
||||
// );
|
||||
// }
|
||||
decryptedConfig.trusted =
|
||||
Env.TRUSTED_UUIDS?.split(',').some((u) => new RegExp(u).test(uuid)) ??
|
||||
false;
|
||||
logger.info(`Retrieved configuration for user ${uuid}`);
|
||||
return decryptedConfig;
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
`Error retrieving user ${uuid}: ${error instanceof Error ? error.message : String(error)}`
|
||||
);
|
||||
return Promise.reject(
|
||||
new APIError(constants.ErrorCode.INTERNAL_SERVER_ERROR)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
static async updateUser(
|
||||
uuid: string,
|
||||
password: string,
|
||||
config: UserData
|
||||
): Promise<void> {
|
||||
return txQueue.enqueue(async () => {
|
||||
let tx;
|
||||
let committed = false;
|
||||
try {
|
||||
tx = await db.begin();
|
||||
const currentUser = await tx.execute(
|
||||
'SELECT config_salt, password_hash FROM users WHERE uuid = ?',
|
||||
[uuid]
|
||||
);
|
||||
|
||||
if (!currentUser.rows.length) {
|
||||
throw new APIError(constants.ErrorCode.USER_NOT_FOUND);
|
||||
}
|
||||
let validatedConfig: UserData;
|
||||
try {
|
||||
validatedConfig = await validateConfig(config, false, false);
|
||||
} catch (error: any) {
|
||||
throw new APIError(
|
||||
constants.ErrorCode.USER_INVALID_CONFIG,
|
||||
undefined,
|
||||
error.message
|
||||
);
|
||||
}
|
||||
const storedHash = currentUser.rows[0].password_hash;
|
||||
const isValid = await this.verifyUserPassword(password, storedHash);
|
||||
if (!isValid) {
|
||||
throw new APIError(constants.ErrorCode.USER_INVALID_PASSWORD);
|
||||
}
|
||||
const { encryptedConfig } = await this.encryptConfig(
|
||||
validatedConfig,
|
||||
password,
|
||||
currentUser.rows[0].config_salt
|
||||
);
|
||||
await tx.execute(
|
||||
'UPDATE users SET config = ?, updated_at = CURRENT_TIMESTAMP WHERE uuid = ?',
|
||||
[encryptedConfig, uuid]
|
||||
);
|
||||
await tx.commit();
|
||||
committed = true;
|
||||
logger.info(`Updated user ${uuid} with an updated configuration`);
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
`Failed to update user ${uuid}: ${error instanceof Error ? error.message : String(error)}`
|
||||
);
|
||||
if (error instanceof APIError) {
|
||||
throw error;
|
||||
}
|
||||
throw new APIError(constants.ErrorCode.INTERNAL_SERVER_ERROR);
|
||||
} finally {
|
||||
if (tx && !committed) {
|
||||
await tx.rollback();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static async getUserCount(): Promise<number> {
|
||||
try {
|
||||
const result = await db.query('SELECT * FROM users');
|
||||
return result.length;
|
||||
} catch (error) {
|
||||
logger.error(`Error getting user count: ${error}`);
|
||||
return Promise.reject(new APIError(constants.ErrorCode.USER_ERROR));
|
||||
}
|
||||
}
|
||||
|
||||
static async deleteUser(uuid: string): Promise<void> {
|
||||
return txQueue.enqueue(async () => {
|
||||
let tx;
|
||||
let committed = false;
|
||||
try {
|
||||
tx = await db.begin();
|
||||
const result = await tx.execute('DELETE FROM users WHERE uuid = ?', [
|
||||
uuid,
|
||||
]);
|
||||
|
||||
if (result.rowCount === 0) {
|
||||
throw new APIError(constants.ErrorCode.USER_NOT_FOUND);
|
||||
}
|
||||
|
||||
await tx.commit();
|
||||
committed = true;
|
||||
logger.info(`Deleted user ${uuid}`);
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
`Failed to delete user ${uuid}: ${error instanceof Error ? error.message : String(error)}`
|
||||
);
|
||||
if (error instanceof APIError) {
|
||||
throw error;
|
||||
}
|
||||
throw new APIError(constants.ErrorCode.INTERNAL_SERVER_ERROR);
|
||||
} finally {
|
||||
if (tx && !committed) {
|
||||
await tx.rollback();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static async pruneUsers(maxDays: number = 30): Promise<number> {
|
||||
try {
|
||||
const query =
|
||||
db.getDialect() === 'postgres'
|
||||
? `DELETE FROM users WHERE accessed_at < NOW() - INTERVAL '${maxDays} days'`
|
||||
: `DELETE FROM users WHERE accessed_at < datetime('now', '-' || ${maxDays} || ' days')`;
|
||||
|
||||
const result = await db.execute(query);
|
||||
const deletedCount = result.changes || result.rowCount || 0;
|
||||
logger.info(`Pruned ${deletedCount} users older than ${maxDays} days`);
|
||||
return deletedCount;
|
||||
} catch (error) {
|
||||
logger.error('Failed to prune users:', error);
|
||||
return Promise.reject(new APIError(constants.ErrorCode.USER_ERROR));
|
||||
}
|
||||
}
|
||||
|
||||
private static async verifyUserPassword(
|
||||
password: string,
|
||||
storedHash: string
|
||||
): Promise<boolean> {
|
||||
return verifyHash(password, storedHash);
|
||||
}
|
||||
|
||||
private static async encryptConfig(
|
||||
config: UserData,
|
||||
password: string,
|
||||
salt?: string
|
||||
): Promise<{
|
||||
encryptedConfig: string;
|
||||
salt: string;
|
||||
}> {
|
||||
const { key, salt: saltUsed } = await deriveKey(
|
||||
`${password}:${Env.SECRET_KEY}`,
|
||||
salt
|
||||
);
|
||||
const configString = JSON.stringify(config);
|
||||
const { success, data, error } = encryptString(configString, key);
|
||||
|
||||
if (!success) {
|
||||
return Promise.reject(new APIError(constants.ErrorCode.USER_ERROR));
|
||||
}
|
||||
|
||||
return { encryptedConfig: data, salt: saltUsed };
|
||||
}
|
||||
|
||||
private static async decryptConfig(
|
||||
encryptedConfig: string,
|
||||
password: string,
|
||||
salt: string
|
||||
): Promise<UserData> {
|
||||
const { key } = await deriveKey(`${password}:${Env.SECRET_KEY}`, salt);
|
||||
const {
|
||||
success,
|
||||
data: decryptedString,
|
||||
error,
|
||||
} = decryptString(encryptedConfig, key);
|
||||
|
||||
if (!success || !decryptedString) {
|
||||
return Promise.reject(new APIError(constants.ErrorCode.USER_ERROR));
|
||||
}
|
||||
|
||||
return JSON.parse(decryptedString);
|
||||
}
|
||||
|
||||
private static async generateUUID(count: number = 1): Promise<string> {
|
||||
if (count > 10) {
|
||||
return Promise.reject(new APIError(constants.ErrorCode.USER_ERROR));
|
||||
}
|
||||
|
||||
const uuid = generateUUID();
|
||||
const existingUser = await this.checkUserExists(uuid);
|
||||
|
||||
if (existingUser) {
|
||||
return this.generateUUID(count + 1);
|
||||
}
|
||||
|
||||
return uuid;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
import { URL } from 'url';
|
||||
import { createLogger } from '../utils/logger';
|
||||
import path from 'path';
|
||||
|
||||
type BaseConnectionURI = {
|
||||
url: URL;
|
||||
driverName: string;
|
||||
};
|
||||
|
||||
type PostgresConnectionURI = BaseConnectionURI & {
|
||||
dialect: 'postgres';
|
||||
};
|
||||
|
||||
type SQLiteConnectionURI = BaseConnectionURI & {
|
||||
filename: string;
|
||||
dialect: 'sqlite';
|
||||
};
|
||||
|
||||
export type ConnectionURI = PostgresConnectionURI | SQLiteConnectionURI;
|
||||
|
||||
type DBDialect = 'postgres' | 'sqlite';
|
||||
|
||||
type DSNModifier = (url: URL, query: URLSearchParams) => void;
|
||||
const logger = createLogger('database');
|
||||
|
||||
function parseConnectionURI(uri: string): ConnectionURI {
|
||||
const url = new URL(uri);
|
||||
let driverName: string;
|
||||
let dialect: DBDialect;
|
||||
|
||||
switch (url.protocol) {
|
||||
case 'sqlite:': {
|
||||
driverName = 'sqlite3';
|
||||
dialect = 'sqlite';
|
||||
let filename = url.pathname;
|
||||
if (url.hostname && url.hostname !== '.') {
|
||||
throw new Error("Invalid path, must start with '/' or './'");
|
||||
}
|
||||
if (!url.pathname) {
|
||||
throw new Error('Invalid path, must be absolute');
|
||||
}
|
||||
if (url.hostname === '.') {
|
||||
// resolve relative path using process.cwd()
|
||||
filename = path.join(process.cwd(), url.pathname.replace(/^\//, ''));
|
||||
}
|
||||
return {
|
||||
url,
|
||||
driverName,
|
||||
filename: filename,
|
||||
dialect,
|
||||
};
|
||||
}
|
||||
case 'postgres:': {
|
||||
driverName = 'pg';
|
||||
dialect = 'postgres';
|
||||
return {
|
||||
url,
|
||||
|
||||
driverName,
|
||||
dialect,
|
||||
};
|
||||
}
|
||||
default:
|
||||
throw new Error('Unsupported scheme: ' + url.protocol);
|
||||
}
|
||||
}
|
||||
|
||||
function adaptQuery(query: string, dialect: DBDialect): string {
|
||||
if (dialect === 'sqlite') {
|
||||
return query;
|
||||
}
|
||||
|
||||
let position = 1;
|
||||
return query.replace(/\?/g, () => `$${position++}`);
|
||||
}
|
||||
|
||||
export { parseConnectionURI, adaptQuery };
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// vs code...
|
||||
declare namespace Intl {
|
||||
type Key =
|
||||
| 'calendar'
|
||||
| 'collation'
|
||||
| 'currency'
|
||||
| 'numberingSystem'
|
||||
| 'timeZone'
|
||||
| 'unit';
|
||||
|
||||
function supportedValuesOf(input: Key): string[];
|
||||
}
|
||||
@@ -0,0 +1,593 @@
|
||||
import { ParsedStream } from '../db';
|
||||
// import { constants, Env, createLogger } from '../utils';
|
||||
import * as constants from '../utils/constants';
|
||||
import { createLogger } from '../utils/logger';
|
||||
import { formatBytes, formatDuration, languageToEmoji } from './utils';
|
||||
import { Env } from '../utils/env';
|
||||
|
||||
const logger = createLogger('formatter');
|
||||
|
||||
/**
|
||||
*
|
||||
* The custom formatter code in this file was adapted from https://github.com/diced/zipline/blob/trunk/src/lib/parser/index.ts
|
||||
*
|
||||
* The original code is licensed under the MIT License.
|
||||
*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 dicedtomato
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
export interface FormatterConfig {
|
||||
name: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
export interface ParseValue {
|
||||
config?: {
|
||||
addonName: string | null;
|
||||
};
|
||||
stream?: {
|
||||
filename: string | null;
|
||||
folderName: string | null;
|
||||
size: number | null;
|
||||
folderSize: number | null;
|
||||
library: boolean | null;
|
||||
quality: string | null;
|
||||
resolution: string | null;
|
||||
languages: string[] | null;
|
||||
languageEmojis: string[] | null;
|
||||
wedontknowwhatakilometeris: string[] | null;
|
||||
visualTags: string[] | null;
|
||||
audioTags: string[] | null;
|
||||
releaseGroup: string | null;
|
||||
regexMatched: string | null;
|
||||
encode: string | null;
|
||||
audioChannels: string[] | null;
|
||||
indexer: string | null;
|
||||
year: string | null;
|
||||
title: string | null;
|
||||
season: number | null;
|
||||
seasons: number[] | null;
|
||||
episode: number | null;
|
||||
seasonEpisode: string[] | null;
|
||||
seeders: number | null;
|
||||
age: string | null;
|
||||
duration: number | null;
|
||||
infoHash: string | null;
|
||||
type: string | null;
|
||||
message: string | null;
|
||||
proxied: boolean | null;
|
||||
};
|
||||
service?: {
|
||||
id: string | null;
|
||||
shortName: string | null;
|
||||
name: string | null;
|
||||
cached: boolean | null;
|
||||
};
|
||||
addon?: {
|
||||
name: string;
|
||||
manifestUrl: string;
|
||||
};
|
||||
debug?: {
|
||||
json: string | null;
|
||||
jsonf: string | null;
|
||||
};
|
||||
}
|
||||
|
||||
export abstract class BaseFormatter {
|
||||
protected config: FormatterConfig;
|
||||
protected addonName: string;
|
||||
|
||||
constructor(config: FormatterConfig, addonName?: string) {
|
||||
this.config = config;
|
||||
this.addonName = addonName || Env.ADDON_NAME;
|
||||
}
|
||||
|
||||
public format(stream: ParsedStream): { name: string; description: string } {
|
||||
const parseValue = this.convertStreamToParseValue(stream);
|
||||
return {
|
||||
name: this.parseString(this.config.name, parseValue) || '',
|
||||
description: this.parseString(this.config.description, parseValue) || '',
|
||||
};
|
||||
}
|
||||
|
||||
protected convertStreamToParseValue(stream: ParsedStream): ParseValue {
|
||||
return {
|
||||
config: {
|
||||
addonName: this.addonName,
|
||||
},
|
||||
stream: {
|
||||
filename: stream.filename || null,
|
||||
folderName: stream.folderName || null,
|
||||
size: stream.size || null,
|
||||
folderSize: stream.folderSize || null,
|
||||
library: stream.library !== undefined ? stream.library : null,
|
||||
quality: stream.parsedFile?.quality || null,
|
||||
resolution: stream.parsedFile?.resolution || null,
|
||||
languages: stream.parsedFile?.languages || null,
|
||||
languageEmojis: stream.parsedFile?.languages
|
||||
? stream.parsedFile.languages
|
||||
.map((lang) => languageToEmoji(lang) || lang)
|
||||
.filter((value, index, self) => self.indexOf(value) === index)
|
||||
: null,
|
||||
wedontknowwhatakilometeris: stream.parsedFile?.languages
|
||||
? stream.parsedFile.languages
|
||||
.map((lang) => languageToEmoji(lang) || lang)
|
||||
.map((emoji) => emoji.replace('🇬🇧', '🇺🇸🦅'))
|
||||
.filter((value, index, self) => self.indexOf(value) === index)
|
||||
: null,
|
||||
visualTags: stream.parsedFile?.visualTags || null,
|
||||
audioTags: stream.parsedFile?.audioTags || null,
|
||||
releaseGroup: stream.parsedFile?.releaseGroup || null,
|
||||
regexMatched: stream.regexMatched?.name || null,
|
||||
encode: stream.parsedFile?.encode || null,
|
||||
audioChannels: stream.parsedFile?.audioChannels || null,
|
||||
indexer: stream.indexer || null,
|
||||
seeders: stream.torrent?.seeders ?? null,
|
||||
year: stream.parsedFile?.year || null,
|
||||
type: stream.type || null,
|
||||
title: stream.parsedFile?.title || null,
|
||||
season: stream.parsedFile?.season || null,
|
||||
seasons: stream.parsedFile?.seasons || null,
|
||||
episode: stream.parsedFile?.episode || null,
|
||||
seasonEpisode: stream.parsedFile?.seasonEpisode || null,
|
||||
duration: stream.duration || null,
|
||||
infoHash: stream.torrent?.infoHash || null,
|
||||
age: stream.age || null,
|
||||
message: stream.message || null,
|
||||
proxied: stream.proxied !== undefined ? stream.proxied : null,
|
||||
},
|
||||
addon: {
|
||||
name: stream.addon.name,
|
||||
manifestUrl: stream.addon.manifestUrl,
|
||||
},
|
||||
service: {
|
||||
id: stream.service?.id || null,
|
||||
shortName: stream.service?.id
|
||||
? Object.values(constants.SERVICE_DETAILS).find(
|
||||
(service) => service.id === stream.service?.id
|
||||
)?.shortName || null
|
||||
: null,
|
||||
name: stream.service?.id
|
||||
? Object.values(constants.SERVICE_DETAILS).find(
|
||||
(service) => service.id === stream.service?.id
|
||||
)?.name || null
|
||||
: null,
|
||||
cached:
|
||||
stream.service?.cached !== undefined ? stream.service?.cached : null,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
protected parseString(str: string, value: ParseValue): string | null {
|
||||
if (!str) return null;
|
||||
|
||||
const replacer = (key: string, value: unknown) => {
|
||||
return value;
|
||||
};
|
||||
|
||||
const data = {
|
||||
stream: value.stream,
|
||||
service: value.service,
|
||||
addon: value.addon,
|
||||
config: value.config,
|
||||
};
|
||||
|
||||
value.debug = {
|
||||
json: JSON.stringify(data, replacer),
|
||||
jsonf: JSON.stringify(data, replacer, 2),
|
||||
};
|
||||
|
||||
const re =
|
||||
/\{(?<type>stream|service|addon|config|debug)\.(?<prop>\w+)(::(?<mod>(\w+(\([^)]*\))?|<|<=|=|>=|>|\^|\$|~|\/)+))?((::(?<mod_tzlocale>\S+?))|(?<mod_check>\[(?<mod_check_true>".*?")\|\|(?<mod_check_false>".*?")\]))?\}/gi;
|
||||
let matches: RegExpExecArray | null;
|
||||
|
||||
while ((matches = re.exec(str))) {
|
||||
if (!matches.groups) continue;
|
||||
|
||||
const index = matches.index as number;
|
||||
|
||||
const getV = value[matches.groups.type as keyof ParseValue];
|
||||
|
||||
if (!getV) {
|
||||
str = this.replaceCharsFromString(
|
||||
str,
|
||||
'{unknown_type}',
|
||||
index,
|
||||
re.lastIndex
|
||||
);
|
||||
re.lastIndex = index;
|
||||
continue;
|
||||
}
|
||||
|
||||
const v =
|
||||
getV[
|
||||
matches.groups.prop as
|
||||
| keyof ParseValue['stream']
|
||||
| keyof ParseValue['service']
|
||||
| keyof ParseValue['addon']
|
||||
];
|
||||
|
||||
if (v === undefined) {
|
||||
str = this.replaceCharsFromString(
|
||||
str,
|
||||
'{unknown_value}',
|
||||
index,
|
||||
re.lastIndex
|
||||
);
|
||||
re.lastIndex = index;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (matches.groups.mod) {
|
||||
str = this.replaceCharsFromString(
|
||||
str,
|
||||
this.modifier(
|
||||
matches.groups.mod,
|
||||
v,
|
||||
matches.groups.mod_tzlocale ?? undefined,
|
||||
matches.groups.mod_check_true ?? undefined,
|
||||
matches.groups.mod_check_false ?? undefined,
|
||||
value
|
||||
),
|
||||
index,
|
||||
re.lastIndex
|
||||
);
|
||||
re.lastIndex = index;
|
||||
continue;
|
||||
}
|
||||
|
||||
str = this.replaceCharsFromString(str, v, index, re.lastIndex);
|
||||
re.lastIndex = index;
|
||||
}
|
||||
|
||||
return str
|
||||
.replace(/\\n/g, '\n')
|
||||
.split('\n')
|
||||
.filter(
|
||||
(line) => line.trim() !== '' && !line.includes('{tools.removeLine}')
|
||||
)
|
||||
.join('\n')
|
||||
.replace(/\{tools.newLine\}/g, '\n');
|
||||
}
|
||||
|
||||
protected modifier(
|
||||
mod: string,
|
||||
value: unknown,
|
||||
tzlocale?: string,
|
||||
check_true?: string,
|
||||
check_false?: string,
|
||||
_value?: ParseValue
|
||||
): string {
|
||||
mod = mod.toLowerCase();
|
||||
check_true = check_true?.slice(1, -1);
|
||||
check_false = check_false?.slice(1, -1);
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
switch (true) {
|
||||
case mod === 'join':
|
||||
return value.join(', ');
|
||||
case mod.startsWith('join(') && mod.endsWith(')'): {
|
||||
// Extract the separator from join(separator)
|
||||
// e.g. join(' - ')
|
||||
const separator = mod
|
||||
.substring(5, mod.length - 1)
|
||||
.replace(/^['"]|['"]$/g, '');
|
||||
return value.join(separator);
|
||||
}
|
||||
case mod == 'length':
|
||||
return value.length.toString();
|
||||
case mod == 'first':
|
||||
return value.length > 0 ? String(value[0]) : '';
|
||||
case mod == 'last':
|
||||
return value.length > 0 ? String(value[value.length - 1]) : '';
|
||||
case mod == 'random':
|
||||
return value.length > 0
|
||||
? String(value[Math.floor(Math.random() * value.length)])
|
||||
: '';
|
||||
case mod == 'sort':
|
||||
return [...value].sort().join(', ');
|
||||
case mod == 'reverse':
|
||||
return [...value].reverse().join(', ');
|
||||
case mod.startsWith('~'): {
|
||||
if (typeof check_true !== 'string' || typeof check_false !== 'string')
|
||||
return `{unknown_array_modifier(${mod})}`;
|
||||
|
||||
const check = mod.replace('~', '').replace('_', ' ');
|
||||
|
||||
if (_value) {
|
||||
return value.some((item) => item.toLowerCase().includes(check))
|
||||
? this.parseString(check_true, _value) || check_true
|
||||
: this.parseString(check_false, _value) || check_false;
|
||||
}
|
||||
|
||||
return value.some((item) => item.toLowerCase().includes(check))
|
||||
? check_true
|
||||
: check_false;
|
||||
}
|
||||
case mod == 'exists': {
|
||||
if (typeof check_true !== 'string' || typeof check_false !== 'string')
|
||||
return `{unknown_array_modifier(${mod})}`;
|
||||
|
||||
if (_value) {
|
||||
return value.length > 0
|
||||
? this.parseString(check_true, _value) || check_true
|
||||
: this.parseString(check_false, _value) || check_false;
|
||||
}
|
||||
|
||||
return value.length > 0 ? check_true : check_false;
|
||||
}
|
||||
default:
|
||||
return `{unknown_array_modifier(${mod})}`;
|
||||
}
|
||||
} else if (typeof value === 'string') {
|
||||
switch (true) {
|
||||
case mod == 'upper':
|
||||
return value.toUpperCase();
|
||||
case mod == 'lower':
|
||||
return value.toLowerCase();
|
||||
case mod == 'title':
|
||||
return value.charAt(0).toUpperCase() + value.slice(1);
|
||||
case mod == 'length':
|
||||
return value.length.toString();
|
||||
case mod == 'reverse':
|
||||
return value.split('').reverse().join('');
|
||||
case mod == 'base64':
|
||||
return btoa(value);
|
||||
case mod == 'string':
|
||||
return value;
|
||||
case mod == 'exists': {
|
||||
if (typeof check_true !== 'string' || typeof check_false !== 'string')
|
||||
return `{unknown_str_modifier(${mod})}`;
|
||||
|
||||
if (_value) {
|
||||
return value != 'null' && value
|
||||
? this.parseString(check_true, _value) || check_true
|
||||
: this.parseString(check_false, _value) || check_false;
|
||||
}
|
||||
|
||||
return value != 'null' && value ? check_true : check_false;
|
||||
}
|
||||
case mod.startsWith('='): {
|
||||
if (typeof check_true !== 'string' || typeof check_false !== 'string')
|
||||
return `{unknown_str_modifier(${mod})}`;
|
||||
|
||||
const check = mod.replace('=', '');
|
||||
|
||||
if (!check) return `{unknown_str_modifier(${mod})}`;
|
||||
|
||||
if (_value) {
|
||||
return value.toLowerCase() == check
|
||||
? this.parseString(check_true, _value) || check_true
|
||||
: this.parseString(check_false, _value) || check_false;
|
||||
}
|
||||
|
||||
return value.toLowerCase() == check ? check_true : check_false;
|
||||
}
|
||||
case mod.startsWith('$'): {
|
||||
if (typeof check_true !== 'string' || typeof check_false !== 'string')
|
||||
return `{unknown_str_modifier(${mod})}`;
|
||||
|
||||
const check = mod.replace('$', '');
|
||||
|
||||
if (!check) return `{unknown_str_modifier(${mod})}`;
|
||||
|
||||
if (_value) {
|
||||
return value.toLowerCase().startsWith(check)
|
||||
? this.parseString(check_true, _value) || check_true
|
||||
: this.parseString(check_false, _value) || check_false;
|
||||
}
|
||||
|
||||
return value.toLowerCase().startsWith(check)
|
||||
? check_true
|
||||
: check_false;
|
||||
}
|
||||
case mod.startsWith('^'): {
|
||||
if (typeof check_true !== 'string' || typeof check_false !== 'string')
|
||||
return `{unknown_str_modifier(${mod})}`;
|
||||
|
||||
const check = mod.replace('^', '');
|
||||
|
||||
if (!check) return `{unknown_str_modifier(${mod})}`;
|
||||
|
||||
if (_value) {
|
||||
return value.toLowerCase().endsWith(check)
|
||||
? this.parseString(check_true, _value) || check_true
|
||||
: this.parseString(check_false, _value) || check_false;
|
||||
}
|
||||
|
||||
return value.toLowerCase().endsWith(check) ? check_true : check_false;
|
||||
}
|
||||
case mod.startsWith('~'): {
|
||||
if (typeof check_true !== 'string' || typeof check_false !== 'string')
|
||||
return `{unknown_str_modifier(${mod})}`;
|
||||
|
||||
const check = mod.replace('~', '');
|
||||
|
||||
if (!check) return `{unknown_str_modifier(${mod})}`;
|
||||
|
||||
if (_value) {
|
||||
return value.toLowerCase().includes(check)
|
||||
? this.parseString(check_true, _value) || check_true
|
||||
: this.parseString(check_false, _value) || check_false;
|
||||
}
|
||||
|
||||
return value.toLowerCase().includes(check) ? check_true : check_false;
|
||||
}
|
||||
default:
|
||||
return `{unknown_str_modifier(${mod})}`;
|
||||
}
|
||||
} else if (typeof value === 'number') {
|
||||
switch (true) {
|
||||
case mod == 'comma':
|
||||
return value.toLocaleString();
|
||||
case mod == 'hex':
|
||||
return value.toString(16);
|
||||
case mod == 'octal':
|
||||
return value.toString(8);
|
||||
case mod == 'binary':
|
||||
return value.toString(2);
|
||||
case mod == 'bytes10' || mod == 'bytes':
|
||||
return formatBytes(value, 1000);
|
||||
case mod == 'bytes2':
|
||||
return formatBytes(value, 1024);
|
||||
case mod == 'string':
|
||||
return value.toString();
|
||||
case mod == 'time':
|
||||
return formatDuration(value);
|
||||
case mod.startsWith('>='): {
|
||||
if (typeof check_true !== 'string' || typeof check_false !== 'string')
|
||||
return `{unknown_int_modifier(${mod})}`;
|
||||
|
||||
const check = Number(mod.replace('>=', ''));
|
||||
|
||||
if (Number.isNaN(check)) return `{unknown_int_modifier(${mod})}`;
|
||||
|
||||
if (_value) {
|
||||
return value >= check
|
||||
? this.parseString(check_true, _value) || check_true
|
||||
: this.parseString(check_false, _value) || check_false;
|
||||
}
|
||||
|
||||
return value >= check ? check_true : check_false;
|
||||
}
|
||||
case mod.startsWith('>'): {
|
||||
if (typeof check_true !== 'string' || typeof check_false !== 'string')
|
||||
return `{unknown_int_modifier(${mod})}`;
|
||||
|
||||
const check = Number(mod.replace('>', ''));
|
||||
|
||||
if (Number.isNaN(check)) return `{unknown_int_modifier(${mod})}`;
|
||||
|
||||
if (_value) {
|
||||
return value > check
|
||||
? this.parseString(check_true, _value) || check_true
|
||||
: this.parseString(check_false, _value) || check_false;
|
||||
}
|
||||
|
||||
return value > check ? check_true : check_false;
|
||||
}
|
||||
case mod.startsWith('='): {
|
||||
if (typeof check_true !== 'string' || typeof check_false !== 'string')
|
||||
return `{unknown_int_modifier(${mod})}`;
|
||||
|
||||
const check = Number(mod.replace('=', ''));
|
||||
|
||||
if (Number.isNaN(check)) return `{unknown_int_modifier(${mod})}`;
|
||||
|
||||
if (_value) {
|
||||
return value == check
|
||||
? this.parseString(check_true, _value) || check_true
|
||||
: this.parseString(check_false, _value) || check_false;
|
||||
}
|
||||
|
||||
return value == check ? check_true : check_false;
|
||||
}
|
||||
case mod.startsWith('<='): {
|
||||
if (typeof check_true !== 'string' || typeof check_false !== 'string')
|
||||
return `{unknown_int_modifier(${mod})}`;
|
||||
|
||||
const check = Number(mod.replace('<=', ''));
|
||||
|
||||
if (Number.isNaN(check)) return `{unknown_int_modifier(${mod})}`;
|
||||
|
||||
if (_value) {
|
||||
return value <= check
|
||||
? this.parseString(check_true, _value) || check_true
|
||||
: this.parseString(check_false, _value) || check_false;
|
||||
}
|
||||
|
||||
return value <= check ? check_true : check_false;
|
||||
}
|
||||
case mod.startsWith('<'): {
|
||||
if (typeof check_true !== 'string' || typeof check_false !== 'string')
|
||||
return `{unknown_int_modifier(${mod})}`;
|
||||
|
||||
const check = Number(mod.replace('<', ''));
|
||||
|
||||
if (Number.isNaN(check)) return `{unknown_int_modifier(${mod})}`;
|
||||
|
||||
if (_value) {
|
||||
return value < check
|
||||
? this.parseString(check_true, _value) || check_true
|
||||
: this.parseString(check_false, _value) || check_false;
|
||||
}
|
||||
|
||||
return value < check ? check_true : check_false;
|
||||
}
|
||||
default:
|
||||
return `{unknown_int_modifier(${mod})}`;
|
||||
}
|
||||
} else if (typeof value === 'boolean') {
|
||||
switch (true) {
|
||||
case mod == 'istrue': {
|
||||
if (typeof check_true !== 'string' || typeof check_false !== 'string')
|
||||
return `{unknown_bool_modifier(${mod})}`;
|
||||
|
||||
if (_value) {
|
||||
return value
|
||||
? this.parseString(check_true, _value) || check_true
|
||||
: this.parseString(check_false, _value) || check_false;
|
||||
}
|
||||
|
||||
return value ? check_true : check_false;
|
||||
}
|
||||
case mod == 'isfalse': {
|
||||
if (typeof check_true !== 'string' || typeof check_false !== 'string')
|
||||
return `{unknown_bool_modifier(${mod})}`;
|
||||
|
||||
if (_value) {
|
||||
return !value
|
||||
? this.parseString(check_true, _value) || check_true
|
||||
: this.parseString(check_false, _value) || check_false;
|
||||
}
|
||||
|
||||
return !value ? check_true : check_false;
|
||||
}
|
||||
default:
|
||||
return `{unknown_bool_modifier(${mod})}`;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
typeof check_false == 'string' &&
|
||||
(['>', '>=', '=', '<=', '<', '~', '$', '^'].some((modif) =>
|
||||
mod.startsWith(modif)
|
||||
) ||
|
||||
['istrue', 'exists', 'isfalse'].includes(mod))
|
||||
) {
|
||||
if (_value) return this.parseString(check_false, _value) || check_false;
|
||||
return check_false;
|
||||
}
|
||||
|
||||
return `{unknown_modifier(${mod})}`;
|
||||
}
|
||||
|
||||
protected replaceCharsFromString(
|
||||
str: string,
|
||||
replace: string,
|
||||
start: number,
|
||||
end: number
|
||||
): string {
|
||||
return str.slice(0, start) + replace + str.slice(end);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import { BaseFormatter, FormatterConfig } from './base';
|
||||
|
||||
export class CustomFormatter extends BaseFormatter {
|
||||
constructor(
|
||||
nameTemplate: string,
|
||||
descriptionTemplate: string,
|
||||
addonName?: string
|
||||
) {
|
||||
super(
|
||||
{
|
||||
name: nameTemplate,
|
||||
description: descriptionTemplate,
|
||||
},
|
||||
addonName
|
||||
);
|
||||
}
|
||||
|
||||
public static fromConfig(
|
||||
config: FormatterConfig,
|
||||
addonName: string | undefined
|
||||
): CustomFormatter {
|
||||
return new CustomFormatter(config.name, config.description, addonName);
|
||||
}
|
||||
|
||||
public updateTemplate(
|
||||
nameTemplate: string,
|
||||
descriptionTemplate: string
|
||||
): void {
|
||||
this.config = {
|
||||
name: nameTemplate,
|
||||
description: descriptionTemplate,
|
||||
};
|
||||
}
|
||||
|
||||
public getTemplate(): FormatterConfig {
|
||||
return this.config;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
export * from './base';
|
||||
export * from './predefined';
|
||||
export * from './custom';
|
||||
export * from './utils';
|
||||
|
||||
import { BaseFormatter, FormatterConfig } from './base';
|
||||
import {
|
||||
TorrentioFormatter,
|
||||
TorboxFormatter,
|
||||
GDriveFormatter,
|
||||
LightGDriveFormatter,
|
||||
MinimalisticGdriveFormatter,
|
||||
} from './predefined';
|
||||
import { CustomFormatter } from './custom';
|
||||
import { FormatterType } from '../utils/constants';
|
||||
|
||||
export function createFormatter(
|
||||
type: FormatterType,
|
||||
config?: FormatterConfig,
|
||||
addonName?: string
|
||||
): BaseFormatter {
|
||||
switch (type) {
|
||||
case 'torrentio':
|
||||
return new TorrentioFormatter(addonName);
|
||||
case 'torbox':
|
||||
return new TorboxFormatter(addonName);
|
||||
case 'gdrive':
|
||||
return new GDriveFormatter(addonName);
|
||||
case 'lightgdrive':
|
||||
return new LightGDriveFormatter(addonName);
|
||||
case 'minimalisticgdrive':
|
||||
return new MinimalisticGdriveFormatter(addonName);
|
||||
case 'custom':
|
||||
if (!config) {
|
||||
throw new Error('Config is required for custom formatter');
|
||||
}
|
||||
return CustomFormatter.fromConfig(config, addonName);
|
||||
default:
|
||||
throw new Error(`Unknown formatter type: ${type}`);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
import { BaseFormatter, FormatterConfig } from './base';
|
||||
|
||||
export class TorrentioFormatter extends BaseFormatter {
|
||||
constructor(addonName?: string) {
|
||||
super(
|
||||
{
|
||||
name: `
|
||||
{stream.proxied::istrue["🕵️♂️ "||""]}{stream.type::=p2p["[P2P] "||""]}{service.id::exists["[{service.shortName}"||""]}{service.cached::istrue["+] "||""]}{service.cached::isfalse[" download] "||""]}{addon.name} {stream.resolution::exists["{stream.resolution}"||"Unknown"]}
|
||||
{stream.visualTags::exists["{stream.visualTags::join(' | ')}"||""]}
|
||||
`,
|
||||
description: `
|
||||
{stream.message::exists["ℹ️{stream.message}"||""]}
|
||||
{stream.folderName::exists["{stream.folderName}"||""]}
|
||||
{stream.filename::exists["{stream.filename}"||""]}
|
||||
{stream.size::>0["💾{stream.size::bytes2} "||""]}{stream.folderSize::>0["/ 💾{stream.folderSize::bytes2}"||""]}{stream.seeders::>=0["👤{stream.seeders} "||""]}{stream.age::exists["📅{stream.age} "||""]}{stream.indexer::exists["⚙️{stream.indexer}"||""]}
|
||||
{stream.languageEmojis::exists["{stream.languageEmojis::join( / ')}"||""]}
|
||||
`,
|
||||
},
|
||||
addonName
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class TorboxFormatter extends BaseFormatter {
|
||||
constructor(addonName?: string) {
|
||||
super(
|
||||
{
|
||||
name: `
|
||||
{stream.proxied::istrue["🕵️♂️ "||""]}{stream.type::=p2p["[P2P] "||""]}{addon.name}{stream.library::istrue[" (Your Media) "||""]}{service.cached::istrue[" (Instant "||""]}{service.cached::isfalse[" ("||""]}{service.id::exists["{service.shortName})"||""]}{stream.resolution::exists[" ({stream.resolution})"||""]}
|
||||
`,
|
||||
description: `
|
||||
Quality: {stream.quality::exists["{stream.quality}"||"Unknown"]}
|
||||
Name: {stream.filename::exists["{stream.filename}"||"Unknown"]}
|
||||
Size: {stream.size::>0["{stream.size::bytes} "||""]}{stream.folderSize::>0["/ {stream.folderSize::bytes} "||""]}{stream.indexer::exists["| Source: {stream.indexer} "||""]}{stream.duration::>0["| Duration: {stream.duration::time} "||""]}
|
||||
Language: {stream.languages::exists["{stream.languages::join(', ')}"||""]}
|
||||
Type: {stream.type::title}{stream.seeders::>=0[" | Seeders: {stream.seeders}"||""]}{stream.age::exists[" | Age: {stream.age}"||""]}
|
||||
{stream.message::exists["Message: {stream.message}"||""]}
|
||||
`,
|
||||
},
|
||||
addonName
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class GDriveFormatter extends BaseFormatter {
|
||||
constructor(addonName?: string) {
|
||||
super(
|
||||
{
|
||||
name: `
|
||||
{stream.proxied::istrue["🕵️ "||""]}{stream.type::=p2p["[P2P] "||""]}{service.shortName::exists["[{service.shortName}"||""]}{service.cached::istrue["⚡] "||""]}{service.cached::isfalse["⏳] "||""]}{addon.name}{stream.library::istrue[" (Your Media)"||""]} {stream.resolution::exists["{stream.resolution}"||""]}{stream.regexMatched::exists[" ({stream.regexMatched})"||""]}
|
||||
`,
|
||||
description: `
|
||||
{stream.quality::exists["🎥 {stream.quality} "||""]}{stream.encode::exists["🎞️ {stream.encode} "||""]}{stream.releaseGroup::exists["🏷️ {stream.releaseGroup}"||""]}
|
||||
{stream.visualTags::exists["📺 {stream.visualTags::join(' | ')} "||""]}{stream.audioTags::exists["🎧 {stream.audioTags::join(' | ')} "||""]}{stream.audioChannels::exists["🔊 {stream.audioChannels::join(' | ')}"||""]}
|
||||
{stream.size::>0["📦 {stream.size::bytes} "||""]}{stream.folderSize::>0["/ 📦 {stream.folderSize::bytes}"||""]}{stream.duration::>0["⏱️ {stream.duration::time} "||""]}{stream.seeders::>0["👥 {stream.seeders} "||""]}{stream.age::exists["📅 {stream.age} "||""]}{stream.indexer::exists["🔍 {stream.indexer}"||""]}
|
||||
{stream.languages::exists["🌎 {stream.languages::join(' | ')}"||""]}
|
||||
{stream.filename::exists["📁"||""]} {stream.folderName::exists["{stream.folderName}/"||""]}{stream.filename::exists["{stream.filename}"||""]}
|
||||
{stream.message::exists["ℹ️ {stream.message}"||""]}
|
||||
`,
|
||||
},
|
||||
addonName
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class LightGDriveFormatter extends BaseFormatter {
|
||||
constructor(addonName?: string) {
|
||||
super(
|
||||
{
|
||||
name: `
|
||||
{stream.proxied::istrue["🕵️ "||""]}{stream.type::=p2p["[P2P] "||""]}{service.shortName::exists["[{service.shortName}"||""]}{stream.library::istrue["☁️"||""]}{service.cached::istrue["⚡] "||""]}{service.cached::isfalse["⏳] "||""]}{addon.name}{stream.resolution::exists[" {stream.resolution}"||""]}{stream.regexMatched::exists[" ({stream.regexMatched})"||""]}
|
||||
`,
|
||||
description: `
|
||||
{stream.title::exists["📁 {stream.title}"||""]}{stream.year::exists[" ({stream.year})"||""]}{stream.season::>=0[" S"||""]}{stream.season::<=9["0"||""]}{stream.season::>0["{stream.season}"||""]}{stream.episode::>=0[" • E"||""]}{stream.episode::<=9["0"||""]}{stream.episode::>0["{stream.episode}"||""]}
|
||||
{stream.quality::exists["🎥 {stream.quality} "||""]}{stream.encode::exists["🎞️ {stream.encode} "||""]}{stream.releaseGroup::exists["🏷️ {stream.releaseGroup}"||""]}
|
||||
{stream.visualTags::exists["📺 {stream.visualTags::join(' • ')} "||""]}{stream.audioTags::exists["🎧 {stream.audioTags::join(' • ')} "||""]}{stream.audioChannels::exists["🔊 {stream.audioChannels::join(' • ')}"||""]}
|
||||
{stream.size::>0["📦 {stream.size::bytes} "||""]}{stream.folderSize::>0["/ 📦 {stream.folderSize::bytes}"||""]}{stream.duration::>0["⏱️ {stream.duration::time} "||""]}{stream.age::exists["📅 {stream.age} "||""]}{stream.indexer::exists["🔍 {stream.indexer}"||""]}
|
||||
{stream.languageEmojis::exists["🌐 {stream.languageEmojis::join(' / ')}"||""]}
|
||||
`,
|
||||
},
|
||||
addonName
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class MinimalisticGdriveFormatter extends BaseFormatter {
|
||||
constructor(addonName?: string) {
|
||||
super(
|
||||
{
|
||||
name: '{stream.title} {stream.quality}',
|
||||
description: '{stream.size::bytes} {stream.seeders} seeders',
|
||||
},
|
||||
addonName
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
export function formatSize(bytes: number): string {
|
||||
export function formatBytes(bytes: number, k: 1024 | 1000): string {
|
||||
if (bytes === 0) return '0 B';
|
||||
const k = 1024;
|
||||
const sizes = ['Bytes', 'KiB', 'MiB', 'GiB', 'TiB'];
|
||||
const sizes =
|
||||
k === 1024
|
||||
? ['B', 'KiB', 'MiB', 'GiB', 'TiB']
|
||||
: ['B', 'KB', 'MB', 'GB', 'TB'];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
export * from './utils';
|
||||
export * from './db';
|
||||
export * from './main';
|
||||
export * from './parser';
|
||||
export * from './formatters';
|
||||
export * from './transformers';
|
||||
export { PresetManager } from './presets';
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,237 @@
|
||||
import { Parser } from 'expr-eval';
|
||||
import { ParsedStream } from '../db';
|
||||
|
||||
export class ConditionParser {
|
||||
private parser: Parser;
|
||||
private previousStreams: ParsedStream[];
|
||||
private totalStreams: ParsedStream[];
|
||||
private previousGroupTimeTaken: number;
|
||||
private totalTimeTaken: number;
|
||||
|
||||
constructor(
|
||||
previousStreams: ParsedStream[],
|
||||
totalStreams: ParsedStream[],
|
||||
previousGroupTimeTaken: number,
|
||||
totalTimeTaken: number,
|
||||
queryType: string
|
||||
) {
|
||||
this.previousStreams = previousStreams;
|
||||
this.totalStreams = totalStreams;
|
||||
this.previousGroupTimeTaken = previousGroupTimeTaken;
|
||||
this.totalTimeTaken = totalTimeTaken;
|
||||
|
||||
// only allow comparison and logical operators
|
||||
this.parser = new Parser({
|
||||
operators: {
|
||||
comparison: true,
|
||||
logical: true,
|
||||
add: false,
|
||||
concatenate: false,
|
||||
conditional: false,
|
||||
divide: false,
|
||||
factorial: false,
|
||||
multiply: false,
|
||||
power: false,
|
||||
remainder: false,
|
||||
subtract: false,
|
||||
sin: false,
|
||||
cos: false,
|
||||
tan: false,
|
||||
asin: false,
|
||||
acos: false,
|
||||
atan: false,
|
||||
sinh: false,
|
||||
cosh: false,
|
||||
tanh: false,
|
||||
asinh: false,
|
||||
acosh: false,
|
||||
atanh: false,
|
||||
sqrt: false,
|
||||
log: false,
|
||||
ln: false,
|
||||
lg: false,
|
||||
log10: false,
|
||||
abs: false,
|
||||
ceil: false,
|
||||
floor: false,
|
||||
round: false,
|
||||
trunc: false,
|
||||
exp: false,
|
||||
length: false,
|
||||
in: false,
|
||||
random: false,
|
||||
min: false,
|
||||
max: false,
|
||||
assignment: false,
|
||||
fndef: false,
|
||||
cbrt: false,
|
||||
expm1: false,
|
||||
log1p: false,
|
||||
sign: false,
|
||||
log2: false,
|
||||
},
|
||||
});
|
||||
|
||||
this.parser.consts.previousStreams = this.previousStreams;
|
||||
this.parser.consts.totalStreams = this.totalStreams;
|
||||
this.parser.consts.queryType = queryType;
|
||||
this.parser.consts.previousGroupTimeTaken = this.previousGroupTimeTaken;
|
||||
this.parser.consts.totalTimeTaken = this.totalTimeTaken;
|
||||
|
||||
this.parser.functions.regexMatched = function (
|
||||
streams: ParsedStream[],
|
||||
regexName?: string
|
||||
) {
|
||||
return streams.filter((stream) =>
|
||||
regexName
|
||||
? stream.regexMatched?.name === regexName
|
||||
: stream.regexMatched
|
||||
);
|
||||
};
|
||||
this.parser.functions.indexer = function (
|
||||
streams: ParsedStream[],
|
||||
indexer: string
|
||||
) {
|
||||
if (!Array.isArray(streams)) {
|
||||
throw new Error(
|
||||
"Please use one of 'totalStreams' or 'previousStreams' as the first argument"
|
||||
);
|
||||
} else if (typeof indexer !== 'string') {
|
||||
throw new Error('Indexer must be a string');
|
||||
}
|
||||
return streams.filter((stream) => stream.indexer === indexer);
|
||||
};
|
||||
this.parser.functions.resolution = function (
|
||||
streams: ParsedStream[],
|
||||
resolution: string
|
||||
) {
|
||||
if (!Array.isArray(streams)) {
|
||||
throw new Error(
|
||||
"Please use one of 'totalStreams' or 'previousStreams' as the first argument"
|
||||
);
|
||||
} else if (typeof resolution !== 'string') {
|
||||
throw new Error('Resolution must be a string');
|
||||
}
|
||||
return streams.filter(
|
||||
(stream) => (stream.parsedFile?.resolution || 'Unknown') === resolution
|
||||
);
|
||||
};
|
||||
this.parser.functions.quality = function (
|
||||
streams: ParsedStream[],
|
||||
quality: string
|
||||
) {
|
||||
if (!Array.isArray(streams)) {
|
||||
throw new Error(
|
||||
"Please use one of 'totalStreams' or 'previousStreams' as the first argument"
|
||||
);
|
||||
} else if (typeof quality !== 'string') {
|
||||
throw new Error('Quality must be a string');
|
||||
}
|
||||
return streams.filter(
|
||||
(stream) => (stream.parsedFile?.quality || 'Unknown') === quality
|
||||
);
|
||||
};
|
||||
this.parser.functions.type = function (
|
||||
streams: ParsedStream[],
|
||||
type: string
|
||||
) {
|
||||
if (!Array.isArray(streams)) {
|
||||
throw new Error(
|
||||
"Please use one of 'totalStreams' or 'previousStreams' as the first argument"
|
||||
);
|
||||
} else if (typeof type !== 'string') {
|
||||
throw new Error('Type must be a string');
|
||||
}
|
||||
return streams.filter((stream) => stream.type === type);
|
||||
};
|
||||
this.parser.functions.service = function (
|
||||
streams: ParsedStream[],
|
||||
service: string
|
||||
) {
|
||||
if (!Array.isArray(streams)) {
|
||||
throw new Error(
|
||||
"Please use one of 'totalStreams' or 'previousStreams' as the first argument"
|
||||
);
|
||||
} else if (
|
||||
typeof service !== 'string' ||
|
||||
![
|
||||
'realdebrid',
|
||||
'debridlink',
|
||||
'alldebrid',
|
||||
'torbox',
|
||||
'pikpak',
|
||||
'seedr',
|
||||
'offcloud',
|
||||
'premiumize',
|
||||
'easynews',
|
||||
'easydebrid',
|
||||
].includes(service)
|
||||
) {
|
||||
throw new Error(
|
||||
'Service must be a string and one of: realdebrid, debridlink, alldebrid, torbox, pikpak, seedr, offcloud, premiumize, easynews, easydebrid'
|
||||
);
|
||||
}
|
||||
return streams.filter((stream) => stream.service?.id === service);
|
||||
};
|
||||
this.parser.functions.cached = function (streams: ParsedStream[]) {
|
||||
if (!Array.isArray(streams)) {
|
||||
throw new Error(
|
||||
"Please use one of 'totalStreams' or 'previousStreams' as the first argument"
|
||||
);
|
||||
}
|
||||
return streams.filter((stream) => stream.service?.cached === true);
|
||||
};
|
||||
this.parser.functions.uncached = function (streams: ParsedStream[]) {
|
||||
if (!Array.isArray(streams)) {
|
||||
throw new Error(
|
||||
"Please use one of 'totalStreams' or 'previousStreams' as the first argument"
|
||||
);
|
||||
}
|
||||
return streams.filter((stream) => stream.service?.cached === false);
|
||||
};
|
||||
this.parser.functions.releaseGroup = function (
|
||||
streams: ParsedStream[],
|
||||
releaseGroup: string
|
||||
) {
|
||||
if (!Array.isArray(streams)) {
|
||||
throw new Error(
|
||||
"Please use one of 'totalStreams' or 'previousStreams' as the first argument"
|
||||
);
|
||||
} else if (typeof releaseGroup !== 'string') {
|
||||
throw new Error('Release group must be a string');
|
||||
}
|
||||
return streams.filter(
|
||||
(stream) => stream.parsedFile?.releaseGroup === releaseGroup
|
||||
);
|
||||
};
|
||||
this.parser.functions.count = function (streams: ParsedStream[]) {
|
||||
if (!Array.isArray(streams)) {
|
||||
throw new Error(
|
||||
"Please use one of 'totalStreams' or 'previousStreams' as the first argument"
|
||||
);
|
||||
}
|
||||
return streams.length;
|
||||
};
|
||||
}
|
||||
async parse(condition: string) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const timeout = setTimeout(() => {
|
||||
reject(new Error('Condition parsing timed out'));
|
||||
}, 1);
|
||||
|
||||
try {
|
||||
const result = this.parser.evaluate(condition);
|
||||
clearTimeout(timeout);
|
||||
resolve(result);
|
||||
} catch (error) {
|
||||
clearTimeout(timeout);
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static async testParse(condition: string) {
|
||||
const parser = new ConditionParser([], [], 0, 0, 'movie');
|
||||
return await parser.parse(condition);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
import { PARSE_REGEX } from './regex';
|
||||
import * as PTT from 'parse-torrent-title';
|
||||
import { ParsedFile } from '../db';
|
||||
|
||||
function matchPattern(
|
||||
filename: string,
|
||||
patterns: Record<string, RegExp>
|
||||
): string | undefined {
|
||||
return Object.entries(patterns).find(([_, pattern]) =>
|
||||
pattern.test(filename)
|
||||
)?.[0];
|
||||
}
|
||||
|
||||
function matchMultiplePatterns(
|
||||
filename: string,
|
||||
patterns: Record<string, RegExp>
|
||||
): string[] {
|
||||
return Object.entries(patterns)
|
||||
.filter(([_, pattern]) => pattern.test(filename))
|
||||
.map(([tag]) => tag);
|
||||
}
|
||||
|
||||
class FileParser {
|
||||
static parse(filename: string): ParsedFile {
|
||||
filename = filename.replace(/\s+/g, '.').replace(/^\.+|\.+$/g, '');
|
||||
const resolution = matchPattern(filename, PARSE_REGEX.resolutions);
|
||||
const quality = matchPattern(filename, PARSE_REGEX.qualities);
|
||||
const encode = matchPattern(filename, PARSE_REGEX.encodes);
|
||||
const audioChannels = matchMultiplePatterns(
|
||||
filename,
|
||||
PARSE_REGEX.audioChannels
|
||||
);
|
||||
const visualTags = matchMultiplePatterns(filename, PARSE_REGEX.visualTags);
|
||||
const audioTags = matchMultiplePatterns(filename, PARSE_REGEX.audioTags);
|
||||
const languages = matchMultiplePatterns(filename, PARSE_REGEX.languages);
|
||||
|
||||
const getPaddedNumber = (number: number, length: number) =>
|
||||
number.toString().padStart(length, '0');
|
||||
|
||||
const parsed = PTT.parse(filename);
|
||||
const releaseGroup = parsed.group;
|
||||
const title = parsed.title;
|
||||
const year = parsed.year ? parsed.year.toString() : undefined;
|
||||
const season = parsed.season;
|
||||
const seasons = parsed.seasons;
|
||||
const episode = parsed.episode;
|
||||
const formattedSeasonString = seasons?.length
|
||||
? seasons.length === 1
|
||||
? `S${getPaddedNumber(seasons[0], 2)}`
|
||||
: `S${getPaddedNumber(seasons[0], 2)}-${getPaddedNumber(
|
||||
seasons[seasons.length - 1],
|
||||
2
|
||||
)}`
|
||||
: season
|
||||
? `S${getPaddedNumber(season, 2)}`
|
||||
: undefined;
|
||||
const formattedEpisodeString = episode
|
||||
? `E${getPaddedNumber(episode, 2)}`
|
||||
: undefined;
|
||||
|
||||
const seasonEpisode = [
|
||||
formattedSeasonString,
|
||||
formattedEpisodeString,
|
||||
].filter((v) => v !== undefined);
|
||||
|
||||
return {
|
||||
resolution,
|
||||
quality,
|
||||
languages,
|
||||
encode,
|
||||
audioChannels,
|
||||
audioTags,
|
||||
visualTags,
|
||||
releaseGroup,
|
||||
title,
|
||||
year,
|
||||
season,
|
||||
seasons,
|
||||
episode,
|
||||
seasonEpisode,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default FileParser;
|
||||
@@ -0,0 +1,2 @@
|
||||
export { default as FileParser } from './file';
|
||||
export { default as StreamParser } from './streams';
|
||||
@@ -1,10 +1,47 @@
|
||||
import { AUDIO_TAGS, QUALITIES, RESOLUTIONS } from '../utils/constants';
|
||||
import { VISUAL_TAGS } from '../utils/constants';
|
||||
import { ENCODES } from '../utils/constants';
|
||||
import { LANGUAGES } from '../utils/constants';
|
||||
import { AUDIO_CHANNELS } from '../utils/constants';
|
||||
const createRegex = (pattern: string): RegExp =>
|
||||
new RegExp(`(?<![^\\s\\[(_\\-.,])(${pattern})(?=[\\s\\)\\]_.\\-,]|$)`, 'i');
|
||||
|
||||
const createLanguageRegex = (pattern: string): RegExp =>
|
||||
createRegex(`${pattern}(?![ .\\-_]?sub(title)?s?)`);
|
||||
|
||||
export const PARSE_REGEX = {
|
||||
type PARSE_REGEX = {
|
||||
resolutions: Omit<Record<(typeof RESOLUTIONS)[number], RegExp>, 'Unknown'> & {
|
||||
Unknown?: RegExp;
|
||||
};
|
||||
qualities: Omit<Record<(typeof QUALITIES)[number], RegExp>, 'Unknown'> & {
|
||||
Unknown?: RegExp;
|
||||
};
|
||||
visualTags: Omit<
|
||||
Record<(typeof VISUAL_TAGS)[number], RegExp>,
|
||||
'Unknown' | 'HDR+DV'
|
||||
> & {
|
||||
Unknown?: RegExp;
|
||||
'HDR+DV'?: RegExp;
|
||||
};
|
||||
audioTags: Omit<Record<(typeof AUDIO_TAGS)[number], RegExp>, 'Unknown'> & {
|
||||
Unknown?: RegExp;
|
||||
};
|
||||
audioChannels: Omit<
|
||||
Record<(typeof AUDIO_CHANNELS)[number], RegExp>,
|
||||
'Unknown'
|
||||
> & {
|
||||
Unknown?: RegExp;
|
||||
};
|
||||
languages: Omit<Record<(typeof LANGUAGES)[number], RegExp>, 'Unknown'> & {
|
||||
Unknown?: RegExp;
|
||||
};
|
||||
encodes: Omit<Record<(typeof ENCODES)[number], RegExp>, 'Unknown'> & {
|
||||
Unknown?: RegExp;
|
||||
};
|
||||
releaseGroup: RegExp;
|
||||
};
|
||||
|
||||
export const PARSE_REGEX: PARSE_REGEX = {
|
||||
resolutions: {
|
||||
'2160p': createRegex(
|
||||
'(bd|hd|m)?(4k|2160(p|i)?)|u(ltra)?[ .\\-_]?hd|3840\s?x\s?(\d{4})'
|
||||
@@ -16,7 +53,11 @@ export const PARSE_REGEX = {
|
||||
'(bd|hd|m)?(1080(p|i)?)|f(ull)?[ .\\-_]?hd|1920\s?x\s?(\d{3,4})'
|
||||
),
|
||||
'720p': createRegex('(bd|hd|m)?(720(p|i)?)|hd|1280\s?x\s?(\d{3,4})'),
|
||||
'576p': createRegex('(bd|hd|m)?(576(p|i)?)'),
|
||||
'480p': createRegex('(bd|hd|m)?(480(p|i)?)|sd'),
|
||||
'360p': createRegex('(bd|hd|m)?(360(p|i)?)'),
|
||||
'240p': createRegex('(bd|hd|m)?(240(p|i)?)'),
|
||||
'144p': createRegex('(bd|hd|m)?(144(p|i)?)'),
|
||||
},
|
||||
qualities: {
|
||||
'BluRay REMUX':
|
||||
@@ -58,22 +99,30 @@ export const PARSE_REGEX = {
|
||||
),
|
||||
'DTS-HD MA': createRegex('dts[ .\\-_]?hd[ .\\-_]?ma'),
|
||||
'DTS-HD': createRegex('dts[ .\\-_]?hd(?![ .\\-_]?ma)'),
|
||||
DTS: createRegex('dts(?![ .\\-_]?hd[ .\\-_]?ma|[ .\\-_]?hd)'),
|
||||
'DTS-ES': createRegex('dts[ .\\-_]?es'),
|
||||
DTS: createRegex('dts(?![ .\\-_]?hd[ .\\-_]?ma|[ .\\-_]?hd|[ .\\-_]?es)'),
|
||||
TrueHD: createRegex('true[ .\\-_]?hd'),
|
||||
5.1: createRegex(
|
||||
'(d(olby)?[ .\\-_]?d(igital)?[ .\\-_]?(p(lus)?|\\+)?)?5[ .\\-_]?1(ch)?'
|
||||
),
|
||||
7.1: createRegex(
|
||||
'(d(olby)?[ .\\-_]?d(igital)?[ .\\-_]?(p(lus)?|\\+)?)?7[ .\\-_]?1(ch)?'
|
||||
),
|
||||
OPUS: createRegex('opus'),
|
||||
AAC: createRegex('q?aac(?:[ .\\-_]?2)?'),
|
||||
FLAC: createRegex('flac(?:[ .\\-_]?(lossless|2\\.0|x[2-4]))?'),
|
||||
},
|
||||
audioChannels: {
|
||||
'2.0': createRegex('(2[ .\\-_]?0)(ch)?'),
|
||||
'5.1': createRegex(
|
||||
'(d(olby)?[ .\\-_]?d(igital)?[ .\\-_]?(p(lus)?|\\+)?)?5[ .\\-_]?1(ch)?'
|
||||
),
|
||||
'6.1': createRegex(
|
||||
'(d(olby)?[ .\\-_]?d(igital)?[ .\\-_]?(p(lus)?|\\+)?)?6[ .\\-_]?1(ch)?'
|
||||
),
|
||||
'7.1': createRegex(
|
||||
'(d(olby)?[ .\\-_]?d(igital)?[ .\\-_]?(p(lus)?|\\+)?)?7[ .\\-_]?1(ch)?'
|
||||
),
|
||||
},
|
||||
encodes: {
|
||||
HEVC: createRegex('hevc[ .\\-_]?(10)?|[xh][ .\\-_]?265'),
|
||||
AVC: createRegex('avc|[xh][ .\\-_]?264'),
|
||||
AV1: createRegex('av1'),
|
||||
Xvid: createRegex('xvid'),
|
||||
XviD: createRegex('xvid'),
|
||||
DivX: createRegex('divx|dvix'),
|
||||
'H-OU': createRegex('h?(alf)?[ .\\-_]?(ou|over[ .\\-_]?under)'),
|
||||
'H-SBS': createRegex('h?(alf)?[ .\\-_]?(sbs|side[ .\\-_]?by[ .\\-_]?side)'),
|
||||
@@ -85,18 +134,18 @@ export const PARSE_REGEX = {
|
||||
),
|
||||
Dubbed: createLanguageRegex('dub(bed)?'),
|
||||
English: createLanguageRegex('english|eng'),
|
||||
Japanese: createLanguageRegex('japanese|jap'),
|
||||
Japanese: createLanguageRegex('japanese|jap|jpn'),
|
||||
Chinese: createLanguageRegex('chinese|chi'),
|
||||
Russian: createLanguageRegex('russian|rus'),
|
||||
Arabic: createLanguageRegex('arabic|ara'),
|
||||
Portuguese: createLanguageRegex('portuguese|por'),
|
||||
Spanish: createLanguageRegex('spanish|spa|esp'),
|
||||
French: createLanguageRegex('french|fra'),
|
||||
French: createLanguageRegex('french|fra|fr|vf|vff|vfi|vf2|vfq|truefrench'),
|
||||
German: createLanguageRegex('german|ger'),
|
||||
Italian: createLanguageRegex('italian|ita'),
|
||||
Korean: createLanguageRegex('korean|kor'),
|
||||
Hindi: createLanguageRegex('hindi|hin'),
|
||||
Bengali: createLanguageRegex('bengali|ben'),
|
||||
Bengali: createLanguageRegex('bengali|ben(?![ .\\-_]?the[ .\\-_]?men)'),
|
||||
Punjabi: createLanguageRegex('punjabi|pan'),
|
||||
Marathi: createLanguageRegex('marathi|mar'),
|
||||
Gujarati: createLanguageRegex('gujarati|guj'),
|
||||
@@ -0,0 +1,484 @@
|
||||
import { Stream, ParsedStream, Addon } from '../db';
|
||||
import { constants, createLogger, FULL_LANGUAGE_MAPPING } from '../utils';
|
||||
import FileParser from './file';
|
||||
const logger = createLogger('parser');
|
||||
class StreamParser {
|
||||
get errorRegexes(): { pattern: RegExp; message: string }[] | undefined {
|
||||
return [
|
||||
{
|
||||
pattern: /invalid\s+\w+\s+(account|apikey|token)/i,
|
||||
message: 'Invalid account or apikey or token',
|
||||
},
|
||||
];
|
||||
}
|
||||
protected get filenameRegex(): RegExp | undefined {
|
||||
return undefined;
|
||||
}
|
||||
protected get folderNameRegex(): RegExp | undefined {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
protected get sizeRegex(): RegExp | undefined {
|
||||
return /(\d+(\.\d+)?)\s?(KB|MB|GB|TB)/i;
|
||||
}
|
||||
protected get sizeK(): 1024 | 1000 {
|
||||
return 1024;
|
||||
}
|
||||
|
||||
protected get seedersRegex(): RegExp | undefined {
|
||||
return /[👥👤]\s*(\d+)/u;
|
||||
}
|
||||
|
||||
protected get indexerEmojis(): string[] {
|
||||
return ['🌐', '⚙️', '🔗', '🔎', '🔍', '☁️'];
|
||||
}
|
||||
|
||||
protected get indexerRegex(): RegExp | undefined {
|
||||
return this.getRegexForTextAfterEmojis(this.indexerEmojis);
|
||||
}
|
||||
|
||||
protected get ageRegex(): RegExp | undefined {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
protected getRegexForTextAfterEmojis(emojis: string[]): RegExp {
|
||||
return new RegExp(
|
||||
`(?:${emojis.join('|')})\\s*([^\\p{Emoji_Presentation}\\n]*?)(?=\\p{Emoji_Presentation}|$|\\n)`,
|
||||
'u'
|
||||
);
|
||||
}
|
||||
|
||||
constructor(protected readonly addon: Addon) {}
|
||||
|
||||
parse(stream: Stream): ParsedStream {
|
||||
let parsedStream: ParsedStream = {
|
||||
addon: this.addon,
|
||||
type: 'http',
|
||||
url: this.applyUrlModifications(stream.url),
|
||||
externalUrl: stream.externalUrl,
|
||||
ytId: stream.ytId,
|
||||
requestHeaders: stream.behaviorHints?.proxyHeaders?.request,
|
||||
responseHeaders: stream.behaviorHints?.proxyHeaders?.response,
|
||||
notWebReady: stream.behaviorHints?.notWebReady,
|
||||
videoHash: stream.behaviorHints?.videoHash,
|
||||
originalName: stream.name,
|
||||
originalDescription: stream.description || stream.title,
|
||||
};
|
||||
|
||||
stream.description = stream.description || stream.title;
|
||||
|
||||
this.raiseErrorIfNecessary(stream, parsedStream);
|
||||
|
||||
parsedStream.error = this.getError(stream, parsedStream);
|
||||
if (parsedStream.error) {
|
||||
parsedStream.type = constants.ERROR_STREAM_TYPE;
|
||||
return parsedStream;
|
||||
}
|
||||
|
||||
parsedStream.filename = this.getFilename(stream, parsedStream);
|
||||
parsedStream.folderName = this.getFolder(stream, parsedStream);
|
||||
parsedStream.size = this.getSize(stream, parsedStream);
|
||||
parsedStream.folderSize = this.getFolderSize(stream, parsedStream);
|
||||
parsedStream.indexer = this.getIndexer(stream, parsedStream);
|
||||
parsedStream.service = this.getService(stream, parsedStream);
|
||||
parsedStream.duration = this.getDuration(stream, parsedStream);
|
||||
parsedStream.type = this.getStreamType(
|
||||
stream,
|
||||
parsedStream.service,
|
||||
parsedStream
|
||||
);
|
||||
parsedStream.library = this.getInLibrary(stream, parsedStream);
|
||||
parsedStream.age = this.getAge(stream, parsedStream);
|
||||
parsedStream.message = this.getMessage(stream, parsedStream);
|
||||
|
||||
if (parsedStream.filename) {
|
||||
parsedStream.parsedFile = FileParser.parse(parsedStream.filename);
|
||||
parsedStream.parsedFile.languages = Array.from(
|
||||
new Set([
|
||||
...parsedStream.parsedFile.languages,
|
||||
...this.getLanguages(stream, parsedStream),
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
if (parsedStream.folderName && parsedStream.parsedFile) {
|
||||
const parsedFolder = FileParser.parse(parsedStream.folderName);
|
||||
parsedStream.parsedFile = {
|
||||
...parsedStream.parsedFile,
|
||||
title: parsedFolder.title, // prefer titles from the folder name if it exists
|
||||
};
|
||||
}
|
||||
|
||||
parsedStream.torrent = {
|
||||
infoHash:
|
||||
parsedStream.type === 'p2p'
|
||||
? stream.infoHash
|
||||
: this.getInfoHash(stream, parsedStream),
|
||||
seeders: this.getSeeders(stream, parsedStream),
|
||||
sources: stream.sources,
|
||||
fileIdx: stream.fileIdx,
|
||||
};
|
||||
|
||||
return parsedStream;
|
||||
}
|
||||
|
||||
protected applyUrlModifications(url: string | undefined): string | undefined {
|
||||
return url;
|
||||
}
|
||||
|
||||
protected raiseErrorIfNecessary(
|
||||
stream: Stream,
|
||||
currentParsedStream: ParsedStream
|
||||
) {
|
||||
if (!this.errorRegexes) {
|
||||
return;
|
||||
}
|
||||
for (const errorRegex of this.errorRegexes) {
|
||||
if (errorRegex.pattern.test(stream.description || stream.title || '')) {
|
||||
throw new Error(errorRegex.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected getError(
|
||||
stream: Stream,
|
||||
currentParsedStream: ParsedStream
|
||||
): ParsedStream['error'] | undefined {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
protected getFilename(
|
||||
stream: Stream,
|
||||
currentParsedStream: ParsedStream
|
||||
): string | undefined {
|
||||
let filename = stream.behaviorHints?.filename;
|
||||
|
||||
if (filename) {
|
||||
return filename;
|
||||
}
|
||||
|
||||
const description = stream.description || stream.title;
|
||||
if (!description) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (this.filenameRegex) {
|
||||
const match = description.match(this.filenameRegex);
|
||||
if (match) {
|
||||
return match[1];
|
||||
}
|
||||
}
|
||||
|
||||
// attempt to find a filename by finding the most suitable line that has more info
|
||||
const potentialFilenames = description
|
||||
.split('\n')
|
||||
.filter((line) => line.trim() !== '')
|
||||
.splice(0, 5);
|
||||
|
||||
for (const line of potentialFilenames) {
|
||||
const parsed = FileParser.parse(line);
|
||||
if (parsed.year || (parsed.season && parsed.episode) || parsed.episode) {
|
||||
filename = line;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!filename) {
|
||||
filename = description.split('\n')[0];
|
||||
}
|
||||
return filename
|
||||
?.trim()
|
||||
?.replace(/^\p{Emoji_Presentation}+/gu, '')
|
||||
?.replace(/^[^:]+:\s*/g, '');
|
||||
}
|
||||
|
||||
protected getFolder(
|
||||
stream: Stream,
|
||||
currentParsedStream: ParsedStream
|
||||
): string | undefined {
|
||||
if (this.folderNameRegex) {
|
||||
const match = stream.description?.match(this.folderNameRegex);
|
||||
if (match) {
|
||||
return match[1];
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
protected getSize(
|
||||
stream: Stream,
|
||||
currentParsedStream: ParsedStream
|
||||
): number | undefined {
|
||||
let description = stream.description || stream.title;
|
||||
if (currentParsedStream.filename && description) {
|
||||
description = description.replace(currentParsedStream.filename, '');
|
||||
}
|
||||
if (currentParsedStream.folderName && description) {
|
||||
description = description.replace(currentParsedStream.folderName, '');
|
||||
}
|
||||
let size =
|
||||
stream.behaviorHints?.videoSize ||
|
||||
(stream as any).size ||
|
||||
(stream as any).sizeBytes ||
|
||||
(stream as any).sizebytes ||
|
||||
(description && this.calculateBytesFromSizeString(description)) ||
|
||||
(stream.name && this.calculateBytesFromSizeString(stream.name));
|
||||
|
||||
if (typeof size === 'string') {
|
||||
size = parseInt(size);
|
||||
} else if (typeof size === 'number') {
|
||||
size = Math.round(size);
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
protected getFolderSize(
|
||||
stream: Stream,
|
||||
currentParsedStream: ParsedStream
|
||||
): number | undefined {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
protected getSeeders(
|
||||
stream: Stream,
|
||||
currentParsedStream: ParsedStream
|
||||
): number | undefined {
|
||||
const regex = this.seedersRegex;
|
||||
if (!regex) {
|
||||
return undefined;
|
||||
}
|
||||
const match = stream.description?.match(regex);
|
||||
if (match) {
|
||||
return parseInt(match[1]);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
protected getAge(
|
||||
stream: Stream,
|
||||
currentParsedStream: ParsedStream
|
||||
): string | undefined {
|
||||
const regex = this.ageRegex;
|
||||
if (!regex) {
|
||||
return undefined;
|
||||
}
|
||||
const match = stream.description?.match(regex);
|
||||
if (match) {
|
||||
return match[1];
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
protected getIndexer(
|
||||
stream: Stream,
|
||||
currentParsedStream: ParsedStream
|
||||
): string | undefined {
|
||||
const regex = this.indexerRegex;
|
||||
if (!regex) {
|
||||
return undefined;
|
||||
}
|
||||
const match = stream.description?.match(regex);
|
||||
if (match) {
|
||||
return match[1];
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
protected getMessage(
|
||||
stream: Stream,
|
||||
currentParsedStream: ParsedStream
|
||||
): string | undefined {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
protected getService(
|
||||
stream: Stream,
|
||||
currentParsedStream: ParsedStream
|
||||
): ParsedStream['service'] | undefined {
|
||||
return this.parseServiceData(stream.name || '');
|
||||
}
|
||||
|
||||
protected getInfoHash(
|
||||
stream: Stream,
|
||||
currentParsedStream: ParsedStream
|
||||
): string | undefined {
|
||||
return stream.url
|
||||
? stream.url.match(/(?<=[-/[(;:&])[a-fA-F0-9]{40}(?=[-\]\)/:;&])/)?.[0]
|
||||
: undefined;
|
||||
}
|
||||
|
||||
protected getDuration(
|
||||
stream: Stream,
|
||||
currentParsedStream: ParsedStream
|
||||
): number | undefined {
|
||||
// Regular expression to match different formats of time durations
|
||||
const regex =
|
||||
/(?<![^\s\[(_\-,.])(?:(\d+)h[:\s]?(\d+)m[:\s]?(\d+)s|(\d+)h[:\s]?(\d+)m|(\d+)h|(\d+)m|(\d+)s)(?=[\s\)\]_.\-,]|$)/gi;
|
||||
|
||||
const match = regex.exec(stream.description || stream.title || '');
|
||||
if (!match) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const hours = parseInt(match[1] || match[4] || match[6] || '0', 10);
|
||||
const minutes = parseInt(match[2] || match[5] || match[7] || '0', 10);
|
||||
const seconds = parseInt(match[3] || match[8] || '0', 10);
|
||||
|
||||
// Convert to milliseconds
|
||||
const totalMilliseconds = (hours * 3600 + minutes * 60 + seconds) * 1000;
|
||||
|
||||
return totalMilliseconds;
|
||||
}
|
||||
|
||||
protected getStreamType(
|
||||
stream: Stream,
|
||||
service: ParsedStream['service'],
|
||||
currentParsedStream: ParsedStream
|
||||
): ParsedStream['type'] {
|
||||
if (stream.infoHash) {
|
||||
return 'p2p';
|
||||
}
|
||||
|
||||
if (stream.url?.endsWith('.m3u8')) {
|
||||
return 'live';
|
||||
}
|
||||
|
||||
if (service?.id === constants.EASYNEWS_SERVICE) {
|
||||
return 'usenet';
|
||||
} else if (service) {
|
||||
return 'debrid';
|
||||
}
|
||||
|
||||
// return 'http';
|
||||
if (stream.url) {
|
||||
return 'http';
|
||||
}
|
||||
|
||||
if (stream.externalUrl) {
|
||||
return 'external';
|
||||
}
|
||||
|
||||
if (stream.ytId) {
|
||||
return 'youtube';
|
||||
}
|
||||
|
||||
throw new Error('Invalid stream, missing a required stream property');
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts languages from the stream description using country flags.
|
||||
* @param stream - The stream object containing the description.
|
||||
* @param currentParsedStream - The current parsed stream object.
|
||||
* @returns An array of language strings.
|
||||
*/
|
||||
protected getLanguages(
|
||||
stream: Stream,
|
||||
currentParsedStream: ParsedStream
|
||||
): string[] {
|
||||
const countryFlagPattern = /[\u{1F1E6}-\u{1F1FF}]{2}/gu;
|
||||
const descriptionMatches = stream.description?.match(countryFlagPattern);
|
||||
const nameMatches = stream.name?.match(countryFlagPattern);
|
||||
const flags = [
|
||||
...(descriptionMatches ? [...new Set(descriptionMatches)] : []),
|
||||
...(nameMatches ? [...new Set(nameMatches)] : []),
|
||||
];
|
||||
const languages = flags
|
||||
.map((flag) => {
|
||||
const possibleLanguages = FULL_LANGUAGE_MAPPING.filter(
|
||||
(language) => language.flag === flag
|
||||
);
|
||||
|
||||
const language = (
|
||||
possibleLanguages.find((l) => l.flag_priority) || possibleLanguages[0]
|
||||
).english_name
|
||||
?.split('(')?.[0]
|
||||
?.trim();
|
||||
if (language && constants.LANGUAGES.includes(language as any)) {
|
||||
return language;
|
||||
}
|
||||
return undefined;
|
||||
})
|
||||
.filter((language) => language !== undefined);
|
||||
return languages;
|
||||
}
|
||||
|
||||
protected convertISO6392ToLanguage(code: string): string | undefined {
|
||||
const lang = FULL_LANGUAGE_MAPPING.find(
|
||||
(language) => language.iso_639_2 === code
|
||||
);
|
||||
return lang?.english_name?.split('(')?.[0]?.trim();
|
||||
}
|
||||
|
||||
protected getInLibrary(
|
||||
stream: Stream,
|
||||
currentParsedStream: ParsedStream
|
||||
): boolean {
|
||||
return this.addon.library ?? false;
|
||||
}
|
||||
|
||||
protected calculateBytesFromSizeString(size: string): number | undefined {
|
||||
const k = this.sizeK;
|
||||
if (!this.sizeRegex) {
|
||||
return undefined;
|
||||
}
|
||||
const sizePattern = this.sizeRegex;
|
||||
const match = size.match(sizePattern);
|
||||
if (!match) return 0;
|
||||
const value = parseFloat(match[1]);
|
||||
const unit = match[3];
|
||||
|
||||
switch (unit.toUpperCase()) {
|
||||
case 'TB':
|
||||
return value * k * k * k * k;
|
||||
case 'GB':
|
||||
return value * k * k * k;
|
||||
case 'MB':
|
||||
return value * k * k;
|
||||
case 'KB':
|
||||
return value * k;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
protected parseServiceData(
|
||||
string: string
|
||||
): ParsedStream['service'] | undefined {
|
||||
const cleanString = string.replace(/web-?dl/i, '');
|
||||
const services = constants.SERVICE_DETAILS;
|
||||
const cachedSymbols = ['+', '⚡', '🚀', 'cached'];
|
||||
const uncachedSymbols = ['⏳', 'download', 'UNCACHED'];
|
||||
let streamService: ParsedStream['service'] | undefined;
|
||||
Object.values(services).forEach((service) => {
|
||||
// for each service, generate a regexp which creates a regex with all known names separated by |
|
||||
const regex = new RegExp(
|
||||
`(^|(?<![^ |[(_\\/\\-.]))(${service.knownNames.join('|')})(?=[ ⬇️⏳⚡+/|\\)\\]_.-]|$|\n)`,
|
||||
'im'
|
||||
);
|
||||
// check if the string contains the regex
|
||||
if (regex.test(cleanString)) {
|
||||
let cached: boolean = false;
|
||||
// check if any of the uncachedSymbols are in the string
|
||||
if (uncachedSymbols.some((symbol) => string.includes(symbol))) {
|
||||
cached = false;
|
||||
}
|
||||
// check if any of the cachedSymbols are in the string
|
||||
else if (cachedSymbols.some((symbol) => string.includes(symbol))) {
|
||||
cached = true;
|
||||
}
|
||||
|
||||
streamService = {
|
||||
id: service.id,
|
||||
cached: cached,
|
||||
};
|
||||
}
|
||||
});
|
||||
return streamService;
|
||||
}
|
||||
}
|
||||
|
||||
export default StreamParser;
|
||||
@@ -0,0 +1,151 @@
|
||||
import {
|
||||
Addon,
|
||||
Option,
|
||||
UserData,
|
||||
ParsedStream,
|
||||
Stream,
|
||||
AIOStream,
|
||||
} from '../db';
|
||||
import { Preset, baseOptions } from './preset';
|
||||
import { Env, formatZodError, RESOURCES } from '../utils';
|
||||
import { StreamParser } from '../parser';
|
||||
import { createLogger } from '../utils';
|
||||
|
||||
const logger = createLogger('parser');
|
||||
|
||||
class AIOStreamsStreamParser extends StreamParser {
|
||||
override parse(stream: Stream): ParsedStream {
|
||||
const aioStream = stream as AIOStream;
|
||||
const parsed = AIOStream.safeParse(aioStream);
|
||||
if (!parsed.success) {
|
||||
logger.error(
|
||||
`Stream from AIOStream was not detected as a valid stream: ${formatZodError(parsed.error)}`
|
||||
);
|
||||
throw new Error('Invalid stream');
|
||||
}
|
||||
return {
|
||||
addon: {
|
||||
...this.addon,
|
||||
name: `${this.addon.name} | ${aioStream.streamData?.addon ?? ''}`,
|
||||
},
|
||||
error: aioStream.streamData?.error,
|
||||
type: aioStream.streamData?.type ?? 'http',
|
||||
url: aioStream.url,
|
||||
externalUrl: aioStream.externalUrl,
|
||||
ytId: aioStream.ytId,
|
||||
requestHeaders: aioStream.behaviorHints?.proxyHeaders?.request,
|
||||
responseHeaders: aioStream.behaviorHints?.proxyHeaders?.response,
|
||||
notWebReady: aioStream.behaviorHints?.notWebReady,
|
||||
videoHash: aioStream.behaviorHints?.videoHash,
|
||||
filename: aioStream.streamData?.filename,
|
||||
folderName: aioStream.streamData?.folderName,
|
||||
size: aioStream.streamData?.size,
|
||||
folderSize: aioStream.streamData?.folderSize,
|
||||
indexer: aioStream.streamData?.indexer,
|
||||
service: aioStream.streamData?.service,
|
||||
duration: aioStream.streamData?.duration,
|
||||
library: aioStream.streamData?.library ?? false,
|
||||
age: aioStream.streamData?.age,
|
||||
message: aioStream.streamData?.message,
|
||||
torrent: aioStream.streamData?.torrent,
|
||||
parsedFile: aioStream.streamData?.parsedFile,
|
||||
keywordMatched: aioStream.streamData?.keywordMatched,
|
||||
regexMatched: aioStream.streamData?.regexMatched,
|
||||
originalName: aioStream.name,
|
||||
originalDescription: aioStream.description || stream.title,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export class AIOStreamsPreset extends Preset {
|
||||
static override getParser(): typeof StreamParser {
|
||||
return AIOStreamsStreamParser;
|
||||
}
|
||||
|
||||
static override get METADATA() {
|
||||
const options: Option[] = [
|
||||
{
|
||||
id: 'name',
|
||||
name: 'Name',
|
||||
description: 'What to call this addon',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: 'AIOStreams',
|
||||
},
|
||||
{
|
||||
id: 'manifestUrl',
|
||||
name: 'Manifest URL',
|
||||
description: 'Provide the Manifest URL for this AIOStreams addon.',
|
||||
type: 'url',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
id: 'timeout',
|
||||
name: 'Timeout',
|
||||
description: 'The timeout for this addon',
|
||||
type: 'number',
|
||||
default: Env.DEFAULT_TIMEOUT,
|
||||
constraints: {
|
||||
min: Env.MIN_TIMEOUT,
|
||||
max: Env.MAX_TIMEOUT,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'resources',
|
||||
name: 'Resources',
|
||||
description:
|
||||
'Optionally override the resources that are fetched from this addon ',
|
||||
type: 'multi-select',
|
||||
required: false,
|
||||
default: undefined,
|
||||
options: RESOURCES.map((resource) => ({
|
||||
label: resource,
|
||||
value: resource,
|
||||
})),
|
||||
},
|
||||
];
|
||||
|
||||
return {
|
||||
ID: 'aiostreams',
|
||||
NAME: 'AIOStreams',
|
||||
LOGO: 'https://raw.githubusercontent.com/Viren070/AIOStreams/refs/heads/main/packages/frontend/public/assets/logo.png',
|
||||
URL: '',
|
||||
TIMEOUT: Env.DEFAULT_TIMEOUT,
|
||||
USER_AGENT: Env.DEFAULT_USER_AGENT,
|
||||
SUPPORTED_SERVICES: [],
|
||||
DESCRIPTION: 'Wrap AIOStreams within AIOStreams!',
|
||||
OPTIONS: options,
|
||||
SUPPORTED_STREAM_TYPES: [],
|
||||
SUPPORTED_RESOURCES: [],
|
||||
};
|
||||
}
|
||||
|
||||
static async generateAddons(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Promise<Addon[]> {
|
||||
if (!options.manifestUrl.endsWith('/manifest.json')) {
|
||||
throw new Error('Invalid manifest URL');
|
||||
}
|
||||
return [this.generateAddon(userData, options)];
|
||||
}
|
||||
|
||||
private static generateAddon(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Addon {
|
||||
return {
|
||||
name: options.name || this.METADATA.NAME,
|
||||
identifyingName: options.name || this.METADATA.NAME,
|
||||
manifestUrl: options.manifestUrl.replace('stremio://', 'https://'),
|
||||
enabled: true,
|
||||
library: false,
|
||||
resources: options.resources || undefined,
|
||||
timeout: options.timeout || this.METADATA.TIMEOUT,
|
||||
fromPresetId: this.METADATA.ID,
|
||||
headers: {
|
||||
'User-Agent': this.METADATA.USER_AGENT,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import { Addon, Option, UserData } from '../db';
|
||||
import { Preset, baseOptions } from './preset';
|
||||
import { constants, Env } from '../utils';
|
||||
|
||||
export class AnimeKitsuPreset extends Preset {
|
||||
static override get METADATA() {
|
||||
const supportedResources = [
|
||||
constants.CATALOG_RESOURCE,
|
||||
constants.META_RESOURCE,
|
||||
];
|
||||
|
||||
const options: Option[] = [
|
||||
...baseOptions(
|
||||
'Anime Kitsu',
|
||||
supportedResources,
|
||||
Env.DEFAULT_ANIME_KITSU_TIMEOUT
|
||||
),
|
||||
];
|
||||
|
||||
return {
|
||||
ID: 'anime-kitsu',
|
||||
NAME: 'Anime Kitsu',
|
||||
LOGO: 'https://i.imgur.com/7N6XGoO.png',
|
||||
URL: Env.ANIME_KITSU_URL,
|
||||
TIMEOUT: Env.DEFAULT_ANIME_KITSU_TIMEOUT || Env.DEFAULT_TIMEOUT,
|
||||
USER_AGENT: Env.DEFAULT_ANIME_KITSU_USER_AGENT || Env.DEFAULT_USER_AGENT,
|
||||
SUPPORTED_SERVICES: [],
|
||||
DESCRIPTION: 'Anime catalog using Kitsu',
|
||||
OPTIONS: options,
|
||||
SUPPORTED_STREAM_TYPES: [],
|
||||
SUPPORTED_RESOURCES: supportedResources,
|
||||
};
|
||||
}
|
||||
|
||||
static async generateAddons(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Promise<Addon[]> {
|
||||
return [this.generateAddon(userData, options)];
|
||||
}
|
||||
|
||||
private static generateAddon(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Addon {
|
||||
const baseUrl = options.url
|
||||
? new URL(options.url).origin
|
||||
: Env.ANIME_KITSU_URL;
|
||||
return {
|
||||
name: options.name || this.METADATA.NAME,
|
||||
identifyingName: options.name || this.METADATA.NAME,
|
||||
manifestUrl: `${baseUrl}/manifest.json`,
|
||||
enabled: true,
|
||||
library: false,
|
||||
resources: options.resources || this.METADATA.SUPPORTED_RESOURCES,
|
||||
timeout: options.timeout || this.METADATA.TIMEOUT,
|
||||
fromPresetId: this.METADATA.ID,
|
||||
headers: {
|
||||
'User-Agent': this.METADATA.USER_AGENT,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
import { Addon, Option, UserData, Resource } from '../db';
|
||||
import { baseOptions, Preset } from './preset';
|
||||
import { Env } from '../utils';
|
||||
import { constants, ServiceId } from '../utils';
|
||||
import { StreamParser } from '../parser';
|
||||
|
||||
class CometStreamParser extends StreamParser {
|
||||
override applyUrlModifications(url: string | undefined): string | undefined {
|
||||
if (!url) {
|
||||
return url;
|
||||
}
|
||||
if (
|
||||
Env.FORCE_COMET_HOSTNAME !== undefined ||
|
||||
Env.FORCE_COMET_PORT !== undefined ||
|
||||
Env.FORCE_COMET_PROTOCOL !== undefined
|
||||
) {
|
||||
// modify the URL according to settings, needed when using a local URL for requests but a public stream URL is needed.
|
||||
const urlObj = new URL(url);
|
||||
|
||||
if (Env.FORCE_COMET_PROTOCOL !== undefined) {
|
||||
urlObj.protocol = Env.FORCE_COMET_PROTOCOL;
|
||||
}
|
||||
if (Env.FORCE_COMET_PORT !== undefined) {
|
||||
urlObj.port = Env.FORCE_COMET_PORT.toString();
|
||||
}
|
||||
if (Env.FORCE_COMET_HOSTNAME !== undefined) {
|
||||
urlObj.hostname = Env.FORCE_COMET_HOSTNAME;
|
||||
}
|
||||
return urlObj.toString();
|
||||
}
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
export class CometPreset extends Preset {
|
||||
static override getParser(): typeof StreamParser {
|
||||
return CometStreamParser;
|
||||
}
|
||||
|
||||
static override get METADATA() {
|
||||
const supportedServices: ServiceId[] = [
|
||||
constants.REALDEBRID_SERVICE,
|
||||
constants.PREMIUMIZE_SERVICE,
|
||||
constants.ALLEDEBRID_SERVICE,
|
||||
constants.TORBOX_SERVICE,
|
||||
constants.EASYDEBRID_SERVICE,
|
||||
constants.DEBRIDLINK_SERVICE,
|
||||
constants.OFFCLOUD_SERVICE,
|
||||
constants.PIKPAK_SERVICE,
|
||||
];
|
||||
|
||||
const supportedResources = [constants.STREAM_RESOURCE];
|
||||
|
||||
const options: Option[] = [
|
||||
...baseOptions('Comet', supportedResources, Env.DEFAULT_COMET_TIMEOUT),
|
||||
{
|
||||
id: 'includeP2P',
|
||||
name: 'Include P2P',
|
||||
description: 'Include P2P results, even if a debrid service is enabled',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
id: 'removeTrash',
|
||||
name: 'Remove Trash',
|
||||
description:
|
||||
'Remove all trash from results (Adult Content, CAM, Clean Audio, PDTV, R5, Screener, Size, Telecine and Telesync)',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
{
|
||||
id: 'services',
|
||||
name: 'Services',
|
||||
description:
|
||||
'Optionally override the services that are used. If not specified, then the services that are enabled and supported will be used.',
|
||||
type: 'multi-select',
|
||||
required: false,
|
||||
options: supportedServices.map((service) => ({
|
||||
value: service,
|
||||
label: constants.SERVICE_DETAILS[service].name,
|
||||
})),
|
||||
default: undefined,
|
||||
emptyIsUndefined: true,
|
||||
},
|
||||
];
|
||||
|
||||
return {
|
||||
ID: 'comet',
|
||||
NAME: 'Comet',
|
||||
LOGO: 'https://i.imgur.com/jmVoVMu.jpeg',
|
||||
URL: Env.COMET_URL,
|
||||
TIMEOUT: Env.DEFAULT_COMET_TIMEOUT || Env.DEFAULT_TIMEOUT,
|
||||
USER_AGENT: Env.DEFAULT_COMET_USER_AGENT || Env.DEFAULT_USER_AGENT,
|
||||
SUPPORTED_SERVICES: supportedServices,
|
||||
DESCRIPTION: "Stremio's fastest Torrent/Debrid addon",
|
||||
OPTIONS: options,
|
||||
SUPPORTED_STREAM_TYPES: [
|
||||
constants.P2P_STREAM_TYPE,
|
||||
constants.DEBRID_STREAM_TYPE,
|
||||
],
|
||||
SUPPORTED_RESOURCES: supportedResources,
|
||||
};
|
||||
}
|
||||
|
||||
static async generateAddons(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Promise<Addon[]> {
|
||||
// url can either be something like https://torrentio.com/ or it can be a custom manifest url.
|
||||
// if it is a custom manifest url, return a single addon with the custom manifest url.
|
||||
if (options?.url?.endsWith('/manifest.json')) {
|
||||
return [this.generateAddon(userData, options, undefined)];
|
||||
}
|
||||
|
||||
const usableServices = this.getUsableServices(userData, options.services);
|
||||
// if no services are usable, use p2p
|
||||
if (!usableServices || usableServices.length === 0) {
|
||||
return [this.generateAddon(userData, options, undefined)];
|
||||
}
|
||||
|
||||
let addons = usableServices.map((service) =>
|
||||
this.generateAddon(userData, options, service.id)
|
||||
);
|
||||
|
||||
if (options.includeP2P) {
|
||||
addons.push(this.generateAddon(userData, options, undefined));
|
||||
}
|
||||
|
||||
return addons;
|
||||
}
|
||||
|
||||
private static generateAddon(
|
||||
userData: UserData,
|
||||
options: Record<string, any>,
|
||||
serviceId?: ServiceId
|
||||
): Addon {
|
||||
return {
|
||||
name: options.name || this.METADATA.NAME,
|
||||
identifyingName: serviceId
|
||||
? `${options.name || this.METADATA.NAME} ${constants.SERVICE_DETAILS[serviceId].shortName}`
|
||||
: options.name || this.METADATA.NAME,
|
||||
manifestUrl: this.generateManifestUrl(userData, options, serviceId),
|
||||
enabled: true,
|
||||
resources: options.resources || this.METADATA.SUPPORTED_RESOURCES,
|
||||
timeout: options.timeout || this.METADATA.TIMEOUT,
|
||||
fromPresetId: this.METADATA.ID,
|
||||
headers: {
|
||||
'User-Agent': this.METADATA.USER_AGENT,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private static generateManifestUrl(
|
||||
userData: UserData,
|
||||
options: Record<string, any>,
|
||||
serviceId: ServiceId | undefined
|
||||
) {
|
||||
let url = options.url || this.METADATA.URL;
|
||||
if (url.endsWith('/manifest.json')) {
|
||||
return url;
|
||||
}
|
||||
url = url.replace(/\/$/, '');
|
||||
const configString = this.base64EncodeJSON({
|
||||
maxResultsPerResolution: 0,
|
||||
maxSize: 0,
|
||||
cachedOnly: false,
|
||||
removeTrash: options.removeTrash ?? true,
|
||||
resultFormat: ['all'],
|
||||
debridService: serviceId || 'torrent',
|
||||
debridApiKey: serviceId
|
||||
? this.getServiceCredential(serviceId, userData, {
|
||||
[constants.OFFCLOUD_SERVICE]: (credentials: any) =>
|
||||
`${credentials.email}:${credentials.password}`,
|
||||
[constants.PIKPAK_SERVICE]: (credentials: any) =>
|
||||
`${credentials.email}:${credentials.password}`,
|
||||
})
|
||||
: '',
|
||||
debridStreamProxyPassword: '',
|
||||
languages: { required: [], exclude: [], preferred: [] },
|
||||
resolutions: {},
|
||||
options: {
|
||||
remove_ranks_under: -10000000000,
|
||||
allow_english_in_languages: false,
|
||||
remove_unknown_languages: false,
|
||||
},
|
||||
});
|
||||
|
||||
return `${url}${configString ? '/' + configString : ''}/manifest.json`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
import { Addon, Option, UserData } from '../db';
|
||||
import { Preset, baseOptions } from './preset';
|
||||
import { Env, RESOURCES } from '../utils';
|
||||
|
||||
export class CustomPreset extends Preset {
|
||||
static override get METADATA() {
|
||||
const options: Option[] = [
|
||||
{
|
||||
id: 'name',
|
||||
name: 'Name',
|
||||
description: 'What to call this addon',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: 'Custom Addon',
|
||||
},
|
||||
{
|
||||
id: 'manifestUrl',
|
||||
name: 'Manifest URL',
|
||||
description: 'Provide the Manifest URL for this custom addon.',
|
||||
type: 'url',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
id: 'libraryAddon',
|
||||
name: 'Library Addon',
|
||||
description:
|
||||
'Whether to mark this addon as a library addon. This will result in all streams from this addon being marked as library streams.',
|
||||
type: 'boolean',
|
||||
required: false,
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
id: 'streamPassthrough',
|
||||
name: 'Stream Passthrough',
|
||||
description:
|
||||
'Whether to pass through the stream formatting. This means your formatting will not be applied and original stream formatting is retained.',
|
||||
type: 'boolean',
|
||||
},
|
||||
{
|
||||
id: 'timeout',
|
||||
name: 'Timeout',
|
||||
description: 'The timeout for this addon',
|
||||
type: 'number',
|
||||
default: Env.DEFAULT_TIMEOUT,
|
||||
constraints: {
|
||||
min: Env.MIN_TIMEOUT,
|
||||
max: Env.MAX_TIMEOUT,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'resources',
|
||||
name: 'Resources',
|
||||
description:
|
||||
'Optionally override the resources that are fetched from this addon ',
|
||||
type: 'multi-select',
|
||||
required: false,
|
||||
default: undefined,
|
||||
options: RESOURCES.map((resource) => ({
|
||||
label: resource,
|
||||
value: resource,
|
||||
})),
|
||||
},
|
||||
];
|
||||
|
||||
return {
|
||||
ID: 'custom',
|
||||
NAME: 'Custom',
|
||||
LOGO: '',
|
||||
URL: '',
|
||||
TIMEOUT: Env.DEFAULT_TIMEOUT,
|
||||
USER_AGENT: Env.DEFAULT_USER_AGENT,
|
||||
SUPPORTED_SERVICES: [],
|
||||
DESCRIPTION: 'Add your own addon by providing its Manifest URL.',
|
||||
OPTIONS: options,
|
||||
SUPPORTED_STREAM_TYPES: [],
|
||||
SUPPORTED_RESOURCES: [],
|
||||
};
|
||||
}
|
||||
|
||||
static async generateAddons(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Promise<Addon[]> {
|
||||
if (!options.manifestUrl.endsWith('/manifest.json')) {
|
||||
throw new Error('Invalid manifest URL');
|
||||
}
|
||||
return [this.generateAddon(userData, options)];
|
||||
}
|
||||
|
||||
private static generateAddon(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Addon {
|
||||
return {
|
||||
name: options.name || this.METADATA.NAME,
|
||||
identifyingName: options.name || this.METADATA.NAME,
|
||||
manifestUrl: options.manifestUrl,
|
||||
enabled: true,
|
||||
library: options.libraryAddon ?? false,
|
||||
resources: options.resources || undefined,
|
||||
timeout: options.timeout || this.METADATA.TIMEOUT,
|
||||
fromPresetId: this.METADATA.ID,
|
||||
streamPassthrough: options.streamPassthrough ?? false,
|
||||
headers: {
|
||||
'User-Agent': this.METADATA.USER_AGENT,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
import { Addon, Option, UserData } from '../db';
|
||||
import { Preset, baseOptions } from './preset';
|
||||
import { constants, Env } from '../utils';
|
||||
|
||||
export class DcUniversePreset extends Preset {
|
||||
// dc-batman-animations%2C
|
||||
// dc-superman-animations%2C
|
||||
// dc-batman%2C
|
||||
// dc-superman
|
||||
private static catalogs = [
|
||||
{
|
||||
label: 'DC Chronological Order',
|
||||
value: 'dc-chronological',
|
||||
},
|
||||
{
|
||||
label: 'DC Release Order',
|
||||
value: 'dc-release',
|
||||
},
|
||||
{
|
||||
label: 'Movies',
|
||||
value: 'dc-movies',
|
||||
},
|
||||
{
|
||||
label: 'DCEU Movies',
|
||||
value: 'dceu_movies',
|
||||
},
|
||||
{
|
||||
label: 'Series',
|
||||
value: 'dc-series',
|
||||
},
|
||||
{
|
||||
label: 'DC Modern Series',
|
||||
value: 'dc_modern_series',
|
||||
},
|
||||
{
|
||||
label: 'Animations',
|
||||
value: 'dc-animations',
|
||||
},
|
||||
{
|
||||
label: 'Batman Animations',
|
||||
value: 'dc-batman-animations',
|
||||
},
|
||||
{
|
||||
label: 'Superman Animations',
|
||||
value: 'dc-superman-animations',
|
||||
},
|
||||
{
|
||||
label: 'Batman Collection',
|
||||
value: 'dc-batman',
|
||||
},
|
||||
{
|
||||
label: 'Superman Collection',
|
||||
value: 'dc-superman',
|
||||
},
|
||||
];
|
||||
static override get METADATA() {
|
||||
const supportedResources = [
|
||||
constants.CATALOG_RESOURCE,
|
||||
constants.META_RESOURCE,
|
||||
];
|
||||
|
||||
const options: Option[] = [
|
||||
...baseOptions(
|
||||
'DC Universe',
|
||||
supportedResources,
|
||||
Env.DEFAULT_DC_UNIVERSE_TIMEOUT
|
||||
).filter((option) => option.id !== 'url'),
|
||||
// series movies animations xmen release-order marvel-mcu
|
||||
{
|
||||
id: 'catalogs',
|
||||
name: 'Catalogs',
|
||||
description: 'The catalogs to display',
|
||||
type: 'multi-select',
|
||||
required: true,
|
||||
options: this.catalogs,
|
||||
default: this.catalogs.map((catalog) => catalog.value),
|
||||
},
|
||||
];
|
||||
|
||||
return {
|
||||
ID: 'dc-universe',
|
||||
NAME: 'DC Universe',
|
||||
LOGO: 'https://raw.githubusercontent.com/tapframe/addon-dc/refs/heads/main/assets/icon.png',
|
||||
URL: Env.DC_UNIVERSE_URL,
|
||||
TIMEOUT: Env.DEFAULT_DC_UNIVERSE_TIMEOUT || Env.DEFAULT_TIMEOUT,
|
||||
USER_AGENT: Env.DEFAULT_DC_UNIVERSE_USER_AGENT || Env.DEFAULT_USER_AGENT,
|
||||
SUPPORTED_SERVICES: [],
|
||||
DESCRIPTION:
|
||||
'Explore the DC Universe by release date, movies, series, and animations!',
|
||||
OPTIONS: options,
|
||||
SUPPORTED_STREAM_TYPES: [],
|
||||
SUPPORTED_RESOURCES: supportedResources,
|
||||
};
|
||||
}
|
||||
|
||||
static async generateAddons(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Promise<Addon[]> {
|
||||
return [this.generateAddon(userData, options)];
|
||||
}
|
||||
|
||||
private static generateAddon(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Addon {
|
||||
const config =
|
||||
options.catalogs.length !== this.catalogs.length
|
||||
? options.catalogs.join('%2C')
|
||||
: '';
|
||||
return {
|
||||
name: options.name || this.METADATA.NAME,
|
||||
identifyingName: options.name || this.METADATA.NAME,
|
||||
manifestUrl: `${Env.DC_UNIVERSE_URL}/${config ? 'catalog/' + config + '/' : ''}manifest.json`,
|
||||
enabled: true,
|
||||
library: false,
|
||||
resources: options.resources || this.METADATA.SUPPORTED_RESOURCES,
|
||||
timeout: options.timeout || this.METADATA.TIMEOUT,
|
||||
fromPresetId: this.METADATA.ID,
|
||||
headers: {
|
||||
'User-Agent': this.METADATA.USER_AGENT,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
import { Addon, Option, UserData, Resource, Stream } from '../db';
|
||||
import { Preset, baseOptions } from './preset';
|
||||
import { Env, SERVICE_DETAILS } from '../utils';
|
||||
import { constants, ServiceId } from '../utils';
|
||||
import { StreamParser } from '../parser';
|
||||
|
||||
export class DebridioPreset extends Preset {
|
||||
static override get METADATA() {
|
||||
const supportedServices: ServiceId[] = [constants.EASYDEBRID_SERVICE];
|
||||
const supportedResources = [constants.STREAM_RESOURCE];
|
||||
|
||||
const options: Option[] = [
|
||||
...baseOptions(
|
||||
'Debridio',
|
||||
supportedResources,
|
||||
Env.DEFAULT_DEBRIDIO_TIMEOUT
|
||||
),
|
||||
// {
|
||||
// id: 'services',
|
||||
// name: 'Services',
|
||||
// description:
|
||||
// 'Optionally override the services that are used. If not specified, then the services that are enabled and supported will be used.',
|
||||
// type: 'multi-select',
|
||||
// required: false,
|
||||
// options: supportedServices.map((service) => ({
|
||||
// value: service,
|
||||
// label: constants.SERVICE_DETAILS[service].name,
|
||||
// })),
|
||||
// default: undefined,
|
||||
// emptyIsUndefined: true,
|
||||
// },
|
||||
// {
|
||||
// id: 'useMultipleInstances',
|
||||
// name: 'Use Multiple Instances',
|
||||
// description:
|
||||
// 'When using multiple services, use a different Torrentio addon for each service, rather than using one instance for all services',
|
||||
// type: 'boolean',
|
||||
// default: false,
|
||||
// required: true,
|
||||
// },
|
||||
];
|
||||
|
||||
return {
|
||||
ID: 'debridio',
|
||||
NAME: 'Debridio',
|
||||
LOGO: 'https://res.cloudinary.com/adobotec/image/upload/w_120,h_120/v1735925306/debridio/logo.png.png',
|
||||
URL: Env.DEBRIDIO_URL,
|
||||
TIMEOUT: Env.DEFAULT_DEBRIDIO_TIMEOUT || Env.DEFAULT_TIMEOUT,
|
||||
USER_AGENT: Env.DEFAULT_DEBRIDIO_USER_AGENT || Env.DEFAULT_USER_AGENT,
|
||||
SUPPORTED_SERVICES: supportedServices,
|
||||
DESCRIPTION: 'Torrent streaming using Debrid providers.',
|
||||
OPTIONS: options,
|
||||
SUPPORTED_STREAM_TYPES: [constants.DEBRID_STREAM_TYPE],
|
||||
SUPPORTED_RESOURCES: supportedResources,
|
||||
};
|
||||
}
|
||||
|
||||
static async generateAddons(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Promise<Addon[]> {
|
||||
if (options?.url?.endsWith('/manifest.json')) {
|
||||
return [this.generateAddon(userData, options, undefined)];
|
||||
}
|
||||
|
||||
const usableServices = this.getUsableServices(userData);
|
||||
|
||||
// if no services are usable, return a single addon with no services
|
||||
if (!usableServices || usableServices.length === 0) {
|
||||
throw new Error(
|
||||
`${this.METADATA.NAME} requires at least one of the following services to be enabled: ${this.METADATA.SUPPORTED_SERVICES.join(
|
||||
', '
|
||||
)}`
|
||||
);
|
||||
}
|
||||
|
||||
return usableServices.map((service) =>
|
||||
this.generateAddon(userData, options, service.id)
|
||||
);
|
||||
}
|
||||
|
||||
private static generateAddon(
|
||||
userData: UserData,
|
||||
options: Record<string, any>,
|
||||
service?: ServiceId
|
||||
): Addon {
|
||||
return {
|
||||
name: options.name || this.METADATA.NAME,
|
||||
identifyingName: service
|
||||
? `${options.name || this.METADATA.NAME} ${constants.SERVICE_DETAILS[service].shortName}`
|
||||
: options.name || this.METADATA.NAME,
|
||||
manifestUrl: this.generateManifestUrl(userData, service, options.url),
|
||||
enabled: true,
|
||||
resources: options.resources || this.METADATA.SUPPORTED_RESOURCES,
|
||||
timeout: options.timeout || this.METADATA.TIMEOUT,
|
||||
fromPresetId: this.METADATA.ID,
|
||||
headers: {
|
||||
'User-Agent': this.METADATA.USER_AGENT,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private static generateManifestUrl(
|
||||
userData: UserData,
|
||||
service?: ServiceId,
|
||||
url?: string
|
||||
) {
|
||||
url = url || this.METADATA.URL;
|
||||
if (url.endsWith('/manifest.json')) {
|
||||
return url;
|
||||
}
|
||||
if (!service) {
|
||||
throw new Error(
|
||||
`${this.METADATA.NAME} requires at least one of the following services to be enabled: ${this.METADATA.SUPPORTED_SERVICES.join(
|
||||
', '
|
||||
)}`
|
||||
);
|
||||
}
|
||||
|
||||
const configString = this.base64EncodeJSON({
|
||||
provider: service,
|
||||
apiKey: this.getServiceCredential(service, userData),
|
||||
disableUncached: false,
|
||||
qualityOrder: [],
|
||||
excludeSize: '',
|
||||
maxReturnPerQuality: '',
|
||||
});
|
||||
|
||||
return `${url}${configString ? '/' + configString : ''}/manifest.json`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
import { Addon, Option, UserData } from '../db';
|
||||
import { Preset, baseOptions } from './preset';
|
||||
import { constants, Env, FULL_LANGUAGE_MAPPING } from '../utils';
|
||||
|
||||
export class DebridioTmdbPreset extends Preset {
|
||||
static override get METADATA() {
|
||||
const supportedResources = [
|
||||
constants.CATALOG_RESOURCE,
|
||||
constants.META_RESOURCE,
|
||||
];
|
||||
|
||||
const options: Option[] = [
|
||||
...baseOptions(
|
||||
'Debridio TMDB',
|
||||
supportedResources,
|
||||
Env.DEFAULT_DEBRIDIO_TMDB_TIMEOUT
|
||||
),
|
||||
{
|
||||
id: 'debridioApiKey',
|
||||
name: 'Debridio API Key',
|
||||
description:
|
||||
'Your Debridio API Key, located at your [account settings](https://debridio.com/account)',
|
||||
type: 'password',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
id: 'language',
|
||||
name: 'Language',
|
||||
description: 'The language of the catalogs',
|
||||
type: 'select',
|
||||
default: 'en-US',
|
||||
options: FULL_LANGUAGE_MAPPING.sort((a, b) =>
|
||||
a.english_name.localeCompare(b.english_name)
|
||||
).map((language) => ({
|
||||
label: language.english_name,
|
||||
value: `${language.iso_639_1}-${language.iso_3166_1}`,
|
||||
})),
|
||||
required: false,
|
||||
},
|
||||
];
|
||||
|
||||
return {
|
||||
ID: 'debridio-tmdb',
|
||||
NAME: 'Debridio TMDB',
|
||||
LOGO: 'https://res.cloudinary.com/adobotec/image/upload/w_120,h_120/v1735925306/debridio/logo.png.png',
|
||||
URL: Env.DEBRIDIO_TMDB_URL,
|
||||
TIMEOUT: Env.DEFAULT_DEBRIDIO_TMDB_TIMEOUT || Env.DEFAULT_TIMEOUT,
|
||||
USER_AGENT:
|
||||
Env.DEFAULT_DEBRIDIO_TMDB_USER_AGENT || Env.DEFAULT_USER_AGENT,
|
||||
SUPPORTED_SERVICES: [],
|
||||
DESCRIPTION: 'Catalogs for the Debridio TMDB',
|
||||
OPTIONS: options,
|
||||
SUPPORTED_STREAM_TYPES: [],
|
||||
SUPPORTED_RESOURCES: supportedResources,
|
||||
};
|
||||
}
|
||||
|
||||
static async generateAddons(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Promise<Addon[]> {
|
||||
if (!options.debridioApiKey && !options.url) {
|
||||
throw new Error(
|
||||
'To access the Debridio addons, you must provide your Debridio API Key'
|
||||
);
|
||||
}
|
||||
return [this.generateAddon(userData, options)];
|
||||
}
|
||||
|
||||
private static generateAddon(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Addon {
|
||||
let url = this.METADATA.URL;
|
||||
if (options.url?.endsWith('/manifest.json')) {
|
||||
url = options.url;
|
||||
} else {
|
||||
let baseUrl = this.METADATA.URL;
|
||||
if (options.url) {
|
||||
baseUrl = new URL(options.url).origin;
|
||||
}
|
||||
// remove trailing slash
|
||||
baseUrl = baseUrl.replace(/\/$/, '');
|
||||
if (!options.debridioApiKey) {
|
||||
throw new Error(
|
||||
'To access the Debridio addons, you must provide your Debridio API Key'
|
||||
);
|
||||
}
|
||||
const config = this.base64EncodeJSON({
|
||||
api_key: options.debridioApiKey,
|
||||
language: options.language || 'en-US',
|
||||
rpdb_api: '',
|
||||
catalogs: [
|
||||
{
|
||||
id: 'debridio_tmdb.movie_trending',
|
||||
home: true,
|
||||
enabled: true,
|
||||
name: 'Trending',
|
||||
},
|
||||
{
|
||||
id: 'debridio_tmdb.movie_popular',
|
||||
home: true,
|
||||
enabled: true,
|
||||
name: 'Popular',
|
||||
},
|
||||
{
|
||||
id: 'debridio_tmdb.tv_trending',
|
||||
home: true,
|
||||
enabled: true,
|
||||
name: 'Trending',
|
||||
},
|
||||
{
|
||||
id: 'debridio_tmdb.tv_popular',
|
||||
home: true,
|
||||
enabled: true,
|
||||
name: 'Popular',
|
||||
},
|
||||
{
|
||||
id: 'debridio_tmdb.search_collections',
|
||||
home: false,
|
||||
enabled: true,
|
||||
name: 'Search',
|
||||
},
|
||||
],
|
||||
});
|
||||
url = `${baseUrl}/${config}/manifest.json`;
|
||||
}
|
||||
|
||||
return {
|
||||
name: options.name || this.METADATA.NAME,
|
||||
identifyingName: options.name || this.METADATA.NAME,
|
||||
manifestUrl: url,
|
||||
enabled: true,
|
||||
library: false,
|
||||
resources: options.resources || this.METADATA.SUPPORTED_RESOURCES,
|
||||
timeout: options.timeout || this.METADATA.TIMEOUT,
|
||||
fromPresetId: this.METADATA.ID,
|
||||
headers: {
|
||||
'User-Agent': this.METADATA.USER_AGENT,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
import { Addon, Option, UserData } from '../db';
|
||||
import { Preset, baseOptions } from './preset';
|
||||
import { constants, Env } from '../utils';
|
||||
|
||||
export class DebridioTvPreset extends Preset {
|
||||
static override get METADATA() {
|
||||
const supportedResources = [
|
||||
constants.CATALOG_RESOURCE,
|
||||
constants.META_RESOURCE,
|
||||
constants.STREAM_RESOURCE,
|
||||
];
|
||||
|
||||
const channels = [
|
||||
{
|
||||
label: 'USA',
|
||||
value: 'usa',
|
||||
},
|
||||
{
|
||||
label: 'Mexico',
|
||||
value: 'mx',
|
||||
},
|
||||
{
|
||||
label: 'UK',
|
||||
value: 'uk',
|
||||
},
|
||||
{
|
||||
label: 'Chile',
|
||||
value: 'cl',
|
||||
},
|
||||
{
|
||||
label: 'Estonia',
|
||||
value: 'ee',
|
||||
},
|
||||
];
|
||||
const options: Option[] = [
|
||||
...baseOptions(
|
||||
'Debridio TV',
|
||||
supportedResources,
|
||||
Env.DEFAULT_DEBRIDIO_TV_TIMEOUT
|
||||
),
|
||||
{
|
||||
id: 'debridioApiKey',
|
||||
name: 'Debridio API Key',
|
||||
description:
|
||||
'Your Debridio API Key, located at your [account settings](https://debridio.com/account)',
|
||||
type: 'password',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
id: 'channels',
|
||||
name: 'Channels',
|
||||
description: 'The channels to display',
|
||||
type: 'multi-select',
|
||||
required: true,
|
||||
options: channels,
|
||||
default: channels.map((channel) => channel.value),
|
||||
},
|
||||
];
|
||||
|
||||
return {
|
||||
ID: 'debridio-tv',
|
||||
NAME: 'Debridio TV',
|
||||
LOGO: 'https://res.cloudinary.com/adobotec/image/upload/w_120,h_120/v1735925306/debridio/logo.png.png',
|
||||
URL: Env.DEBRIDIO_TV_URL,
|
||||
TIMEOUT: Env.DEFAULT_DEBRIDIO_TV_TIMEOUT || Env.DEFAULT_TIMEOUT,
|
||||
USER_AGENT: Env.DEFAULT_DEBRIDIO_TV_USER_AGENT || Env.DEFAULT_USER_AGENT,
|
||||
SUPPORTED_SERVICES: [],
|
||||
DESCRIPTION: 'Live streaming of a wide variety of channels.',
|
||||
OPTIONS: options,
|
||||
SUPPORTED_STREAM_TYPES: [constants.LIVE_STREAM_TYPE],
|
||||
SUPPORTED_RESOURCES: supportedResources,
|
||||
};
|
||||
}
|
||||
|
||||
static async generateAddons(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Promise<Addon[]> {
|
||||
if (!options.url && !options.debridioApiKey) {
|
||||
throw new Error(
|
||||
'To access the Debridio addons, you must provide your Debridio API Key'
|
||||
);
|
||||
}
|
||||
return [this.generateAddon(userData, options)];
|
||||
}
|
||||
|
||||
private static generateAddon(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Addon {
|
||||
let url = this.METADATA.URL;
|
||||
if (options.url?.endsWith('/manifest.json')) {
|
||||
url = options.url;
|
||||
} else {
|
||||
let baseUrl = this.METADATA.URL;
|
||||
if (options.url) {
|
||||
baseUrl = new URL(options.url).origin;
|
||||
}
|
||||
// remove trailing slash
|
||||
baseUrl = baseUrl.replace(/\/$/, '');
|
||||
if (!options.debridioApiKey) {
|
||||
throw new Error(
|
||||
'To access the Debridio addons, you must provide your Debridio API Key'
|
||||
);
|
||||
}
|
||||
const config = this.base64EncodeJSON({
|
||||
api_key: options.debridioApiKey,
|
||||
channels: options.channels,
|
||||
});
|
||||
url = `${baseUrl}/${config}/manifest.json`;
|
||||
}
|
||||
return {
|
||||
name: options.name || this.METADATA.NAME,
|
||||
identifyingName: options.name || this.METADATA.NAME,
|
||||
manifestUrl: url,
|
||||
enabled: true,
|
||||
library: false,
|
||||
resources: options.resources || this.METADATA.SUPPORTED_RESOURCES,
|
||||
timeout: options.timeout || this.METADATA.TIMEOUT,
|
||||
fromPresetId: this.METADATA.ID,
|
||||
headers: {
|
||||
'User-Agent': this.METADATA.USER_AGENT,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
import { Addon, Option, UserData } from '../db';
|
||||
import { Preset, baseOptions } from './preset';
|
||||
import { constants, Env } from '../utils';
|
||||
|
||||
export class DebridioTvdbPreset extends Preset {
|
||||
static override get METADATA() {
|
||||
const supportedResources = [
|
||||
constants.CATALOG_RESOURCE,
|
||||
constants.META_RESOURCE,
|
||||
];
|
||||
|
||||
const options: Option[] = [
|
||||
...baseOptions(
|
||||
'Debridio TVDB',
|
||||
supportedResources,
|
||||
Env.DEFAULT_DEBRIDIO_TVDB_TIMEOUT
|
||||
),
|
||||
{
|
||||
id: 'debridioApiKey',
|
||||
name: 'Debridio API Key',
|
||||
description:
|
||||
'Your Debridio API Key, located at your [account settings](https://debridio.com/account)',
|
||||
type: 'password',
|
||||
required: true,
|
||||
},
|
||||
];
|
||||
|
||||
return {
|
||||
ID: 'debridio-tvdb',
|
||||
NAME: 'Debridio TVDB',
|
||||
LOGO: 'https://res.cloudinary.com/adobotec/image/upload/w_120,h_120/v1735925306/debridio/logo.png.png',
|
||||
URL: Env.DEBRIDIO_TVDB_URL,
|
||||
TIMEOUT: Env.DEFAULT_DEBRIDIO_TVDB_TIMEOUT || Env.DEFAULT_TIMEOUT,
|
||||
USER_AGENT:
|
||||
Env.DEFAULT_DEBRIDIO_TVDB_USER_AGENT || Env.DEFAULT_USER_AGENT,
|
||||
SUPPORTED_SERVICES: [],
|
||||
DESCRIPTION: 'Catalogs for the Debridio TVDB',
|
||||
OPTIONS: options,
|
||||
SUPPORTED_STREAM_TYPES: [],
|
||||
SUPPORTED_RESOURCES: supportedResources,
|
||||
};
|
||||
}
|
||||
|
||||
static async generateAddons(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Promise<Addon[]> {
|
||||
if (!options.url && !options.debridioApiKey) {
|
||||
throw new Error(
|
||||
'To access the Debridio addons, you must provide your Debridio API Key'
|
||||
);
|
||||
}
|
||||
return [this.generateAddon(userData, options)];
|
||||
}
|
||||
|
||||
private static generateAddon(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Addon {
|
||||
let url = this.METADATA.URL;
|
||||
if (options.url?.endsWith('/manifest.json')) {
|
||||
url = options.url;
|
||||
} else {
|
||||
let baseUrl = this.METADATA.URL;
|
||||
if (options.url) {
|
||||
baseUrl = new URL(options.url).origin;
|
||||
}
|
||||
// remove trailing slash
|
||||
baseUrl = baseUrl.replace(/\/$/, '');
|
||||
const config = this.base64EncodeJSON({
|
||||
api_key: options.debridioApiKey,
|
||||
language: 'eng',
|
||||
});
|
||||
url = `${baseUrl}/${config}/manifest.json`;
|
||||
}
|
||||
return {
|
||||
name: options.name || this.METADATA.NAME,
|
||||
identifyingName: options.name || this.METADATA.NAME,
|
||||
manifestUrl: url,
|
||||
enabled: true,
|
||||
library: false,
|
||||
resources: options.resources || this.METADATA.SUPPORTED_RESOURCES,
|
||||
timeout: options.timeout || this.METADATA.TIMEOUT,
|
||||
fromPresetId: this.METADATA.ID,
|
||||
headers: {
|
||||
'User-Agent': this.METADATA.USER_AGENT,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
import { Addon, Option, ParsedStream, Stream, UserData } from '../db';
|
||||
import { Preset, baseOptions } from './preset';
|
||||
import { constants, Env } from '../utils';
|
||||
import { FileParser, StreamParser } from '../parser';
|
||||
|
||||
class DebridioWatchtowerStreamParser extends StreamParser {
|
||||
parse(stream: Stream): ParsedStream {
|
||||
let parsedStream: ParsedStream = {
|
||||
addon: this.addon,
|
||||
type: 'http',
|
||||
url: this.applyUrlModifications(stream.url),
|
||||
externalUrl: stream.externalUrl,
|
||||
ytId: stream.ytId,
|
||||
requestHeaders: stream.behaviorHints?.proxyHeaders?.request,
|
||||
responseHeaders: stream.behaviorHints?.proxyHeaders?.response,
|
||||
notWebReady: stream.behaviorHints?.notWebReady,
|
||||
videoHash: stream.behaviorHints?.videoHash,
|
||||
originalName: stream.name,
|
||||
originalDescription: stream.description || stream.title,
|
||||
};
|
||||
|
||||
stream.description = stream.description || stream.title;
|
||||
|
||||
parsedStream.filename = this.getFilename(stream, parsedStream);
|
||||
|
||||
parsedStream.type = this.getStreamType(
|
||||
stream,
|
||||
parsedStream.service,
|
||||
parsedStream
|
||||
);
|
||||
|
||||
if (parsedStream.filename) {
|
||||
parsedStream.parsedFile = FileParser.parse(parsedStream.filename);
|
||||
parsedStream.parsedFile = {
|
||||
resolution: parsedStream.parsedFile.resolution,
|
||||
languages: [],
|
||||
audioChannels: [],
|
||||
visualTags: [],
|
||||
audioTags: [],
|
||||
};
|
||||
parsedStream.parsedFile.languages = Array.from(
|
||||
new Set([
|
||||
...parsedStream.parsedFile.languages,
|
||||
...this.getLanguages(stream, parsedStream),
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
parsedStream.filename = undefined;
|
||||
parsedStream.folderName = undefined;
|
||||
|
||||
parsedStream.message = stream.description?.replace(/\d+p?/g, '');
|
||||
|
||||
parsedStream.torrent = {
|
||||
infoHash:
|
||||
parsedStream.type === 'p2p'
|
||||
? stream.infoHash
|
||||
: this.getInfoHash(stream, parsedStream),
|
||||
seeders: this.getSeeders(stream, parsedStream),
|
||||
sources: stream.sources,
|
||||
fileIdx: stream.fileIdx,
|
||||
};
|
||||
|
||||
return parsedStream;
|
||||
}
|
||||
}
|
||||
|
||||
export class DebridioWatchtowerPreset extends Preset {
|
||||
static override getParser(): typeof StreamParser {
|
||||
return DebridioWatchtowerStreamParser;
|
||||
}
|
||||
|
||||
static override get METADATA() {
|
||||
const supportedResources = [constants.STREAM_RESOURCE];
|
||||
|
||||
const options: Option[] = [
|
||||
...baseOptions(
|
||||
'Debridio Watchtower',
|
||||
supportedResources,
|
||||
Env.DEFAULT_DEBRIDIO_WATCHTOWER_TIMEOUT
|
||||
),
|
||||
{
|
||||
id: 'debridioApiKey',
|
||||
name: 'Debridio API Key',
|
||||
description:
|
||||
'Your Debridio API Key, located at your [account settings](https://debridio.com/account)',
|
||||
type: 'password',
|
||||
required: true,
|
||||
},
|
||||
];
|
||||
|
||||
return {
|
||||
ID: 'debridio-watchtower',
|
||||
NAME: 'Debridio Watchtower',
|
||||
LOGO: 'https://res.cloudinary.com/adobotec/image/upload/w_120,h_120/v1735925306/debridio/logo.png.png',
|
||||
URL: Env.DEBRIDIO_WATCHTOWER_URL,
|
||||
TIMEOUT: Env.DEFAULT_DEBRIDIO_WATCHTOWER_TIMEOUT || Env.DEFAULT_TIMEOUT,
|
||||
USER_AGENT:
|
||||
Env.DEFAULT_DEBRIDIO_WATCHTOWER_USER_AGENT || Env.DEFAULT_USER_AGENT,
|
||||
SUPPORTED_SERVICES: [],
|
||||
DESCRIPTION: 'Watchtower is a http stream provider.',
|
||||
OPTIONS: options,
|
||||
SUPPORTED_STREAM_TYPES: [constants.HTTP_STREAM_TYPE],
|
||||
SUPPORTED_RESOURCES: supportedResources,
|
||||
};
|
||||
}
|
||||
|
||||
static async generateAddons(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Promise<Addon[]> {
|
||||
if (!options.url && !options.debridioApiKey) {
|
||||
throw new Error(
|
||||
'To access the Debridio addons, you must provide your Debridio API Key'
|
||||
);
|
||||
}
|
||||
return [this.generateAddon(userData, options)];
|
||||
}
|
||||
|
||||
private static generateAddon(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Addon {
|
||||
let url = this.METADATA.URL;
|
||||
if (options.url?.endsWith('/manifest.json')) {
|
||||
url = options.url;
|
||||
} else {
|
||||
let baseUrl = this.METADATA.URL;
|
||||
if (options.url) {
|
||||
baseUrl = new URL(options.url).origin;
|
||||
}
|
||||
// remove trailing slash
|
||||
baseUrl = baseUrl.replace(/\/$/, '');
|
||||
if (!options.debridioApiKey) {
|
||||
throw new Error(
|
||||
'To access the Debridio addons, you must provide your Debridio API Key'
|
||||
);
|
||||
}
|
||||
const config = this.base64EncodeJSON({
|
||||
api_key: options.debridioApiKey,
|
||||
});
|
||||
url = `${baseUrl}/${config}/manifest.json`;
|
||||
}
|
||||
return {
|
||||
name: options.name || this.METADATA.NAME,
|
||||
identifyingName: options.name || this.METADATA.NAME,
|
||||
manifestUrl: url,
|
||||
enabled: true,
|
||||
library: false,
|
||||
resources: options.resources || this.METADATA.SUPPORTED_RESOURCES,
|
||||
timeout: options.timeout || this.METADATA.TIMEOUT,
|
||||
fromPresetId: this.METADATA.ID,
|
||||
headers: {
|
||||
'User-Agent': this.METADATA.USER_AGENT,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
import {
|
||||
Addon,
|
||||
Option,
|
||||
UserData,
|
||||
ParsedStream,
|
||||
Stream,
|
||||
AIOStream,
|
||||
} from '../db';
|
||||
import { Preset, baseOptions } from './preset';
|
||||
import { constants, Env, RESOURCES } from '../utils';
|
||||
import { StreamParser } from '../parser';
|
||||
|
||||
class DMMCastStreamParser extends StreamParser {
|
||||
protected override getFilename(
|
||||
stream: Stream,
|
||||
currentParsedStream: ParsedStream
|
||||
): string | undefined {
|
||||
let filename = stream.description
|
||||
? stream.description
|
||||
.split('\n')
|
||||
.map((line) => line.replace(/-$/, ''))
|
||||
.filter((line) => !line.includes('📦'))
|
||||
.join('')
|
||||
: stream.behaviorHints?.filename?.trim();
|
||||
return filename;
|
||||
}
|
||||
|
||||
protected override getMessage(
|
||||
stream: Stream,
|
||||
currentParsedStream: ParsedStream
|
||||
): string | undefined {
|
||||
if (!stream.description?.includes('📦')) {
|
||||
currentParsedStream.filename = undefined;
|
||||
return `${stream.name} - ${stream.description}`;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
protected override getInLibrary(
|
||||
stream: Stream,
|
||||
currentParsedStream: ParsedStream
|
||||
): boolean {
|
||||
if (stream.name?.includes('Yours')) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export class DMMCastPreset extends Preset {
|
||||
static override getParser(): typeof StreamParser {
|
||||
return DMMCastStreamParser;
|
||||
}
|
||||
|
||||
static override get METADATA() {
|
||||
const supportedResources = [constants.STREAM_RESOURCE];
|
||||
const options: Option[] = [
|
||||
{
|
||||
id: 'name',
|
||||
name: 'Name',
|
||||
description: 'What to call this addon',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: 'DMM Cast',
|
||||
},
|
||||
{
|
||||
id: 'installationUrl',
|
||||
name: 'Installation URL',
|
||||
description:
|
||||
'Provide the Unique Installation URL for your DMM Cast addon, available [here](https://debridmediamanager.com/stremio)',
|
||||
type: 'url',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
id: 'timeout',
|
||||
name: 'Timeout',
|
||||
description: 'The timeout for this addon',
|
||||
type: 'number',
|
||||
default: Env.DEFAULT_DMM_CAST_TIMEOUT || Env.DEFAULT_TIMEOUT,
|
||||
constraints: {
|
||||
min: Env.MIN_TIMEOUT,
|
||||
max: Env.MAX_TIMEOUT,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'resources',
|
||||
name: 'Resources',
|
||||
description:
|
||||
'Optionally override the resources that are fetched from this addon ',
|
||||
type: 'multi-select',
|
||||
required: false,
|
||||
default: undefined,
|
||||
options: RESOURCES.map((resource) => ({
|
||||
label: resource,
|
||||
value: resource,
|
||||
})),
|
||||
},
|
||||
];
|
||||
|
||||
return {
|
||||
ID: 'dmm-cast',
|
||||
NAME: 'DMM Cast',
|
||||
LOGO: 'https://static.debridmediamanager.com/dmmcast.png',
|
||||
URL: '',
|
||||
TIMEOUT: Env.DEFAULT_DMM_CAST_TIMEOUT || Env.DEFAULT_TIMEOUT,
|
||||
USER_AGENT: Env.DEFAULT_DMM_CAST_USER_AGENT || Env.DEFAULT_USER_AGENT,
|
||||
SUPPORTED_SERVICES: [],
|
||||
DESCRIPTION:
|
||||
'Access streams casted from [DMM](https://debridmediamanager.com) by you or other users',
|
||||
OPTIONS: options,
|
||||
SUPPORTED_STREAM_TYPES: [],
|
||||
SUPPORTED_RESOURCES: supportedResources,
|
||||
};
|
||||
}
|
||||
|
||||
static async generateAddons(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Promise<Addon[]> {
|
||||
if (!options.installationUrl.endsWith('/manifest.json')) {
|
||||
throw new Error('Invalid installation URL');
|
||||
}
|
||||
return [this.generateAddon(userData, options)];
|
||||
}
|
||||
|
||||
private static generateAddon(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Addon {
|
||||
return {
|
||||
name: options.name || this.METADATA.NAME,
|
||||
identifyingName: options.name || this.METADATA.NAME,
|
||||
manifestUrl: options.installationUrl,
|
||||
enabled: true,
|
||||
library: false,
|
||||
resources: options.resources || this.METADATA.SUPPORTED_RESOURCES,
|
||||
timeout: options.timeout || this.METADATA.TIMEOUT,
|
||||
fromPresetId: this.METADATA.ID,
|
||||
headers: {
|
||||
'User-Agent': this.METADATA.USER_AGENT,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
import { baseOptions, Preset } from './preset';
|
||||
import { constants, Env } from '../utils';
|
||||
import {
|
||||
PresetMetadata,
|
||||
Option,
|
||||
Addon,
|
||||
UserData,
|
||||
ParsedStream,
|
||||
Stream,
|
||||
} from '../db';
|
||||
import { StreamParser } from '../parser';
|
||||
|
||||
export class EasynewsParser extends StreamParser {
|
||||
protected override getStreamType(
|
||||
stream: Stream,
|
||||
service: ParsedStream['service'],
|
||||
currentParsedStream: ParsedStream
|
||||
): ParsedStream['type'] {
|
||||
return constants.USENET_STREAM_TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
export class EasynewsPreset extends Preset {
|
||||
static override getParser(): typeof StreamParser {
|
||||
return EasynewsParser;
|
||||
}
|
||||
|
||||
static override get METADATA(): PresetMetadata {
|
||||
const supportedServices = [constants.EASYNEWS_SERVICE];
|
||||
const supportedResources = [constants.STREAM_RESOURCE];
|
||||
|
||||
const options: Option[] = [
|
||||
...baseOptions(
|
||||
'Easynews',
|
||||
supportedResources,
|
||||
Env.DEFAULT_EASYNEWS_TIMEOUT
|
||||
),
|
||||
];
|
||||
|
||||
return {
|
||||
ID: 'easynews',
|
||||
NAME: 'Easynews',
|
||||
DESCRIPTION:
|
||||
'The original Easynews addon, to access streams from Easynews',
|
||||
LOGO: `https://pbs.twimg.com/profile_images/479627852757733376/8v9zH7Yo_400x400.jpeg`,
|
||||
URL: Env.EASYNEWS_URL,
|
||||
TIMEOUT: Env.DEFAULT_EASYNEWS_TIMEOUT || Env.DEFAULT_TIMEOUT,
|
||||
USER_AGENT: Env.DEFAULT_EASYNEWS_USER_AGENT || Env.DEFAULT_USER_AGENT,
|
||||
SUPPORTED_SERVICES: supportedServices,
|
||||
SUPPORTED_RESOURCES: supportedResources,
|
||||
SUPPORTED_STREAM_TYPES: [constants.USENET_STREAM_TYPE],
|
||||
OPTIONS: options,
|
||||
};
|
||||
}
|
||||
|
||||
static async generateAddons(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Promise<Addon[]> {
|
||||
return [this.generateAddon(userData, options)];
|
||||
}
|
||||
|
||||
private static generateAddon(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Addon {
|
||||
return {
|
||||
name: options.name || this.METADATA.NAME,
|
||||
identifyingName: options.name || this.METADATA.NAME,
|
||||
manifestUrl: this.generateManifestUrl(userData, options),
|
||||
enabled: true,
|
||||
resources: options.resources || this.METADATA.SUPPORTED_RESOURCES,
|
||||
timeout: options.timeout || this.METADATA.TIMEOUT,
|
||||
fromPresetId: this.METADATA.ID,
|
||||
headers: {
|
||||
'User-Agent': this.METADATA.USER_AGENT,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
protected static generateConfig(
|
||||
easynewsCredentials: {
|
||||
username: string;
|
||||
password: string;
|
||||
},
|
||||
options: Record<string, any>
|
||||
) {
|
||||
return this.urlEncodeJSON({
|
||||
username: easynewsCredentials.username,
|
||||
password: easynewsCredentials.password,
|
||||
});
|
||||
}
|
||||
|
||||
private static generateManifestUrl(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
) {
|
||||
let url = options.url || this.METADATA.URL;
|
||||
if (url.endsWith('/manifest.json')) {
|
||||
return url;
|
||||
}
|
||||
url = url.replace(/\/$/, '');
|
||||
const easynewsCredentials = this.getServiceCredential(
|
||||
constants.EASYNEWS_SERVICE,
|
||||
userData,
|
||||
{
|
||||
[constants.EASYNEWS_SERVICE]: (credentials: any) => ({
|
||||
username: credentials.username,
|
||||
password: credentials.password,
|
||||
}),
|
||||
}
|
||||
);
|
||||
if (!easynewsCredentials) {
|
||||
throw new Error(
|
||||
`${this.METADATA.NAME} requires the Easynews service to be enabled.`
|
||||
);
|
||||
}
|
||||
return `${url}/${this.generateConfig(easynewsCredentials, options)}/manifest.json`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import { PresetMetadata } from '../db';
|
||||
import { EasynewsPreset } from './easynews';
|
||||
import { constants, Env } from '../utils';
|
||||
import { baseOptions } from './preset';
|
||||
|
||||
export class EasynewsPlusPreset extends EasynewsPreset {
|
||||
static override get METADATA(): PresetMetadata {
|
||||
return {
|
||||
...super.METADATA,
|
||||
ID: 'easynewsPlus',
|
||||
NAME: 'Easynews+',
|
||||
DESCRIPTION:
|
||||
'Easynews+ provides content from Easynews & includes a search catalog',
|
||||
URL: Env.EASYNEWS_PLUS_URL,
|
||||
TIMEOUT: Env.DEFAULT_EASYNEWS_PLUS_TIMEOUT || Env.DEFAULT_TIMEOUT,
|
||||
USER_AGENT:
|
||||
Env.DEFAULT_EASYNEWS_PLUS_USER_AGENT || Env.DEFAULT_USER_AGENT,
|
||||
SUPPORTED_RESOURCES: [
|
||||
...super.METADATA.SUPPORTED_RESOURCES,
|
||||
constants.CATALOG_RESOURCE,
|
||||
constants.META_RESOURCE,
|
||||
],
|
||||
OPTIONS: [
|
||||
...baseOptions(
|
||||
'Easynews+',
|
||||
[
|
||||
...super.METADATA.SUPPORTED_RESOURCES,
|
||||
constants.CATALOG_RESOURCE,
|
||||
constants.META_RESOURCE,
|
||||
],
|
||||
Env.DEFAULT_EASYNEWS_PLUS_TIMEOUT || Env.DEFAULT_TIMEOUT
|
||||
),
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
protected static override generateConfig(
|
||||
easynewsCredentials: {
|
||||
username: string;
|
||||
password: string;
|
||||
},
|
||||
options: Record<string, any>
|
||||
): string {
|
||||
return this.urlEncodeJSON({
|
||||
username: easynewsCredentials.username,
|
||||
password: easynewsCredentials.password,
|
||||
sort1: 'Size',
|
||||
sort1Direction: 'Descending',
|
||||
sort2: 'Relevance',
|
||||
sort2Direction: 'Descending',
|
||||
sort3: 'Date & Time',
|
||||
sort3Direction: 'Descending',
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
import { ParsedStream, PresetMetadata, Stream } from '../db';
|
||||
import { EasynewsPreset, EasynewsParser } from './easynews';
|
||||
import { constants, Env } from '../utils';
|
||||
import { baseOptions } from './preset';
|
||||
import { StreamParser } from '../parser';
|
||||
|
||||
class EasynewsPlusPlusParser extends EasynewsParser {
|
||||
protected override get ageRegex(): RegExp {
|
||||
return /📅\s*(\d+[a-zA-Z])/;
|
||||
}
|
||||
|
||||
protected get indexerRegex(): RegExp | undefined {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
protected override getLanguages(
|
||||
stream: Stream,
|
||||
currentParsedStream: ParsedStream
|
||||
): string[] {
|
||||
const regex = this.getRegexForTextAfterEmojis(['🌐']);
|
||||
const langs = stream.description?.match(regex)?.[1];
|
||||
return (
|
||||
langs
|
||||
?.split(',')
|
||||
?.map((lang) => this.convertISO6392ToLanguage(lang.trim()))
|
||||
.filter((lang) => lang !== undefined) || []
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class EasynewsPlusPlusPreset extends EasynewsPreset {
|
||||
static override getParser(): typeof StreamParser {
|
||||
return EasynewsPlusPlusParser;
|
||||
}
|
||||
|
||||
static override get METADATA(): PresetMetadata {
|
||||
return {
|
||||
...super.METADATA,
|
||||
ID: 'easynewsPlusPlus',
|
||||
NAME: 'Easynews++',
|
||||
DESCRIPTION: 'Easynews++ provides content from Easynews',
|
||||
URL: Env.EASYNEWS_PLUS_PLUS_URL,
|
||||
TIMEOUT: Env.DEFAULT_EASYNEWS_PLUS_PLUS_TIMEOUT || Env.DEFAULT_TIMEOUT,
|
||||
USER_AGENT:
|
||||
Env.DEFAULT_EASYNEWS_PLUS_PLUS_USER_AGENT || Env.DEFAULT_USER_AGENT,
|
||||
OPTIONS: [
|
||||
...baseOptions(
|
||||
'Easynews++',
|
||||
super.METADATA.SUPPORTED_RESOURCES,
|
||||
Env.DEFAULT_EASYNEWS_PLUS_PLUS_TIMEOUT || Env.DEFAULT_TIMEOUT
|
||||
),
|
||||
{
|
||||
id: 'strictTitleMatching',
|
||||
name: 'Strict Title Matching',
|
||||
description:
|
||||
"Whether to filter out results that don't match the title exactly",
|
||||
type: 'boolean',
|
||||
required: true,
|
||||
default: false,
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
protected static override generateConfig(
|
||||
easynewsCredentials: {
|
||||
username: string;
|
||||
password: string;
|
||||
},
|
||||
options: Record<string, any>
|
||||
): string {
|
||||
return this.urlEncodeJSON({
|
||||
uiLanguage: 'eng',
|
||||
username: easynewsCredentials.username,
|
||||
password: easynewsCredentials.password,
|
||||
strictTitleMatching: options.strictTitleMatching ? 'on' : 'off',
|
||||
baseUrl: options.url
|
||||
? new URL(options.url).origin
|
||||
: Env.EASYNEWS_PLUS_PLUS_URL,
|
||||
preferredLanguage: '',
|
||||
sortingPreference: 'quality_first',
|
||||
showQualities: '4k,1080p,720p,480p',
|
||||
maxResultsPerQuality: '',
|
||||
maxFileSize: '',
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './preset';
|
||||
export * from './presetManager';
|
||||
@@ -0,0 +1,183 @@
|
||||
import { Addon, Option, UserData, Resource } from '../db';
|
||||
import { baseOptions, Preset } from './preset';
|
||||
import { Env } from '../utils';
|
||||
import { constants, ServiceId } from '../utils';
|
||||
import { StreamParser } from '../parser';
|
||||
|
||||
class JackettioStreamParser extends StreamParser {
|
||||
override applyUrlModifications(url: string | undefined): string | undefined {
|
||||
if (!url) {
|
||||
return url;
|
||||
}
|
||||
if (
|
||||
Env.FORCE_JACKETTIO_HOSTNAME !== undefined ||
|
||||
Env.FORCE_JACKETTIO_PORT !== undefined ||
|
||||
Env.FORCE_JACKETTIO_PROTOCOL !== undefined
|
||||
) {
|
||||
// modify the URL according to settings, needed when using a local URL for requests but a public stream URL is needed.
|
||||
const urlObj = new URL(url);
|
||||
|
||||
if (Env.FORCE_JACKETTIO_PROTOCOL !== undefined) {
|
||||
urlObj.protocol = Env.FORCE_JACKETTIO_PROTOCOL;
|
||||
}
|
||||
if (Env.FORCE_JACKETTIO_PORT !== undefined) {
|
||||
urlObj.port = Env.FORCE_JACKETTIO_PORT.toString();
|
||||
}
|
||||
if (Env.FORCE_JACKETTIO_HOSTNAME !== undefined) {
|
||||
urlObj.hostname = Env.FORCE_JACKETTIO_HOSTNAME;
|
||||
}
|
||||
return urlObj.toString();
|
||||
}
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
export class JackettioPreset extends Preset {
|
||||
static override getParser(): typeof StreamParser {
|
||||
return JackettioStreamParser;
|
||||
}
|
||||
|
||||
static override get METADATA() {
|
||||
const supportedServices: ServiceId[] = [
|
||||
constants.REALDEBRID_SERVICE,
|
||||
constants.PREMIUMIZE_SERVICE,
|
||||
constants.ALLEDEBRID_SERVICE,
|
||||
constants.TORBOX_SERVICE,
|
||||
constants.EASYDEBRID_SERVICE,
|
||||
constants.DEBRIDLINK_SERVICE,
|
||||
constants.OFFCLOUD_SERVICE,
|
||||
constants.PIKPAK_SERVICE,
|
||||
];
|
||||
|
||||
const supportedResources = [constants.STREAM_RESOURCE];
|
||||
|
||||
const options: Option[] = [
|
||||
...baseOptions(
|
||||
'Jackettio',
|
||||
supportedResources,
|
||||
Env.DEFAULT_JACKETTIO_TIMEOUT
|
||||
),
|
||||
{
|
||||
id: 'services',
|
||||
name: 'Services',
|
||||
description:
|
||||
'Optionally override the services that are used. If not specified, then the services that are enabled and supported will be used.',
|
||||
type: 'multi-select',
|
||||
required: false,
|
||||
options: supportedServices.map((service) => ({
|
||||
value: service,
|
||||
label: constants.SERVICE_DETAILS[service].name,
|
||||
})),
|
||||
default: undefined,
|
||||
emptyIsUndefined: true,
|
||||
},
|
||||
];
|
||||
|
||||
return {
|
||||
ID: 'jackettio',
|
||||
NAME: 'Jackettio',
|
||||
LOGO: 'https://raw.githubusercontent.com/Jackett/Jackett/bbea5febd623f6e536e11aa1fa8d6674d8d4043f/src/Jackett.Common/Content/jacket_medium.png',
|
||||
URL: Env.JACKETTIO_URL,
|
||||
TIMEOUT: Env.DEFAULT_JACKETTIO_TIMEOUT || Env.DEFAULT_TIMEOUT,
|
||||
USER_AGENT: Env.DEFAULT_JACKETTIO_USER_AGENT || Env.DEFAULT_USER_AGENT,
|
||||
SUPPORTED_SERVICES: supportedServices,
|
||||
DESCRIPTION:
|
||||
'Stremio addon that resolves streams using Jackett and Debrid',
|
||||
OPTIONS: options,
|
||||
SUPPORTED_STREAM_TYPES: [constants.DEBRID_STREAM_TYPE],
|
||||
SUPPORTED_RESOURCES: supportedResources,
|
||||
};
|
||||
}
|
||||
|
||||
static async generateAddons(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Promise<Addon[]> {
|
||||
if (options?.url?.endsWith('/manifest.json')) {
|
||||
return [this.generateAddon(userData, options, undefined)];
|
||||
}
|
||||
|
||||
const usableServices = this.getUsableServices(userData, options.services);
|
||||
if (!usableServices || usableServices.length === 0) {
|
||||
throw new Error(
|
||||
`${this.METADATA.NAME} requires at least one usable service from the list of supported services: ${this.METADATA.SUPPORTED_SERVICES.map((service) => constants.SERVICE_DETAILS[service].name).join(', ')}`
|
||||
);
|
||||
}
|
||||
|
||||
let addons = usableServices.map((service) =>
|
||||
this.generateAddon(userData, options, service.id)
|
||||
);
|
||||
|
||||
return addons;
|
||||
}
|
||||
|
||||
private static generateAddon(
|
||||
userData: UserData,
|
||||
options: Record<string, any>,
|
||||
serviceId?: ServiceId
|
||||
): Addon {
|
||||
return {
|
||||
name: options.name || this.METADATA.NAME,
|
||||
identifyingName: serviceId
|
||||
? `${options.name || this.METADATA.NAME} ${constants.SERVICE_DETAILS[serviceId].shortName}`
|
||||
: options.name || this.METADATA.NAME,
|
||||
manifestUrl: this.generateManifestUrl(userData, options, serviceId),
|
||||
enabled: true,
|
||||
resources: options.resources || this.METADATA.SUPPORTED_RESOURCES,
|
||||
timeout: options.timeout || this.METADATA.TIMEOUT,
|
||||
fromPresetId: this.METADATA.ID,
|
||||
headers: {
|
||||
'User-Agent': this.METADATA.USER_AGENT,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private static generateManifestUrl(
|
||||
userData: UserData,
|
||||
options: Record<string, any>,
|
||||
serviceId: ServiceId | undefined
|
||||
) {
|
||||
let url = options.url || this.METADATA.URL;
|
||||
if (url.endsWith('/manifest.json')) {
|
||||
return url;
|
||||
}
|
||||
if (!serviceId) {
|
||||
throw new Error(
|
||||
`${this.METADATA.NAME} requires at least one usable service from the list of supported services: ${this.METADATA.SUPPORTED_SERVICES.map((service) => constants.SERVICE_DETAILS[service].name).join(', ')}`
|
||||
);
|
||||
}
|
||||
url = url.replace(/\/$/, '');
|
||||
const configString = this.base64EncodeJSON({
|
||||
maxTorrents: 30,
|
||||
priotizePackTorrents: 2,
|
||||
excludeKeywords: [],
|
||||
debridId: serviceId,
|
||||
debridApiKey: this.getServiceCredential(serviceId, userData, {
|
||||
[constants.OFFCLOUD_SERVICE]: (credentials: any) =>
|
||||
`${credentials.email}:${credentials.password}`,
|
||||
[constants.PIKPAK_SERVICE]: (credentials: any) =>
|
||||
`${credentials.email}:${credentials.password}`,
|
||||
}),
|
||||
hideUncached: false,
|
||||
sortCached: [
|
||||
['quality', true],
|
||||
['size', true],
|
||||
],
|
||||
sortUncached: [['seeders', true]],
|
||||
forceCacheNextEpisode: false,
|
||||
priotizeLanguages: [],
|
||||
indexerTimeoutSec: 60,
|
||||
metaLanguage: '',
|
||||
enableMediaFlow: false,
|
||||
mediaflowProxyUrl: '',
|
||||
mediaflowApiPassword: '',
|
||||
mediaflowPublicIp: '',
|
||||
useStremThru: true,
|
||||
stremthruUrl: Env.DEFAULT_JACKETTIO_STREMTHRU_URL,
|
||||
qualities: [0, 360, 480, 720, 1080, 2160],
|
||||
indexers: Env.DEFAULT_JACKETTIO_INDEXERS,
|
||||
});
|
||||
|
||||
return `${url}${configString ? '/' + configString : ''}/manifest.json`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
import { Addon, Option, UserData } from '../db';
|
||||
import { Preset, baseOptions } from './preset';
|
||||
import { constants, Env } from '../utils';
|
||||
|
||||
export class MarvelPreset extends Preset {
|
||||
private static catalogs = [
|
||||
{
|
||||
label: 'MCU Chronological Order',
|
||||
value: 'marvel-mcu',
|
||||
},
|
||||
{
|
||||
label: 'MCU Release Order',
|
||||
value: 'release-order',
|
||||
},
|
||||
{
|
||||
label: 'X-Men Chronological Order',
|
||||
value: 'xmen',
|
||||
},
|
||||
{
|
||||
label: 'Marvel Movies',
|
||||
value: 'movies',
|
||||
},
|
||||
{
|
||||
label: 'Marvel TV Shows',
|
||||
value: 'series',
|
||||
},
|
||||
{
|
||||
label: 'Marvel Animated Series',
|
||||
value: 'animations',
|
||||
},
|
||||
];
|
||||
static override get METADATA() {
|
||||
const supportedResources = [
|
||||
constants.CATALOG_RESOURCE,
|
||||
constants.META_RESOURCE,
|
||||
];
|
||||
|
||||
const options: Option[] = [
|
||||
...baseOptions(
|
||||
'Marvel Universe',
|
||||
supportedResources,
|
||||
Env.DEFAULT_MARVEL_CATALOG_TIMEOUT
|
||||
).filter((option) => option.id !== 'url'),
|
||||
// series movies animations xmen release-order marvel-mcu
|
||||
{
|
||||
id: 'catalogs',
|
||||
name: 'Catalogs',
|
||||
description: 'The catalogs to display',
|
||||
type: 'multi-select',
|
||||
required: true,
|
||||
options: this.catalogs,
|
||||
default: this.catalogs.map((catalog) => catalog.value),
|
||||
},
|
||||
];
|
||||
|
||||
return {
|
||||
ID: 'marvel-universe',
|
||||
NAME: 'Marvel Universe',
|
||||
LOGO: 'https://upload.wikimedia.org/wikipedia/commons/b/b9/Marvel_Logo.svg',
|
||||
URL: Env.MARVEL_UNIVERSE_URL,
|
||||
TIMEOUT: Env.DEFAULT_MARVEL_CATALOG_TIMEOUT || Env.DEFAULT_TIMEOUT,
|
||||
USER_AGENT:
|
||||
Env.DEFAULT_MARVEL_CATALOG_USER_AGENT || Env.DEFAULT_USER_AGENT,
|
||||
SUPPORTED_SERVICES: [],
|
||||
DESCRIPTION: 'Catalogs for the Marvel Universe',
|
||||
OPTIONS: options,
|
||||
SUPPORTED_STREAM_TYPES: [],
|
||||
SUPPORTED_RESOURCES: supportedResources,
|
||||
};
|
||||
}
|
||||
|
||||
static async generateAddons(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Promise<Addon[]> {
|
||||
return [this.generateAddon(userData, options)];
|
||||
}
|
||||
|
||||
private static generateAddon(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Addon {
|
||||
const config =
|
||||
options.catalogs.length !== this.catalogs.length
|
||||
? options.catalogs.join('%2C')
|
||||
: '';
|
||||
return {
|
||||
name: options.name || this.METADATA.NAME,
|
||||
identifyingName: options.name || this.METADATA.NAME,
|
||||
manifestUrl: `${Env.MARVEL_UNIVERSE_URL}/${config ? 'catalog/' + config + '/' : ''}manifest.json`,
|
||||
enabled: true,
|
||||
library: false,
|
||||
resources: options.resources || this.METADATA.SUPPORTED_RESOURCES,
|
||||
timeout: options.timeout || this.METADATA.TIMEOUT,
|
||||
fromPresetId: this.METADATA.ID,
|
||||
headers: {
|
||||
'User-Agent': this.METADATA.USER_AGENT,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,424 @@
|
||||
import { Addon, Option, UserData, Resource, Stream, ParsedStream } from '../db';
|
||||
import { baseOptions, Preset } from './preset';
|
||||
import { createLogger, Env } from '../utils';
|
||||
import { constants, ServiceId } from '../utils';
|
||||
import { StreamParser } from '../parser';
|
||||
|
||||
const logger = createLogger('core');
|
||||
|
||||
class MediaFusionStreamParser extends StreamParser {
|
||||
protected override raiseErrorIfNecessary(
|
||||
stream: Stream,
|
||||
currentParsedStream: ParsedStream
|
||||
): void {
|
||||
if (stream.description?.includes('Content Warning')) {
|
||||
throw new Error(stream.description);
|
||||
}
|
||||
}
|
||||
|
||||
protected override get indexerEmojis(): string[] {
|
||||
return ['🔗'];
|
||||
}
|
||||
|
||||
protected override getFolder(
|
||||
stream: Stream,
|
||||
currentParsedStream: ParsedStream
|
||||
): string | undefined {
|
||||
const regex = this.getRegexForTextAfterEmojis(['📂']);
|
||||
const file = stream.description?.match(regex)?.[1];
|
||||
if (file && file.includes('┈➤')) {
|
||||
return file.split('┈➤')[0].trim();
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
protected override getFolderSize(
|
||||
stream: Stream,
|
||||
currentParsedStream: ParsedStream
|
||||
): number | undefined {
|
||||
const regex = /💾\s?.*\s?\/\s?💾\s?([^💾\n]+)/;
|
||||
const match = stream.description?.match(regex);
|
||||
if (match) {
|
||||
const folderSize = match[1].trim();
|
||||
return this.calculateBytesFromSizeString(folderSize);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
protected override getFilename(
|
||||
stream: Stream,
|
||||
currentParsedStream: ParsedStream
|
||||
): string | undefined {
|
||||
const regex = this.getRegexForTextAfterEmojis(['📂']);
|
||||
const file = stream.description?.match(regex)?.[1];
|
||||
if (file && file.includes('┈➤')) {
|
||||
return file.split('┈➤')[1].trim();
|
||||
}
|
||||
return file?.trim();
|
||||
}
|
||||
|
||||
protected override getIndexer(
|
||||
stream: Stream,
|
||||
currentParsedStream: ParsedStream
|
||||
): string | undefined {
|
||||
const indexer = super.getIndexer(stream, currentParsedStream);
|
||||
if (indexer?.includes('Contribution')) {
|
||||
const contributor = stream.description?.match(
|
||||
this.getRegexForTextAfterEmojis(['🧑💻'])
|
||||
)?.[1];
|
||||
return contributor ? `Contributor|${contributor}` : undefined;
|
||||
}
|
||||
return indexer;
|
||||
}
|
||||
|
||||
protected override getLanguages(
|
||||
stream: Stream,
|
||||
currentParsedStream: ParsedStream
|
||||
): string[] {
|
||||
const languages = super.getLanguages(stream, currentParsedStream);
|
||||
const regex = this.getRegexForTextAfterEmojis(['🌐']);
|
||||
const languagesString = stream.description?.match(regex)?.[1];
|
||||
if (languagesString) {
|
||||
return languages.concat(
|
||||
languagesString
|
||||
.split('+')
|
||||
.map((language) => language.trim())
|
||||
.filter((language) => constants.LANGUAGES.includes(language as any))
|
||||
);
|
||||
}
|
||||
return languages;
|
||||
}
|
||||
}
|
||||
|
||||
export class MediaFusionPreset extends Preset {
|
||||
static override getParser(): typeof StreamParser {
|
||||
return MediaFusionStreamParser;
|
||||
}
|
||||
|
||||
static override get METADATA() {
|
||||
const supportedServices: ServiceId[] = [
|
||||
constants.REALDEBRID_SERVICE,
|
||||
constants.PREMIUMIZE_SERVICE,
|
||||
constants.ALLEDEBRID_SERVICE,
|
||||
constants.TORBOX_SERVICE,
|
||||
constants.DEBRIDLINK_SERVICE,
|
||||
constants.EASYDEBRID_SERVICE,
|
||||
constants.OFFCLOUD_SERVICE,
|
||||
constants.PIKPAK_SERVICE,
|
||||
constants.SEEDR_SERVICE,
|
||||
];
|
||||
|
||||
const supportedResources = [constants.STREAM_RESOURCE];
|
||||
|
||||
const options: Option[] = [
|
||||
...baseOptions(
|
||||
'MediaFusion',
|
||||
supportedResources,
|
||||
Env.DEFAULT_MEDIAFUSION_TIMEOUT
|
||||
),
|
||||
{
|
||||
id: 'useCachedResultsOnly',
|
||||
name: 'Use Cached Results Only',
|
||||
description:
|
||||
"Only show results that are already cached in MediaFusion's database from previous searches. This disables live searching, making requests faster but potentially showing fewer results.",
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
{
|
||||
id: 'enableWatchlistCatalogs',
|
||||
name: 'Enable Watchlist Catalogs',
|
||||
description: 'Enable watchlist catalogs for the selected services.',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
id: 'downloadViaBrowser',
|
||||
name: 'Download via Browser',
|
||||
description:
|
||||
'Show download streams to allow downloading the stream from your service, rather than streaming.',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
id: 'certificationLevelsFilter',
|
||||
name: 'Certification Levels Filter',
|
||||
description:
|
||||
'Choose to not display streams for titles of a certain certification level. Leave blank to show all results.',
|
||||
type: 'multi-select',
|
||||
required: false,
|
||||
options: [
|
||||
{
|
||||
value: 'Unknown',
|
||||
label: 'Unknown',
|
||||
},
|
||||
{
|
||||
value: 'All Ages',
|
||||
label: 'All Ages',
|
||||
},
|
||||
{
|
||||
value: 'Children',
|
||||
label: 'Children',
|
||||
},
|
||||
{
|
||||
value: 'Parental Guidance',
|
||||
label: 'Parental Guidance',
|
||||
},
|
||||
{
|
||||
value: 'Teen',
|
||||
label: 'Teen',
|
||||
},
|
||||
{
|
||||
value: 'Adults',
|
||||
label: 'Adults',
|
||||
},
|
||||
{
|
||||
value: 'Adults+',
|
||||
label: 'Adults+',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'nudityFilter',
|
||||
name: 'Nudity Filter',
|
||||
description:
|
||||
'Choose to not display streams that a certain level of nudity. Leave blank to show all results.',
|
||||
type: 'multi-select',
|
||||
required: false,
|
||||
options: [
|
||||
{
|
||||
value: 'Unknown',
|
||||
label: 'Unknown',
|
||||
},
|
||||
{
|
||||
value: 'None',
|
||||
label: 'None',
|
||||
},
|
||||
{
|
||||
value: 'Mild',
|
||||
label: 'Mild',
|
||||
},
|
||||
{
|
||||
value: 'Moderate',
|
||||
label: 'Moderate',
|
||||
},
|
||||
{
|
||||
value: 'Severe',
|
||||
label: 'Severe',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
{
|
||||
id: 'services',
|
||||
name: 'Services',
|
||||
description:
|
||||
'Optionally override the services that are used. If not specified, then the services that are enabled and supported will be used.',
|
||||
type: 'multi-select',
|
||||
required: false,
|
||||
options: supportedServices.map((service) => ({
|
||||
value: service,
|
||||
label: constants.SERVICE_DETAILS[service].name,
|
||||
})),
|
||||
default: undefined,
|
||||
emptyIsUndefined: true,
|
||||
},
|
||||
];
|
||||
|
||||
return {
|
||||
ID: 'mediafusion',
|
||||
NAME: 'MediaFusion',
|
||||
LOGO: `https://raw.githubusercontent.com/mhdzumair/MediaFusion/refs/heads/main/resources/images/mediafusion_logo.png`,
|
||||
URL: Env.MEDIAFUSION_URL,
|
||||
TIMEOUT: Env.DEFAULT_MEDIAFUSION_TIMEOUT || Env.DEFAULT_TIMEOUT,
|
||||
USER_AGENT: Env.DEFAULT_MEDIAFUSION_USER_AGENT || Env.DEFAULT_USER_AGENT,
|
||||
SUPPORTED_SERVICES: supportedServices,
|
||||
DESCRIPTION:
|
||||
'Universal Stremio Add-on for Movies, Series, Live TV & Sports Events',
|
||||
OPTIONS: options,
|
||||
SUPPORTED_STREAM_TYPES: [
|
||||
constants.P2P_STREAM_TYPE,
|
||||
constants.DEBRID_STREAM_TYPE,
|
||||
],
|
||||
SUPPORTED_RESOURCES: supportedResources,
|
||||
};
|
||||
}
|
||||
|
||||
static async generateAddons(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Promise<Addon[]> {
|
||||
if (options?.url?.endsWith('/manifest.json')) {
|
||||
return [this.generateAddon(userData, options, undefined)];
|
||||
}
|
||||
|
||||
const usableServices = this.getUsableServices(userData, options.services);
|
||||
|
||||
if (!usableServices || usableServices.length === 0) {
|
||||
return [this.generateAddon(userData, options, undefined)];
|
||||
}
|
||||
|
||||
let addons = usableServices.map((service) =>
|
||||
this.generateAddon(userData, options, service.id)
|
||||
);
|
||||
|
||||
if (options.includeP2P) {
|
||||
addons.push(this.generateAddon(userData, options, undefined));
|
||||
}
|
||||
|
||||
return addons;
|
||||
}
|
||||
|
||||
private static generateAddon(
|
||||
userData: UserData,
|
||||
options: Record<string, any>,
|
||||
serviceId?: ServiceId
|
||||
): Addon {
|
||||
return {
|
||||
name: options.name || this.METADATA.NAME,
|
||||
identifyingName: serviceId
|
||||
? `${options.name || this.METADATA.NAME} ${constants.SERVICE_DETAILS[serviceId].shortName}`
|
||||
: options.name || this.METADATA.NAME,
|
||||
manifestUrl: `${Env.MEDIAFUSION_URL}/manifest.json`,
|
||||
enabled: true,
|
||||
resources: options.resources || this.METADATA.SUPPORTED_RESOURCES,
|
||||
timeout: options.timeout || this.METADATA.TIMEOUT,
|
||||
fromPresetId: this.METADATA.ID,
|
||||
headers: {
|
||||
'User-Agent': this.METADATA.USER_AGENT,
|
||||
encoded_user_data: this.generateEncodedUserData(
|
||||
userData,
|
||||
options,
|
||||
serviceId
|
||||
),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private static generateEncodedUserData(
|
||||
userData: UserData,
|
||||
options: Record<string, any>,
|
||||
serviceId: ServiceId | undefined
|
||||
) {
|
||||
let url = options.url || this.METADATA.URL;
|
||||
if (url.endsWith('/manifest.json')) {
|
||||
return url;
|
||||
}
|
||||
url = url.replace(/\/$/, '');
|
||||
const encodedUserData = this.base64EncodeJSON(
|
||||
{
|
||||
streaming_provider: !serviceId
|
||||
? null
|
||||
: {
|
||||
token: this.getServiceCredential(serviceId, userData),
|
||||
service: serviceId,
|
||||
enable_watchlist_catalogs:
|
||||
options.enableWatchlistCatalogs || false,
|
||||
download_via_browser: options.downloadViaBrowser || false,
|
||||
only_show_cached_streams: false,
|
||||
},
|
||||
selected_catalogs: [],
|
||||
selected_resolutions: [
|
||||
'4k',
|
||||
'2160p',
|
||||
'1440p',
|
||||
'1080p',
|
||||
'720p',
|
||||
'576p',
|
||||
'480p',
|
||||
'360p',
|
||||
'240p',
|
||||
null,
|
||||
],
|
||||
enable_catalogs: true,
|
||||
enable_imdb_metadata: false,
|
||||
max_size: 'inf',
|
||||
max_streams_per_resolution: '10',
|
||||
torrent_sorting_priority: [
|
||||
{ key: 'language', direction: 'desc' },
|
||||
{ key: 'cached', direction: 'desc' },
|
||||
{ key: 'resolution', direction: 'desc' },
|
||||
{ key: 'quality', direction: 'desc' },
|
||||
{ key: 'size', direction: 'desc' },
|
||||
{ key: 'seeders', direction: 'desc' },
|
||||
{ key: 'created_at', direction: 'desc' },
|
||||
],
|
||||
show_full_torrent_name: true,
|
||||
show_language_country_flag: false,
|
||||
nudity_filter: options.nudityFilter?.length
|
||||
? options.nudityFilter
|
||||
: ['Disable'],
|
||||
certification_filter: options.certificationLevelsFilter?.length
|
||||
? options.certificationLevelsFilter
|
||||
: ['Disable'],
|
||||
language_sorting: [
|
||||
'English',
|
||||
'Tamil',
|
||||
'Hindi',
|
||||
'Malayalam',
|
||||
'Kannada',
|
||||
'Telugu',
|
||||
'Chinese',
|
||||
'Russian',
|
||||
'Arabic',
|
||||
'Japanese',
|
||||
'Korean',
|
||||
'Taiwanese',
|
||||
'Latino',
|
||||
'French',
|
||||
'Spanish',
|
||||
'Portuguese',
|
||||
'Italian',
|
||||
'German',
|
||||
'Ukrainian',
|
||||
'Polish',
|
||||
'Czech',
|
||||
'Thai',
|
||||
'Indonesian',
|
||||
'Vietnamese',
|
||||
'Dutch',
|
||||
'Bengali',
|
||||
'Turkish',
|
||||
'Greek',
|
||||
'Swedish',
|
||||
'Romanian',
|
||||
'Hungarian',
|
||||
'Finnish',
|
||||
'Norwegian',
|
||||
'Danish',
|
||||
'Hebrew',
|
||||
'Lithuanian',
|
||||
'Punjabi',
|
||||
'Marathi',
|
||||
'Gujarati',
|
||||
'Bhojpuri',
|
||||
'Nepali',
|
||||
'Urdu',
|
||||
'Tagalog',
|
||||
'Filipino',
|
||||
'Malay',
|
||||
'Mongolian',
|
||||
'Armenian',
|
||||
'Georgian',
|
||||
null,
|
||||
],
|
||||
quality_filter: [
|
||||
'BluRay/UHD',
|
||||
'WEB/HD',
|
||||
'DVD/TV/SAT',
|
||||
'CAM/Screener',
|
||||
'Unknown',
|
||||
],
|
||||
api_password: Env.MEDIAFUSION_API_PASSWORD,
|
||||
mediaflow_config: null,
|
||||
rpdb_config: null,
|
||||
live_search_streams: options.liveSearchStreams || false,
|
||||
contribution_streams: false,
|
||||
mdblist_config: null,
|
||||
},
|
||||
false,
|
||||
true
|
||||
);
|
||||
|
||||
return encodedUserData;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
import { Addon, Option, UserData, Resource, Stream } from '../db';
|
||||
import { Preset, baseOptions } from './preset';
|
||||
import { Env, SERVICE_DETAILS } from '../utils';
|
||||
import { constants, ServiceId } from '../utils';
|
||||
import { StreamParser } from '../parser';
|
||||
|
||||
export class NuvioStreamsPreset extends Preset {
|
||||
static override get METADATA() {
|
||||
const supportedResources = [constants.STREAM_RESOURCE];
|
||||
const regions = [
|
||||
{
|
||||
value: 'USA7',
|
||||
label: 'USA East',
|
||||
},
|
||||
{
|
||||
value: 'USA6',
|
||||
label: 'USA West',
|
||||
},
|
||||
{
|
||||
value: 'USA5',
|
||||
label: 'USA Middle',
|
||||
},
|
||||
{
|
||||
value: 'UK3',
|
||||
label: 'United Kingdom',
|
||||
},
|
||||
{
|
||||
value: 'CA1',
|
||||
label: 'Canada',
|
||||
},
|
||||
{
|
||||
value: 'FR1',
|
||||
label: 'France',
|
||||
},
|
||||
{
|
||||
value: 'DE2',
|
||||
label: 'Germany',
|
||||
},
|
||||
{
|
||||
value: 'HK1',
|
||||
label: 'Hong Kong',
|
||||
},
|
||||
{
|
||||
value: 'IN1',
|
||||
label: 'India',
|
||||
},
|
||||
{
|
||||
value: 'AU1',
|
||||
label: 'Australia',
|
||||
},
|
||||
{
|
||||
value: 'SZ',
|
||||
label: 'China',
|
||||
},
|
||||
];
|
||||
const providers = [
|
||||
{
|
||||
value: 'showbox',
|
||||
label: 'Showbox',
|
||||
},
|
||||
{
|
||||
value: 'xprime',
|
||||
label: 'XPrime',
|
||||
},
|
||||
{
|
||||
value: 'hollymoviehd',
|
||||
label: 'HollyMovieHD',
|
||||
},
|
||||
{
|
||||
value: 'cuevana',
|
||||
label: 'Cuevana',
|
||||
},
|
||||
{
|
||||
value: 'soapertv',
|
||||
label: 'Soapertv',
|
||||
},
|
||||
{
|
||||
value: 'vidzee',
|
||||
label: 'Vidzee',
|
||||
},
|
||||
{
|
||||
value: 'hianime',
|
||||
label: 'HiAnime',
|
||||
},
|
||||
{
|
||||
value: 'vidsrc',
|
||||
label: 'Vidsrc',
|
||||
},
|
||||
];
|
||||
|
||||
const options: Option[] = [
|
||||
...baseOptions(
|
||||
'Nuvio Streams',
|
||||
supportedResources,
|
||||
Env.DEFAULT_NUVIOSTREAMS_TIMEOUT
|
||||
),
|
||||
{
|
||||
id: 'scraperApiKey',
|
||||
name: 'Scraper API Key',
|
||||
description:
|
||||
'Optionally provide a [ScraperAPI](https://www.scraperapi.com/) API Key from',
|
||||
type: 'string',
|
||||
required: false,
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
id: 'showBoxCookie',
|
||||
name: 'ShowBox Cookie',
|
||||
description:
|
||||
'The cookie for the ShowBox provider. Highly recommended to get streams greater than 9GB. Log in at [Febbox](https://www.febbox.com/) > DevTools > Storage > Cookied > Copy the value of the `ui` cookie. ',
|
||||
type: 'string',
|
||||
required: false,
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
id: 'showBoxRegion',
|
||||
name: 'ShowBox Region',
|
||||
description: 'The region to use for the ShowBox provider',
|
||||
type: 'select',
|
||||
required: false,
|
||||
options: regions,
|
||||
default: regions[0].value,
|
||||
},
|
||||
{
|
||||
id: 'providers',
|
||||
name: 'Providers',
|
||||
description: 'The providers to use',
|
||||
type: 'multi-select',
|
||||
required: true,
|
||||
options: providers,
|
||||
default: providers.map((provider) => provider.value),
|
||||
},
|
||||
{
|
||||
id: 'streamPassthrough',
|
||||
name: 'Stream Passthrough',
|
||||
description:
|
||||
'Whether to use the original stream name and description. Recommended to be left on in order to get all the information.',
|
||||
type: 'boolean',
|
||||
required: false,
|
||||
default: true,
|
||||
},
|
||||
];
|
||||
|
||||
return {
|
||||
ID: 'nuvio-streams',
|
||||
NAME: 'Nuvio Streams',
|
||||
LOGO: 'https://raw.githubusercontent.com/tapframe/NuvioStreaming/main/assets/titlelogo.png',
|
||||
URL: Env.NUVIOSTREAMS_URL,
|
||||
TIMEOUT: Env.DEFAULT_NUVIOSTREAMS_TIMEOUT || Env.DEFAULT_TIMEOUT,
|
||||
USER_AGENT: Env.DEFAULT_NUVIOSTREAMS_USER_AGENT || Env.DEFAULT_USER_AGENT,
|
||||
SUPPORTED_SERVICES: [],
|
||||
DESCRIPTION: 'Free high quality streaming using multiple providers. ',
|
||||
OPTIONS: options,
|
||||
SUPPORTED_STREAM_TYPES: [constants.HTTP_STREAM_TYPE],
|
||||
SUPPORTED_RESOURCES: supportedResources,
|
||||
};
|
||||
}
|
||||
|
||||
static async generateAddons(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Promise<Addon[]> {
|
||||
return [this.generateAddon(userData, options)];
|
||||
}
|
||||
|
||||
private static generateAddon(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Addon {
|
||||
return {
|
||||
name: options.name || this.METADATA.NAME,
|
||||
identifyingName: options.name || this.METADATA.NAME,
|
||||
manifestUrl: this.generateManifestUrl(userData, options),
|
||||
enabled: true,
|
||||
streamPassthrough: options.streamPassthrough ?? true,
|
||||
resources: options.resources || this.METADATA.SUPPORTED_RESOURCES,
|
||||
timeout: options.timeout || this.METADATA.TIMEOUT,
|
||||
fromPresetId: this.METADATA.ID,
|
||||
headers: {
|
||||
'User-Agent': this.METADATA.USER_AGENT,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private static generateManifestUrl(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
) {
|
||||
const url = options.url || this.METADATA.URL;
|
||||
if (url.endsWith('/manifest.json')) {
|
||||
return url;
|
||||
}
|
||||
|
||||
const cookie = options.showBoxCookie;
|
||||
const providers = options.providers;
|
||||
const scraperApiKey = options.scraperApiKey;
|
||||
let config = [];
|
||||
if (cookie) {
|
||||
config.push(['cookie', cookie]);
|
||||
}
|
||||
if (options.showBoxRegion) {
|
||||
config.push(['region', options.showBoxRegion]);
|
||||
}
|
||||
if (providers) {
|
||||
config.push(['providers', providers.join(',')]);
|
||||
}
|
||||
if (scraperApiKey) {
|
||||
config.push(['scraper_api_key', scraperApiKey]);
|
||||
}
|
||||
|
||||
const configString = this.urlEncodeKeyValuePairs(config, '/', false);
|
||||
|
||||
return `${url}${configString ? '/' + configString : ''}/manifest.json`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import { Addon, Option, UserData } from '../db';
|
||||
import { Preset, baseOptions } from './preset';
|
||||
import { Env, RESOURCES, SUBTITLES_RESOURCE } from '../utils';
|
||||
|
||||
export class OpenSubtitlesPreset extends Preset {
|
||||
static override get METADATA() {
|
||||
const supportedResources = [SUBTITLES_RESOURCE];
|
||||
const options: Option[] = [
|
||||
...baseOptions(
|
||||
'OpenSubtitles',
|
||||
supportedResources,
|
||||
Env.DEFAULT_OPENSUBTITLES_TIMEOUT
|
||||
).filter((option) => option.id !== 'url'),
|
||||
];
|
||||
|
||||
return {
|
||||
ID: 'opensubtitles',
|
||||
NAME: 'OpenSubtitles v3',
|
||||
LOGO: 'https://iwf1.com/scrapekod/icons/service.subtitles.opensubtitles_by_opensubtitles_dualsub.png',
|
||||
URL: Env.OPENSUBTITLES_URL,
|
||||
TIMEOUT: Env.DEFAULT_OPENSUBTITLES_TIMEOUT || Env.DEFAULT_TIMEOUT,
|
||||
USER_AGENT:
|
||||
Env.DEFAULT_OPENSUBTITLES_USER_AGENT || Env.DEFAULT_USER_AGENT,
|
||||
SUPPORTED_SERVICES: [],
|
||||
DESCRIPTION: 'OpenSubtitles addon',
|
||||
OPTIONS: options,
|
||||
SUPPORTED_STREAM_TYPES: [],
|
||||
SUPPORTED_RESOURCES: supportedResources,
|
||||
};
|
||||
}
|
||||
|
||||
static async generateAddons(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Promise<Addon[]> {
|
||||
return [this.generateAddon(userData, options)];
|
||||
}
|
||||
|
||||
private static generateAddon(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Addon {
|
||||
return {
|
||||
name: options.name || this.METADATA.NAME,
|
||||
identifyingName: options.name || this.METADATA.NAME,
|
||||
manifestUrl: `${Env.OPENSUBTITLES_URL}/manifest.json`,
|
||||
enabled: true,
|
||||
library: false,
|
||||
resources: options.resources || this.METADATA.SUPPORTED_RESOURCES,
|
||||
timeout: options.timeout || this.METADATA.TIMEOUT,
|
||||
fromPresetId: this.METADATA.ID,
|
||||
headers: {
|
||||
'User-Agent': this.METADATA.USER_AGENT,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
import { Addon, Option, UserData, Resource, ParsedStream, Stream } from '../db';
|
||||
import { baseOptions, Preset } from './preset';
|
||||
import { Env } from '../utils';
|
||||
import { constants, ServiceId } from '../utils';
|
||||
import { StreamParser } from '../parser';
|
||||
|
||||
class OrionStreamParser extends StreamParser {
|
||||
protected override raiseErrorIfNecessary(
|
||||
stream: Stream,
|
||||
currentParsedStream: ParsedStream
|
||||
): void {
|
||||
if (stream.title?.includes('ERROR')) {
|
||||
throw new Error(stream.title);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class OrionPreset extends Preset {
|
||||
static override getParser(): typeof StreamParser {
|
||||
return OrionStreamParser;
|
||||
}
|
||||
|
||||
static override get METADATA() {
|
||||
const supportedServices: ServiceId[] = [
|
||||
constants.REALDEBRID_SERVICE,
|
||||
constants.PREMIUMIZE_SERVICE,
|
||||
constants.ALLEDEBRID_SERVICE,
|
||||
// constants.TORBOX_SERVICE,
|
||||
constants.DEBRIDLINK_SERVICE,
|
||||
constants.OFFCLOUD_SERVICE,
|
||||
];
|
||||
|
||||
const supportedResources = [constants.STREAM_RESOURCE];
|
||||
|
||||
const options: Option[] = [
|
||||
...baseOptions('Orion', supportedResources, Env.DEFAULT_ORION_TIMEOUT),
|
||||
{
|
||||
id: 'orionApiKey',
|
||||
name: 'Orion API Key',
|
||||
description:
|
||||
'The API key for the Orion addon, obtain it from the [Orion Panel](https://panel.orionoid.com)',
|
||||
type: 'password',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
id: 'showP2P',
|
||||
name: 'Show P2P',
|
||||
description: 'Show P2P results, even if a debrid service is enabled',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
id: 'linkLimit',
|
||||
name: 'Link Limit',
|
||||
description: 'The maximum number of links to fetch from Orion.',
|
||||
type: 'number',
|
||||
default: 10,
|
||||
constraints: {
|
||||
max: 50,
|
||||
min: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'services',
|
||||
name: 'Services',
|
||||
description:
|
||||
'Optionally override the services that are used. If not specified, then the services that are enabled and supported will be used.',
|
||||
type: 'multi-select',
|
||||
required: false,
|
||||
options: supportedServices.map((service) => ({
|
||||
value: service,
|
||||
label: constants.SERVICE_DETAILS[service].name,
|
||||
})),
|
||||
default: undefined,
|
||||
emptyIsUndefined: true,
|
||||
},
|
||||
];
|
||||
|
||||
return {
|
||||
ID: 'orion',
|
||||
NAME: 'Orion',
|
||||
LOGO: 'https://orionoid.com/web/images/logo/logo256.png',
|
||||
URL: Env.ORION_STREMIO_ADDON_URL,
|
||||
TIMEOUT: Env.DEFAULT_ORION_TIMEOUT || Env.DEFAULT_TIMEOUT,
|
||||
USER_AGENT: Env.DEFAULT_ORION_USER_AGENT || Env.DEFAULT_USER_AGENT,
|
||||
SUPPORTED_SERVICES: supportedServices,
|
||||
DESCRIPTION: "Stremio's fastest Torrent/Debrid addon",
|
||||
OPTIONS: options,
|
||||
SUPPORTED_STREAM_TYPES: [
|
||||
constants.P2P_STREAM_TYPE,
|
||||
constants.DEBRID_STREAM_TYPE,
|
||||
],
|
||||
SUPPORTED_RESOURCES: supportedResources,
|
||||
};
|
||||
}
|
||||
|
||||
static async generateAddons(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Promise<Addon[]> {
|
||||
// url can either be something like https://torrentio.com/ or it can be a custom manifest url.
|
||||
// if it is a custom manifest url, return a single addon with the custom manifest url.
|
||||
if (options?.url?.endsWith('/manifest.json')) {
|
||||
return [this.generateAddon(userData, options, [])];
|
||||
}
|
||||
|
||||
const usableServices = this.getUsableServices(userData, options.services);
|
||||
// if no services are usable, use p2p
|
||||
if (!usableServices || usableServices.length === 0) {
|
||||
return [this.generateAddon(userData, options, [])];
|
||||
}
|
||||
|
||||
const showP2P = options.showP2P ?? false;
|
||||
const addonOptions = { ...options, showP2P: false };
|
||||
|
||||
let addons = usableServices.map((service) =>
|
||||
this.generateAddon(userData, addonOptions, [service.id])
|
||||
);
|
||||
|
||||
if (showP2P) {
|
||||
// we only want to push a single p2p addon, rather than a p2p addon for each service.
|
||||
addons.push(this.generateAddon(userData, addonOptions, []));
|
||||
}
|
||||
|
||||
return addons;
|
||||
}
|
||||
|
||||
private static generateAddon(
|
||||
userData: UserData,
|
||||
options: Record<string, any>,
|
||||
serviceIds: ServiceId[]
|
||||
): Addon {
|
||||
return {
|
||||
name: options.name || this.METADATA.NAME,
|
||||
identifyingName: `${options.name || this.METADATA.NAME} ${serviceIds.map((id) => constants.SERVICE_DETAILS[id].shortName).join(', ')}`,
|
||||
manifestUrl: this.generateManifestUrl(userData, options, serviceIds),
|
||||
enabled: true,
|
||||
resources: options.resources || this.METADATA.SUPPORTED_RESOURCES,
|
||||
timeout: options.timeout || this.METADATA.TIMEOUT,
|
||||
fromPresetId: this.METADATA.ID,
|
||||
headers: {
|
||||
'User-Agent': this.METADATA.USER_AGENT,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private static generateManifestUrl(
|
||||
userData: UserData,
|
||||
options: Record<string, any>,
|
||||
serviceIds: ServiceId[]
|
||||
) {
|
||||
let url = options.url || this.METADATA.URL;
|
||||
if (url.endsWith('/manifest.json')) {
|
||||
return url;
|
||||
}
|
||||
url = url.replace(/\/$/, '');
|
||||
const configString = this.base64EncodeJSON({
|
||||
api: options.orionApiKey,
|
||||
linkLimit: options.linkLimit.toString(),
|
||||
sortValue: 'best',
|
||||
audiochannels: '1,2,6,8',
|
||||
videoquality:
|
||||
'hd8k,hd6k,hd4k,hd2k,hd1080,hd720,sd,scr1080,scr720,scr,cam1080,cam720,cam',
|
||||
listOpt:
|
||||
serviceIds.length > 0
|
||||
? options.showP2P
|
||||
? 'both'
|
||||
: 'debrid'
|
||||
: 'torrent',
|
||||
debridservices: serviceIds,
|
||||
audiolanguages: [],
|
||||
additionalParameters: '',
|
||||
});
|
||||
|
||||
return `${url}${configString ? '/' + configString : ''}/manifest.json`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
import { Addon, Option, UserData, Resource, Stream } from '../db';
|
||||
import { Preset, baseOptions } from './preset';
|
||||
import { Env, SERVICE_DETAILS } from '../utils';
|
||||
import { constants, ServiceId } from '../utils';
|
||||
import { StreamParser } from '../parser';
|
||||
|
||||
export class PeerflixPreset extends Preset {
|
||||
static override get METADATA() {
|
||||
const supportedServices: ServiceId[] = [
|
||||
constants.REALDEBRID_SERVICE,
|
||||
constants.PREMIUMIZE_SERVICE,
|
||||
constants.ALLEDEBRID_SERVICE,
|
||||
constants.TORBOX_SERVICE,
|
||||
constants.PUTIO_SERVICE,
|
||||
constants.DEBRIDLINK_SERVICE,
|
||||
constants.OFFCLOUD_SERVICE,
|
||||
];
|
||||
const supportedResources = [
|
||||
constants.STREAM_RESOURCE,
|
||||
constants.CATALOG_RESOURCE,
|
||||
constants.META_RESOURCE,
|
||||
];
|
||||
|
||||
const options: Option[] = [
|
||||
...baseOptions(
|
||||
'Peerflix',
|
||||
supportedResources,
|
||||
Env.DEFAULT_PEERFLIX_TIMEOUT
|
||||
),
|
||||
{
|
||||
id: 'services',
|
||||
name: 'Services',
|
||||
description:
|
||||
'Optionally override the services that are used. If not specified, then the services that are enabled and supported will be used.',
|
||||
type: 'multi-select',
|
||||
required: false,
|
||||
options: supportedServices.map((service) => ({
|
||||
value: service,
|
||||
label: constants.SERVICE_DETAILS[service].name,
|
||||
})),
|
||||
default: undefined,
|
||||
emptyIsUndefined: true,
|
||||
},
|
||||
{
|
||||
id: 'useMultipleInstances',
|
||||
name: 'Use Multiple Instances',
|
||||
description:
|
||||
'When using multiple services, use a different Peerflix addon for each service, rather than using one instance for all services',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
id: 'showTorrentLinks',
|
||||
name: 'Show P2P Streams for Uncached torrents',
|
||||
description:
|
||||
'If enabled, the addon will show P2P streams for uncached torrents. This is useful for users who want to use the addon to stream torrents that are not cached by the debrid service.',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
required: true,
|
||||
},
|
||||
];
|
||||
|
||||
return {
|
||||
ID: 'peerflix',
|
||||
NAME: 'Peerflix',
|
||||
LOGO: `https://config.peerflix.mov/static/media/logo.28f42024a3538640d047201d05416a09.svg`,
|
||||
URL: Env.PEERFLIX_URL,
|
||||
TIMEOUT: Env.DEFAULT_PEERFLIX_TIMEOUT || Env.DEFAULT_TIMEOUT,
|
||||
USER_AGENT: Env.DEFAULT_PEERFLIX_USER_AGENT || Env.DEFAULT_USER_AGENT,
|
||||
SUPPORTED_SERVICES: supportedServices,
|
||||
REQUIRES_SERVICE: false,
|
||||
DESCRIPTION:
|
||||
'Provides Spanish and English streams to Movies and TV Shows.',
|
||||
OPTIONS: options,
|
||||
SUPPORTED_STREAM_TYPES: [
|
||||
constants.P2P_STREAM_TYPE,
|
||||
constants.DEBRID_STREAM_TYPE,
|
||||
],
|
||||
SUPPORTED_RESOURCES: supportedResources,
|
||||
};
|
||||
}
|
||||
|
||||
static async generateAddons(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Promise<Addon[]> {
|
||||
if (options?.url?.endsWith('/manifest.json')) {
|
||||
return [this.generateAddon(userData, options, [])];
|
||||
}
|
||||
|
||||
const usableServices = this.getUsableServices(userData, options.services);
|
||||
|
||||
// if no services are usable, return a single addon with no services
|
||||
if (!usableServices || usableServices.length === 0) {
|
||||
return [this.generateAddon(userData, options, [])];
|
||||
}
|
||||
|
||||
// if user has specified useMultipleInstances, return a single addon for each service
|
||||
if (options?.useMultipleInstances) {
|
||||
return usableServices.map((service) =>
|
||||
this.generateAddon(userData, options, [service.id])
|
||||
);
|
||||
}
|
||||
|
||||
// return a single addon with all usable services
|
||||
return [
|
||||
this.generateAddon(
|
||||
userData,
|
||||
options,
|
||||
usableServices.map((service) => service.id)
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
private static generateAddon(
|
||||
userData: UserData,
|
||||
options: Record<string, any>,
|
||||
services: ServiceId[]
|
||||
): Addon {
|
||||
return {
|
||||
name: options.name || this.METADATA.NAME,
|
||||
identifyingName: `${options.name || this.METADATA.NAME} ${services.map((id) => constants.SERVICE_DETAILS[id].shortName).join(' | ')}`,
|
||||
manifestUrl: this.generateManifestUrl(userData, services, options),
|
||||
enabled: true,
|
||||
resources: options.resources || this.METADATA.SUPPORTED_RESOURCES,
|
||||
timeout: options.timeout || this.METADATA.TIMEOUT,
|
||||
fromPresetId: this.METADATA.ID,
|
||||
headers: {
|
||||
'User-Agent': this.METADATA.USER_AGENT,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private static generateManifestUrl(
|
||||
userData: UserData,
|
||||
services: ServiceId[],
|
||||
options: Record<string, any>
|
||||
) {
|
||||
const url = options.url || this.METADATA.URL;
|
||||
if (url.endsWith('/manifest.json')) {
|
||||
return url;
|
||||
}
|
||||
|
||||
let configOptions = services.map((service) => [
|
||||
service,
|
||||
this.getServiceCredential(service, userData, {
|
||||
[constants.PUTIO_SERVICE]: (credentials: any) =>
|
||||
`${credentials.clientId}@${credentials.token}`,
|
||||
}),
|
||||
]);
|
||||
|
||||
if (options.showTorrentLinks) {
|
||||
configOptions.push(['debridOptions', 'torrentlinks']);
|
||||
}
|
||||
|
||||
const configString = configOptions.length
|
||||
? this.urlEncodeKeyValuePairs(configOptions)
|
||||
: '';
|
||||
|
||||
return `${url}${configString ? '/' + configString : ''}/manifest.json`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
import {
|
||||
Option,
|
||||
Resource,
|
||||
Stream,
|
||||
ParsedStream,
|
||||
UserData,
|
||||
PresetMetadata,
|
||||
Addon,
|
||||
} from '../db';
|
||||
import { StreamParser } from '../parser';
|
||||
import { Env, ServiceId, constants } from '../utils';
|
||||
/**
|
||||
*
|
||||
* What modifications are needed for each preset:
|
||||
*
|
||||
* comet: apply FORCE_COMET_HOSTNAME, FORCE_COMET_PORT, FORCE_COMET_PROTOCOl to stream urls if they are defined
|
||||
* dmm cast: need to split title by newline, replace trailing dashes, excluding lines with box emoji, and
|
||||
* then joining the array back together.
|
||||
* easynews,easynews+,easynews++: need to set type as usenet
|
||||
* jackettio: apply FORCE_JACKETTIO_HOSTNAME, FORCE_JACKETTIO_PORT, FORCE_JACKETTIO_PROTOCOL to stream urls if they are defined
|
||||
* mediafusion: need to add hint for folder name, 📁 emoji, and split on arrow, take last index.
|
||||
* stremio-jacektt: need to inspect stream urls to extract service info.
|
||||
* stremthruStore: need to mark each stream as 'inLibrary' and unset any parsed 'indexer'
|
||||
* torbox: need to use different regex for probably everything.
|
||||
* torrentio: extract folder name from first line
|
||||
*/
|
||||
|
||||
// name: z.string().min(1),
|
||||
// enabled: z.boolean().optional(),
|
||||
// baseUrl: z.string().url().optional(),
|
||||
// timeout: z.number().min(1).optional(),
|
||||
// resources: ResourceList.optional(),
|
||||
|
||||
export const baseOptions = (
|
||||
name: string,
|
||||
resources: Resource[],
|
||||
timeout: number = Env.DEFAULT_TIMEOUT
|
||||
): Option[] => [
|
||||
{
|
||||
id: 'name',
|
||||
name: 'Name',
|
||||
description: 'What to call this addon',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: name,
|
||||
},
|
||||
{
|
||||
id: 'timeout',
|
||||
name: 'Timeout',
|
||||
description: 'The timeout for this addon',
|
||||
type: 'number',
|
||||
required: true,
|
||||
default: timeout,
|
||||
constraints: {
|
||||
min: Env.MIN_TIMEOUT,
|
||||
max: Env.MAX_TIMEOUT,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'resources',
|
||||
name: 'Resources',
|
||||
description: 'Optionally override the resources to use ',
|
||||
type: 'multi-select',
|
||||
required: false,
|
||||
default: resources,
|
||||
options: resources.map((resource) => ({
|
||||
label: resource,
|
||||
value: resource,
|
||||
})),
|
||||
},
|
||||
{
|
||||
id: 'url',
|
||||
name: 'URL',
|
||||
description:
|
||||
'Optionally override either the manifest generated, or override the base url used when generating the manifests',
|
||||
type: 'url',
|
||||
required: false,
|
||||
emptyIsUndefined: true,
|
||||
default: undefined,
|
||||
},
|
||||
];
|
||||
|
||||
export abstract class Preset {
|
||||
static get METADATA(): PresetMetadata {
|
||||
throw new Error('METADATA must be implemented by derived classes');
|
||||
}
|
||||
|
||||
static getParser(): typeof StreamParser {
|
||||
return StreamParser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a preset from a preset id.
|
||||
* @param presetId - The id of the preset to create.
|
||||
* @returns The preset.
|
||||
*/
|
||||
|
||||
static generateAddons(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Promise<Addon[]> {
|
||||
throw new Error('generateAddons must be implemented by derived classes');
|
||||
}
|
||||
|
||||
// Utility functions for generating config strings
|
||||
/**
|
||||
* Encodes a JSON object into a base64 encoded string.
|
||||
* @param json - The JSON object to encode.
|
||||
* @returns The base64 encoded string.
|
||||
*/
|
||||
protected static base64EncodeJSON(
|
||||
json: any,
|
||||
urlEncode: boolean = false, // url encode the string
|
||||
makeUrlSafe: boolean = false // replace + with -, / with _ and = with nothing
|
||||
) {
|
||||
let encoded = Buffer.from(JSON.stringify(json)).toString('base64');
|
||||
if (makeUrlSafe) {
|
||||
encoded = encoded
|
||||
.replace(/\+/g, '-')
|
||||
.replace(/\//g, '_')
|
||||
.replace(/=+$/, '');
|
||||
} else if (urlEncode) {
|
||||
encoded = encodeURIComponent(encoded);
|
||||
}
|
||||
return encoded;
|
||||
}
|
||||
|
||||
protected static urlEncodeJSON(json: any) {
|
||||
return encodeURIComponent(JSON.stringify(json));
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms key-value pairs into a url encoded string
|
||||
* @param options - The key-value pair object to encode.
|
||||
* @returns The encoded string.
|
||||
*/
|
||||
protected static urlEncodeKeyValuePairs(
|
||||
options: Record<string, string> | string[][],
|
||||
separator: string = '|',
|
||||
encode: boolean = true
|
||||
) {
|
||||
const string = (Array.isArray(options) ? options : Object.entries(options))
|
||||
.map(([key, value]) => `${key}=${value}`)
|
||||
.join(separator);
|
||||
return encode ? encodeURIComponent(string) : string;
|
||||
}
|
||||
|
||||
protected static getUsableServices(
|
||||
userData: UserData,
|
||||
specifiedServices?: ServiceId[]
|
||||
) {
|
||||
let usableServices = userData.services?.filter(
|
||||
(service) =>
|
||||
this.METADATA.SUPPORTED_SERVICES.includes(service.id) && service.enabled
|
||||
);
|
||||
|
||||
if (specifiedServices) {
|
||||
// Validate specified services exist and are enabled
|
||||
for (const service of specifiedServices) {
|
||||
const userService = userData.services?.find((s) => s.id === service);
|
||||
const meta = Object.values(constants.SERVICE_DETAILS).find(
|
||||
(s) => s.id === service
|
||||
);
|
||||
if (!userService || !userService.enabled || !userService.credentials) {
|
||||
throw new Error(
|
||||
`You have specified ${meta?.name || service} in your configuration, but it is not enabled or has missing credentials`
|
||||
);
|
||||
}
|
||||
}
|
||||
// Filter to only specified services
|
||||
usableServices = usableServices?.filter((service) =>
|
||||
specifiedServices.includes(service.id)
|
||||
);
|
||||
}
|
||||
|
||||
return usableServices;
|
||||
}
|
||||
|
||||
protected static getServiceCredential(
|
||||
serviceId: ServiceId,
|
||||
userData: UserData,
|
||||
specialCases?: Partial<Record<ServiceId, (credentials: any) => any>>
|
||||
) {
|
||||
const service = constants.SERVICE_DETAILS[serviceId];
|
||||
if (!service) {
|
||||
throw new Error(`Service ${serviceId} not found`);
|
||||
}
|
||||
|
||||
const serviceCredentials = userData.services?.find(
|
||||
(service) => service.id === serviceId
|
||||
)?.credentials;
|
||||
|
||||
if (!serviceCredentials) {
|
||||
throw new Error(`No credentials found for service ${serviceId}`);
|
||||
}
|
||||
|
||||
// Handle special cases if provided
|
||||
if (specialCases?.[serviceId]) {
|
||||
return specialCases[serviceId](serviceCredentials);
|
||||
}
|
||||
|
||||
// handle seedr
|
||||
if (serviceId === constants.SEEDR_SERVICE) {
|
||||
if (serviceCredentials.encodedToken) {
|
||||
return serviceCredentials.encodedToken;
|
||||
}
|
||||
throw new Error(
|
||||
`Missing encoded token for ${serviceId}. Please add an encoded token using MediaFusion`
|
||||
);
|
||||
}
|
||||
// handle easynews
|
||||
if (serviceId === constants.EASYNEWS_SERVICE) {
|
||||
if (!serviceCredentials.username || !serviceCredentials.password) {
|
||||
throw new Error(
|
||||
`Missing username or password for ${serviceId}. Please add a username and password.`
|
||||
);
|
||||
}
|
||||
return `${serviceCredentials.username}:${serviceCredentials.password}`;
|
||||
}
|
||||
// Default case - API key
|
||||
const { apiKey } = serviceCredentials;
|
||||
if (!apiKey) {
|
||||
throw new Error(
|
||||
`Missing credentials for ${serviceId}. Please add an API key.`
|
||||
);
|
||||
}
|
||||
return apiKey;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
import { PresetMetadata } from '../db';
|
||||
import { CometPreset } from './comet';
|
||||
import { CustomPreset } from './custom';
|
||||
import { MediaFusionPreset } from './mediafusion';
|
||||
import { StremthruStorePreset } from './stremthruStore';
|
||||
import { TorrentioPreset } from './torrentio';
|
||||
import { TorboxAddonPreset } from './torbox';
|
||||
import { EasynewsPreset } from './easynews';
|
||||
import { EasynewsPlusPreset } from './easynewsPlus';
|
||||
import { EasynewsPlusPlusPreset } from './easynewsPlusPlus';
|
||||
import { StremthruTorzPreset } from './stremthruTorz';
|
||||
import { DebridioPreset } from './debridio';
|
||||
import { AIOStreamsPreset } from './aiostreams';
|
||||
import { OpenSubtitlesPreset } from './opensubtitles';
|
||||
import { PeerflixPreset } from './peerflix';
|
||||
import { DMMCastPreset } from './dmmCast';
|
||||
import { MarvelPreset } from './marvel';
|
||||
import { JackettioPreset } from './jackettio';
|
||||
import { OrionPreset } from './orion';
|
||||
import { StreamFusionPreset } from './streamfusion';
|
||||
import { AnimeKitsuPreset } from './animeKitsu';
|
||||
import { NuvioStreamsPreset } from './nuviostreams';
|
||||
import { RpdbCatalogsPreset } from './rpdbCatalogs';
|
||||
import { TmdbCollectionsPreset } from './tmdbCollections';
|
||||
import { DebridioWatchtowerPreset } from './debridioWatchtower';
|
||||
import { DebridioTmdbPreset } from './debridioTmdb';
|
||||
import { StarWarsUniversePreset } from './starWarsUniverse';
|
||||
import { DebridioTvdbPreset } from './debridioTvdb';
|
||||
import { DcUniversePreset } from './dcUniverse';
|
||||
import { DebridioTvPreset } from './debridioTv';
|
||||
import { TorrentCatalogsPreset } from './torrentCatalogs';
|
||||
|
||||
const PRESET_LIST: string[] = [
|
||||
'custom',
|
||||
'torrentio',
|
||||
'comet',
|
||||
'mediafusion',
|
||||
'stremthruTorz',
|
||||
'stremthruStore',
|
||||
'torbox',
|
||||
'jackettio',
|
||||
'peerflix',
|
||||
'easynews',
|
||||
'easynewsPlus',
|
||||
'easynewsPlusPlus',
|
||||
'nuvio-streams',
|
||||
'debridio',
|
||||
'debridio-tv',
|
||||
'debridio-watchtower',
|
||||
'streamfusion',
|
||||
'dmm-cast',
|
||||
'orion',
|
||||
'opensubtitles',
|
||||
'debridio-tmdb',
|
||||
'debridio-tvdb',
|
||||
'torrent-catalogs',
|
||||
'rpdb-catalogs',
|
||||
'tmdb-collections',
|
||||
'anime-kitsu',
|
||||
'marvel-universe',
|
||||
'star-wars-universe',
|
||||
'dc-universe',
|
||||
'aiostreams',
|
||||
];
|
||||
|
||||
export class PresetManager {
|
||||
static getPresetList(): PresetMetadata[] {
|
||||
return PRESET_LIST.map((presetId) => this.fromId(presetId).METADATA);
|
||||
}
|
||||
|
||||
static fromId(id: string) {
|
||||
switch (id) {
|
||||
case 'torrentio':
|
||||
return TorrentioPreset;
|
||||
case 'stremthruStore':
|
||||
return StremthruStorePreset;
|
||||
case 'stremthruTorz':
|
||||
return StremthruTorzPreset;
|
||||
case 'comet':
|
||||
return CometPreset;
|
||||
case 'mediafusion':
|
||||
return MediaFusionPreset;
|
||||
case 'custom':
|
||||
return CustomPreset;
|
||||
case 'torbox':
|
||||
return TorboxAddonPreset;
|
||||
case 'jackettio':
|
||||
return JackettioPreset;
|
||||
case 'easynews':
|
||||
return EasynewsPreset;
|
||||
case 'easynewsPlus':
|
||||
return EasynewsPlusPreset;
|
||||
case 'easynewsPlusPlus':
|
||||
return EasynewsPlusPlusPreset;
|
||||
case 'debridio':
|
||||
return DebridioPreset;
|
||||
case 'debridio-watchtower':
|
||||
return DebridioWatchtowerPreset;
|
||||
case 'debridio-tv':
|
||||
return DebridioTvPreset;
|
||||
case 'debridio-tmdb':
|
||||
return DebridioTmdbPreset;
|
||||
case 'debridio-tvdb':
|
||||
return DebridioTvdbPreset;
|
||||
case 'aiostreams':
|
||||
return AIOStreamsPreset;
|
||||
case 'opensubtitles':
|
||||
return OpenSubtitlesPreset;
|
||||
case 'peerflix':
|
||||
return PeerflixPreset;
|
||||
case 'dmm-cast':
|
||||
return DMMCastPreset;
|
||||
case 'marvel-universe':
|
||||
return MarvelPreset;
|
||||
case 'orion':
|
||||
return OrionPreset;
|
||||
case 'streamfusion':
|
||||
return StreamFusionPreset;
|
||||
case 'anime-kitsu':
|
||||
return AnimeKitsuPreset;
|
||||
case 'nuvio-streams':
|
||||
return NuvioStreamsPreset;
|
||||
case 'torrent-catalogs':
|
||||
return TorrentCatalogsPreset;
|
||||
case 'rpdb-catalogs':
|
||||
return RpdbCatalogsPreset;
|
||||
case 'tmdb-collections':
|
||||
return TmdbCollectionsPreset;
|
||||
case 'star-wars-universe':
|
||||
return StarWarsUniversePreset;
|
||||
case 'dc-universe':
|
||||
return DcUniversePreset;
|
||||
default:
|
||||
throw new Error(`Preset ${id} not found`);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
import { Addon, Option, UserData } from '../db';
|
||||
import { Preset, baseOptions } from './preset';
|
||||
import { constants, Env } from '../utils';
|
||||
|
||||
export class RpdbCatalogsPreset extends Preset {
|
||||
private static catalogs = [
|
||||
{
|
||||
label: 'Movies',
|
||||
value: 'movies',
|
||||
},
|
||||
{
|
||||
label: 'Series',
|
||||
value: 'series',
|
||||
},
|
||||
{
|
||||
label: 'Other (News / Talk-Shows / Reality TV etc.)',
|
||||
value: 'other',
|
||||
},
|
||||
];
|
||||
static override get METADATA() {
|
||||
const supportedResources = [constants.CATALOG_RESOURCE];
|
||||
|
||||
const options: Option[] = [
|
||||
...baseOptions(
|
||||
'RPDB Catalogs',
|
||||
supportedResources,
|
||||
Env.DEFAULT_RPDB_CATALOGS_TIMEOUT
|
||||
).filter((option) => option.id !== 'url'),
|
||||
// series movies animations xmen release-order marvel-mcu
|
||||
{
|
||||
id: 'catalogs',
|
||||
name: 'Catalogs',
|
||||
description: 'The catalogs to display',
|
||||
type: 'multi-select',
|
||||
required: true,
|
||||
options: this.catalogs,
|
||||
default: this.catalogs.map((catalog) => catalog.value),
|
||||
},
|
||||
];
|
||||
|
||||
return {
|
||||
ID: 'rpdb-catalogs',
|
||||
NAME: 'RPDB Catalogs',
|
||||
LOGO: `${Env.RPDB_CATALOGS_URL}/addon-logo.png`,
|
||||
URL: Env.RPDB_CATALOGS_URL,
|
||||
TIMEOUT: Env.DEFAULT_RPDB_CATALOGS_TIMEOUT || Env.DEFAULT_TIMEOUT,
|
||||
USER_AGENT:
|
||||
Env.DEFAULT_RPDB_CATALOGS_USER_AGENT || Env.DEFAULT_USER_AGENT,
|
||||
SUPPORTED_SERVICES: [],
|
||||
DESCRIPTION: 'Catalogs to accurately track new / popular / best release!',
|
||||
OPTIONS: options,
|
||||
SUPPORTED_STREAM_TYPES: [],
|
||||
SUPPORTED_RESOURCES: supportedResources,
|
||||
};
|
||||
}
|
||||
|
||||
static async generateAddons(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Promise<Addon[]> {
|
||||
if (!userData.rpdbApiKey) {
|
||||
throw new Error(
|
||||
`${this.METADATA.NAME} requires an RPDB API Key. Please provide one in the services section`
|
||||
);
|
||||
}
|
||||
return [this.generateAddon(userData, options)];
|
||||
}
|
||||
|
||||
private static generateAddon(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Addon {
|
||||
return {
|
||||
name: options.name || this.METADATA.NAME,
|
||||
identifyingName: options.name || this.METADATA.NAME,
|
||||
manifestUrl: `${Env.RPDB_CATALOGS_URL}/${userData.rpdbApiKey}/poster-default/${options.catalogs.join('_')}/manifest.json`,
|
||||
enabled: true,
|
||||
library: false,
|
||||
resources: options.resources || this.METADATA.SUPPORTED_RESOURCES,
|
||||
timeout: options.timeout || this.METADATA.TIMEOUT,
|
||||
fromPresetId: this.METADATA.ID,
|
||||
headers: {
|
||||
'User-Agent': this.METADATA.USER_AGENT,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
import { Addon, Option, UserData } from '../db';
|
||||
import { Preset, baseOptions } from './preset';
|
||||
import { constants, Env } from '../utils';
|
||||
|
||||
export class StarWarsUniversePreset extends Preset {
|
||||
private static catalogs = [
|
||||
{
|
||||
label: 'Movies & Series Chronological',
|
||||
value: 'sw-movies-series-chronological',
|
||||
},
|
||||
{
|
||||
label: 'Movies & Series Release',
|
||||
value: 'sw-movies-series-release',
|
||||
},
|
||||
{
|
||||
label: 'Skywalker Saga',
|
||||
value: 'sw-skywalker-saga',
|
||||
},
|
||||
{
|
||||
label: 'Anthology Films',
|
||||
value: 'sw-anthology-films',
|
||||
},
|
||||
{
|
||||
label: 'Live-Action Series',
|
||||
value: 'sw-live-action-series',
|
||||
},
|
||||
{
|
||||
label: 'Animated Series',
|
||||
value: 'sw-animated-series',
|
||||
},
|
||||
{
|
||||
label: 'Micro-Series & Shorts',
|
||||
value: 'sw-micro-series-shorts',
|
||||
},
|
||||
{
|
||||
label: 'High Republic Era',
|
||||
value: 'sw-high-republic-era',
|
||||
},
|
||||
{
|
||||
label: 'Empire Era',
|
||||
value: 'sw-empire-era',
|
||||
},
|
||||
{
|
||||
label: 'New Republic Era',
|
||||
value: 'sw-new-republic-era',
|
||||
},
|
||||
{
|
||||
label: 'Bounty Hunters & Underworld',
|
||||
value: 'sw-bounty-hunters-underworld',
|
||||
},
|
||||
{
|
||||
label: 'Jedi & Sith Lore',
|
||||
value: 'sw-jedi-sith-lore',
|
||||
},
|
||||
{
|
||||
label: 'Droids & Creatures',
|
||||
value: 'sw-droids-creatures',
|
||||
},
|
||||
];
|
||||
static override get METADATA() {
|
||||
const supportedResources = [
|
||||
constants.CATALOG_RESOURCE,
|
||||
constants.META_RESOURCE,
|
||||
];
|
||||
|
||||
const options: Option[] = [
|
||||
...baseOptions(
|
||||
'Star Wars Universe',
|
||||
supportedResources,
|
||||
Env.DEFAULT_STAR_WARS_UNIVERSE_TIMEOUT
|
||||
).filter((option) => option.id !== 'url'),
|
||||
{
|
||||
id: 'catalogs',
|
||||
name: 'Catalogs',
|
||||
description: 'The catalogs to display',
|
||||
type: 'multi-select',
|
||||
required: true,
|
||||
options: this.catalogs,
|
||||
default: this.catalogs.map((catalog) => catalog.value),
|
||||
},
|
||||
];
|
||||
|
||||
return {
|
||||
ID: 'star-wars-universe',
|
||||
NAME: 'Star Wars Universe',
|
||||
LOGO: 'https://www.freeiconspng.com/uploads/logo-star-wars-png-4.png',
|
||||
URL: Env.DEFAULT_STAR_WARS_UNIVERSE_URL,
|
||||
TIMEOUT: Env.DEFAULT_STAR_WARS_UNIVERSE_TIMEOUT || Env.DEFAULT_TIMEOUT,
|
||||
USER_AGENT:
|
||||
Env.DEFAULT_STAR_WARS_UNIVERSE_USER_AGENT || Env.DEFAULT_USER_AGENT,
|
||||
SUPPORTED_SERVICES: [],
|
||||
DESCRIPTION:
|
||||
'Explore the Star Wars Universe by sagas, series, eras, and more!',
|
||||
OPTIONS: options,
|
||||
SUPPORTED_STREAM_TYPES: [],
|
||||
SUPPORTED_RESOURCES: supportedResources,
|
||||
};
|
||||
}
|
||||
|
||||
static async generateAddons(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Promise<Addon[]> {
|
||||
return [this.generateAddon(userData, options)];
|
||||
}
|
||||
|
||||
private static generateAddon(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Addon {
|
||||
const config =
|
||||
options.catalogs.length !== this.catalogs.length
|
||||
? options.catalogs.join('%2C')
|
||||
: '';
|
||||
return {
|
||||
name: options.name || this.METADATA.NAME,
|
||||
identifyingName: options.name || this.METADATA.NAME,
|
||||
manifestUrl: `${Env.DEFAULT_STAR_WARS_UNIVERSE_URL}/${config ? 'catalog/' + config + '/' : ''}manifest.json`,
|
||||
enabled: true,
|
||||
library: false,
|
||||
resources: options.resources || this.METADATA.SUPPORTED_RESOURCES,
|
||||
timeout: options.timeout || this.METADATA.TIMEOUT,
|
||||
fromPresetId: this.METADATA.ID,
|
||||
headers: {
|
||||
'User-Agent': this.METADATA.USER_AGENT,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,251 @@
|
||||
import { Addon, Option, UserData, Resource } from '../db';
|
||||
import { baseOptions, Preset } from './preset';
|
||||
import { Env } from '../utils';
|
||||
import { constants, ServiceId } from '../utils';
|
||||
|
||||
export class StreamFusionPreset extends Preset {
|
||||
static override get METADATA() {
|
||||
const supportedServices: ServiceId[] = [
|
||||
constants.REALDEBRID_SERVICE,
|
||||
constants.PREMIUMIZE_SERVICE,
|
||||
constants.ALLEDEBRID_SERVICE,
|
||||
constants.TORBOX_SERVICE,
|
||||
constants.EASYDEBRID_SERVICE,
|
||||
constants.DEBRIDLINK_SERVICE,
|
||||
constants.OFFCLOUD_SERVICE,
|
||||
constants.PIKPAK_SERVICE,
|
||||
];
|
||||
|
||||
const supportedResources = [
|
||||
constants.STREAM_RESOURCE,
|
||||
constants.CATALOG_RESOURCE,
|
||||
constants.META_RESOURCE,
|
||||
];
|
||||
|
||||
const options: Option[] = [
|
||||
...baseOptions(
|
||||
'StreamFusion',
|
||||
supportedResources,
|
||||
Env.DEFAULT_STREAMFUSION_TIMEOUT
|
||||
),
|
||||
{
|
||||
id: 'streamFusionApiKey',
|
||||
name: 'StreamFusion API Key',
|
||||
description:
|
||||
'The API key for the StreamFusion service. You can get it by sending the `/generate` command to the [StremioFR Telegram bot](https://t.me/Stremiofr_bot)',
|
||||
type: 'password',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
id: 'torboxSearch',
|
||||
name: 'Torbox Search',
|
||||
description:
|
||||
"Enable or disable the use of Torbox's Public Torrent Search Engine",
|
||||
type: 'boolean',
|
||||
required: false,
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
id: 'torboxUsenet',
|
||||
name: 'Torbox Usenet',
|
||||
description:
|
||||
"Enable or disable the use of Torbox's Usenet search and download functionality.",
|
||||
type: 'boolean',
|
||||
required: false,
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
id: 'catalogs',
|
||||
name: 'Catalogs',
|
||||
description: 'What catalogs should be displayed',
|
||||
type: 'multi-select',
|
||||
required: false,
|
||||
options: [
|
||||
{
|
||||
value: 'yggtorrent',
|
||||
label: 'YggTorrent',
|
||||
},
|
||||
{
|
||||
value: 'yggflix',
|
||||
label: 'YggFlix',
|
||||
},
|
||||
],
|
||||
default: ['yggtorrent', 'yggflix'],
|
||||
},
|
||||
{
|
||||
id: 'torrenting',
|
||||
name: 'Torrenting',
|
||||
description:
|
||||
"Use direct torrent streaming instead of debrid. If you haven't provided any debrid SERVICES, torrenting is automatically used and this option does not apply to you.",
|
||||
type: 'boolean',
|
||||
required: false,
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
id: 'services',
|
||||
name: 'Services',
|
||||
description:
|
||||
'Optionally override the services that are used. If not specified, then the services that are enabled and supported will be used.',
|
||||
type: 'multi-select',
|
||||
required: false,
|
||||
options: supportedServices.map((service) => ({
|
||||
value: service,
|
||||
label: constants.SERVICE_DETAILS[service].name,
|
||||
})),
|
||||
default: undefined,
|
||||
emptyIsUndefined: true,
|
||||
},
|
||||
];
|
||||
|
||||
return {
|
||||
ID: 'streamfusion',
|
||||
NAME: 'StreamFusion',
|
||||
LOGO: 'https://stream-fusion.stremiofr.com/static/logo-stream-fusion.png',
|
||||
URL: Env.DEFAULT_STREAMFUSION_URL,
|
||||
TIMEOUT: Env.DEFAULT_STREAMFUSION_TIMEOUT || Env.DEFAULT_TIMEOUT,
|
||||
USER_AGENT: Env.DEFAULT_STREAMFUSION_USER_AGENT || Env.DEFAULT_USER_AGENT,
|
||||
SUPPORTED_SERVICES: supportedServices,
|
||||
DESCRIPTION: 'Stremio addon focusing on french content',
|
||||
OPTIONS: options,
|
||||
SUPPORTED_STREAM_TYPES: [
|
||||
constants.DEBRID_STREAM_TYPE,
|
||||
constants.P2P_STREAM_TYPE,
|
||||
],
|
||||
SUPPORTED_RESOURCES: supportedResources,
|
||||
};
|
||||
}
|
||||
|
||||
static async generateAddons(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Promise<Addon[]> {
|
||||
if (options?.url?.endsWith('/manifest.json')) {
|
||||
return [this.generateAddon(userData, options, [])];
|
||||
}
|
||||
|
||||
const usableServices = this.getUsableServices(userData, options.services);
|
||||
if (!usableServices || usableServices.length === 0) {
|
||||
throw new Error(
|
||||
`${this.METADATA.NAME} requires at least one usable service from the list of supported services: ${this.METADATA.SUPPORTED_SERVICES.map((service) => constants.SERVICE_DETAILS[service].name).join(', ')}`
|
||||
);
|
||||
}
|
||||
|
||||
return [
|
||||
this.generateAddon(
|
||||
userData,
|
||||
options,
|
||||
usableServices.map((service) => service.id)
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
private static generateAddon(
|
||||
userData: UserData,
|
||||
options: Record<string, any>,
|
||||
serviceIds: ServiceId[]
|
||||
): Addon {
|
||||
return {
|
||||
name: options.name || this.METADATA.NAME,
|
||||
identifyingName: `${options.name || this.METADATA.NAME} ${serviceIds
|
||||
.map((serviceId) => constants.SERVICE_DETAILS[serviceId].shortName)
|
||||
.join(' | ')}`,
|
||||
manifestUrl: this.generateManifestUrl(userData, options, serviceIds),
|
||||
enabled: true,
|
||||
resources: options.resources || this.METADATA.SUPPORTED_RESOURCES,
|
||||
timeout: options.timeout || this.METADATA.TIMEOUT,
|
||||
fromPresetId: this.METADATA.ID,
|
||||
headers: {
|
||||
'User-Agent': this.METADATA.USER_AGENT,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private static generateManifestUrl(
|
||||
userData: UserData,
|
||||
options: Record<string, any>,
|
||||
serviceIds: ServiceId[]
|
||||
) {
|
||||
let url = options.url || this.METADATA.URL;
|
||||
if (url.endsWith('/manifest.json')) {
|
||||
return url;
|
||||
}
|
||||
|
||||
const specialCases = {
|
||||
[constants.OFFCLOUD_SERVICE]: (credentials: any) =>
|
||||
`${credentials.email}:${credentials.password}`,
|
||||
[constants.PIKPAK_SERVICE]: (credentials: any) =>
|
||||
`${credentials.email}:${credentials.password}`,
|
||||
};
|
||||
|
||||
url = url.replace(/\/$/, '');
|
||||
const configString = this.base64EncodeJSON({
|
||||
addonHost: options.url ? new URL(options.url).origin : this.METADATA.URL,
|
||||
apiKey: options.streamFusionApiKey,
|
||||
service: serviceIds.map(
|
||||
(serviceId) => constants.SERVICE_DETAILS[serviceId].name
|
||||
),
|
||||
// this probably doesnt work for RD and AD as configuration page uses oauth flow and puts json response from RD/AD as values.
|
||||
RDToken: serviceIds.includes(constants.REALDEBRID_SERVICE)
|
||||
? this.getServiceCredential(constants.REALDEBRID_SERVICE, userData)
|
||||
: '',
|
||||
ADToken: serviceIds.includes(constants.ALLEDEBRID_SERVICE)
|
||||
? this.getServiceCredential(constants.ALLEDEBRID_SERVICE, userData)
|
||||
: '',
|
||||
TBToken: serviceIds.includes(constants.TORBOX_SERVICE)
|
||||
? this.getServiceCredential(constants.TORBOX_SERVICE, userData)
|
||||
: '',
|
||||
PMToken: serviceIds.includes(constants.PREMIUMIZE_SERVICE)
|
||||
? this.getServiceCredential(constants.PREMIUMIZE_SERVICE, userData)
|
||||
: '',
|
||||
debridlinkApiKey: serviceIds.includes(constants.DEBRIDLINK_SERVICE)
|
||||
? this.getServiceCredential(constants.DEBRIDLINK_SERVICE, userData)
|
||||
: '',
|
||||
easydebridApiKey: serviceIds.includes(constants.EASYDEBRID_SERVICE)
|
||||
? this.getServiceCredential(constants.EASYDEBRID_SERVICE, userData)
|
||||
: '',
|
||||
offcloudCredentials: serviceIds.includes(constants.OFFCLOUD_SERVICE)
|
||||
? this.getServiceCredential(
|
||||
constants.OFFCLOUD_SERVICE,
|
||||
userData,
|
||||
specialCases
|
||||
)
|
||||
: '',
|
||||
pikpakCredentials: serviceIds.includes(constants.PIKPAK_SERVICE)
|
||||
? this.getServiceCredential(
|
||||
constants.PIKPAK_SERVICE,
|
||||
userData,
|
||||
specialCases
|
||||
)
|
||||
: '',
|
||||
TBUsenet: options.torboxUsenet,
|
||||
TBSearch: options.torboxSearch,
|
||||
maxSize: 18,
|
||||
exclusionKeywords: [],
|
||||
languages: ['en', 'fr', 'multi'],
|
||||
sort: 'quality',
|
||||
resultsPerQuality: 10,
|
||||
maxResults: 30,
|
||||
minCachedResults: 10,
|
||||
exclusion: [],
|
||||
cacheUrl: 'https://stremio-jackett-cacher.elfhosted.com/',
|
||||
cache: true,
|
||||
zilean: false, //true,
|
||||
yggflix: false, //true,
|
||||
sharewood: false, //true,
|
||||
yggtorrentCtg: options.catalogs?.includes('yggtorrent') ?? false,
|
||||
yggflixCtg: options.catalogs?.includes('yggflix') ?? false,
|
||||
torrenting:
|
||||
serviceIds.length === 0 ? true : (options.torrenting ?? false),
|
||||
debrid: serviceIds.length > 0,
|
||||
metadataProvider: 'tmdb',
|
||||
debridDownloader:
|
||||
serviceIds.length > 0
|
||||
? constants.SERVICE_DETAILS[serviceIds[0]].name
|
||||
: '',
|
||||
stremthru: true,
|
||||
stremthruUrl: Env.DEFAULT_STREAMFUSION_STREMTHRU_URL,
|
||||
});
|
||||
|
||||
return `${url}${configString ? '/' + configString : ''}/manifest.json`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
import { Addon, Option, UserData, Resource, Stream } from '../db';
|
||||
import { baseOptions, Preset } from './preset';
|
||||
import { Env } from '../utils';
|
||||
import { constants, ServiceId } from '../utils';
|
||||
import { StreamParser } from '../parser';
|
||||
|
||||
export class StremthruStorePreset extends Preset {
|
||||
static override get METADATA() {
|
||||
const supportedServices: ServiceId[] = [
|
||||
constants.REALDEBRID_SERVICE,
|
||||
constants.PREMIUMIZE_SERVICE,
|
||||
constants.ALLEDEBRID_SERVICE,
|
||||
constants.TORBOX_SERVICE,
|
||||
constants.EASYDEBRID_SERVICE,
|
||||
constants.DEBRIDLINK_SERVICE,
|
||||
constants.OFFCLOUD_SERVICE,
|
||||
constants.PIKPAK_SERVICE,
|
||||
];
|
||||
|
||||
const supportedResources = [
|
||||
constants.STREAM_RESOURCE,
|
||||
constants.CATALOG_RESOURCE,
|
||||
constants.META_RESOURCE,
|
||||
];
|
||||
|
||||
const options: Option[] = [
|
||||
...baseOptions(
|
||||
'StremThru Store',
|
||||
supportedResources,
|
||||
Env.DEFAULT_STREMTHRU_STORE_TIMEOUT
|
||||
),
|
||||
{
|
||||
id: 'services',
|
||||
name: 'Services',
|
||||
description:
|
||||
'Optionally override the services that are used. If not specified, then the services that are enabled and supported will be used.',
|
||||
type: 'multi-select',
|
||||
required: false,
|
||||
options: supportedServices.map((service) => ({
|
||||
value: service,
|
||||
label: constants.SERVICE_DETAILS[service].name,
|
||||
})),
|
||||
default: undefined,
|
||||
emptyIsUndefined: true,
|
||||
},
|
||||
{
|
||||
id: 'webDl',
|
||||
name: 'Web DL',
|
||||
description: 'Enable web DL',
|
||||
type: 'boolean',
|
||||
},
|
||||
];
|
||||
|
||||
return {
|
||||
ID: 'stremthruStore',
|
||||
NAME: 'StremThru Store',
|
||||
LOGO: 'https://emojiapi.dev/api/v1/sparkles/256.png',
|
||||
URL: Env.STREMTHRU_STORE_URL,
|
||||
TIMEOUT: Env.DEFAULT_STREMTHRU_STORE_TIMEOUT || Env.DEFAULT_TIMEOUT,
|
||||
USER_AGENT:
|
||||
Env.DEFAULT_STREMTHRU_STORE_USER_AGENT || Env.DEFAULT_USER_AGENT,
|
||||
SUPPORTED_SERVICES: supportedServices,
|
||||
DESCRIPTION: 'Access your debrid library through catalogs and streams.',
|
||||
OPTIONS: options,
|
||||
SUPPORTED_STREAM_TYPES: [constants.DEBRID_STREAM_TYPE],
|
||||
SUPPORTED_RESOURCES: supportedResources,
|
||||
};
|
||||
}
|
||||
|
||||
static async generateAddons(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Promise<Addon[]> {
|
||||
// url can either be something like https://torrentio.com/ or it can be a custom manifest url.
|
||||
// if it is a custom manifest url, return a single addon with the custom manifest url.
|
||||
if (options?.url?.endsWith('/manifest.json')) {
|
||||
return [this.generateAddon(userData, options, undefined)];
|
||||
}
|
||||
|
||||
const usableServices = this.getUsableServices(userData, options.services);
|
||||
// if no services are usable, throw an error
|
||||
if (!usableServices || usableServices.length === 0) {
|
||||
throw new Error(
|
||||
`${this.METADATA.NAME} requires at least one usable service, but none were found. Please enable at least one of the following services: ${this.METADATA.SUPPORTED_SERVICES.join(
|
||||
', '
|
||||
)}`
|
||||
);
|
||||
}
|
||||
|
||||
return usableServices.map((service) =>
|
||||
this.generateAddon(userData, options, service.id)
|
||||
);
|
||||
}
|
||||
|
||||
private static generateAddon(
|
||||
userData: UserData,
|
||||
options: Record<string, any>,
|
||||
serviceId?: ServiceId
|
||||
): Addon {
|
||||
return {
|
||||
name: options.name || this.METADATA.NAME,
|
||||
identifyingName: serviceId
|
||||
? `${options.name || this.METADATA.NAME} ${constants.SERVICE_DETAILS[serviceId].shortName}`
|
||||
: options.name || this.METADATA.NAME,
|
||||
manifestUrl: this.generateManifestUrl(userData, options, serviceId),
|
||||
enabled: true,
|
||||
library: true,
|
||||
resources: options.resources || this.METADATA.SUPPORTED_RESOURCES,
|
||||
timeout: options.timeout || this.METADATA.TIMEOUT,
|
||||
fromPresetId: this.METADATA.ID,
|
||||
headers: {
|
||||
'User-Agent': this.METADATA.USER_AGENT,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private static generateManifestUrl(
|
||||
userData: UserData,
|
||||
options: Record<string, any>,
|
||||
serviceId: ServiceId | undefined
|
||||
) {
|
||||
let url = options.url || this.METADATA.URL;
|
||||
if (url.endsWith('/manifest.json')) {
|
||||
return url;
|
||||
}
|
||||
url = url.replace(/\/$/, '');
|
||||
if (!serviceId) {
|
||||
throw new Error(
|
||||
`${this.METADATA.NAME} requires at least one service, but none were found. Please enable at least one of the following services: ${this.METADATA.SUPPORTED_SERVICES.join(
|
||||
', '
|
||||
)}`
|
||||
);
|
||||
}
|
||||
const configString = this.base64EncodeJSON({
|
||||
store_name: serviceId,
|
||||
store_token: this.getServiceCredential(serviceId, userData, {
|
||||
[constants.OFFCLOUD_SERVICE]: (credentials: any) =>
|
||||
`${credentials.email}:${credentials.password}`,
|
||||
[constants.PIKPAK_SERVICE]: (credentials: any) =>
|
||||
`${credentials.email}:${credentials.password}`,
|
||||
}),
|
||||
hide_catalog: false,
|
||||
hide_stream: false,
|
||||
web_dl: options.webDl ?? false,
|
||||
});
|
||||
|
||||
return `${url}${configString ? '/' + configString : ''}/manifest.json`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
import { Addon, Option, UserData, Resource, ParsedStream, Stream } from '../db';
|
||||
import { baseOptions, Preset } from './preset';
|
||||
import { Env } from '../utils';
|
||||
import { constants, ServiceId } from '../utils';
|
||||
import { StreamParser } from '../parser';
|
||||
|
||||
class StremthruTorzStreamParser extends StreamParser {
|
||||
// ensure release groups aren't misidentified as indexers
|
||||
protected override getIndexer(
|
||||
stream: Stream,
|
||||
currentParsedStream: ParsedStream
|
||||
): string | undefined {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export class StremthruTorzPreset extends Preset {
|
||||
static override getParser(): typeof StreamParser {
|
||||
return StremthruTorzStreamParser;
|
||||
}
|
||||
|
||||
static override get METADATA() {
|
||||
const supportedServices: ServiceId[] = [
|
||||
constants.REALDEBRID_SERVICE,
|
||||
constants.PREMIUMIZE_SERVICE,
|
||||
constants.ALLEDEBRID_SERVICE,
|
||||
constants.TORBOX_SERVICE,
|
||||
constants.EASYDEBRID_SERVICE,
|
||||
constants.DEBRIDLINK_SERVICE,
|
||||
constants.OFFCLOUD_SERVICE,
|
||||
constants.PIKPAK_SERVICE,
|
||||
];
|
||||
|
||||
const supportedResources = [constants.STREAM_RESOURCE];
|
||||
|
||||
const options: Option[] = [
|
||||
...baseOptions(
|
||||
'StremThru Torz',
|
||||
supportedResources,
|
||||
Env.DEFAULT_STREMTHRU_STORE_TIMEOUT
|
||||
),
|
||||
{
|
||||
id: 'services',
|
||||
name: 'Services',
|
||||
description:
|
||||
'Optionally override the services that are used. If not specified, then the services that are enabled and supported will be used.',
|
||||
type: 'multi-select',
|
||||
required: false,
|
||||
options: supportedServices.map((service) => ({
|
||||
value: service,
|
||||
label: constants.SERVICE_DETAILS[service].name,
|
||||
})),
|
||||
default: undefined,
|
||||
emptyIsUndefined: true,
|
||||
},
|
||||
{
|
||||
id: 'useMultipleInstances',
|
||||
name: 'Use Multiple Instances',
|
||||
description:
|
||||
'StremThru Torz supports multiple services in one instance of the addon - which is used by default. If this is enabled, then the addon will be created for each service.',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
];
|
||||
|
||||
return {
|
||||
ID: 'stremthruTorz',
|
||||
NAME: 'StremThru Torz',
|
||||
LOGO: 'https://emojiapi.dev/api/v1/sparkles/256.png',
|
||||
URL: Env.STREMTHRU_TORZ_URL,
|
||||
TIMEOUT: Env.DEFAULT_STREMTHRU_TORZ_TIMEOUT || Env.DEFAULT_TIMEOUT,
|
||||
USER_AGENT:
|
||||
Env.DEFAULT_STREMTHRU_TORZ_USER_AGENT || Env.DEFAULT_USER_AGENT,
|
||||
SUPPORTED_SERVICES: supportedServices,
|
||||
DESCRIPTION:
|
||||
'Access a crowdsourced torrent library supplemented by DMM hashlists',
|
||||
OPTIONS: options,
|
||||
SUPPORTED_STREAM_TYPES: [constants.DEBRID_STREAM_TYPE],
|
||||
SUPPORTED_RESOURCES: supportedResources,
|
||||
};
|
||||
}
|
||||
|
||||
static async generateAddons(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Promise<Addon[]> {
|
||||
// url can either be something like https://torrentio.com/ or it can be a custom manifest url.
|
||||
// if it is a custom manifest url, return a single addon with the custom manifest url.
|
||||
if (options?.url?.endsWith('/manifest.json')) {
|
||||
return [this.generateAddon(userData, options, [])];
|
||||
}
|
||||
|
||||
const usableServices = this.getUsableServices(userData, options.services);
|
||||
// if no services are usable, throw an error
|
||||
if (!usableServices || usableServices.length === 0) {
|
||||
throw new Error(
|
||||
`${this.METADATA.NAME} requires at least one usable service, but none were found. Please enable at least one of the following services: ${this.METADATA.SUPPORTED_SERVICES.join(
|
||||
', '
|
||||
)}`
|
||||
);
|
||||
}
|
||||
|
||||
if (options.useMultipleInstances) {
|
||||
return usableServices.map((service) =>
|
||||
this.generateAddon(userData, options, [service.id])
|
||||
);
|
||||
}
|
||||
|
||||
return [
|
||||
this.generateAddon(
|
||||
userData,
|
||||
options,
|
||||
usableServices.map((s) => s.id)
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
private static generateAddon(
|
||||
userData: UserData,
|
||||
options: Record<string, any>,
|
||||
serviceIds: ServiceId[]
|
||||
): Addon {
|
||||
return {
|
||||
name: options.name || this.METADATA.NAME,
|
||||
identifyingName: `${options.name || this.METADATA.NAME} ${serviceIds.map((id) => constants.SERVICE_DETAILS[id].shortName).join(' | ')}`,
|
||||
manifestUrl: this.generateManifestUrl(userData, options, serviceIds),
|
||||
enabled: true,
|
||||
resources: options.resources || this.METADATA.SUPPORTED_RESOURCES,
|
||||
timeout: options.timeout || this.METADATA.TIMEOUT,
|
||||
fromPresetId: this.METADATA.ID,
|
||||
headers: {
|
||||
'User-Agent': this.METADATA.USER_AGENT,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private static generateManifestUrl(
|
||||
userData: UserData,
|
||||
options: Record<string, any>,
|
||||
serviceIds: ServiceId[]
|
||||
) {
|
||||
let url = options.url || this.METADATA.URL;
|
||||
if (url.endsWith('/manifest.json')) {
|
||||
return url;
|
||||
}
|
||||
url = url.replace(/\/$/, '');
|
||||
if (!serviceIds || serviceIds.length === 0) {
|
||||
throw new Error(
|
||||
`${this.METADATA.NAME} requires at least one service, but none were found. Please enable at least one of the following services: ${this.METADATA.SUPPORTED_SERVICES.join(
|
||||
', '
|
||||
)}`
|
||||
);
|
||||
}
|
||||
const configString = this.base64EncodeJSON({
|
||||
stores: serviceIds.map((serviceId) => ({
|
||||
c:
|
||||
serviceId === constants.PIKPAK_SERVICE
|
||||
? 'pp'
|
||||
: constants.SERVICE_DETAILS[serviceId].shortName.toLowerCase(),
|
||||
t: this.getServiceCredential(serviceId, userData, {
|
||||
[constants.OFFCLOUD_SERVICE]: (credentials: any) =>
|
||||
`${credentials.email}:${credentials.password}`,
|
||||
[constants.PIKPAK_SERVICE]: (credentials: any) =>
|
||||
`${credentials.email}:${credentials.password}`,
|
||||
}),
|
||||
})),
|
||||
});
|
||||
|
||||
return `${url}${configString ? '/' + configString : ''}/manifest.json`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
import { Addon, Option, UserData } from '../db';
|
||||
import { Preset, baseOptions } from './preset';
|
||||
import { constants, Env, FULL_LANGUAGE_MAPPING } from '../utils';
|
||||
|
||||
export class TmdbCollectionsPreset extends Preset {
|
||||
static override get METADATA() {
|
||||
const supportedResources = [
|
||||
constants.CATALOG_RESOURCE,
|
||||
constants.META_RESOURCE,
|
||||
];
|
||||
|
||||
const options: Option[] = [
|
||||
...baseOptions(
|
||||
'TMDB Collections',
|
||||
supportedResources,
|
||||
Env.DEFAULT_TMDB_COLLECTIONS_TIMEOUT
|
||||
),
|
||||
{
|
||||
id: 'enableAdultContent',
|
||||
name: 'Enable Adult Content',
|
||||
description: 'Enable adult content in the catalogs',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
required: false,
|
||||
},
|
||||
{
|
||||
id: 'enableSearch',
|
||||
name: 'Enable Search',
|
||||
description: 'Enable search in the catalogs',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
required: false,
|
||||
},
|
||||
{
|
||||
id: 'language',
|
||||
name: 'Language',
|
||||
description: 'The language of the catalogs',
|
||||
type: 'select',
|
||||
default: 'en',
|
||||
options: FULL_LANGUAGE_MAPPING.sort((a, b) =>
|
||||
a.english_name.localeCompare(b.english_name)
|
||||
)
|
||||
.filter(
|
||||
(language, index, self) =>
|
||||
index ===
|
||||
self.findIndex((l) => l.iso_639_1 === language.iso_639_1)
|
||||
)
|
||||
.map((language) => ({
|
||||
label: language.english_name.split('(')[0].trim(),
|
||||
value: `${language.iso_639_1}`,
|
||||
})),
|
||||
required: false,
|
||||
},
|
||||
];
|
||||
|
||||
return {
|
||||
ID: 'tmdb-collections',
|
||||
NAME: 'TMDB Collections',
|
||||
LOGO: 'https://raw.githubusercontent.com/youchi1/tmdb-collections/main/Images/logo.png',
|
||||
URL: Env.TMDB_COLLECTIONS_URL,
|
||||
TIMEOUT: Env.DEFAULT_TMDB_COLLECTIONS_TIMEOUT || Env.DEFAULT_TIMEOUT,
|
||||
USER_AGENT:
|
||||
Env.DEFAULT_TMDB_COLLECTIONS_USER_AGENT || Env.DEFAULT_USER_AGENT,
|
||||
SUPPORTED_SERVICES: [],
|
||||
DESCRIPTION: 'Catalogs for the TMDB Collections',
|
||||
OPTIONS: options,
|
||||
SUPPORTED_STREAM_TYPES: [],
|
||||
SUPPORTED_RESOURCES: supportedResources,
|
||||
};
|
||||
}
|
||||
|
||||
static async generateAddons(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Promise<Addon[]> {
|
||||
return [this.generateAddon(userData, options)];
|
||||
}
|
||||
|
||||
private static generateAddon(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Addon {
|
||||
const config = this.urlEncodeJSON({
|
||||
enableAdultContent: options.enableAdultContent ?? false,
|
||||
enableSearch: options.enableSearch ?? true,
|
||||
language: options.language,
|
||||
catalogList: ['popular', 'topRated', 'newReleases'],
|
||||
discoverOnly: { popular: false, topRated: false, newReleases: false },
|
||||
});
|
||||
return {
|
||||
name: options.name || this.METADATA.NAME,
|
||||
identifyingName: options.name || this.METADATA.NAME,
|
||||
manifestUrl: `${this.METADATA.URL}/${config}/manifest.json`,
|
||||
enabled: true,
|
||||
library: false,
|
||||
resources: options.resources || this.METADATA.SUPPORTED_RESOURCES,
|
||||
timeout: options.timeout || this.METADATA.TIMEOUT,
|
||||
fromPresetId: this.METADATA.ID,
|
||||
headers: {
|
||||
'User-Agent': this.METADATA.USER_AGENT,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
import { Addon, Option, UserData, Resource, ParsedStream } from '../db';
|
||||
import { baseOptions, Preset } from './preset';
|
||||
import { Env } from '../utils';
|
||||
import { constants, ServiceId } from '../utils';
|
||||
import { StreamParser } from '../parser';
|
||||
import { Stream } from '../db';
|
||||
|
||||
class TorboxStreamParser extends StreamParser {
|
||||
override getSeeders(
|
||||
stream: Stream,
|
||||
currentParsedStream: ParsedStream
|
||||
): number | undefined {
|
||||
return (stream as any).seeders && (stream as any).seeders >= 0
|
||||
? (stream as any).seeders
|
||||
: undefined;
|
||||
}
|
||||
override get ageRegex() {
|
||||
return /\|\sAge:\s([0-9]+[dmyh])/i;
|
||||
}
|
||||
override get indexerRegex() {
|
||||
return /Source:\s*([^\n]+)/;
|
||||
}
|
||||
override getInfoHash(
|
||||
stream: Stream,
|
||||
currentParsedStream: ParsedStream
|
||||
): string | undefined {
|
||||
return (stream as any).hash;
|
||||
}
|
||||
override getInLibrary(
|
||||
stream: Stream,
|
||||
currentParsedStream: ParsedStream
|
||||
): boolean {
|
||||
return (stream as any).is_your_media || stream.name?.includes('Your Media');
|
||||
}
|
||||
protected override getService(
|
||||
stream: Stream,
|
||||
currentParsedStream: ParsedStream
|
||||
): ParsedStream['service'] | undefined {
|
||||
return {
|
||||
id: constants.TORBOX_SERVICE,
|
||||
cached: (stream as any).is_cached ?? true,
|
||||
};
|
||||
}
|
||||
|
||||
protected override getMessage(
|
||||
stream: Stream,
|
||||
currentParsedStream: ParsedStream
|
||||
): string | undefined {
|
||||
if (stream.description?.includes('Click play to start')) {
|
||||
currentParsedStream.filename = undefined;
|
||||
return 'Click play to start streaming your media';
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
protected override getStreamType(
|
||||
stream: Stream,
|
||||
service: ParsedStream['service'],
|
||||
currentParsedStream: ParsedStream
|
||||
): ParsedStream['type'] {
|
||||
if ((stream as any).type === 'usenet') {
|
||||
return constants.USENET_STREAM_TYPE;
|
||||
}
|
||||
const type = stream.description?.match(/Type:\s*([^\n\s]+)/)?.[1];
|
||||
if (type) {
|
||||
if (type.includes('Torrent')) {
|
||||
return constants.DEBRID_STREAM_TYPE;
|
||||
} else if (type.includes('Usenet')) {
|
||||
return constants.USENET_STREAM_TYPE;
|
||||
}
|
||||
}
|
||||
return super.getStreamType(stream, service, currentParsedStream);
|
||||
}
|
||||
}
|
||||
|
||||
export class TorboxAddonPreset extends Preset {
|
||||
static override getParser(): typeof StreamParser {
|
||||
return TorboxStreamParser;
|
||||
}
|
||||
|
||||
static override get METADATA() {
|
||||
const supportedServices: ServiceId[] = [constants.TORBOX_SERVICE];
|
||||
|
||||
const supportedResources = [
|
||||
constants.STREAM_RESOURCE,
|
||||
constants.META_RESOURCE,
|
||||
constants.CATALOG_RESOURCE,
|
||||
];
|
||||
|
||||
const options: Option[] = [
|
||||
...baseOptions('TorBox', supportedResources, Env.DEFAULT_TORBOX_TIMEOUT),
|
||||
];
|
||||
|
||||
return {
|
||||
ID: 'torbox',
|
||||
NAME: 'TorBox',
|
||||
LOGO: 'https://torbox.app/android-chrome-512x512.png',
|
||||
URL: Env.TORBOX_STREMIO_URL,
|
||||
TIMEOUT: Env.DEFAULT_TORBOX_TIMEOUT || Env.DEFAULT_TIMEOUT,
|
||||
USER_AGENT: Env.DEFAULT_TORBOX_USER_AGENT || Env.DEFAULT_USER_AGENT,
|
||||
SUPPORTED_SERVICES: supportedServices,
|
||||
DESCRIPTION:
|
||||
'Provides torrent and usenet streams for users of TorBox.app',
|
||||
OPTIONS: options,
|
||||
SUPPORTED_STREAM_TYPES: [
|
||||
constants.DEBRID_STREAM_TYPE,
|
||||
constants.USENET_STREAM_TYPE,
|
||||
],
|
||||
SUPPORTED_RESOURCES: supportedResources,
|
||||
};
|
||||
}
|
||||
|
||||
static async generateAddons(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Promise<Addon[]> {
|
||||
return [this.generateAddon(userData, options)];
|
||||
}
|
||||
|
||||
private static generateAddon(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Addon {
|
||||
return {
|
||||
name: options.name || this.METADATA.NAME,
|
||||
identifyingName: options.name || this.METADATA.NAME,
|
||||
manifestUrl: this.generateManifestUrl(userData, options),
|
||||
enabled: true,
|
||||
resources: options.resources || this.METADATA.SUPPORTED_RESOURCES,
|
||||
timeout: options.timeout || this.METADATA.TIMEOUT,
|
||||
fromPresetId: this.METADATA.ID,
|
||||
headers: {
|
||||
'User-Agent': this.METADATA.USER_AGENT,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private static generateManifestUrl(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
) {
|
||||
let url = options.url || this.METADATA.URL;
|
||||
if (url.endsWith('/manifest.json')) {
|
||||
return url;
|
||||
}
|
||||
url = url.replace(/\/$/, '');
|
||||
const torboxApiKey = this.getServiceCredential(
|
||||
constants.TORBOX_SERVICE,
|
||||
userData
|
||||
);
|
||||
if (!torboxApiKey) {
|
||||
throw new Error(
|
||||
`${this.METADATA.NAME} requires the Torbox service to be enabled.`
|
||||
);
|
||||
}
|
||||
|
||||
return `${url}/${torboxApiKey}/manifest.json`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import { Addon, Option, UserData } from '../db';
|
||||
import { Preset, baseOptions } from './preset';
|
||||
import { constants, Env } from '../utils';
|
||||
|
||||
export class TorrentCatalogsPreset extends Preset {
|
||||
static override get METADATA() {
|
||||
const supportedResources = [constants.CATALOG_RESOURCE];
|
||||
|
||||
const options: Option[] = [
|
||||
...baseOptions(
|
||||
'Torrent Catalogs',
|
||||
supportedResources,
|
||||
Env.DEFAULT_TORRENT_CATALOGS_TIMEOUT
|
||||
).filter((option) => option.id !== 'url'),
|
||||
];
|
||||
|
||||
return {
|
||||
ID: 'torrent-catalogs',
|
||||
NAME: 'Torrent Catalogs',
|
||||
LOGO: 'https://i.ibb.co/w4BnkC9/GwxAcDV.png',
|
||||
URL: Env.TORRENT_CATALOGS_URL,
|
||||
TIMEOUT: Env.DEFAULT_TORRENT_CATALOGS_TIMEOUT || Env.DEFAULT_TIMEOUT,
|
||||
USER_AGENT:
|
||||
Env.DEFAULT_TORRENT_CATALOGS_USER_AGENT || Env.DEFAULT_USER_AGENT,
|
||||
SUPPORTED_SERVICES: [],
|
||||
DESCRIPTION:
|
||||
'Provides catalogs for movies/series/anime based on top seeded torrents. Requires Kitsu addon for anime.',
|
||||
OPTIONS: options,
|
||||
SUPPORTED_STREAM_TYPES: [],
|
||||
SUPPORTED_RESOURCES: supportedResources,
|
||||
};
|
||||
}
|
||||
|
||||
static async generateAddons(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Promise<Addon[]> {
|
||||
return [this.generateAddon(userData, options)];
|
||||
}
|
||||
|
||||
private static generateAddon(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Addon {
|
||||
return {
|
||||
name: options.name || this.METADATA.NAME,
|
||||
identifyingName: options.name || this.METADATA.NAME,
|
||||
manifestUrl: `${Env.TORRENT_CATALOGS_URL}/manifest.json`,
|
||||
enabled: true,
|
||||
library: false,
|
||||
resources: options.resources || this.METADATA.SUPPORTED_RESOURCES,
|
||||
timeout: options.timeout || this.METADATA.TIMEOUT,
|
||||
fromPresetId: this.METADATA.ID,
|
||||
headers: {
|
||||
'User-Agent': this.METADATA.USER_AGENT,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
import { Addon, Option, UserData, Resource, Stream, ParsedStream } from '../db';
|
||||
import { Preset, baseOptions } from './preset';
|
||||
import { Env, SERVICE_DETAILS } from '../utils';
|
||||
import { constants, ServiceId } from '../utils';
|
||||
import { StreamParser } from '../parser';
|
||||
|
||||
export class TorrentioParser extends StreamParser {
|
||||
override getFolder(stream: Stream): string | undefined {
|
||||
const description = stream.description || stream.title;
|
||||
if (!description) {
|
||||
return undefined;
|
||||
}
|
||||
const folderName = description.split('\n')[0];
|
||||
return folderName;
|
||||
}
|
||||
|
||||
protected override getLanguages(
|
||||
stream: Stream,
|
||||
currentParsedStream: ParsedStream
|
||||
): string[] {
|
||||
if (stream.description?.includes('Multi Subs')) {
|
||||
return [];
|
||||
}
|
||||
return super.getLanguages(stream, currentParsedStream);
|
||||
}
|
||||
}
|
||||
|
||||
export class TorrentioPreset extends Preset {
|
||||
static override getParser(): typeof StreamParser {
|
||||
return TorrentioParser;
|
||||
}
|
||||
|
||||
static override get METADATA() {
|
||||
const supportedServices: ServiceId[] = [
|
||||
constants.REALDEBRID_SERVICE,
|
||||
constants.PREMIUMIZE_SERVICE,
|
||||
constants.ALLEDEBRID_SERVICE,
|
||||
constants.TORBOX_SERVICE,
|
||||
constants.EASYDEBRID_SERVICE,
|
||||
constants.PUTIO_SERVICE,
|
||||
constants.DEBRIDLINK_SERVICE,
|
||||
constants.OFFCLOUD_SERVICE,
|
||||
];
|
||||
const supportedResources = [
|
||||
constants.STREAM_RESOURCE,
|
||||
constants.CATALOG_RESOURCE,
|
||||
constants.META_RESOURCE,
|
||||
];
|
||||
|
||||
const options: Option[] = [
|
||||
...baseOptions(
|
||||
'Torrentio',
|
||||
supportedResources,
|
||||
Env.DEFAULT_TORRENTIO_TIMEOUT
|
||||
),
|
||||
{
|
||||
id: 'services',
|
||||
name: 'Services',
|
||||
description:
|
||||
'Optionally override the services that are used. If not specified, then the services that are enabled and supported will be used.',
|
||||
type: 'multi-select',
|
||||
required: false,
|
||||
options: supportedServices.map((service) => ({
|
||||
value: service,
|
||||
label: constants.SERVICE_DETAILS[service].name,
|
||||
})),
|
||||
default: undefined,
|
||||
emptyIsUndefined: true,
|
||||
},
|
||||
{
|
||||
id: 'useMultipleInstances',
|
||||
name: 'Use Multiple Instances',
|
||||
description:
|
||||
'When using multiple services, use a different Torrentio addon for each service, rather than using one instance for all services',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
required: true,
|
||||
},
|
||||
];
|
||||
|
||||
return {
|
||||
ID: 'torrentio',
|
||||
NAME: 'Torrentio',
|
||||
LOGO: `${Env.TORRENTIO_URL}/images/logo_v1.png`,
|
||||
URL: Env.TORRENTIO_URL,
|
||||
TIMEOUT: Env.DEFAULT_TORRENTIO_TIMEOUT || Env.DEFAULT_TIMEOUT,
|
||||
USER_AGENT: Env.DEFAULT_TORRENTIO_USER_AGENT || Env.DEFAULT_USER_AGENT,
|
||||
SUPPORTED_SERVICES: supportedServices,
|
||||
REQUIRES_SERVICE: false,
|
||||
DESCRIPTION:
|
||||
'Provides torrent streams from a multitude of providers and has debrid support.',
|
||||
OPTIONS: options,
|
||||
SUPPORTED_STREAM_TYPES: [
|
||||
constants.P2P_STREAM_TYPE,
|
||||
constants.DEBRID_STREAM_TYPE,
|
||||
],
|
||||
SUPPORTED_RESOURCES: [
|
||||
constants.STREAM_RESOURCE,
|
||||
constants.META_RESOURCE,
|
||||
constants.CATALOG_RESOURCE,
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
static async generateAddons(
|
||||
userData: UserData,
|
||||
options: Record<string, any>
|
||||
): Promise<Addon[]> {
|
||||
// baseUrl can either be something like https://torrentio.com/ or it can be a custom manifest url.
|
||||
// if it is a custom manifest url, return a single addon with the custom manifest url.
|
||||
if (options?.url?.endsWith('/manifest.json')) {
|
||||
return [this.generateAddon(userData, options, [])];
|
||||
}
|
||||
|
||||
const usableServices = this.getUsableServices(userData, options.services);
|
||||
|
||||
// if no services are usable, return a single addon with no services
|
||||
if (!usableServices || usableServices.length === 0) {
|
||||
return [this.generateAddon(userData, options, [])];
|
||||
}
|
||||
|
||||
// if user has specified useMultipleInstances, return a single addon for each service
|
||||
if (options?.useMultipleInstances) {
|
||||
return usableServices.map((service) =>
|
||||
this.generateAddon(userData, options, [service.id])
|
||||
);
|
||||
}
|
||||
|
||||
// return a single addon with all usable services
|
||||
return [
|
||||
this.generateAddon(
|
||||
userData,
|
||||
options,
|
||||
usableServices.map((service) => service.id)
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
private static generateAddon(
|
||||
userData: UserData,
|
||||
options: Record<string, any>,
|
||||
services: ServiceId[]
|
||||
): Addon {
|
||||
return {
|
||||
name: options.name || this.METADATA.NAME,
|
||||
identifyingName: `${options.name || this.METADATA.NAME} ${services.map((id) => constants.SERVICE_DETAILS[id].shortName).join(' | ')}`,
|
||||
manifestUrl: this.generateManifestUrl(userData, services, options.url),
|
||||
enabled: true,
|
||||
resources: options.resources || this.METADATA.SUPPORTED_RESOURCES,
|
||||
timeout: options.timeout || this.METADATA.TIMEOUT,
|
||||
fromPresetId: this.METADATA.ID,
|
||||
headers: {
|
||||
'User-Agent': this.METADATA.USER_AGENT,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private static generateManifestUrl(
|
||||
userData: UserData,
|
||||
services: ServiceId[],
|
||||
url?: string
|
||||
) {
|
||||
url = url || this.METADATA.URL;
|
||||
if (url.endsWith('/manifest.json')) {
|
||||
return url;
|
||||
}
|
||||
|
||||
const configString = services.length
|
||||
? this.urlEncodeKeyValuePairs(
|
||||
services.map((service) => [
|
||||
service,
|
||||
this.getServiceCredential(service, userData, {
|
||||
[constants.PUTIO_SERVICE]: (credentials: any) =>
|
||||
`${credentials.clientId}@${credentials.token}`,
|
||||
}),
|
||||
])
|
||||
)
|
||||
: '';
|
||||
|
||||
return `${url}${configString ? '/' + configString : ''}/manifest.json`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
import { StreamProxyConfig } from '../db';
|
||||
import { Cache, createLogger, maskSensitiveInfo, Env } from '../utils';
|
||||
|
||||
const logger = createLogger('proxy');
|
||||
const cache = Cache.getInstance<string, string>('publicIp');
|
||||
|
||||
export interface ProxyStream {
|
||||
url: string;
|
||||
filename?: string;
|
||||
headers?: {
|
||||
request?: Record<string, string>;
|
||||
response?: Record<string, string>;
|
||||
};
|
||||
}
|
||||
|
||||
type ValidatedStreamProxyConfig = StreamProxyConfig & {
|
||||
id: 'mediaflow' | 'stremthru';
|
||||
url: string;
|
||||
credentials: string;
|
||||
};
|
||||
|
||||
export abstract class BaseProxy {
|
||||
protected readonly config: ValidatedStreamProxyConfig;
|
||||
private readonly PRIVATE_CIDR =
|
||||
/^(10\.|127\.|172\.(1[6-9]|2[0-9]|3[01])\.|192\.168\.)/;
|
||||
|
||||
constructor(config: StreamProxyConfig) {
|
||||
if (!config.id || !config.credentials || !config.url) {
|
||||
throw new Error('Proxy configuration is missing');
|
||||
}
|
||||
|
||||
this.config = {
|
||||
enabled: config.enabled ?? false,
|
||||
id: config.id,
|
||||
url: config.url,
|
||||
credentials: config.credentials,
|
||||
publicIp: config.publicIp,
|
||||
proxiedAddons: config.proxiedAddons,
|
||||
proxiedServices: config.proxiedServices,
|
||||
};
|
||||
}
|
||||
|
||||
public getConfig(): StreamProxyConfig {
|
||||
return this.config;
|
||||
}
|
||||
|
||||
protected abstract generateProxyUrl(endpoint: string): URL;
|
||||
protected abstract getPublicIpEndpoint(): string;
|
||||
protected abstract getPublicIpFromResponse(data: any): string | null;
|
||||
protected abstract generateStreamUrls(
|
||||
streams: ProxyStream[]
|
||||
): Promise<string[] | null>;
|
||||
|
||||
public async getPublicIp(): Promise<string | null> {
|
||||
if (!this.config.url) {
|
||||
logger.error('Proxy URL is missing');
|
||||
throw new Error('Proxy URL is missing');
|
||||
}
|
||||
|
||||
if (this.config.publicIp) {
|
||||
return this.config.publicIp;
|
||||
}
|
||||
|
||||
const proxyUrl = new URL(this.config.url.replace(/\/$/, ''));
|
||||
if (this.PRIVATE_CIDR.test(proxyUrl.hostname)) {
|
||||
logger.error('Proxy URL is a private IP address, returning null');
|
||||
return null;
|
||||
}
|
||||
|
||||
const cacheKey = `${this.config.id}:${this.config.url}:${this.config.credentials}`;
|
||||
const cachedPublicIp = cache ? cache.get(cacheKey) : null;
|
||||
if (cachedPublicIp) {
|
||||
logger.debug('Returning cached public IP');
|
||||
return cachedPublicIp;
|
||||
}
|
||||
|
||||
const ipUrl = this.generateProxyUrl(this.getPublicIpEndpoint());
|
||||
|
||||
if (Env.LOG_SENSITIVE_INFO) {
|
||||
logger.debug(`GET ${ipUrl.toString()}`);
|
||||
} else {
|
||||
logger.debug(
|
||||
`GET ${ipUrl.protocol}://${maskSensitiveInfo(ipUrl.hostname)}${ipUrl.port ? `:${ipUrl.port}` : ''}${ipUrl.pathname}`
|
||||
);
|
||||
}
|
||||
|
||||
const response = await fetch(ipUrl.toString(), {
|
||||
method: 'GET',
|
||||
headers: this.getHeaders(),
|
||||
signal: AbortSignal.timeout(30000), // 30 second timeout
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`${response.status}: ${response.statusText}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
const publicIp = this.getPublicIpFromResponse(data);
|
||||
|
||||
if (publicIp && cache) {
|
||||
cache.set(cacheKey, publicIp, 900); // 15 minute cache
|
||||
} else {
|
||||
logger.error(
|
||||
`Proxy did not respond with a public IP. Response: ${JSON.stringify(data)}`
|
||||
);
|
||||
throw new Error('Proxy did not respond with a public IP');
|
||||
}
|
||||
|
||||
return publicIp;
|
||||
}
|
||||
|
||||
protected abstract getHeaders(): Record<string, string>;
|
||||
|
||||
public async generateUrls(streams: ProxyStream[]): Promise<string[] | null> {
|
||||
if (!streams.length) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (!this.config) {
|
||||
throw new Error('Proxy configuration is missing');
|
||||
}
|
||||
|
||||
try {
|
||||
return await this.generateStreamUrls(streams);
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
`Failed to generate proxy URLs: ${error instanceof Error ? error.message : String(error)}`
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
export * from './base';
|
||||
export * from './mediaflow';
|
||||
export * from './stremthru';
|
||||
|
||||
import { constants } from '../utils';
|
||||
import { BaseProxy } from './base';
|
||||
import { MediaFlowProxy } from './mediaflow';
|
||||
import { StremThruProxy } from './stremthru';
|
||||
import { StreamProxyConfig } from '../db';
|
||||
|
||||
export function createProxy(config: StreamProxyConfig): BaseProxy {
|
||||
switch (config.id) {
|
||||
case constants.MEDIAFLOW_SERVICE:
|
||||
return new MediaFlowProxy(config);
|
||||
case constants.STREMTHRU_SERVICE:
|
||||
return new StremThruProxy(config);
|
||||
default:
|
||||
throw new Error(`Unknown proxy type: ${config.id}`);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
import { BaseProxy, ProxyStream } from './base';
|
||||
import { createLogger, maskSensitiveInfo, Env } from '../utils';
|
||||
import path from 'path';
|
||||
|
||||
const logger = createLogger('mediaflow');
|
||||
|
||||
export class MediaFlowProxy extends BaseProxy {
|
||||
protected generateProxyUrl(endpoint: string): URL {
|
||||
const proxyUrl = new URL(this.config.url.replace(/\/$/, ''));
|
||||
proxyUrl.pathname = `${proxyUrl.pathname === '/' ? '' : proxyUrl.pathname}${endpoint}`;
|
||||
if (endpoint === '/proxy/ip') {
|
||||
proxyUrl.searchParams.set('api_password', this.config.credentials);
|
||||
}
|
||||
return proxyUrl;
|
||||
}
|
||||
|
||||
protected getPublicIpEndpoint(): string {
|
||||
return '/proxy/ip';
|
||||
}
|
||||
|
||||
protected getPublicIpFromResponse(data: any): string | null {
|
||||
return data.ip || null;
|
||||
}
|
||||
|
||||
protected getHeaders(): Record<string, string> {
|
||||
return {
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
}
|
||||
|
||||
protected async generateStreamUrls(
|
||||
streams: ProxyStream[]
|
||||
): Promise<string[] | null> {
|
||||
const proxyUrl = this.generateProxyUrl('/generate_urls');
|
||||
|
||||
const data = {
|
||||
mediaflow_proxy_url: this.config.url.replace(/\/$/, ''),
|
||||
api_password: Env.ENCRYPT_MEDIAFLOW_URLS
|
||||
? this.config.credentials
|
||||
: undefined,
|
||||
urls: streams.map((stream) => ({
|
||||
endpoint: '/proxy/stream',
|
||||
filename: stream.filename || path.basename(stream.url),
|
||||
query_params: Env.ENCRYPT_MEDIAFLOW_URLS
|
||||
? undefined
|
||||
: {
|
||||
api_password: this.config.credentials,
|
||||
},
|
||||
destination_url: stream.url,
|
||||
request_headers: stream.headers?.request,
|
||||
response_headers: stream.headers?.response,
|
||||
})),
|
||||
};
|
||||
|
||||
if (Env.LOG_SENSITIVE_INFO) {
|
||||
logger.debug(`POST ${proxyUrl.toString()}`);
|
||||
} else {
|
||||
logger.debug(
|
||||
`POST ${proxyUrl.protocol}://${maskSensitiveInfo(proxyUrl.hostname)}${proxyUrl.port ? `:${proxyUrl.port}` : ''}/generate_urls`
|
||||
);
|
||||
}
|
||||
|
||||
const response = await fetch(proxyUrl.toString(), {
|
||||
method: 'POST',
|
||||
headers: this.getHeaders(),
|
||||
body: JSON.stringify(data),
|
||||
signal: AbortSignal.timeout(30000),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`${response.status}: ${response.statusText}`);
|
||||
}
|
||||
|
||||
let responseData: any;
|
||||
try {
|
||||
responseData = await response.json();
|
||||
} catch (error) {
|
||||
const text = await response.text();
|
||||
logger.debug(`Response body: ${text}`);
|
||||
throw new Error('Failed to parse JSON response from MediaFlow');
|
||||
}
|
||||
|
||||
if (responseData.error) {
|
||||
throw new Error(responseData.error);
|
||||
}
|
||||
|
||||
if (responseData.urls) {
|
||||
return responseData.urls;
|
||||
} else {
|
||||
throw new Error('No URLs were returned from MediaFlow');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
import { BaseProxy, ProxyStream } from './base';
|
||||
import { createLogger, maskSensitiveInfo, Env } from '../utils';
|
||||
|
||||
const logger = createLogger('stremthru');
|
||||
|
||||
export class StremThruProxy extends BaseProxy {
|
||||
protected generateProxyUrl(endpoint: string): URL {
|
||||
const proxyUrl = new URL(this.config.url.replace(/\/$/, ''));
|
||||
proxyUrl.pathname = `${proxyUrl.pathname === '/' ? '' : proxyUrl.pathname}${endpoint}`;
|
||||
return proxyUrl;
|
||||
}
|
||||
|
||||
protected getPublicIpEndpoint(): string {
|
||||
return '/v0/health/__debug__';
|
||||
}
|
||||
|
||||
protected getPublicIpFromResponse(data: any): string | null {
|
||||
return typeof data.data?.ip?.exposed === 'object'
|
||||
? data.data.ip.exposed['*'] || data.data.ip.machine
|
||||
: data.data?.ip?.machine || null;
|
||||
}
|
||||
|
||||
protected getHeaders(): Record<string, string> {
|
||||
const headers: Record<string, string> = {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
};
|
||||
|
||||
if (Env.ENCRYPT_STREMTHRU_URLS) {
|
||||
headers['X-StremThru-Authorization'] = `Basic ${this.config.credentials}`;
|
||||
}
|
||||
|
||||
return headers;
|
||||
}
|
||||
|
||||
protected async generateStreamUrls(
|
||||
streams: ProxyStream[]
|
||||
): Promise<string[] | null> {
|
||||
const proxyUrl = this.generateProxyUrl('/v0/proxy');
|
||||
|
||||
if (!Env.ENCRYPT_STREMTHRU_URLS) {
|
||||
proxyUrl.searchParams.set('token', this.config.credentials);
|
||||
}
|
||||
|
||||
const data = new URLSearchParams();
|
||||
|
||||
streams.forEach((stream, i) => {
|
||||
data.append('url', stream.url);
|
||||
let req_headers = '';
|
||||
if (stream.headers?.request) {
|
||||
for (const [key, value] of Object.entries(stream.headers.request)) {
|
||||
req_headers += `${key}: ${value}\n`;
|
||||
}
|
||||
}
|
||||
data.append(`req_headers[${i}]`, req_headers);
|
||||
if (stream.filename) {
|
||||
data.append(`filename[${i}]`, stream.filename);
|
||||
}
|
||||
});
|
||||
|
||||
if (Env.LOG_SENSITIVE_INFO) {
|
||||
logger.debug(`POST ${proxyUrl.toString()}`);
|
||||
} else {
|
||||
logger.debug(
|
||||
`POST ${proxyUrl.protocol}://${maskSensitiveInfo(proxyUrl.hostname)}${proxyUrl.port ? `:${proxyUrl.port}` : ''}/v0/proxy`
|
||||
);
|
||||
}
|
||||
|
||||
const response = await fetch(proxyUrl.toString(), {
|
||||
method: 'POST',
|
||||
headers: this.getHeaders(),
|
||||
body: data,
|
||||
signal: AbortSignal.timeout(30000),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`${response.status}: ${response.statusText}`);
|
||||
}
|
||||
|
||||
let responseData: any;
|
||||
try {
|
||||
responseData = await response.json();
|
||||
} catch (error) {
|
||||
const text = await response.text();
|
||||
logger.debug(`Response body: ${text}`);
|
||||
throw new Error('Failed to parse JSON response from StremThru');
|
||||
}
|
||||
|
||||
if (responseData.error) {
|
||||
throw new Error(responseData.error);
|
||||
}
|
||||
|
||||
if (responseData.data?.items) {
|
||||
return responseData.data.items;
|
||||
} else {
|
||||
throw new Error('No URLs were returned from StremThru');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export * from './stremio';
|
||||
@@ -0,0 +1,325 @@
|
||||
import { constants, Env } from '..';
|
||||
import {
|
||||
Meta,
|
||||
MetaPreview,
|
||||
ParsedStream,
|
||||
Resource,
|
||||
AIOStream,
|
||||
Subtitle,
|
||||
UserData,
|
||||
AddonCatalog,
|
||||
Stream,
|
||||
AddonCatalogResponse,
|
||||
AIOStreamResponse,
|
||||
SubtitleResponse,
|
||||
MetaResponse,
|
||||
CatalogResponse,
|
||||
StreamResponse,
|
||||
} from '../db';
|
||||
import { createFormatter } from '../formatters';
|
||||
import { AIOStreamsError, AIOStreamsResponse } from '../main';
|
||||
import { createLogger } from '../utils';
|
||||
|
||||
type ErrorOptions = {
|
||||
errorTitle?: string;
|
||||
errorDescription?: string;
|
||||
errorUrl?: string;
|
||||
};
|
||||
|
||||
const logger = createLogger('stremio');
|
||||
|
||||
export class StremioTransformer {
|
||||
constructor(private readonly userData: UserData) {}
|
||||
|
||||
public showError(resource: Resource, errors: AIOStreamsError[]) {
|
||||
if (
|
||||
errors.length > 0 &&
|
||||
!this.userData.hideErrors &&
|
||||
!this.userData.hideErrorsForResources?.includes(resource)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
async transformStreams(
|
||||
response: AIOStreamsResponse<ParsedStream[]>
|
||||
): Promise<AIOStreamResponse> {
|
||||
const { data: streams, errors } = response;
|
||||
|
||||
let transformedStreams: AIOStream[] = [];
|
||||
|
||||
let formatter;
|
||||
if (this.userData.formatter.id === constants.CUSTOM_FORMATTER) {
|
||||
const template = this.userData.formatter.definition;
|
||||
if (!template) {
|
||||
throw new Error('No template defined for custom formatter');
|
||||
}
|
||||
formatter = createFormatter(
|
||||
this.userData.formatter.id,
|
||||
template,
|
||||
this.userData.addonName
|
||||
);
|
||||
} else {
|
||||
formatter = createFormatter(
|
||||
this.userData.formatter.id,
|
||||
undefined,
|
||||
this.userData.addonName
|
||||
);
|
||||
}
|
||||
|
||||
logger.info(
|
||||
`Transforming ${streams.length} streams, using formatter ${this.userData.formatter.id}`
|
||||
);
|
||||
|
||||
transformedStreams = await Promise.all(
|
||||
streams.map(async (stream: ParsedStream): Promise<AIOStream> => {
|
||||
const { name, description } = stream.addon.streamPassthrough
|
||||
? {
|
||||
name: stream.originalName,
|
||||
description: stream.originalDescription,
|
||||
}
|
||||
: formatter.format(stream);
|
||||
const identifyingAttributes = [
|
||||
stream.parsedFile?.resolution,
|
||||
stream.parsedFile?.quality,
|
||||
stream.parsedFile?.encode,
|
||||
stream.parsedFile?.audioTags,
|
||||
stream.parsedFile?.visualTags,
|
||||
stream.parsedFile?.languages,
|
||||
stream.parsedFile?.releaseGroup,
|
||||
stream.indexer,
|
||||
].filter(Boolean);
|
||||
const bingeGroup = `${stream.proxied ? 'proxied.' : ''}${identifyingAttributes.join('|')}`;
|
||||
return {
|
||||
name,
|
||||
description,
|
||||
url: ['http', 'usenet', 'debrid', 'live'].includes(stream.type)
|
||||
? stream.url
|
||||
: undefined,
|
||||
infoHash:
|
||||
stream.type === 'p2p' ? stream.torrent?.infoHash : undefined,
|
||||
ytId: stream.type === 'youtube' ? stream.ytId : undefined,
|
||||
externalUrl:
|
||||
stream.type === 'external' ? stream.externalUrl : undefined,
|
||||
sources: stream.type === 'p2p' ? stream.torrent?.sources : undefined,
|
||||
subtitles: stream.subtitles,
|
||||
behaviorHints: {
|
||||
countryWhitelist: stream.countryWhitelist,
|
||||
notWebReady: stream.notWebReady,
|
||||
bingeGroup: bingeGroup,
|
||||
proxyHeaders:
|
||||
stream.requestHeaders || stream.responseHeaders
|
||||
? {
|
||||
request: stream.requestHeaders,
|
||||
response: stream.responseHeaders,
|
||||
}
|
||||
: undefined,
|
||||
videoHash: stream.videoHash,
|
||||
videoSize: stream.size,
|
||||
filename: stream.filename,
|
||||
},
|
||||
streamData: {
|
||||
type: stream.type,
|
||||
proxied: stream.proxied,
|
||||
indexer: stream.indexer,
|
||||
age: stream.age,
|
||||
duration: stream.duration,
|
||||
library: stream.library,
|
||||
size: stream.size,
|
||||
folderSize: stream.folderSize,
|
||||
torrent: stream.torrent,
|
||||
addon: stream.addon.name,
|
||||
filename: stream.filename,
|
||||
folderName: stream.folderName,
|
||||
service: stream.service,
|
||||
parsedFile: stream.parsedFile,
|
||||
message: stream.message,
|
||||
regexMatched: stream.regexMatched,
|
||||
keywordMatched: stream.keywordMatched,
|
||||
},
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
// add errors to the end (if this.userData.hideErrors is false or the resource is not in this.userData.hideErrorsForResources)
|
||||
if (this.showError('stream', errors)) {
|
||||
transformedStreams.push(
|
||||
...errors.map((error) =>
|
||||
StremioTransformer.createErrorStream({
|
||||
errorTitle: error.title,
|
||||
errorDescription: error.description,
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
streams: transformedStreams,
|
||||
};
|
||||
}
|
||||
|
||||
transformSubtitles(
|
||||
response: AIOStreamsResponse<Subtitle[]>
|
||||
): SubtitleResponse {
|
||||
const { data: subtitles, errors } = response;
|
||||
|
||||
if (this.showError('subtitles', errors)) {
|
||||
subtitles.push(
|
||||
...errors.map((error) =>
|
||||
StremioTransformer.createErrorSubtitle({
|
||||
errorTitle: error.title,
|
||||
errorDescription: error.description,
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
subtitles,
|
||||
};
|
||||
}
|
||||
|
||||
transformCatalog(
|
||||
response: AIOStreamsResponse<MetaPreview[]>
|
||||
): CatalogResponse {
|
||||
const { data: metas, errors } = response;
|
||||
|
||||
if (this.showError('catalog', errors)) {
|
||||
metas.push(
|
||||
...errors.map((error) =>
|
||||
StremioTransformer.createErrorMeta({
|
||||
errorTitle: error.title,
|
||||
errorDescription: error.description,
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
metas,
|
||||
};
|
||||
}
|
||||
|
||||
transformMeta(response: AIOStreamsResponse<Meta | null>): MetaResponse {
|
||||
const { data: meta, errors } = response;
|
||||
|
||||
if (this.showError('meta', errors) || !meta) {
|
||||
return {
|
||||
meta: StremioTransformer.createErrorMeta({
|
||||
errorTitle: errors.length > 0 ? errors[0].title : undefined,
|
||||
errorDescription: errors[0]?.description || 'Unknown error',
|
||||
}),
|
||||
};
|
||||
}
|
||||
return {
|
||||
meta,
|
||||
};
|
||||
}
|
||||
|
||||
transformAddonCatalog(
|
||||
response: AIOStreamsResponse<AddonCatalog[]>
|
||||
): AddonCatalogResponse {
|
||||
const { data: addonCatalogs, errors } = response;
|
||||
if (this.showError('addon_catalog', errors)) {
|
||||
addonCatalogs.push(
|
||||
...errors.map((error) =>
|
||||
StremioTransformer.createErrorAddonCatalog({
|
||||
errorTitle: error.title,
|
||||
errorDescription: error.description,
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
return {
|
||||
addons: addonCatalogs,
|
||||
};
|
||||
}
|
||||
static createErrorStream(options: ErrorOptions = {}): AIOStream {
|
||||
const {
|
||||
errorTitle = `[❌] ${Env.ADDON_NAME}`,
|
||||
errorDescription = 'Unknown error',
|
||||
errorUrl = 'https://github.com/Viren070/AIOStreams',
|
||||
} = options;
|
||||
return {
|
||||
name: errorTitle,
|
||||
description: errorDescription,
|
||||
externalUrl: errorUrl,
|
||||
streamData: {
|
||||
type: constants.ERROR_STREAM_TYPE,
|
||||
error: {
|
||||
title: errorTitle,
|
||||
description: errorDescription,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
static createErrorSubtitle(options: ErrorOptions = {}) {
|
||||
const {
|
||||
errorTitle = 'Unknown error',
|
||||
errorDescription = 'Unknown error',
|
||||
errorUrl = 'https://github.com/Viren070/AIOStreams',
|
||||
} = options;
|
||||
return {
|
||||
id: `error.${errorTitle}`,
|
||||
lang: `[❌] ${errorTitle} - ${errorDescription}`,
|
||||
url: errorUrl,
|
||||
};
|
||||
}
|
||||
|
||||
static createErrorMeta(options: ErrorOptions = {}): MetaPreview {
|
||||
const {
|
||||
errorTitle = `[❌] ${Env.ADDON_NAME} - Error`,
|
||||
errorDescription = 'Unknown error',
|
||||
} = options;
|
||||
return {
|
||||
id: `error.${errorTitle}`,
|
||||
name: errorTitle,
|
||||
description: errorDescription,
|
||||
type: 'movie',
|
||||
};
|
||||
}
|
||||
|
||||
static createErrorAddonCatalog(options: ErrorOptions = {}): AddonCatalog {
|
||||
const {
|
||||
errorTitle = `[❌] ${Env.ADDON_NAME} - Error`,
|
||||
errorDescription = 'Unknown error',
|
||||
} = options;
|
||||
return {
|
||||
transportName: 'http',
|
||||
transportUrl: 'https://github.com/Viren070/AIOStreams',
|
||||
manifest: {
|
||||
name: errorTitle,
|
||||
description: errorDescription,
|
||||
id: `error.${errorTitle}`,
|
||||
version: '1.0.0',
|
||||
types: ['addon_catalog'],
|
||||
resources: [{ name: 'addon_catalog', types: ['addon_catalog'] }],
|
||||
catalogs: [],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
static createDynamicError(
|
||||
resource: Resource,
|
||||
options: ErrorOptions = {}
|
||||
): any {
|
||||
if (resource === 'meta') {
|
||||
return { meta: StremioTransformer.createErrorMeta(options) };
|
||||
}
|
||||
if (resource === 'addon_catalog') {
|
||||
return { addons: [StremioTransformer.createErrorAddonCatalog(options)] };
|
||||
}
|
||||
if (resource === 'catalog') {
|
||||
return { metas: [StremioTransformer.createErrorMeta(options)] };
|
||||
}
|
||||
if (resource === 'stream') {
|
||||
return { streams: [StremioTransformer.createErrorStream(options)] };
|
||||
}
|
||||
if (resource === 'subtitles') {
|
||||
return { subtitles: [StremioTransformer.createErrorSubtitle(options)] };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { createLogger } from './logger';
|
||||
import { Settings } from './settings';
|
||||
import { Env } from './env';
|
||||
|
||||
const logger = createLogger('cache');
|
||||
|
||||
@@ -28,7 +28,7 @@ export class Cache<K, V> {
|
||||
*/
|
||||
public static getInstance<K, V>(
|
||||
name: string,
|
||||
maxSize: number = Settings.MAX_CACHE_SIZE
|
||||
maxSize: number = Env.MAX_CACHE_SIZE
|
||||
): Cache<K, V> {
|
||||
if (!this.instances.has(name)) {
|
||||
logger.debug(`Creating new cache instance: ${name}`);
|
||||
@@ -48,22 +48,22 @@ export class Cache<K, V> {
|
||||
* @param ttl Time-To-Live in seconds for the cached value
|
||||
* @param args The arguments to pass to the function
|
||||
*/
|
||||
wrap<T extends (...args: any[]) => any>(
|
||||
async wrap<T extends (...args: any[]) => any>(
|
||||
fn: T,
|
||||
key: K,
|
||||
ttl: number,
|
||||
...args: Parameters<T>
|
||||
): ReturnType<T> {
|
||||
): Promise<ReturnType<T>> {
|
||||
const cachedValue = this.get(key);
|
||||
if (cachedValue !== undefined) {
|
||||
return cachedValue as ReturnType<T>;
|
||||
}
|
||||
const result = fn(...args);
|
||||
const result = await fn(...args);
|
||||
this.set(key, result, ttl);
|
||||
return result;
|
||||
}
|
||||
|
||||
get(key: K): V | undefined {
|
||||
get(key: K, updateTTL: boolean = true): V | undefined {
|
||||
const item = this.cache.get(key);
|
||||
if (item) {
|
||||
const now = Date.now();
|
||||
@@ -71,12 +71,20 @@ export class Cache<K, V> {
|
||||
this.cache.delete(key);
|
||||
return undefined;
|
||||
}
|
||||
item.lastAccessed = now;
|
||||
if (updateTTL) {
|
||||
item.lastAccessed = now;
|
||||
}
|
||||
return item.value;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a value in the cache with a specific TTL
|
||||
* @param key The key to set the value for
|
||||
* @param value The value to set
|
||||
* @param ttl The TTL in seconds
|
||||
*/
|
||||
set(key: K, value: V, ttl: number): void {
|
||||
if (this.cache.size >= this.maxSize) {
|
||||
this.evict();
|
||||
@@ -84,6 +92,18 @@ export class Cache<K, V> {
|
||||
this.cache.set(key, new CacheItem<V>(value, Date.now(), ttl * 1000));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the value of an existing key in the cache without changing the TTL
|
||||
* @param key The key to update
|
||||
* @param value The new value
|
||||
*/
|
||||
update(key: K, value: V): void {
|
||||
const item = this.cache.get(key);
|
||||
if (item) {
|
||||
item.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
clear(): void {
|
||||
this.cache.clear();
|
||||
}
|
||||
@@ -0,0 +1,625 @@
|
||||
import {
|
||||
UserData,
|
||||
UserDataSchema,
|
||||
PresetObject,
|
||||
Service,
|
||||
Option,
|
||||
StreamProxyConfig,
|
||||
Group,
|
||||
} from '../db/schemas';
|
||||
import { AIOStreams } from '../main';
|
||||
import { Preset, PresetManager } from '../presets';
|
||||
import { createProxy } from '../proxy';
|
||||
import { constants } from '.';
|
||||
import { isEncrypted, decryptString, encryptString } from './crypto';
|
||||
import { Env } from './env';
|
||||
import { createLogger, maskSensitiveInfo } from './logger';
|
||||
import { ZodError } from 'zod';
|
||||
import { ConditionParser } from '../parser/conditions';
|
||||
import { RPDB } from './rpdb';
|
||||
import { FeatureControl } from './feature';
|
||||
import { compileRegex } from './regex';
|
||||
|
||||
const logger = createLogger('core');
|
||||
|
||||
export const formatZodError = (error: ZodError) => {
|
||||
let errs = [];
|
||||
for (const issue of error.issues) {
|
||||
errs.push(`Invalid value for ${issue.path.join('.')}: ${issue.message}`);
|
||||
}
|
||||
return errs.join(' | ');
|
||||
};
|
||||
|
||||
function getServiceCredentialDefault(
|
||||
serviceId: constants.ServiceId,
|
||||
credentialId: string
|
||||
) {
|
||||
// env mapping
|
||||
switch (serviceId) {
|
||||
case constants.REALDEBRID_SERVICE:
|
||||
switch (credentialId) {
|
||||
case 'apiKey':
|
||||
return Env.DEFAULT_REALDEBRID_API_KEY;
|
||||
}
|
||||
break;
|
||||
case constants.ALLEDEBRID_SERVICE:
|
||||
switch (credentialId) {
|
||||
case 'apiKey':
|
||||
return Env.DEFAULT_ALLDEBRID_API_KEY;
|
||||
}
|
||||
break;
|
||||
case constants.PREMIUMIZE_SERVICE:
|
||||
switch (credentialId) {
|
||||
case 'apiKey':
|
||||
return Env.DEFAULT_PREMIUMIZE_API_KEY;
|
||||
}
|
||||
break;
|
||||
case constants.DEBRIDLINK_SERVICE:
|
||||
switch (credentialId) {
|
||||
case 'apiKey':
|
||||
return Env.DEFAULT_DEBRIDLINK_API_KEY;
|
||||
}
|
||||
break;
|
||||
case constants.TORBOX_SERVICE:
|
||||
switch (credentialId) {
|
||||
case 'apiKey':
|
||||
return Env.DEFAULT_TORBOX_API_KEY;
|
||||
}
|
||||
break;
|
||||
case constants.EASYDEBRID_SERVICE:
|
||||
switch (credentialId) {
|
||||
case 'apiKey':
|
||||
return Env.DEFAULT_EASYDEBRID_API_KEY;
|
||||
}
|
||||
break;
|
||||
case constants.PUTIO_SERVICE:
|
||||
switch (credentialId) {
|
||||
case 'clientId':
|
||||
return Env.DEFAULT_PUTIO_CLIENT_ID;
|
||||
case 'clientSecret':
|
||||
return Env.DEFAULT_PUTIO_CLIENT_SECRET;
|
||||
}
|
||||
break;
|
||||
case constants.PIKPAK_SERVICE:
|
||||
switch (credentialId) {
|
||||
case 'email':
|
||||
return Env.DEFAULT_PIKPAK_EMAIL;
|
||||
case 'password':
|
||||
return Env.DEFAULT_PIKPAK_PASSWORD;
|
||||
}
|
||||
break;
|
||||
case constants.OFFCLOUD_SERVICE:
|
||||
switch (credentialId) {
|
||||
case 'apiKey':
|
||||
return Env.DEFAULT_OFFCLOUD_API_KEY;
|
||||
case 'email':
|
||||
return Env.DEFAULT_OFFCLOUD_EMAIL;
|
||||
case 'password':
|
||||
return Env.DEFAULT_OFFCLOUD_PASSWORD;
|
||||
}
|
||||
break;
|
||||
case constants.SEEDR_SERVICE:
|
||||
switch (credentialId) {
|
||||
case 'encodedToken':
|
||||
return Env.DEFAULT_SEEDR_ENCODED_TOKEN;
|
||||
}
|
||||
break;
|
||||
case constants.EASYNEWS_SERVICE:
|
||||
switch (credentialId) {
|
||||
case 'username':
|
||||
return Env.DEFAULT_EASYNEWS_USERNAME;
|
||||
case 'password':
|
||||
return Env.DEFAULT_EASYNEWS_PASSWORD;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function getServiceCredentialForced(
|
||||
serviceId: constants.ServiceId,
|
||||
credentialId: string
|
||||
) {
|
||||
// env mapping
|
||||
switch (serviceId) {
|
||||
case constants.REALDEBRID_SERVICE:
|
||||
switch (credentialId) {
|
||||
case 'apiKey':
|
||||
return Env.FORCED_REALDEBRID_API_KEY;
|
||||
}
|
||||
break;
|
||||
case constants.ALLEDEBRID_SERVICE:
|
||||
switch (credentialId) {
|
||||
case 'apiKey':
|
||||
return Env.FORCED_ALLDEBRID_API_KEY;
|
||||
}
|
||||
break;
|
||||
case constants.PREMIUMIZE_SERVICE:
|
||||
switch (credentialId) {
|
||||
case 'apiKey':
|
||||
return Env.FORCED_PREMIUMIZE_API_KEY;
|
||||
}
|
||||
break;
|
||||
case constants.DEBRIDLINK_SERVICE:
|
||||
switch (credentialId) {
|
||||
case 'apiKey':
|
||||
return Env.FORCED_DEBRIDLINK_API_KEY;
|
||||
}
|
||||
break;
|
||||
case constants.TORBOX_SERVICE:
|
||||
switch (credentialId) {
|
||||
case 'apiKey':
|
||||
return Env.FORCED_TORBOX_API_KEY;
|
||||
}
|
||||
break;
|
||||
case constants.EASYDEBRID_SERVICE:
|
||||
switch (credentialId) {
|
||||
case 'apiKey':
|
||||
return Env.FORCED_EASYDEBRID_API_KEY;
|
||||
}
|
||||
break;
|
||||
case constants.PUTIO_SERVICE:
|
||||
switch (credentialId) {
|
||||
case 'clientId':
|
||||
return Env.FORCED_PUTIO_CLIENT_ID;
|
||||
case 'clientSecret':
|
||||
return Env.FORCED_PUTIO_CLIENT_SECRET;
|
||||
}
|
||||
break;
|
||||
case constants.PIKPAK_SERVICE:
|
||||
switch (credentialId) {
|
||||
case 'email':
|
||||
return Env.FORCED_PIKPAK_EMAIL;
|
||||
case 'password':
|
||||
return Env.FORCED_PIKPAK_PASSWORD;
|
||||
}
|
||||
break;
|
||||
case constants.OFFCLOUD_SERVICE:
|
||||
switch (credentialId) {
|
||||
case 'apiKey':
|
||||
return Env.FORCED_OFFCLOUD_API_KEY;
|
||||
case 'email':
|
||||
return Env.FORCED_OFFCLOUD_EMAIL;
|
||||
case 'password':
|
||||
return Env.FORCED_OFFCLOUD_PASSWORD;
|
||||
}
|
||||
break;
|
||||
case constants.SEEDR_SERVICE:
|
||||
switch (credentialId) {
|
||||
case 'encodedToken':
|
||||
return Env.FORCED_SEEDR_ENCODED_TOKEN;
|
||||
}
|
||||
break;
|
||||
case constants.EASYNEWS_SERVICE:
|
||||
switch (credentialId) {
|
||||
case 'username':
|
||||
return Env.FORCED_EASYNEWS_USERNAME;
|
||||
case 'password':
|
||||
return Env.FORCED_EASYNEWS_PASSWORD;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function getEnvironmentServiceDetails(): typeof constants.SERVICE_DETAILS {
|
||||
return Object.fromEntries(
|
||||
Object.entries(constants.SERVICE_DETAILS)
|
||||
.filter(([id, _]) => !FeatureControl.disabledServices.has(id))
|
||||
.map(([id, service]) => [
|
||||
id as constants.ServiceId,
|
||||
{
|
||||
id: service.id,
|
||||
name: service.name,
|
||||
shortName: service.shortName,
|
||||
knownNames: service.knownNames,
|
||||
signUpText: service.signUpText,
|
||||
credentials: service.credentials.map((cred) => ({
|
||||
id: cred.id,
|
||||
name: cred.name,
|
||||
description: cred.description,
|
||||
type: cred.type,
|
||||
required: cred.required,
|
||||
default: getServiceCredentialDefault(service.id, cred.id)
|
||||
? encryptString(getServiceCredentialDefault(service.id, cred.id)!)
|
||||
.data
|
||||
: null,
|
||||
forced: getServiceCredentialForced(service.id, cred.id)
|
||||
? encryptString(getServiceCredentialForced(service.id, cred.id)!)
|
||||
.data
|
||||
: null,
|
||||
})),
|
||||
},
|
||||
])
|
||||
) as typeof constants.SERVICE_DETAILS;
|
||||
}
|
||||
|
||||
export async function validateConfig(
|
||||
data: any,
|
||||
skipErrorsFromAddonsOrProxies: boolean = false,
|
||||
decryptValues: boolean = false
|
||||
): Promise<UserData> {
|
||||
const { success, data: config, error } = UserDataSchema.safeParse(data);
|
||||
if (!success) {
|
||||
throw new Error(formatZodError(error));
|
||||
}
|
||||
|
||||
if (Env.ADDON_PASSWORD && config.addonPassword !== Env.ADDON_PASSWORD) {
|
||||
throw new Error(
|
||||
'The password in the config does not match the password in the environment variables'
|
||||
);
|
||||
}
|
||||
|
||||
// now, validate preset options and service credentials.
|
||||
|
||||
if (config.presets) {
|
||||
for (const preset of config.presets) {
|
||||
validatePreset(preset);
|
||||
}
|
||||
}
|
||||
|
||||
if (config.groups) {
|
||||
for (const group of config.groups) {
|
||||
await validateGroup(group);
|
||||
}
|
||||
}
|
||||
|
||||
if (config.services) {
|
||||
config.services = config.services.map((service: Service) =>
|
||||
validateService(service, decryptValues)
|
||||
);
|
||||
}
|
||||
|
||||
if (config.proxy) {
|
||||
const decryptedProxy = ensureDecrypted(config).proxy;
|
||||
if (decryptedProxy) {
|
||||
config.proxy = await validateProxy(
|
||||
config.proxy,
|
||||
decryptedProxy,
|
||||
skipErrorsFromAddonsOrProxies,
|
||||
decryptValues
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (config.rpdbApiKey) {
|
||||
try {
|
||||
const rpdb = new RPDB(config.rpdbApiKey);
|
||||
await rpdb.validateApiKey();
|
||||
} catch (error) {
|
||||
throw new Error(`Invalid RPDB API key: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (FeatureControl.disabledServices.size > 0) {
|
||||
for (const service of config.services ?? []) {
|
||||
if (FeatureControl.disabledServices.has(service.id)) {
|
||||
service.enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (config.uuid) {
|
||||
await validateRegexes(config);
|
||||
}
|
||||
|
||||
await new AIOStreams(
|
||||
ensureDecrypted(config),
|
||||
skipErrorsFromAddonsOrProxies
|
||||
).initialise();
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
async function validateRegexes(config: UserData) {
|
||||
if (!config.uuid) {
|
||||
return;
|
||||
}
|
||||
|
||||
const excludedRegexes = config.excludedRegexPatterns;
|
||||
const includedRegexes = config.includedRegexPatterns;
|
||||
const requiredRegexes = config.requiredRegexPatterns;
|
||||
const preferredRegexes = config.preferredRegexPatterns;
|
||||
const regexAllowed = FeatureControl.isRegexAllowed(config);
|
||||
|
||||
if (
|
||||
!regexAllowed &&
|
||||
(excludedRegexes?.length ||
|
||||
includedRegexes?.length ||
|
||||
requiredRegexes?.length ||
|
||||
preferredRegexes?.length)
|
||||
) {
|
||||
throw new Error(
|
||||
'You do not have permission to use regex filters, please remove them from your config'
|
||||
);
|
||||
}
|
||||
|
||||
const regexes = [
|
||||
...(excludedRegexes ?? []),
|
||||
...(includedRegexes ?? []),
|
||||
...(requiredRegexes ?? []),
|
||||
...(preferredRegexes ?? []).map((regex) => regex.pattern),
|
||||
];
|
||||
|
||||
await Promise.all(
|
||||
regexes.map(async (regex) => {
|
||||
try {
|
||||
await compileRegex(regex);
|
||||
} catch (error: any) {
|
||||
logger.error(`Invalid regex: ${regex}: ${error.message}`);
|
||||
throw new Error(`Invalid regex: ${regex}: ${error.message}`);
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
function ensureDecrypted(config: UserData): UserData {
|
||||
const decryptedConfig = { ...config };
|
||||
|
||||
// Helper function to decrypt a value if needed
|
||||
const tryDecrypt = (value: any, context: string) => {
|
||||
if (!isEncrypted(value)) return value;
|
||||
const { success, data, error } = decryptString(value);
|
||||
if (!success) {
|
||||
throw new Error(`Failed to decrypt ${context}: ${error}`);
|
||||
}
|
||||
return data;
|
||||
};
|
||||
|
||||
// Decrypt service credentials
|
||||
for (const service of decryptedConfig.services ?? []) {
|
||||
if (!service.credentials) continue;
|
||||
for (const [credential, value] of Object.entries(service.credentials)) {
|
||||
service.credentials[credential] = tryDecrypt(
|
||||
decodeURIComponent(value),
|
||||
`credential ${credential}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Decrypt proxy config
|
||||
if (decryptedConfig.proxy) {
|
||||
const proxy = decryptedConfig.proxy;
|
||||
proxy.credentials = proxy.credentials
|
||||
? tryDecrypt(decodeURIComponent(proxy.credentials), 'proxy credentials')
|
||||
: undefined;
|
||||
proxy.url = proxy.url
|
||||
? tryDecrypt(decodeURIComponent(proxy.url), 'proxy URL')
|
||||
: undefined;
|
||||
}
|
||||
|
||||
return decryptedConfig;
|
||||
}
|
||||
|
||||
function validateService(
|
||||
service: Service,
|
||||
decryptValues: boolean = false
|
||||
): Service {
|
||||
const serviceMeta = getEnvironmentServiceDetails()[service.id];
|
||||
|
||||
if (!serviceMeta) {
|
||||
throw new Error(`Service ${service.id} not found`);
|
||||
}
|
||||
|
||||
if (serviceMeta.credentials.every((cred) => cred.forced)) {
|
||||
service.enabled = true;
|
||||
}
|
||||
|
||||
if (service.enabled) {
|
||||
for (const credential of serviceMeta.credentials) {
|
||||
try {
|
||||
service.credentials[credential.id] = validateOption(
|
||||
credential,
|
||||
service.credentials?.[credential.id],
|
||||
decryptValues
|
||||
);
|
||||
} catch (error) {
|
||||
throw new Error(
|
||||
`The value for credential '${credential.name}' in service '${serviceMeta.name}' is invalid: ${error}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return service;
|
||||
}
|
||||
|
||||
function validatePreset(preset: PresetObject) {
|
||||
const presetMeta = PresetManager.fromId(preset.id).METADATA;
|
||||
|
||||
const optionMetas = presetMeta.OPTIONS;
|
||||
|
||||
for (const [optionId, optionValue] of Object.entries(preset.options)) {
|
||||
const optionMeta = optionMetas.find((option) => option.id === optionId);
|
||||
if (!optionMeta) {
|
||||
continue;
|
||||
// throw new Error(`Option ${optionId} not found in preset ${preset.id}`);
|
||||
}
|
||||
try {
|
||||
preset.options[optionId] = validateOption(optionMeta, optionValue);
|
||||
} catch (error) {
|
||||
throw new Error(
|
||||
`The value for option '${optionMeta.name}' in preset '${presetMeta.NAME}' is invalid: ${error}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function validateGroup(group: Group) {
|
||||
if (!group) {
|
||||
return;
|
||||
}
|
||||
|
||||
// each group must have at least one addon, and we must be able to parse the condition
|
||||
if (group.addons.length === 0) {
|
||||
throw new Error('Every group must have at least one addon');
|
||||
}
|
||||
|
||||
// we must be able to parse the condition
|
||||
let result;
|
||||
try {
|
||||
result = await ConditionParser.testParse(group.condition);
|
||||
} catch (error: any) {
|
||||
throw new Error(
|
||||
`Your group condition - '${group.condition}' - is invalid: ${error.message}`
|
||||
);
|
||||
}
|
||||
if (typeof result !== 'boolean') {
|
||||
throw new Error(
|
||||
`Your group condition - '${group.condition}' - is invalid. Expected evaluation to a boolean, instead got '${typeof result}'`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function validateOption(
|
||||
option: Option,
|
||||
value: any,
|
||||
decryptValues: boolean = false
|
||||
): any {
|
||||
if (option.type === 'multi-select') {
|
||||
if (!Array.isArray(value)) {
|
||||
throw new Error(
|
||||
`Option ${option.id} must be an array, got ${typeof value}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (option.type === 'select') {
|
||||
if (typeof value !== 'string') {
|
||||
throw new Error(
|
||||
`Option ${option.id} must be a string, got ${typeof value}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (option.type === 'boolean') {
|
||||
if (typeof value !== 'boolean') {
|
||||
throw new Error(
|
||||
`Option ${option.id} must be a boolean, got ${typeof value}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (option.type === 'number') {
|
||||
if (typeof value !== 'number') {
|
||||
throw new Error(
|
||||
`Option ${option.id} must be a number, got ${typeof value}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (option.type === 'string') {
|
||||
if (typeof value !== 'string') {
|
||||
throw new Error(
|
||||
`Option ${option.id} must be a string, got ${typeof value}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (option.type === 'password') {
|
||||
if (typeof value !== 'string') {
|
||||
throw new Error(
|
||||
`Option ${option.id} must be a string, got ${typeof value}`
|
||||
);
|
||||
}
|
||||
|
||||
if (option.forced) {
|
||||
value = option.forced;
|
||||
}
|
||||
value = decodeURIComponent(value);
|
||||
if (isEncrypted(value) && decryptValues) {
|
||||
const { success, data, error } = decryptString(value);
|
||||
if (!success) {
|
||||
throw new Error(
|
||||
`Option ${option.id} is encrypted but failed to decrypt: ${error}`
|
||||
);
|
||||
}
|
||||
value = data;
|
||||
}
|
||||
}
|
||||
|
||||
if (option.type === 'url') {
|
||||
if (typeof value !== 'string') {
|
||||
throw new Error(
|
||||
`Option ${option.id} must be a string, got ${typeof value}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (option.required && value === undefined) {
|
||||
throw new Error(`Option ${option.id} is required, got ${value}`);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
async function validateProxy(
|
||||
proxy: StreamProxyConfig,
|
||||
decryptedProxy: StreamProxyConfig,
|
||||
skipProxyErrors: boolean = false,
|
||||
decryptCredentials: boolean = false
|
||||
): Promise<StreamProxyConfig> {
|
||||
// apply forced values if they exist
|
||||
proxy.enabled = Env.FORCE_PROXY_ENABLED ?? proxy.enabled;
|
||||
proxy.id = Env.FORCE_PROXY_ID ?? proxy.id;
|
||||
proxy.url = Env.FORCE_PROXY_URL ?? proxy.url;
|
||||
proxy.credentials = Env.FORCE_PROXY_CREDENTIALS ?? proxy.credentials;
|
||||
proxy.publicIp = Env.FORCE_PROXY_PUBLIC_IP ?? proxy.publicIp;
|
||||
proxy.proxiedAddons = Env.FORCE_PROXY_DISABLE_PROXIED_ADDONS
|
||||
? undefined
|
||||
: proxy.proxiedAddons;
|
||||
proxy.proxiedServices =
|
||||
Env.FORCE_PROXY_PROXIED_SERVICES ?? proxy.proxiedServices;
|
||||
if (proxy.enabled) {
|
||||
if (!proxy.id) {
|
||||
throw new Error('Proxy ID is required');
|
||||
}
|
||||
if (!proxy.url) {
|
||||
throw new Error('Proxy URL is required');
|
||||
}
|
||||
if (!proxy.credentials) {
|
||||
throw new Error('Proxy credentials are required');
|
||||
}
|
||||
|
||||
proxy.credentials = decodeURIComponent(proxy.credentials);
|
||||
proxy.url = proxy.url.startsWith('aioEncrypt')
|
||||
? decodeURIComponent(proxy.url)
|
||||
: proxy.url;
|
||||
if (isEncrypted(proxy.credentials) && decryptCredentials) {
|
||||
const { success, data, error } = decryptString(proxy.credentials);
|
||||
if (!success) {
|
||||
throw new Error(
|
||||
`Proxy credentials for ${proxy.id} are encrypted but failed to decrypt: ${error}`
|
||||
);
|
||||
}
|
||||
proxy.credentials = data;
|
||||
}
|
||||
if (isEncrypted(proxy.url) && decryptCredentials) {
|
||||
const { success, data, error } = decryptString(proxy.url);
|
||||
if (!success) {
|
||||
throw new Error(
|
||||
`Proxy URL for ${proxy.id} is encrypted but failed to decrypt: ${error}`
|
||||
);
|
||||
}
|
||||
proxy.url = data;
|
||||
}
|
||||
|
||||
// use decrypted proxy config for validation.
|
||||
const ProxyService = createProxy(decryptedProxy);
|
||||
|
||||
try {
|
||||
proxy.publicIp || (await ProxyService.getPublicIp());
|
||||
} catch (error) {
|
||||
if (!skipProxyErrors) {
|
||||
logger.error(
|
||||
`Failed to get the public IP of the proxy service ${proxy.id} (${maskSensitiveInfo(proxy.url)}): ${error}`
|
||||
);
|
||||
throw new Error(
|
||||
`Failed to get the public IP of the proxy service ${proxy.id}: ${error}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return proxy;
|
||||
}
|
||||
@@ -0,0 +1,891 @@
|
||||
import { Option } from '../db';
|
||||
|
||||
export enum ErrorCode {
|
||||
// User API
|
||||
USER_NOT_FOUND = 'USER_NOT_FOUND',
|
||||
USER_ALREADY_EXISTS = 'USER_ALREADY_EXISTS',
|
||||
USER_INVALID_PASSWORD = 'USER_INVALID_PASSWORD',
|
||||
USER_INVALID_CONFIG = 'USER_INVALID_CONFIG',
|
||||
USER_ERROR = 'USER_ERROR',
|
||||
USER_NEW_PASSWORD_TOO_SHORT = 'USER_NEW_PASSWORD_TOO_SHORT',
|
||||
USER_NEW_PASSWORD_TOO_SIMPLE = 'USER_NEW_PASSWORD_TOO_SIMPLE',
|
||||
// Format API
|
||||
FORMAT_INVALID_FORMATTER = 'FORMAT_INVALID_FORMATTER',
|
||||
FORMAT_INVALID_STREAM = 'FORMAT_INVALID_STREAM',
|
||||
FORMAT_ERROR = 'FORMAT_ERROR',
|
||||
// Other
|
||||
MISSING_REQUIRED_FIELDS = 'MISSING_REQUIRED_FIELDS',
|
||||
INTERNAL_SERVER_ERROR = 'INTERNAL_SERVER_ERROR',
|
||||
METHOD_NOT_ALLOWED = 'METHOD_NOT_ALLOWED',
|
||||
RATE_LIMIT_EXCEEDED = 'RATE_LIMIT_EXCEEDED',
|
||||
}
|
||||
|
||||
interface ErrorDetails {
|
||||
statusCode: number;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export const ErrorMap: Record<ErrorCode, ErrorDetails> = {
|
||||
[ErrorCode.MISSING_REQUIRED_FIELDS]: {
|
||||
statusCode: 400,
|
||||
message: 'Required fields are missing',
|
||||
},
|
||||
[ErrorCode.USER_NOT_FOUND]: {
|
||||
statusCode: 404,
|
||||
message: 'User not found',
|
||||
},
|
||||
[ErrorCode.USER_ALREADY_EXISTS]: {
|
||||
statusCode: 409,
|
||||
message: 'User already exists',
|
||||
},
|
||||
[ErrorCode.USER_INVALID_PASSWORD]: {
|
||||
statusCode: 401,
|
||||
message: 'Invalid password',
|
||||
},
|
||||
[ErrorCode.USER_INVALID_CONFIG]: {
|
||||
statusCode: 400,
|
||||
message: 'The config for this user is invalid',
|
||||
},
|
||||
[ErrorCode.USER_ERROR]: {
|
||||
statusCode: 500,
|
||||
message: 'A generic error while processing the user request',
|
||||
},
|
||||
[ErrorCode.USER_NEW_PASSWORD_TOO_SHORT]: {
|
||||
statusCode: 400,
|
||||
message: 'New password is too short',
|
||||
},
|
||||
[ErrorCode.USER_NEW_PASSWORD_TOO_SIMPLE]: {
|
||||
statusCode: 400,
|
||||
message: 'New password is too simple',
|
||||
},
|
||||
[ErrorCode.INTERNAL_SERVER_ERROR]: {
|
||||
statusCode: 500,
|
||||
message: 'An unexpected error occurred',
|
||||
},
|
||||
[ErrorCode.METHOD_NOT_ALLOWED]: {
|
||||
statusCode: 405,
|
||||
message: 'Method not allowed',
|
||||
},
|
||||
[ErrorCode.RATE_LIMIT_EXCEEDED]: {
|
||||
statusCode: 429,
|
||||
message: 'Too many requests from this IP, please try again later.',
|
||||
},
|
||||
[ErrorCode.FORMAT_INVALID_FORMATTER]: {
|
||||
statusCode: 400,
|
||||
message: 'Invalid formatter',
|
||||
},
|
||||
[ErrorCode.FORMAT_INVALID_STREAM]: {
|
||||
statusCode: 400,
|
||||
message: 'Invalid stream',
|
||||
},
|
||||
[ErrorCode.FORMAT_ERROR]: {
|
||||
statusCode: 500,
|
||||
message: 'An error occurred while formatting the stream',
|
||||
},
|
||||
};
|
||||
|
||||
export class APIError extends Error {
|
||||
constructor(
|
||||
public code: ErrorCode,
|
||||
public statusCode: number = ErrorMap[code].statusCode,
|
||||
message?: string
|
||||
) {
|
||||
super(message || ErrorMap[code].message);
|
||||
this.name = 'APIError';
|
||||
}
|
||||
}
|
||||
|
||||
const HEADERS_FOR_IP_FORWARDING = [
|
||||
'X-Client-IP',
|
||||
'X-Forwarded-For',
|
||||
'X-Real-IP',
|
||||
'True-Client-IP',
|
||||
'X-Forwarded',
|
||||
'Forwarded-For',
|
||||
];
|
||||
|
||||
const API_VERSION = 1;
|
||||
|
||||
export const GDRIVE_FORMATTER = 'gdrive';
|
||||
export const LIGHT_GDRIVE_FORMATTER = 'lightgdrive';
|
||||
export const MINIMALISTIC_GDRIVE_FORMATTER = 'minimalisticgdrive';
|
||||
export const TORRENTIO_FORMATTER = 'torrentio';
|
||||
export const TORBOX_FORMATTER = 'torbox';
|
||||
export const CUSTOM_FORMATTER = 'custom';
|
||||
|
||||
export const FORMATTERS = [
|
||||
GDRIVE_FORMATTER,
|
||||
LIGHT_GDRIVE_FORMATTER,
|
||||
MINIMALISTIC_GDRIVE_FORMATTER,
|
||||
TORRENTIO_FORMATTER,
|
||||
TORBOX_FORMATTER,
|
||||
CUSTOM_FORMATTER,
|
||||
] as const;
|
||||
|
||||
export type FormatterDetail = {
|
||||
id: FormatterType;
|
||||
name: string;
|
||||
description: string;
|
||||
};
|
||||
|
||||
export const FORMATTER_DETAILS: Record<FormatterType, FormatterDetail> = {
|
||||
[GDRIVE_FORMATTER]: {
|
||||
id: GDRIVE_FORMATTER,
|
||||
name: 'Google Drive',
|
||||
description: 'Uses the formatting from the Stremio GDrive addon',
|
||||
},
|
||||
[LIGHT_GDRIVE_FORMATTER]: {
|
||||
id: LIGHT_GDRIVE_FORMATTER,
|
||||
name: 'Light Google Drive',
|
||||
description:
|
||||
'A lighter version of the GDrive formatter, focused on asthetics',
|
||||
},
|
||||
[MINIMALISTIC_GDRIVE_FORMATTER]: {
|
||||
id: MINIMALISTIC_GDRIVE_FORMATTER,
|
||||
name: 'Minimalistic Google Drive',
|
||||
description:
|
||||
'A minimalistic formatter for Google Drive which shows only the bare minimum',
|
||||
},
|
||||
[TORRENTIO_FORMATTER]: {
|
||||
id: TORRENTIO_FORMATTER,
|
||||
name: 'Torrentio',
|
||||
description: 'Uses the formatting from the Torrentio addon',
|
||||
},
|
||||
[TORBOX_FORMATTER]: {
|
||||
id: TORBOX_FORMATTER,
|
||||
name: 'Torbox',
|
||||
description: 'Uses the formatting from the TorBox Stremio addon',
|
||||
},
|
||||
[CUSTOM_FORMATTER]: {
|
||||
id: CUSTOM_FORMATTER,
|
||||
name: 'Custom',
|
||||
description: 'Define your own formatter',
|
||||
},
|
||||
};
|
||||
|
||||
export type FormatterType = (typeof FORMATTERS)[number];
|
||||
|
||||
const REALDEBRID_SERVICE = 'realdebrid';
|
||||
const DEBRIDLINK_SERVICE = 'debridlink';
|
||||
const PREMIUMIZE_SERVICE = 'premiumize';
|
||||
const ALLEDEBRID_SERVICE = 'alldebrid';
|
||||
const TORBOX_SERVICE = 'torbox';
|
||||
const EASYDEBRID_SERVICE = 'easydebrid';
|
||||
const PUTIO_SERVICE = 'putio';
|
||||
const PIKPAK_SERVICE = 'pikpak';
|
||||
const OFFCLOUD_SERVICE = 'offcloud';
|
||||
const SEEDR_SERVICE = 'seedr';
|
||||
const EASYNEWS_SERVICE = 'easynews';
|
||||
|
||||
const SERVICES = [
|
||||
REALDEBRID_SERVICE,
|
||||
DEBRIDLINK_SERVICE,
|
||||
PREMIUMIZE_SERVICE,
|
||||
ALLEDEBRID_SERVICE,
|
||||
TORBOX_SERVICE,
|
||||
EASYDEBRID_SERVICE,
|
||||
PUTIO_SERVICE,
|
||||
PIKPAK_SERVICE,
|
||||
OFFCLOUD_SERVICE,
|
||||
SEEDR_SERVICE,
|
||||
EASYNEWS_SERVICE,
|
||||
] as const;
|
||||
|
||||
export type ServiceId = (typeof SERVICES)[number];
|
||||
|
||||
export const MEDIAFLOW_SERVICE = 'mediaflow' as const;
|
||||
export const STREMTHRU_SERVICE = 'stremthru' as const;
|
||||
|
||||
export const PROXY_SERVICES = [MEDIAFLOW_SERVICE, STREMTHRU_SERVICE] as const;
|
||||
export type ProxyServiceId = (typeof PROXY_SERVICES)[number];
|
||||
|
||||
export const PROXY_SERVICE_DETAILS: Record<
|
||||
ProxyServiceId,
|
||||
{
|
||||
id: ProxyServiceId;
|
||||
name: string;
|
||||
description: string;
|
||||
credentialDescription: string;
|
||||
}
|
||||
> = {
|
||||
[MEDIAFLOW_SERVICE]: {
|
||||
id: MEDIAFLOW_SERVICE,
|
||||
name: 'MediaFlow Proxy',
|
||||
description:
|
||||
'[MediaFlow Proxy](https://github.com/mhdzumair/mediaflow-proxy) is a high performance proxy server which supports HTTP, HLS, and more.',
|
||||
credentialDescription:
|
||||
'The value of your MediaFlow Proxy instance `API_PASSWORD` environment variable.',
|
||||
},
|
||||
[STREMTHRU_SERVICE]: {
|
||||
id: STREMTHRU_SERVICE,
|
||||
name: 'StremThru',
|
||||
description:
|
||||
'[StremThru](https://github.com/MunifTanjim/stremthru) is a feature packed companion to Stremio which also offers a HTTP proxy, written in Go.',
|
||||
credentialDescription:
|
||||
'A valid credential for your StremThru instance, defined in the `STREMTHRU_PROXY_AUTH` environment variable.',
|
||||
},
|
||||
};
|
||||
|
||||
const SERVICE_DETAILS: Record<
|
||||
ServiceId,
|
||||
{
|
||||
id: ServiceId;
|
||||
name: string;
|
||||
shortName: string;
|
||||
knownNames: string[];
|
||||
signUpText: string;
|
||||
credentials: Option[];
|
||||
}
|
||||
> = {
|
||||
[REALDEBRID_SERVICE]: {
|
||||
id: REALDEBRID_SERVICE,
|
||||
name: 'Real-Debrid',
|
||||
shortName: 'RD',
|
||||
knownNames: ['RD', 'Real Debrid', 'RealDebrid', 'Real-Debrid'],
|
||||
signUpText:
|
||||
"Don't have an account? [Sign up here](https://real-debrid.com/?id=9483829)",
|
||||
credentials: [
|
||||
{
|
||||
id: 'apiKey',
|
||||
name: 'API Key',
|
||||
description:
|
||||
'The API key for the Real-Debrid service. Obtain it from [here](https://real-debrid.com/apitoken)',
|
||||
type: 'password',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
[ALLEDEBRID_SERVICE]: {
|
||||
id: ALLEDEBRID_SERVICE,
|
||||
name: 'All-Debrid',
|
||||
shortName: 'AD',
|
||||
knownNames: ['AD', 'All Debrid', 'AllDebrid', 'All-Debrid'],
|
||||
signUpText:
|
||||
"Don't have an account? [Sign up here](https://alldebrid.com/?uid=3n8qa&lang=en)",
|
||||
credentials: [
|
||||
{
|
||||
id: 'apiKey',
|
||||
name: 'API Key',
|
||||
description:
|
||||
'The API key for the All-Debrid service. Create one [here](https://alldebrid.com/apikeys)',
|
||||
type: 'password',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
[PREMIUMIZE_SERVICE]: {
|
||||
id: PREMIUMIZE_SERVICE,
|
||||
name: 'Premiumize',
|
||||
shortName: 'PM',
|
||||
knownNames: ['PM', 'Premiumize'],
|
||||
signUpText:
|
||||
"Don't have an account? [Sign up here](https://www.premiumize.me/register)",
|
||||
credentials: [
|
||||
{
|
||||
id: 'apiKey',
|
||||
name: 'API Key',
|
||||
description:
|
||||
'Your Premiumize API key. Obtain it from [here](https://www.premiumize.me/account)',
|
||||
type: 'password',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
[DEBRIDLINK_SERVICE]: {
|
||||
id: DEBRIDLINK_SERVICE,
|
||||
name: 'Debrid-Link',
|
||||
shortName: 'DL',
|
||||
knownNames: ['DL', 'Debrid Link', 'DebridLink', 'Debrid-Link'],
|
||||
signUpText:
|
||||
"Don't have an account? [Sign up here](https://debrid-link.com/id/EY0JO)",
|
||||
credentials: [
|
||||
{
|
||||
id: 'apiKey',
|
||||
name: 'API Key',
|
||||
description:
|
||||
'Your Debrid-Link API key. Obtain it from [here](https://debrid-link.com/webapp/apikey)',
|
||||
type: 'password',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
[TORBOX_SERVICE]: {
|
||||
id: TORBOX_SERVICE,
|
||||
name: 'TorBox',
|
||||
shortName: 'TB',
|
||||
knownNames: ['TB', 'TorBox', 'Torbox', 'TRB'],
|
||||
signUpText:
|
||||
"Don't have an account? [Sign up here](https://torbox.app/subscription?referral=9ca21adb-dbcb-4fb0-9195-412a5f3519bc) or use my referral code `9ca21adb-dbcb-4fb0-9195-412a5f3519bc`.",
|
||||
credentials: [
|
||||
{
|
||||
id: 'apiKey',
|
||||
name: 'API Key',
|
||||
description:
|
||||
'Your Torbox API key. Obtain it from [here](https://torbox.app/settings)',
|
||||
type: 'password',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
[OFFCLOUD_SERVICE]: {
|
||||
id: OFFCLOUD_SERVICE,
|
||||
name: 'Offcloud',
|
||||
shortName: 'OC',
|
||||
knownNames: ['OC', 'Offcloud'],
|
||||
signUpText:
|
||||
"Don't have an account? [Sign up here](https://offcloud.com/?=06202a3d)",
|
||||
credentials: [
|
||||
{
|
||||
id: 'apiKey',
|
||||
name: 'API Key',
|
||||
description:
|
||||
'Your Offcloud API key. Obtain it from [here](https://offcloud.com/#/account) on the `API Key` tab. ',
|
||||
type: 'password',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
id: 'email',
|
||||
name: 'Email',
|
||||
description:
|
||||
'Your Offcloud email. (These credentials are necessary for some addons)',
|
||||
type: 'password',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
id: 'password',
|
||||
name: 'Password',
|
||||
description:
|
||||
'Your Offcloud password. (These credentials are necessary for some addons)',
|
||||
type: 'password',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
[PUTIO_SERVICE]: {
|
||||
id: PUTIO_SERVICE,
|
||||
name: 'put.io',
|
||||
shortName: 'P.IO',
|
||||
knownNames: ['PO', 'put.io', 'putio'],
|
||||
signUpText: "Don't have an account? [Sign up here](https://put.io/)",
|
||||
credentials: [
|
||||
{
|
||||
id: 'clientId',
|
||||
name: 'Client ID',
|
||||
description:
|
||||
'Your put.io Client ID. Obtain it from [here](https://app.put.io/oauth)',
|
||||
type: 'password',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
id: 'token',
|
||||
name: 'Token',
|
||||
description:
|
||||
'Your put.io Token. Obtain it from [here](https://app.put.io/oauth)',
|
||||
type: 'password',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
[EASYNEWS_SERVICE]: {
|
||||
id: EASYNEWS_SERVICE,
|
||||
name: 'Easynews',
|
||||
shortName: 'EN',
|
||||
knownNames: ['EN', 'Easynews'],
|
||||
signUpText:
|
||||
"Don't have an account? [Sign up here](https://www.easynews.com/)",
|
||||
credentials: [
|
||||
{
|
||||
id: 'username',
|
||||
name: 'Username',
|
||||
description: 'Your Easynews username',
|
||||
type: 'password',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
id: 'password',
|
||||
name: 'Password',
|
||||
description: 'Your Easynews password',
|
||||
type: 'password',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
[EASYDEBRID_SERVICE]: {
|
||||
id: EASYDEBRID_SERVICE,
|
||||
name: 'EasyDebrid',
|
||||
shortName: 'ED',
|
||||
knownNames: ['ED', 'EasyDebrid'],
|
||||
signUpText:
|
||||
"Don't have an account? [Sign up here](https://paradise-cloud.com/products/easydebrid)",
|
||||
credentials: [
|
||||
{
|
||||
id: 'apiKey',
|
||||
name: 'API Key',
|
||||
description:
|
||||
'Your EasyDebrid API key. Obtain it from [here](https://paradise-cloud.com/dashboard/)',
|
||||
type: 'password',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
[PIKPAK_SERVICE]: {
|
||||
id: PIKPAK_SERVICE,
|
||||
name: 'PikPak',
|
||||
shortName: 'PKP',
|
||||
knownNames: ['PP', 'PikPak', 'PKP'],
|
||||
signUpText:
|
||||
"Don't have an account? [Sign up here](https://mypikpak.com/drive/activity/invited?invitation-code=72822731)",
|
||||
credentials: [
|
||||
{
|
||||
id: 'email',
|
||||
name: 'Email',
|
||||
description: 'Your PikPak email address',
|
||||
type: 'password',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
id: 'password',
|
||||
name: 'Password',
|
||||
description: 'Your PikPak password',
|
||||
type: 'password',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
[SEEDR_SERVICE]: {
|
||||
id: SEEDR_SERVICE,
|
||||
name: 'Seedr',
|
||||
shortName: 'SDR',
|
||||
knownNames: ['SR', 'Seedr', 'SDR'],
|
||||
signUpText:
|
||||
"Don't have an account? [Sign up here](https://www.seedr.cc/?r=6542079)",
|
||||
credentials: [
|
||||
{
|
||||
id: 'apiKey',
|
||||
name: 'Encoded Token',
|
||||
description:
|
||||
'Please authorise at MediaFusion and copy the token into here.',
|
||||
type: 'password',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
export const DEDUPLICATOR_KEYS = [
|
||||
'filename',
|
||||
'infoHash',
|
||||
'smartDetect',
|
||||
] as const;
|
||||
|
||||
const RESOLUTIONS = [
|
||||
'2160p',
|
||||
'1440p',
|
||||
'1080p',
|
||||
'720p',
|
||||
'576p',
|
||||
'480p',
|
||||
'360p',
|
||||
'240p',
|
||||
'144p',
|
||||
'Unknown',
|
||||
] as const;
|
||||
|
||||
const QUALITIES = [
|
||||
'BluRay REMUX',
|
||||
'BluRay',
|
||||
'WEB-DL',
|
||||
'WEBRip',
|
||||
'HDRip',
|
||||
'HC HD-Rip',
|
||||
'DVDRip',
|
||||
'HDTV',
|
||||
'CAM',
|
||||
'TS',
|
||||
'TC',
|
||||
'SCR',
|
||||
'Unknown',
|
||||
] as const;
|
||||
|
||||
const VISUAL_TAGS = [
|
||||
'HDR+DV',
|
||||
'HDR10+',
|
||||
'HDR10',
|
||||
'DV',
|
||||
'HDR',
|
||||
'10bit',
|
||||
'3D',
|
||||
'IMAX',
|
||||
'AI',
|
||||
'SDR',
|
||||
'Unknown',
|
||||
] as const;
|
||||
|
||||
const AUDIO_TAGS = [
|
||||
'Atmos',
|
||||
'DD+',
|
||||
'DD',
|
||||
'DTS-HD MA',
|
||||
'DTS-HD',
|
||||
'DTS-ES',
|
||||
'DTS',
|
||||
'TrueHD',
|
||||
'OPUS',
|
||||
'FLAC',
|
||||
'AAC',
|
||||
'Unknown',
|
||||
] as const;
|
||||
|
||||
const AUDIO_CHANNELS = ['2.0', '5.1', '6.1', '7.1', 'Unknown'] as const;
|
||||
|
||||
const ENCODES = [
|
||||
'AV1',
|
||||
'HEVC',
|
||||
'AVC',
|
||||
'XviD',
|
||||
'DivX',
|
||||
'H-OU',
|
||||
'H-SBS',
|
||||
'Unknown',
|
||||
] as const;
|
||||
|
||||
const SORT_CRITERIA = [
|
||||
'quality',
|
||||
'resolution',
|
||||
'language',
|
||||
'visualTag',
|
||||
'audioTag',
|
||||
'audioChannel',
|
||||
'streamType',
|
||||
'encode',
|
||||
'size',
|
||||
'service',
|
||||
'seeders',
|
||||
'addon',
|
||||
'regexPatterns',
|
||||
'cached',
|
||||
'library',
|
||||
'keyword',
|
||||
] as const;
|
||||
|
||||
export const MIN_SIZE = 0;
|
||||
export const MAX_SIZE = 100 * 1000 * 1000 * 1000; // 100GB
|
||||
|
||||
export const MIN_SEEDERS = 0;
|
||||
export const MAX_SEEDERS = 1000;
|
||||
|
||||
export const DEFAULT_POSTERS = [
|
||||
'aHR0cHM6Ly93d3cucG5nbWFydC5jb20vZmlsZXMvMTEvUmlja3JvbGxpbmctUE5HLVBpYy5wbmc=',
|
||||
];
|
||||
|
||||
export const DEFAULT_YT_ID = 'eHZGWmpvNVBnRzA=';
|
||||
|
||||
export const SORT_CRITERIA_DETAILS = {
|
||||
quality: {
|
||||
name: 'Quality',
|
||||
description: 'Sort by the quality of the stream',
|
||||
defaultDirection: 'desc',
|
||||
ascendingDescription:
|
||||
'Streams that are not in your preferred quality list are preferred',
|
||||
descendingDescription:
|
||||
'Streams that are in your preferred quality list are preferred',
|
||||
},
|
||||
resolution: {
|
||||
name: 'Resolution',
|
||||
description: 'Sort by the resolution of the stream',
|
||||
defaultDirection: 'desc',
|
||||
ascendingDescription:
|
||||
'Streams that are not in your preferred resolution list are preferred',
|
||||
descendingDescription:
|
||||
'Streams that are in your preferred resolution list are preferred',
|
||||
},
|
||||
language: {
|
||||
name: 'Language',
|
||||
description: 'Sort by the language of the stream',
|
||||
defaultDirection: 'desc',
|
||||
ascendingDescription:
|
||||
'Streams that are not in your preferred language list are preferred',
|
||||
descendingDescription:
|
||||
'Streams that are in your preferred language list are preferred',
|
||||
},
|
||||
visualTag: {
|
||||
name: 'Visual Tag',
|
||||
description: 'Sort by the visual tags of the stream',
|
||||
defaultDirection: 'desc',
|
||||
ascendingDescription:
|
||||
'Streams that are not in your preferred visual tag list are preferred',
|
||||
descendingDescription:
|
||||
'Streams that are in your preferred visual tag list are preferred',
|
||||
},
|
||||
audioTag: {
|
||||
name: 'Audio Tag',
|
||||
description: 'Sort by the audio tags of the stream',
|
||||
defaultDirection: 'desc',
|
||||
ascendingDescription:
|
||||
'Streams that are not in your preferred audio tag list are preferred',
|
||||
descendingDescription:
|
||||
'Streams that are in your preferred audio tag list are preferred',
|
||||
},
|
||||
audioChannel: {
|
||||
name: 'Audio Channel',
|
||||
description: 'Sort by the audio channels of the stream',
|
||||
defaultDirection: 'desc',
|
||||
ascendingDescription:
|
||||
'Streams that are not in your preferred audio channel list are preferred',
|
||||
descendingDescription:
|
||||
'Streams that are in your preferred audio channel list are preferred',
|
||||
},
|
||||
streamType: {
|
||||
name: 'Stream Type',
|
||||
description: 'Whether the stream is of a preferred stream type',
|
||||
defaultDirection: 'desc',
|
||||
ascendingDescription:
|
||||
'Streams that are not in your preferred stream type list are preferred',
|
||||
descendingDescription:
|
||||
'Streams that are in your preferred stream type list are preferred',
|
||||
},
|
||||
encode: {
|
||||
name: 'Encode',
|
||||
description: 'Whether the stream is of a preferred encode',
|
||||
defaultDirection: 'desc',
|
||||
ascendingDescription:
|
||||
'Streams that are not in your preferred encode list are preferred',
|
||||
descendingDescription:
|
||||
'Streams that are in your preferred encode list are preferred',
|
||||
},
|
||||
size: {
|
||||
name: 'Size',
|
||||
description: 'Sort by the size of the stream',
|
||||
defaultDirection: 'desc',
|
||||
ascendingDescription: 'Streams that are smaller are sorted first',
|
||||
descendingDescription: 'Streams that are larger are sorted first',
|
||||
},
|
||||
service: {
|
||||
name: 'Service',
|
||||
description: 'Sort by the service order',
|
||||
defaultDirection: 'desc',
|
||||
ascendingDescription: 'Streams without a service are preferred',
|
||||
descendingDescription:
|
||||
'Streams are ordered by the order of your service list, with non-service streams at the bottom',
|
||||
},
|
||||
seeders: {
|
||||
name: 'Seeders',
|
||||
description: 'Sort by the number of seeders',
|
||||
defaultDirection: 'desc',
|
||||
ascendingDescription: 'Streams with fewer seeders are preferred',
|
||||
descendingDescription: 'Streams with more seeders are preferred',
|
||||
},
|
||||
addon: {
|
||||
name: 'Addon',
|
||||
description: 'Sort by the addon order',
|
||||
defaultDirection: 'desc',
|
||||
ascendingDescription: 'Streams are sorted by the order of your addon list',
|
||||
descendingDescription: 'Streams are sorted by the order of your addon list',
|
||||
},
|
||||
regexPatterns: {
|
||||
name: 'Regex Patterns',
|
||||
description:
|
||||
'Whether the stream matches any of your preferred regex patterns',
|
||||
defaultDirection: 'desc',
|
||||
ascendingDescription:
|
||||
'Streams that do not match your preferred regex patterns are preferred',
|
||||
descendingDescription:
|
||||
'Streams that match your preferred regex patterns are preferred',
|
||||
},
|
||||
cached: {
|
||||
name: 'Cached',
|
||||
defaultDirection: 'desc',
|
||||
description: 'Whether the stream is cached or not',
|
||||
ascendingDescription: 'Streams that are not cached are preferred',
|
||||
descendingDescription: 'Streams that are cached are preferred',
|
||||
},
|
||||
library: {
|
||||
name: 'Library',
|
||||
defaultDirection: 'desc',
|
||||
description:
|
||||
'Whether the stream is in your library (e.g. debrid account) or not',
|
||||
ascendingDescription: 'Streams that are not in your library are preferred',
|
||||
descendingDescription: 'Streams that are in your library are preferred',
|
||||
},
|
||||
keyword: {
|
||||
name: 'Keyword',
|
||||
defaultDirection: 'desc',
|
||||
description: 'Sort by the keyword of the stream',
|
||||
ascendingDescription:
|
||||
'Streams that do not match any of your keywords are preferred',
|
||||
descendingDescription:
|
||||
'Streams that match any of your keywords are preferred',
|
||||
},
|
||||
} as const;
|
||||
|
||||
const SORT_DIRECTIONS = ['asc', 'desc'] as const;
|
||||
|
||||
export const P2P_STREAM_TYPE = 'p2p' as const;
|
||||
export const LIVE_STREAM_TYPE = 'live' as const;
|
||||
export const USENET_STREAM_TYPE = 'usenet' as const;
|
||||
export const DEBRID_STREAM_TYPE = 'debrid' as const;
|
||||
export const HTTP_STREAM_TYPE = 'http' as const;
|
||||
export const EXTERNAL_STREAM_TYPE = 'external' as const;
|
||||
export const YOUTUBE_STREAM_TYPE = 'youtube' as const;
|
||||
export const ERROR_STREAM_TYPE = 'error' as const;
|
||||
|
||||
const STREAM_TYPES = [
|
||||
P2P_STREAM_TYPE,
|
||||
LIVE_STREAM_TYPE,
|
||||
USENET_STREAM_TYPE,
|
||||
DEBRID_STREAM_TYPE,
|
||||
HTTP_STREAM_TYPE,
|
||||
EXTERNAL_STREAM_TYPE,
|
||||
YOUTUBE_STREAM_TYPE,
|
||||
ERROR_STREAM_TYPE,
|
||||
] as const;
|
||||
|
||||
export type StreamType = (typeof STREAM_TYPES)[number];
|
||||
|
||||
const STREAM_RESOURCE = 'stream' as const;
|
||||
const SUBTITLES_RESOURCE = 'subtitles' as const;
|
||||
const CATALOG_RESOURCE = 'catalog' as const;
|
||||
const META_RESOURCE = 'meta' as const;
|
||||
const ADDON_CATALOG_RESOURCE = 'addon_catalog' as const;
|
||||
|
||||
export const MOVIE_TYPE = 'movie' as const;
|
||||
export const SERIES_TYPE = 'series' as const;
|
||||
export const CHANNEL_TYPE = 'channel' as const;
|
||||
export const TV_TYPE = 'tv' as const;
|
||||
export const ANIME_TYPE = 'anime' as const;
|
||||
|
||||
export const TYPES = [
|
||||
MOVIE_TYPE,
|
||||
SERIES_TYPE,
|
||||
CHANNEL_TYPE,
|
||||
TV_TYPE,
|
||||
ANIME_TYPE,
|
||||
] as const;
|
||||
|
||||
const RESOURCES = [
|
||||
STREAM_RESOURCE,
|
||||
SUBTITLES_RESOURCE,
|
||||
CATALOG_RESOURCE,
|
||||
META_RESOURCE,
|
||||
ADDON_CATALOG_RESOURCE,
|
||||
] as const;
|
||||
|
||||
const LANGUAGES = [
|
||||
'English',
|
||||
'Japanese',
|
||||
'Chinese',
|
||||
'Russian',
|
||||
'Arabic',
|
||||
'Portuguese',
|
||||
'Spanish',
|
||||
'French',
|
||||
'German',
|
||||
'Italian',
|
||||
'Korean',
|
||||
'Hindi',
|
||||
'Bengali',
|
||||
'Punjabi',
|
||||
'Marathi',
|
||||
'Gujarati',
|
||||
'Tamil',
|
||||
'Telugu',
|
||||
'Kannada',
|
||||
'Malayalam',
|
||||
'Thai',
|
||||
'Vietnamese',
|
||||
'Indonesian',
|
||||
'Turkish',
|
||||
'Hebrew',
|
||||
'Persian',
|
||||
'Ukrainian',
|
||||
'Greek',
|
||||
'Lithuanian',
|
||||
'Latvian',
|
||||
'Estonian',
|
||||
'Polish',
|
||||
'Czech',
|
||||
'Slovak',
|
||||
'Hungarian',
|
||||
'Romanian',
|
||||
'Bulgarian',
|
||||
'Serbian',
|
||||
'Croatian',
|
||||
'Slovenian',
|
||||
'Dutch',
|
||||
'Danish',
|
||||
'Finnish',
|
||||
'Swedish',
|
||||
'Norwegian',
|
||||
'Malay',
|
||||
'Latino',
|
||||
'Dual Audio',
|
||||
'Dubbed',
|
||||
'Multi',
|
||||
'Unknown',
|
||||
] as const;
|
||||
|
||||
export const SNIPPETS = [
|
||||
{
|
||||
name: 'Year + Season + Episode',
|
||||
description:
|
||||
'Outputs a nicely formatted year along with the season and episode number',
|
||||
value:
|
||||
'{stream.year::exists["({stream.year}) "||""]}{stream.seasonEpisode::exists["{stream.seasonEpisode::join(\' • \')}"||""]}',
|
||||
},
|
||||
{
|
||||
name: 'File Size',
|
||||
description: 'Outputs the file size of the stream',
|
||||
value: '{stream.size::>0["{stream.size::bytes}"||""]}',
|
||||
},
|
||||
{
|
||||
name: 'Duration',
|
||||
description: 'Outputs the duration of the stream',
|
||||
value: '{stream.duration::>0["{stream.duration::time}"||""]}',
|
||||
},
|
||||
{
|
||||
name: 'P2P marker',
|
||||
description: 'Displays a [P2P] marker if the stream is a P2P stream',
|
||||
value: '{stream.type::=p2p["[P2P]"||""]}',
|
||||
},
|
||||
{
|
||||
name: 'Languages',
|
||||
description:
|
||||
'Outputs the languages of the stream. Tip: use stream.languageEmojis if you prefer the flags',
|
||||
value:
|
||||
'{stream.languages::exists["{stream.languages::join(\' • \')}"||""]}',
|
||||
},
|
||||
];
|
||||
|
||||
export {
|
||||
API_VERSION,
|
||||
SERVICES,
|
||||
RESOLUTIONS,
|
||||
QUALITIES,
|
||||
VISUAL_TAGS,
|
||||
AUDIO_TAGS,
|
||||
AUDIO_CHANNELS,
|
||||
ENCODES,
|
||||
SORT_CRITERIA,
|
||||
SORT_DIRECTIONS,
|
||||
STREAM_TYPES,
|
||||
LANGUAGES,
|
||||
RESOURCES,
|
||||
STREAM_RESOURCE,
|
||||
SUBTITLES_RESOURCE,
|
||||
CATALOG_RESOURCE,
|
||||
META_RESOURCE,
|
||||
ADDON_CATALOG_RESOURCE,
|
||||
REALDEBRID_SERVICE,
|
||||
PREMIUMIZE_SERVICE,
|
||||
ALLEDEBRID_SERVICE,
|
||||
DEBRIDLINK_SERVICE,
|
||||
TORBOX_SERVICE,
|
||||
EASYDEBRID_SERVICE,
|
||||
PUTIO_SERVICE,
|
||||
PIKPAK_SERVICE,
|
||||
OFFCLOUD_SERVICE,
|
||||
SEEDR_SERVICE,
|
||||
EASYNEWS_SERVICE,
|
||||
SERVICE_DETAILS,
|
||||
HEADERS_FOR_IP_FORWARDING,
|
||||
};
|
||||
@@ -0,0 +1,190 @@
|
||||
import {
|
||||
randomBytes,
|
||||
createCipheriv,
|
||||
createDecipheriv,
|
||||
createHash,
|
||||
pbkdf2Sync,
|
||||
randomUUID,
|
||||
} from 'crypto';
|
||||
import { genSalt, hash, compare } from 'bcrypt';
|
||||
import { deflateSync, inflateSync } from 'zlib';
|
||||
import { Env } from './env';
|
||||
import { createLogger } from './logger';
|
||||
|
||||
const logger = createLogger('crypto');
|
||||
|
||||
const saltRounds = 10;
|
||||
|
||||
const compressData = (data: string): Buffer => {
|
||||
return deflateSync(Buffer.from(data, 'utf-8'), {
|
||||
level: 9,
|
||||
});
|
||||
};
|
||||
|
||||
const decompressData = (data: Buffer): string => {
|
||||
return inflateSync(data).toString('utf-8');
|
||||
};
|
||||
|
||||
const encryptData = (
|
||||
secretKey: Buffer,
|
||||
data: Buffer
|
||||
): { iv: string; data: string } => {
|
||||
// Then encrypt the compressed data
|
||||
const iv = randomBytes(16);
|
||||
const cipher = createCipheriv('aes-256-cbc', secretKey, iv);
|
||||
|
||||
const encryptedData = Buffer.concat([cipher.update(data), cipher.final()]);
|
||||
|
||||
return {
|
||||
iv: iv.toString('base64'),
|
||||
data: encryptedData.toString('base64'),
|
||||
};
|
||||
};
|
||||
|
||||
const decryptData = (
|
||||
secretKey: Buffer,
|
||||
encryptedData: Buffer,
|
||||
iv: Buffer
|
||||
): Buffer => {
|
||||
const decipher = createDecipheriv('aes-256-cbc', secretKey, iv);
|
||||
|
||||
// Decrypt the data
|
||||
const decryptedData = Buffer.concat([
|
||||
decipher.update(encryptedData),
|
||||
decipher.final(),
|
||||
]);
|
||||
|
||||
return decryptedData;
|
||||
};
|
||||
|
||||
type SuccessResponse = {
|
||||
success: true;
|
||||
data: string;
|
||||
error: null;
|
||||
};
|
||||
|
||||
type ErrorResponse = {
|
||||
success: false;
|
||||
error: string;
|
||||
data: null;
|
||||
};
|
||||
|
||||
export type Response = SuccessResponse | ErrorResponse;
|
||||
|
||||
export function isEncrypted(data: string): boolean {
|
||||
return data?.startsWith('aioEncrypt:') ?? false;
|
||||
}
|
||||
/**
|
||||
* Encrypts a string using AES-256-CBC encryption, returns a string in the format "iv:encrypted" where
|
||||
* iv and encrypted are url encoded.
|
||||
* @param data Data to encrypt
|
||||
* @param secretKey Secret key used for encryption
|
||||
* @returns Encrypted data or error message
|
||||
*/
|
||||
export function encryptString(data: string, secretKey?: Buffer): Response {
|
||||
if (!secretKey) {
|
||||
secretKey = Buffer.from(Env.SECRET_KEY, 'hex');
|
||||
}
|
||||
try {
|
||||
const compressed = compressData(data);
|
||||
const { iv, data: encrypted } = encryptData(secretKey, compressed);
|
||||
return {
|
||||
success: true,
|
||||
data: encodeURIComponent(`aioEncrypt:${iv}:${encrypted}`),
|
||||
error: null,
|
||||
};
|
||||
} catch (error: any) {
|
||||
logger.error(`Failed to encrypt data: ${error.message}`);
|
||||
return {
|
||||
success: false,
|
||||
error: error.message,
|
||||
data: null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrypts a string using AES-256-CBC encryption
|
||||
* @param data Encrypted data to decrypt
|
||||
* @param secretKey Secret key used for encryption
|
||||
* @returns Decrypted data or error message
|
||||
*/
|
||||
export function decryptString(data: string, secretKey?: Buffer): Response {
|
||||
if (!secretKey) {
|
||||
secretKey = Buffer.from(Env.SECRET_KEY, 'hex');
|
||||
}
|
||||
try {
|
||||
data = decodeURIComponent(data);
|
||||
if (!isEncrypted(data)) {
|
||||
throw new Error('The data was not in an expected encrypted format');
|
||||
}
|
||||
const [_, ivHex, encryptedHex] = data.split(':');
|
||||
const iv = Buffer.from(ivHex, 'base64');
|
||||
const encrypted = Buffer.from(encryptedHex, 'base64');
|
||||
const decrypted = decryptData(secretKey, encrypted, iv);
|
||||
const decompressed = decompressData(decrypted);
|
||||
return {
|
||||
success: true,
|
||||
data: decompressed,
|
||||
error: null,
|
||||
};
|
||||
} catch (error: any) {
|
||||
logger.error(`Failed to decrypt data: ${error.message}`);
|
||||
return {
|
||||
success: false,
|
||||
error: error.message,
|
||||
data: null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function getSimpleTextHash(text: string): string {
|
||||
return createHash('sha256').update(text).digest('hex');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a secure hash of text using PBKDF2
|
||||
* @param text Text to hash
|
||||
* @returns Object containing the hash and salt used
|
||||
*/
|
||||
export async function getTextHash(text: string): Promise<string> {
|
||||
return await hash(text, await genSalt(saltRounds));
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies if the provided text matches a previously generated hash
|
||||
* @param text Text to verify
|
||||
* @param storedHash Previously generated hash
|
||||
* @returns Boolean indicating if the text matches the hash
|
||||
*/
|
||||
export async function verifyHash(
|
||||
text: string,
|
||||
storedHash: string
|
||||
): Promise<boolean> {
|
||||
return compare(text, storedHash);
|
||||
}
|
||||
|
||||
/**
|
||||
* Derives a 64 character hex string from a password using PBKDF2
|
||||
* @param password Password to derive key from
|
||||
* @param salt Optional salt, will be generated if not provided
|
||||
* @returns Object containing the key and salt used
|
||||
*/
|
||||
export async function deriveKey(
|
||||
password: string,
|
||||
salt?: string
|
||||
): Promise<{ key: Buffer; salt: string }> {
|
||||
salt = salt || (await genSalt(saltRounds));
|
||||
const key = pbkdf2Sync(
|
||||
Buffer.from(password, 'utf-8'),
|
||||
Buffer.from(salt, 'hex'),
|
||||
100000,
|
||||
32,
|
||||
'sha512'
|
||||
);
|
||||
return { key, salt };
|
||||
}
|
||||
|
||||
export function generateUUID(): string {
|
||||
return randomUUID();
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,65 @@
|
||||
import { UserData } from '../db/schemas';
|
||||
import { Env } from './env';
|
||||
|
||||
const DEFAULT_REASON = 'Disabled by owner of the instance';
|
||||
|
||||
export class FeatureControl {
|
||||
private static readonly _disabledHosts: Map<string, string> = (() => {
|
||||
const map = new Map<string, string>();
|
||||
if (Env.DISABLED_HOSTS) {
|
||||
for (const disabledHost of Env.DISABLED_HOSTS.split(',')) {
|
||||
const [host, reason] = disabledHost.split(':');
|
||||
map.set(host, reason || DEFAULT_REASON);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
})();
|
||||
|
||||
private static readonly _disabledAddons: Map<string, string> = (() => {
|
||||
const map = new Map<string, string>();
|
||||
if (Env.DISABLED_ADDONS) {
|
||||
for (const disabledAddon of Env.DISABLED_ADDONS.split(',')) {
|
||||
const [addon, reason] = disabledAddon.split(':');
|
||||
map.set(addon, reason || DEFAULT_REASON);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
})();
|
||||
|
||||
private static readonly _disabledServices: Map<string, string> = (() => {
|
||||
const map = new Map<string, string>();
|
||||
if (Env.DISABLED_SERVICES) {
|
||||
for (const disabledService of Env.DISABLED_SERVICES.split(',')) {
|
||||
const [service, reason] = disabledService.split(':');
|
||||
map.set(service, reason || DEFAULT_REASON);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
})();
|
||||
|
||||
public static readonly regexFilterAccess: 'none' | 'trusted' | 'all' =
|
||||
Env.REGEX_FILTER_ACCESS;
|
||||
|
||||
public static get disabledHosts() {
|
||||
return this._disabledHosts;
|
||||
}
|
||||
|
||||
public static get disabledAddons() {
|
||||
return this._disabledAddons;
|
||||
}
|
||||
|
||||
public static get disabledServices() {
|
||||
return this._disabledServices;
|
||||
}
|
||||
|
||||
public static isRegexAllowed(userData: UserData) {
|
||||
switch (this.regexFilterAccess) {
|
||||
case 'trusted':
|
||||
return userData.trusted ?? false;
|
||||
case 'all':
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
import { Cache } from './cache';
|
||||
import { HEADERS_FOR_IP_FORWARDING } from './constants';
|
||||
import { Env } from './env';
|
||||
import { createLogger, maskSensitiveInfo } from './logger';
|
||||
import { fetch, ProxyAgent } from 'undici';
|
||||
|
||||
const logger = createLogger('http');
|
||||
const urlCount = Cache.getInstance<string, number>('url-count');
|
||||
|
||||
export class PossibleRecursiveRequestError extends Error {
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
this.name = 'PossibleRecursiveRequestError';
|
||||
}
|
||||
}
|
||||
export function makeUrlLogSafe(url: string) {
|
||||
// for each component of the path, if it is longer than 10 characters, mask it
|
||||
// and replace the query params of key 'password' with '****'
|
||||
return url
|
||||
.split('/')
|
||||
.map((component) => {
|
||||
if (component.length > 10 && !component.includes('.')) {
|
||||
return maskSensitiveInfo(component);
|
||||
}
|
||||
return component;
|
||||
})
|
||||
.join('/')
|
||||
.replace(/(?<![^?&])(password=[^&]+)/g, 'password=****');
|
||||
}
|
||||
|
||||
export function makeRequest(
|
||||
url: string,
|
||||
timeout: number,
|
||||
headers: HeadersInit = {},
|
||||
forwardIp?: string
|
||||
) {
|
||||
const useProxy = shouldProxy(url);
|
||||
headers = new Headers(headers);
|
||||
if (forwardIp) {
|
||||
for (const header of HEADERS_FOR_IP_FORWARDING) {
|
||||
headers.set(header, forwardIp);
|
||||
}
|
||||
}
|
||||
|
||||
// block recursive requests
|
||||
const key = `${url}-${forwardIp}`;
|
||||
const currentCount = urlCount.get(key, false) ?? 0;
|
||||
if (currentCount > Env.RECURSION_THRESHOLD_LIMIT) {
|
||||
logger.warn(
|
||||
`Detected possible recursive requests to ${url}. Current count: ${currentCount}. Blocking request.`
|
||||
);
|
||||
throw new PossibleRecursiveRequestError(
|
||||
`Possible recursive request to ${url}`
|
||||
);
|
||||
}
|
||||
if (currentCount > 0) {
|
||||
urlCount.update(key, currentCount + 1);
|
||||
} else {
|
||||
urlCount.set(key, 1, Env.RECURSION_THRESHOLD_WINDOW);
|
||||
}
|
||||
logger.debug(
|
||||
`Making a ${useProxy ? 'proxied' : 'direct'} request to ${makeUrlLogSafe(
|
||||
url
|
||||
)} with forwarded ip ${maskSensitiveInfo(forwardIp ?? 'none')}`
|
||||
);
|
||||
let response = fetch(url, {
|
||||
dispatcher: useProxy ? new ProxyAgent(Env.ADDON_PROXY!) : undefined,
|
||||
method: 'GET',
|
||||
headers: headers,
|
||||
signal: AbortSignal.timeout(timeout),
|
||||
});
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
function shouldProxy(url: string) {
|
||||
let shouldProxy = false;
|
||||
let hostname: string;
|
||||
|
||||
try {
|
||||
hostname = new URL(url).hostname;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Env.ADDON_PROXY) {
|
||||
return false;
|
||||
}
|
||||
|
||||
shouldProxy = true;
|
||||
if (Env.ADDON_PROXY_CONFIG) {
|
||||
for (const rule of Env.ADDON_PROXY_CONFIG.split(',')) {
|
||||
const [ruleHostname, ruleShouldProxy] = rule.split(':');
|
||||
if (['true', 'false'].includes(ruleShouldProxy) === false) {
|
||||
logger.error(`Invalid proxy config: ${rule}`);
|
||||
continue;
|
||||
}
|
||||
if (ruleHostname === '*') {
|
||||
shouldProxy = !(ruleShouldProxy === 'false');
|
||||
} else if (ruleHostname.startsWith('*')) {
|
||||
if (hostname.endsWith(ruleHostname.slice(1))) {
|
||||
shouldProxy = !(ruleShouldProxy === 'false');
|
||||
}
|
||||
}
|
||||
if (hostname === ruleHostname) {
|
||||
shouldProxy = !(ruleShouldProxy === 'false');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return shouldProxy;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
export * from './cache';
|
||||
export * from './constants';
|
||||
export * from './env';
|
||||
export * from './logger';
|
||||
export * from './resources';
|
||||
export * from './feature';
|
||||
export * from './crypto';
|
||||
export * from './http';
|
||||
export * from './metadata';
|
||||
export * as constants from './constants';
|
||||
export * from './config';
|
||||
export * from './languages';
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,138 @@
|
||||
import winston from 'winston';
|
||||
import moment from 'moment-timezone';
|
||||
import { Env } from './env';
|
||||
|
||||
// Map log levels to their full names
|
||||
const levelMap: { [key: string]: string } = {
|
||||
error: 'ERROR',
|
||||
warn: 'WARNING',
|
||||
info: 'INFO',
|
||||
debug: 'DEBUG',
|
||||
verbose: 'VERBOSE',
|
||||
silly: 'SILLY',
|
||||
http: 'HTTP',
|
||||
};
|
||||
|
||||
const moduleMap: { [key: string]: string } = {
|
||||
server: '🌐 SERVER',
|
||||
wrappers: '📦 WRAPPERS',
|
||||
crypto: '🔒 CRYPTO',
|
||||
core: '⚡ CORE',
|
||||
parser: '🔍 PARSER',
|
||||
mediaflow: '🌊 MEDIAFLOW',
|
||||
stremthru: '✨ STREMTHRU',
|
||||
cache: '🗄️ CACHE',
|
||||
regex: '🅰️ REGEX',
|
||||
database: '🗃️ DATABASE',
|
||||
users: '👤 USERS',
|
||||
http: '🌐 HTTP',
|
||||
proxy: '🚀 PROXY',
|
||||
stremio: '🎥 STREMIO',
|
||||
};
|
||||
|
||||
// Define colors for each log level using full names
|
||||
const levelColors: { [key: string]: string } = {
|
||||
ERROR: 'red',
|
||||
WARNING: 'yellow',
|
||||
INFO: 'cyan',
|
||||
DEBUG: 'magenta',
|
||||
HTTP: 'green',
|
||||
VERBOSE: 'blue',
|
||||
SILLY: 'grey',
|
||||
};
|
||||
|
||||
const emojiLevelMap: { [key: string]: string } = {
|
||||
error: '❌',
|
||||
warn: '⚠️ ',
|
||||
info: '🔵',
|
||||
debug: '🐞',
|
||||
verbose: '🔍',
|
||||
silly: '🤪',
|
||||
http: '🌐',
|
||||
};
|
||||
|
||||
// Calculate the maximum level name length for padding
|
||||
const MAX_LEVEL_LENGTH = Math.max(
|
||||
...Object.values(levelMap).map((level) => level.length)
|
||||
);
|
||||
|
||||
// Apply colors to Winston
|
||||
winston.addColors(levelColors);
|
||||
|
||||
export const createLogger = (module: string) => {
|
||||
const isJsonFormat = Env.LOG_FORMAT === 'json';
|
||||
const timezone = Env.LOG_TIMEZONE || Env.TZ;
|
||||
|
||||
const timestampFormat = winston.format((info) => {
|
||||
info.timestamp = moment().tz(timezone).format('YYYY-MM-DD HH:mm:ss.SSS z');
|
||||
return info;
|
||||
});
|
||||
|
||||
return winston.createLogger({
|
||||
level: Env.LOG_LEVEL,
|
||||
format: isJsonFormat
|
||||
? winston.format.combine(timestampFormat(), winston.format.json())
|
||||
: winston.format.combine(
|
||||
timestampFormat(),
|
||||
winston.format.printf(({ timestamp, level, message, ...rest }) => {
|
||||
const emoji = emojiLevelMap[level] || '';
|
||||
const formattedModule = moduleMap[module] || module;
|
||||
// Get full level name and pad it for centering
|
||||
const fullLevel = levelMap[level] || level.toUpperCase();
|
||||
const padding = Math.floor(
|
||||
(MAX_LEVEL_LENGTH - fullLevel.length) / 2
|
||||
);
|
||||
const paddedLevel =
|
||||
' '.repeat(padding) +
|
||||
fullLevel +
|
||||
' '.repeat(MAX_LEVEL_LENGTH - fullLevel.length - padding);
|
||||
|
||||
// Apply color to the padded level
|
||||
const coloredLevel = winston.format
|
||||
.colorize()
|
||||
.colorize(fullLevel, paddedLevel);
|
||||
|
||||
const formatLine = (line: unknown) => {
|
||||
return `${emoji} | ${coloredLevel} | ${timestamp} | ${formattedModule} | ${line} ${
|
||||
rest ? `${formatJsonToStyledString(rest)}` : ''
|
||||
}`;
|
||||
};
|
||||
if (typeof message === 'string') {
|
||||
return message.split('\n').map(formatLine).join('\n');
|
||||
} else if (typeof message === 'object') {
|
||||
return formatLine(formatJsonToStyledString(message));
|
||||
}
|
||||
return formatLine(message);
|
||||
})
|
||||
),
|
||||
transports: [new winston.transports.Console()],
|
||||
});
|
||||
};
|
||||
|
||||
function formatJsonToStyledString(json: any) {
|
||||
// return json.formatted
|
||||
if (json.formatted) {
|
||||
return json.formatted;
|
||||
}
|
||||
// extract keys and values, display space separated key=value pairs
|
||||
const keys = Object.keys(json);
|
||||
const values = keys.map((key) => `${key}=${json[key]}`);
|
||||
return values.join(' ');
|
||||
}
|
||||
|
||||
export function maskSensitiveInfo(message: string) {
|
||||
if (Env.LOG_SENSITIVE_INFO) {
|
||||
return message;
|
||||
}
|
||||
return '<redacted>';
|
||||
}
|
||||
|
||||
export const getTimeTakenSincePoint = (point: number) => {
|
||||
const timeNow = new Date().getTime();
|
||||
const duration = timeNow - point;
|
||||
if (duration < 1000) {
|
||||
return `${duration.toFixed(2)}ms`;
|
||||
} else {
|
||||
return `${(duration / 1000).toFixed(2)}s`;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,179 @@
|
||||
import { Env } from './env';
|
||||
import { Cache } from './cache';
|
||||
import { TYPES } from './constants';
|
||||
|
||||
export type ExternalIdType = 'imdb' | 'tmdb' | 'tvdb';
|
||||
|
||||
interface ExternalId {
|
||||
type: ExternalIdType;
|
||||
value: string;
|
||||
}
|
||||
|
||||
const API_BASE_URL = 'https://api.themoviedb.org/3';
|
||||
const FIND_BY_ID_PATH = '/find';
|
||||
const MOVIE_DETAILS_PATH = '/movie';
|
||||
const TV_DETAILS_PATH = '/tv';
|
||||
const ALTERNATIVE_TITLES_PATH = '/alternative_titles';
|
||||
|
||||
// Cache TTLs in seconds
|
||||
const ID_CACHE_TTL = 24 * 60 * 60; // 24 hours
|
||||
const TITLE_CACHE_TTL = 7 * 24 * 60 * 60; // 7 days
|
||||
|
||||
export class TMDBMetadata {
|
||||
private readonly TMDB_ID_REGEX = /^(?:tmdb)[-:](\d+)(?::\d+:\d+)?$/;
|
||||
private readonly TVDB_ID_REGEX = /^(?:tvdb)[-:](\d+)(?::\d+:\d+)?$/;
|
||||
private readonly IMDB_ID_REGEX = /^(?:tt)(\d+)(?::\d+:\d+)?$/;
|
||||
private readonly idCache: Cache<string, string>;
|
||||
private readonly titleCache: Cache<string, string[]>;
|
||||
private readonly accessToken: string;
|
||||
|
||||
public constructor(accessToken?: string) {
|
||||
if (!accessToken && !Env.TMDB_ACCESS_TOKEN) {
|
||||
throw new Error('TMDB Access Token is not set');
|
||||
}
|
||||
this.accessToken = (accessToken || Env.TMDB_ACCESS_TOKEN)!;
|
||||
this.idCache = Cache.getInstance<string, string>('tmdb_id_conversion');
|
||||
this.titleCache = Cache.getInstance<string, string[]>('alternative_titles');
|
||||
}
|
||||
|
||||
private getHeaders(): Record<string, string> {
|
||||
return {
|
||||
Authorization: `Bearer ${this.accessToken}`,
|
||||
};
|
||||
}
|
||||
|
||||
private parseExternalId(id: string): ExternalId | null {
|
||||
if (this.TMDB_ID_REGEX.test(id)) {
|
||||
const match = id.match(this.TMDB_ID_REGEX);
|
||||
return match ? { type: 'tmdb', value: match[1] } : null;
|
||||
}
|
||||
if (this.IMDB_ID_REGEX.test(id)) {
|
||||
const match = id.match(this.IMDB_ID_REGEX);
|
||||
return match ? { type: 'imdb', value: `tt${match[1]}` } : null;
|
||||
}
|
||||
if (this.TVDB_ID_REGEX.test(id)) {
|
||||
const match = id.match(this.TVDB_ID_REGEX);
|
||||
return match ? { type: 'tvdb', value: match[1] } : null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private async convertToTmdbId(
|
||||
id: ExternalId,
|
||||
type: (typeof TYPES)[number]
|
||||
): Promise<string> {
|
||||
if (id.type === 'tmdb') {
|
||||
return id.value;
|
||||
}
|
||||
|
||||
// Check cache first
|
||||
const cacheKey = `${id.type}:${id.value}:${type}`;
|
||||
const cachedId = this.idCache.get(cacheKey);
|
||||
if (cachedId) {
|
||||
return cachedId;
|
||||
}
|
||||
|
||||
const url = new URL(API_BASE_URL + FIND_BY_ID_PATH + `/${id.value}`);
|
||||
url.searchParams.set('external_source', `${id.type}_id`);
|
||||
|
||||
const response = await fetch(url, {
|
||||
headers: this.getHeaders(),
|
||||
signal: AbortSignal.timeout(10000),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`${response.status} - ${response.statusText}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
const results = type === 'movie' ? data.movie_results : data.tv_results;
|
||||
const meta = results?.[0];
|
||||
|
||||
if (!meta) {
|
||||
throw new Error(`No ${type} metadata found for ID: ${id.value}`);
|
||||
}
|
||||
|
||||
const tmdbId = meta.id.toString();
|
||||
// Cache the result
|
||||
this.idCache.set(cacheKey, tmdbId, ID_CACHE_TTL);
|
||||
return tmdbId;
|
||||
}
|
||||
|
||||
public async getTitles(
|
||||
id: string,
|
||||
type: (typeof TYPES)[number]
|
||||
): Promise<string[]> {
|
||||
if (!['movie', 'series', 'anime'].includes(type)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const externalId = this.parseExternalId(id);
|
||||
if (!externalId) {
|
||||
throw new Error(
|
||||
'Invalid ID format. Must be TMDB (tmdb:123) or IMDB (tt123) or TVDB (tvdb:123) format'
|
||||
);
|
||||
}
|
||||
|
||||
const tmdbId = await this.convertToTmdbId(externalId, type);
|
||||
|
||||
// Check cache first
|
||||
const cacheKey = `${tmdbId}:${type}`;
|
||||
const cachedTitles = this.titleCache.get(cacheKey);
|
||||
if (cachedTitles) {
|
||||
return cachedTitles;
|
||||
}
|
||||
|
||||
// Fetch primary title from details endpoint
|
||||
const detailsUrl = new URL(
|
||||
API_BASE_URL +
|
||||
(type === 'movie' ? MOVIE_DETAILS_PATH : TV_DETAILS_PATH) +
|
||||
`/${tmdbId}`
|
||||
);
|
||||
|
||||
const detailsResponse = await fetch(detailsUrl, {
|
||||
headers: this.getHeaders(),
|
||||
signal: AbortSignal.timeout(10000),
|
||||
});
|
||||
|
||||
if (!detailsResponse.ok) {
|
||||
throw new Error(`Failed to fetch details: ${detailsResponse.statusText}`);
|
||||
}
|
||||
|
||||
const detailsData = await detailsResponse.json();
|
||||
const primaryTitle =
|
||||
type === 'movie' ? detailsData.title : detailsData.name;
|
||||
|
||||
// Fetch alternative titles
|
||||
const altTitlesUrl = new URL(
|
||||
API_BASE_URL +
|
||||
(type === 'movie' ? MOVIE_DETAILS_PATH : TV_DETAILS_PATH) +
|
||||
`/${tmdbId}` +
|
||||
ALTERNATIVE_TITLES_PATH
|
||||
);
|
||||
|
||||
const altTitlesResponse = await fetch(altTitlesUrl, {
|
||||
headers: this.getHeaders(),
|
||||
signal: AbortSignal.timeout(10000),
|
||||
});
|
||||
|
||||
if (!altTitlesResponse.ok) {
|
||||
throw new Error(
|
||||
`Failed to fetch alternative titles: ${altTitlesResponse.statusText}`
|
||||
);
|
||||
}
|
||||
|
||||
const altTitlesData = await altTitlesResponse.json();
|
||||
const alternativeTitles =
|
||||
type === 'movie'
|
||||
? altTitlesData.titles.map((title: any) => title.title)
|
||||
: altTitlesData.results.map((title: any) => title.title);
|
||||
|
||||
// Combine primary title with alternative titles, ensuring no duplicates
|
||||
const allTitles = [primaryTitle, ...alternativeTitles];
|
||||
const uniqueTitles = [...new Set(allTitles)];
|
||||
|
||||
// Cache the result
|
||||
this.titleCache.set(cacheKey, uniqueTitles, TITLE_CACHE_TTL);
|
||||
return uniqueTitles;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import { isMatch, firstMatch } from 'super-regex';
|
||||
import { Cache } from './cache';
|
||||
import { getTextHash } from './crypto';
|
||||
import { getSimpleTextHash } from './crypto';
|
||||
import { createLogger } from './logger';
|
||||
import { Settings } from './settings';
|
||||
import { Env } from './env';
|
||||
|
||||
const DEFAULT_TIMEOUT = 1000; // 1 second timeout
|
||||
const regexCache = Cache.getInstance<string, RegExp>('regexCache', 1_000);
|
||||
@@ -20,17 +20,17 @@ const logger = createLogger('regex');
|
||||
* @param timeoutMs Optional timeout in milliseconds (default: 1000ms)
|
||||
* @returns boolean indicating if the pattern matches the string
|
||||
*/
|
||||
export function safeRegexTest(
|
||||
export async function safeRegexTest(
|
||||
pattern: string | RegExp,
|
||||
str: string,
|
||||
timeoutMs: number = DEFAULT_TIMEOUT
|
||||
): boolean {
|
||||
): Promise<boolean> {
|
||||
const compiledPattern =
|
||||
typeof pattern === 'string' ? compileRegex(pattern) : pattern;
|
||||
typeof pattern === 'string' ? await compileRegex(pattern) : pattern;
|
||||
try {
|
||||
return resultCache.wrap(
|
||||
return await resultCache.wrap(
|
||||
(p: RegExp, s: string) => isMatch(p, s, { timeout: timeoutMs }),
|
||||
getTextHash(`${compiledPattern.source}|${str}`),
|
||||
getSimpleTextHash(`${compiledPattern.source}|${str}`),
|
||||
100,
|
||||
compiledPattern,
|
||||
str
|
||||
@@ -41,31 +41,41 @@ export function safeRegexTest(
|
||||
}
|
||||
}
|
||||
|
||||
export function compileRegex(
|
||||
export function parseRegex(pattern: string): {
|
||||
regex: string;
|
||||
flags: string;
|
||||
} {
|
||||
const regexFormatMatch = /^\/(.+)\/([gimuy]*)$/.exec(pattern);
|
||||
return regexFormatMatch
|
||||
? { regex: regexFormatMatch[1], flags: regexFormatMatch[2] }
|
||||
: { regex: pattern, flags: '' };
|
||||
}
|
||||
|
||||
export async function compileRegex(
|
||||
pattern: string,
|
||||
flags: string = '',
|
||||
bypassCache: boolean = false
|
||||
): RegExp {
|
||||
): Promise<RegExp> {
|
||||
const { regex, flags } = parseRegex(pattern);
|
||||
if (bypassCache) {
|
||||
return new RegExp(pattern, flags);
|
||||
return new RegExp(regex, flags);
|
||||
}
|
||||
return regexCache.wrap(
|
||||
(p: string, f: string) => new RegExp(p, f),
|
||||
getTextHash(`${pattern}|${flags}`),
|
||||
|
||||
return await regexCache.wrap(
|
||||
(p: string, f: string) => new RegExp(p, f || undefined),
|
||||
getSimpleTextHash(`${regex}|${flags}`),
|
||||
60,
|
||||
pattern,
|
||||
regex,
|
||||
flags
|
||||
);
|
||||
}
|
||||
|
||||
export function formRegexFromKeywords(
|
||||
keywords: string[],
|
||||
flags: string = 'i'
|
||||
): RegExp {
|
||||
export async function formRegexFromKeywords(
|
||||
keywords: string[]
|
||||
): Promise<RegExp> {
|
||||
const pattern = `(?<![^ [(_\\-.])(${keywords
|
||||
.map((filter) => filter.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'))
|
||||
.map((filter) => filter.replace(/\s/g, '[ .\\-_]?'))
|
||||
.join('|')})(?=[ \\)\\]_.-]|$)`;
|
||||
|
||||
return compileRegex(pattern, flags);
|
||||
return await compileRegex(pattern);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
export class ResourceManager {
|
||||
static getResource(resourceName: string) {
|
||||
// check existence
|
||||
const filePath = path.join(
|
||||
__dirname,
|
||||
'../../../../',
|
||||
'resources',
|
||||
resourceName
|
||||
);
|
||||
if (!fs.existsSync(filePath)) {
|
||||
throw new Error(`Resource ${resourceName} not found at ${filePath}`);
|
||||
}
|
||||
return JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import { makeRequest } from './http';
|
||||
|
||||
export type IdType = 'imdb' | 'tmdb' | 'tvdb';
|
||||
|
||||
interface Id {
|
||||
type: IdType;
|
||||
value: string;
|
||||
}
|
||||
|
||||
export class RPDB {
|
||||
private readonly apiKey: string;
|
||||
|
||||
constructor(apiKey: string) {
|
||||
this.apiKey = apiKey;
|
||||
if (!this.apiKey) {
|
||||
throw new Error('RPDB API key is not set');
|
||||
}
|
||||
}
|
||||
|
||||
public async validateApiKey() {
|
||||
const response = await makeRequest(
|
||||
`https://api.ratingposterdb.com/${this.apiKey}/isValid`,
|
||||
5000
|
||||
);
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`Invalid RPDB API key: ${response.status} - ${response.statusText}`
|
||||
);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param id - the id of the item to get the poster for, if it is of a supported type, the rpdb poster will be returned, otherwise null
|
||||
*/
|
||||
public getPosterUrl(type: string, id: string): string | null {
|
||||
const parsedId = this.parseId(id);
|
||||
if (!parsedId) {
|
||||
return null;
|
||||
}
|
||||
if (parsedId.type === 'tvdb' && type === 'movie') {
|
||||
// rpdb doesnt seem to support tvdb for movies
|
||||
return null;
|
||||
}
|
||||
const posterUrl = `https://api.ratingposterdb.com/${this.apiKey}/${parsedId.type}/poster-default/${parsedId.value}.jpg?fallback=true`;
|
||||
return posterUrl;
|
||||
}
|
||||
|
||||
private parseId(id: string): Id | null {
|
||||
if (id.startsWith('tt')) {
|
||||
return { type: 'imdb', value: id };
|
||||
}
|
||||
if (id.startsWith('tmdb:')) {
|
||||
return { type: 'tmdb', value: id.split(':')[1] };
|
||||
}
|
||||
if (id.startsWith('tvdb:')) {
|
||||
return { type: 'tvdb', value: id.split(':')[1] };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,308 @@
|
||||
import {
|
||||
Addon,
|
||||
AddonCatalog,
|
||||
AddonCatalogResponse,
|
||||
AddonCatalogResponseSchema,
|
||||
AddonCatalogSchema,
|
||||
CatalogResponse,
|
||||
CatalogResponseSchema,
|
||||
Manifest,
|
||||
ManifestSchema,
|
||||
Meta,
|
||||
MetaPreview,
|
||||
MetaPreviewSchema,
|
||||
MetaResponse,
|
||||
MetaResponseSchema,
|
||||
MetaSchema,
|
||||
ParsedStream,
|
||||
Resource,
|
||||
Stream,
|
||||
StreamResponse,
|
||||
StreamResponseSchema,
|
||||
StreamSchema,
|
||||
Subtitle,
|
||||
SubtitleResponse,
|
||||
SubtitleResponseSchema,
|
||||
SubtitleSchema,
|
||||
} from './db/schemas';
|
||||
import {
|
||||
Cache,
|
||||
makeRequest,
|
||||
createLogger,
|
||||
constants,
|
||||
maskSensitiveInfo,
|
||||
makeUrlLogSafe,
|
||||
formatZodError,
|
||||
PossibleRecursiveRequestError,
|
||||
} from './utils';
|
||||
import { PresetManager } from './presets';
|
||||
import { StreamParser } from './parser';
|
||||
import { z } from 'zod';
|
||||
|
||||
const logger = createLogger('wrappers');
|
||||
// const cache = Cache.getInstance<string, any>('wrappers');
|
||||
const manifestCache = Cache.getInstance<string, Manifest>('manifest');
|
||||
const resourceCache = Cache.getInstance<string, any>('resources');
|
||||
|
||||
const RESOURCE_TTL = 5 * 60;
|
||||
const MANIFEST_TTL = 10 * 60;
|
||||
|
||||
type ResourceParams = {
|
||||
type: string;
|
||||
id: string;
|
||||
extras?: string;
|
||||
};
|
||||
|
||||
export class Wrapper {
|
||||
private readonly baseUrl: string;
|
||||
private readonly addon: Addon;
|
||||
private readonly manifestUrl: string;
|
||||
|
||||
constructor(addon: Addon) {
|
||||
this.addon = addon;
|
||||
this.manifestUrl = this.addon.manifestUrl.replace('stremio://', 'https://');
|
||||
this.baseUrl = this.manifestUrl.split('/').slice(0, -1).join('/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates an array of items against a schema, filtering out invalid ones
|
||||
* @param data The data to validate
|
||||
* @param schema The Zod schema to validate against
|
||||
* @param resourceName Name of the resource for error messages
|
||||
* @returns Array of validated items
|
||||
* @throws Error if all items are invalid
|
||||
*/
|
||||
private validateArray<T>(
|
||||
data: unknown,
|
||||
schema: z.ZodSchema<T>,
|
||||
resourceName: string
|
||||
): T[] {
|
||||
if (!Array.isArray(data)) {
|
||||
throw new Error(`${resourceName} is not an array`);
|
||||
}
|
||||
|
||||
if (data.length === 0) {
|
||||
// empty array is valid
|
||||
return [];
|
||||
}
|
||||
|
||||
const validItems = data
|
||||
.map((item) => {
|
||||
const parsed = schema.safeParse(item);
|
||||
if (!parsed.success) {
|
||||
logger.error(
|
||||
`An item in the response for ${resourceName} was invalid, filtering it out: ${formatZodError(parsed.error)}`
|
||||
);
|
||||
return null;
|
||||
}
|
||||
return parsed.data;
|
||||
})
|
||||
.filter((item): item is T => item !== null);
|
||||
|
||||
if (validItems.length === 0) {
|
||||
throw new Error(`No valid ${resourceName} found`);
|
||||
}
|
||||
|
||||
return validItems;
|
||||
}
|
||||
|
||||
async getManifest(): Promise<Manifest> {
|
||||
return await manifestCache.wrap(
|
||||
async () => {
|
||||
logger.debug(
|
||||
`Fetching manifest for ${this.addon.identifyingName} (${makeUrlLogSafe(this.manifestUrl)})`
|
||||
);
|
||||
try {
|
||||
const res = await makeRequest(
|
||||
this.manifestUrl,
|
||||
this.addon.timeout,
|
||||
this.addon.headers,
|
||||
this.addon.ip
|
||||
);
|
||||
if (!res.ok) {
|
||||
throw new Error(`${res.status} - ${res.statusText}`);
|
||||
}
|
||||
const data = await res.json();
|
||||
const manifest = ManifestSchema.safeParse(data);
|
||||
if (!manifest.success) {
|
||||
logger.error(`Manifest response was unexpected`);
|
||||
logger.error(formatZodError(manifest.error));
|
||||
logger.error(JSON.stringify(data, null, 2));
|
||||
throw new Error(
|
||||
`Failed to parse manifest for ${this.addon.identifyingName}`
|
||||
);
|
||||
}
|
||||
return manifest.data;
|
||||
} catch (error: any) {
|
||||
logger.error(
|
||||
`Failed to fetch manifest for ${this.addon.identifyingName}: ${error.message}`
|
||||
);
|
||||
if (error instanceof PossibleRecursiveRequestError) {
|
||||
throw error;
|
||||
}
|
||||
throw new Error(
|
||||
`Failed to fetch manifest for ${this.addon.identifyingName}: ${error.message}`
|
||||
);
|
||||
}
|
||||
},
|
||||
this.manifestUrl,
|
||||
MANIFEST_TTL
|
||||
);
|
||||
}
|
||||
|
||||
async getStreams(type: string, id: string): Promise<ParsedStream[]> {
|
||||
const validator = (data: any): Stream[] => {
|
||||
return this.validateArray(data.streams, StreamSchema, 'streams');
|
||||
};
|
||||
|
||||
const streams = await this.makeResourceRequest(
|
||||
'stream',
|
||||
{ type, id },
|
||||
validator
|
||||
);
|
||||
const Parser = this.addon.fromPresetId
|
||||
? PresetManager.fromId(this.addon.fromPresetId).getParser()
|
||||
: StreamParser;
|
||||
const parser = new Parser(this.addon);
|
||||
return streams.map((stream: Stream) => parser.parse(stream));
|
||||
}
|
||||
|
||||
async getCatalog(
|
||||
type: string,
|
||||
id: string,
|
||||
extras?: string
|
||||
): Promise<MetaPreview[]> {
|
||||
const validator = (data: any): MetaPreview[] => {
|
||||
return this.validateArray(data.metas, MetaPreviewSchema, 'catalog items');
|
||||
};
|
||||
|
||||
return await this.makeResourceRequest(
|
||||
'catalog',
|
||||
{ type, id, extras },
|
||||
validator,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
async getMeta(type: string, id: string): Promise<Meta> {
|
||||
const validator = (data: any): Meta => {
|
||||
const parsed = MetaSchema.safeParse(data.meta);
|
||||
if (!parsed.success) {
|
||||
logger.error(formatZodError(parsed.error));
|
||||
throw new Error(
|
||||
`Failed to parse meta for ${this.addon.identifyingName}`
|
||||
);
|
||||
}
|
||||
return parsed.data;
|
||||
};
|
||||
const meta: Meta = await this.makeResourceRequest(
|
||||
'meta',
|
||||
{ type, id },
|
||||
validator,
|
||||
true
|
||||
);
|
||||
return meta;
|
||||
}
|
||||
|
||||
async getSubtitles(
|
||||
type: string,
|
||||
id: string,
|
||||
extras?: string
|
||||
): Promise<Subtitle[]> {
|
||||
const validator = (data: any): Subtitle[] => {
|
||||
return this.validateArray(data.subtitles, SubtitleSchema, 'subtitles');
|
||||
};
|
||||
|
||||
return await this.makeResourceRequest(
|
||||
'subtitles',
|
||||
{ type, id, extras },
|
||||
validator,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
async getAddonCatalog(type: string, id: string): Promise<AddonCatalog[]> {
|
||||
const validator = (data: any): AddonCatalog[] => {
|
||||
return this.validateArray(
|
||||
data.addons,
|
||||
AddonCatalogSchema,
|
||||
'addon catalog items'
|
||||
);
|
||||
};
|
||||
|
||||
return await this.makeResourceRequest(
|
||||
'addon_catalog',
|
||||
{ type, id },
|
||||
validator
|
||||
);
|
||||
}
|
||||
|
||||
async makeRequest(url: string) {
|
||||
return await makeRequest(
|
||||
url,
|
||||
this.addon.timeout,
|
||||
this.addon.headers,
|
||||
this.addon.ip
|
||||
);
|
||||
}
|
||||
|
||||
private async makeResourceRequest<T>(
|
||||
resource: Resource,
|
||||
params: ResourceParams,
|
||||
validator: (data: unknown) => T,
|
||||
cache: boolean = false
|
||||
) {
|
||||
const { type, id, extras } = params;
|
||||
const url = this.buildResourceUrl(resource, type, id, extras);
|
||||
if (cache) {
|
||||
const cached = resourceCache.get(url);
|
||||
if (cached) {
|
||||
logger.debug(
|
||||
`Returning cached ${resource} for ${this.addon.name} (${makeUrlLogSafe(url)})`
|
||||
);
|
||||
return cached;
|
||||
}
|
||||
}
|
||||
logger.debug(
|
||||
`Fetching ${resource} of type ${type} with id ${id} and extras ${extras} (${makeUrlLogSafe(url)})`
|
||||
);
|
||||
try {
|
||||
const res = await makeRequest(
|
||||
url,
|
||||
this.addon.timeout,
|
||||
this.addon.headers,
|
||||
this.addon.ip
|
||||
);
|
||||
if (!res.ok) {
|
||||
logger.error(
|
||||
`Failed to fetch ${resource} resource for ${this.addon.name}: ${res.status} - ${res.statusText}`
|
||||
);
|
||||
|
||||
throw new Error(`${res.status} - ${res.statusText}`);
|
||||
}
|
||||
const data: unknown = await res.json();
|
||||
|
||||
const validated = validator(data);
|
||||
|
||||
if (cache) {
|
||||
resourceCache.set(url, validated, RESOURCE_TTL);
|
||||
}
|
||||
return validated;
|
||||
} catch (error: any) {
|
||||
logger.error(
|
||||
`Failed to fetch ${resource} resource for ${this.addon.name}: ${error.message}`
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
private buildResourceUrl(
|
||||
resource: Resource,
|
||||
type: string,
|
||||
id: string,
|
||||
extras?: string
|
||||
): string {
|
||||
const extrasPath = extras ? `/${extras}` : '';
|
||||
return `${this.baseUrl}/${resource}/${type}/${encodeURIComponent(id)}${extrasPath}.json`;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"rootDir": "src",
|
||||
"outDir": "dist",
|
||||
"resolveJsonModule": true
|
||||
}
|
||||
},
|
||||
"include": ["src/**/*"]
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
{
|
||||
"name": "@aiostreams/formatters",
|
||||
"version": "1.21.1",
|
||||
"main": "./dist/index.js",
|
||||
"scripts": {
|
||||
"test": "vitest run --passWithNoTests",
|
||||
"build": "tsc"
|
||||
},
|
||||
"description": "Library to take parsed information and return a formatted Stremio stream name and description",
|
||||
"dependencies": {
|
||||
"@aiostreams/types": "^1.0.0",
|
||||
"@aiostreams/utils": "^1.0.0"
|
||||
}
|
||||
}
|
||||
@@ -1,556 +0,0 @@
|
||||
import { Config, CustomFormatter, ParsedStream } from '@aiostreams/types';
|
||||
import { serviceDetails, Settings } from '@aiostreams/utils';
|
||||
import { formatDuration, formatSize, languageToEmoji } from './utils';
|
||||
|
||||
/**
|
||||
*
|
||||
* The custom formatter code in this file was adapted from https://github.com/diced/zipline/blob/trunk/src/lib/parser/index.ts
|
||||
*
|
||||
* The original code is licensed under the MIT License.
|
||||
*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 dicedtomato
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
export function customFormat(
|
||||
stream: ParsedStream,
|
||||
customFormatter: CustomFormatter
|
||||
): {
|
||||
name: string;
|
||||
description: string;
|
||||
} {
|
||||
let name: string = '';
|
||||
let description: string = '';
|
||||
|
||||
// name
|
||||
|
||||
const templateName =
|
||||
parseString(
|
||||
customFormatter.name || '',
|
||||
convertStreamToParseValue(stream)
|
||||
) || '';
|
||||
|
||||
// description
|
||||
const templateDescription =
|
||||
parseString(
|
||||
customFormatter.description || '',
|
||||
convertStreamToParseValue(stream)
|
||||
) || '';
|
||||
|
||||
// Replace placeholders in the template with actual values
|
||||
name = templateName;
|
||||
|
||||
description = templateDescription;
|
||||
|
||||
return { name, description };
|
||||
}
|
||||
|
||||
export type ParseValue = {
|
||||
config?: {
|
||||
addonName: string | null;
|
||||
showDie: boolean | null;
|
||||
};
|
||||
stream?: {
|
||||
/** @deprecated Use filename instead */
|
||||
name: string | null;
|
||||
filename: string | null;
|
||||
folderName: string | null;
|
||||
size: number | null;
|
||||
personal: boolean | null;
|
||||
quality: string | null;
|
||||
resolution: string | null;
|
||||
languages: string[] | null;
|
||||
languageEmojis: string[] | null;
|
||||
visualTags: string[] | null;
|
||||
audioTags: string[] | null;
|
||||
releaseGroup: string | null;
|
||||
regexMatched: string | null;
|
||||
encode: string | null;
|
||||
indexer: string | null;
|
||||
year: string | null;
|
||||
title: string | null;
|
||||
season: number | null;
|
||||
seasons: number[] | null;
|
||||
episode: number | null;
|
||||
seeders: number | null;
|
||||
age: string | null;
|
||||
duration: number | null;
|
||||
infoHash: string | null;
|
||||
message: string | null;
|
||||
proxied: boolean | null;
|
||||
};
|
||||
provider?: {
|
||||
id: string | null;
|
||||
shortName: string | null;
|
||||
name: string | null;
|
||||
cached: boolean | null;
|
||||
};
|
||||
addon?: {
|
||||
id: string;
|
||||
name: string;
|
||||
};
|
||||
debug?: {
|
||||
json: string | null;
|
||||
jsonf: string | null;
|
||||
};
|
||||
};
|
||||
|
||||
const convertStreamToParseValue = (stream: ParsedStream): ParseValue => {
|
||||
return {
|
||||
config: {
|
||||
addonName: Settings.ADDON_NAME,
|
||||
showDie: Settings.SHOW_DIE,
|
||||
},
|
||||
stream: {
|
||||
filename: stream.filename || null,
|
||||
name: stream.filename || null,
|
||||
folderName: stream.folderName || null,
|
||||
size: stream.size || null,
|
||||
personal: stream.personal !== undefined ? stream.personal : null,
|
||||
quality: stream.quality === 'Unknown' ? null : stream.quality,
|
||||
resolution: stream.resolution === 'Unknown' ? null : stream.resolution,
|
||||
languages: stream.languages || null,
|
||||
languageEmojis: stream.languages
|
||||
? stream.languages
|
||||
.map((lang) => languageToEmoji(lang) || lang)
|
||||
.filter((value, index, self) => self.indexOf(value) === index)
|
||||
: null,
|
||||
visualTags: stream.visualTags,
|
||||
audioTags: stream.audioTags,
|
||||
releaseGroup:
|
||||
stream.releaseGroup === 'Unknown' ? null : stream.releaseGroup,
|
||||
regexMatched: stream.regexMatched?.name || null,
|
||||
encode: stream.encode === 'Unknown' ? null : stream.encode,
|
||||
indexer: stream.indexers || null,
|
||||
seeders: stream.torrent?.seeders || null,
|
||||
year: stream.year || null,
|
||||
title: stream.title || null,
|
||||
season: stream.season || null,
|
||||
seasons: stream.seasons || null,
|
||||
episode: stream.episode || null,
|
||||
age: stream.usenet?.age || null,
|
||||
duration: stream.duration || null,
|
||||
infoHash: stream.torrent?.infoHash || null,
|
||||
message: stream.message || null,
|
||||
proxied: stream.proxied !== undefined ? stream.proxied : null,
|
||||
},
|
||||
addon: {
|
||||
id: stream.addon.id,
|
||||
name: stream.addon.name,
|
||||
},
|
||||
provider: {
|
||||
id: stream.provider?.id || null,
|
||||
shortName: stream.provider?.id
|
||||
? serviceDetails.find((service) => service.id === stream.provider?.id)
|
||||
?.shortName || null
|
||||
: null,
|
||||
name: stream.provider?.id
|
||||
? serviceDetails.find((service) => service.id === stream.provider?.id)
|
||||
?.name || null
|
||||
: null,
|
||||
cached:
|
||||
stream.provider?.cached !== undefined ? stream.provider?.cached : null,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
function parseString(str: string, value: ParseValue) {
|
||||
if (!str) return null;
|
||||
|
||||
const replacer = (key: string, value: unknown) => {
|
||||
return value;
|
||||
};
|
||||
|
||||
const data = {
|
||||
stream: value.stream,
|
||||
provider: value.provider,
|
||||
addon: value.addon,
|
||||
config: value.config,
|
||||
};
|
||||
|
||||
value.debug = {
|
||||
json: JSON.stringify(data, replacer),
|
||||
jsonf: JSON.stringify(data, replacer, 2),
|
||||
};
|
||||
|
||||
const re =
|
||||
/\{(?<type>stream|provider|debug|addon|config)\.(?<prop>\w+)(::(?<mod>(\w+(\([^)]*\))?|<|<=|=|>=|>|\^|\$|~|\/)+))?((::(?<mod_tzlocale>\S+?))|(?<mod_check>\[(?<mod_check_true>".*?")\|\|(?<mod_check_false>".*?")\]))?\}/gi;
|
||||
let matches: RegExpExecArray | null;
|
||||
|
||||
while ((matches = re.exec(str))) {
|
||||
if (!matches.groups) continue;
|
||||
|
||||
const index = matches.index as number;
|
||||
|
||||
const getV = value[matches.groups.type as keyof ParseValue];
|
||||
|
||||
if (!getV) {
|
||||
str = replaceCharsFromString(str, '{unknown_type}', index, re.lastIndex);
|
||||
re.lastIndex = index;
|
||||
continue;
|
||||
}
|
||||
|
||||
const v =
|
||||
getV[
|
||||
matches.groups.prop as
|
||||
| keyof ParseValue['stream']
|
||||
| keyof ParseValue['provider']
|
||||
| keyof ParseValue['addon']
|
||||
];
|
||||
|
||||
if (v === undefined) {
|
||||
str = replaceCharsFromString(str, '{unknown_value}', index, re.lastIndex);
|
||||
re.lastIndex = index;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (matches.groups.mod) {
|
||||
str = replaceCharsFromString(
|
||||
str,
|
||||
modifier(
|
||||
matches.groups.mod,
|
||||
v,
|
||||
matches.groups.mod_tzlocale ?? undefined,
|
||||
matches.groups.mod_check_true ?? undefined,
|
||||
matches.groups.mod_check_false ?? undefined,
|
||||
value
|
||||
),
|
||||
index,
|
||||
re.lastIndex
|
||||
);
|
||||
re.lastIndex = index;
|
||||
continue;
|
||||
}
|
||||
|
||||
str = replaceCharsFromString(str, v, index, re.lastIndex);
|
||||
re.lastIndex = index;
|
||||
}
|
||||
|
||||
return str
|
||||
.replace(/\\n/g, '\n')
|
||||
.split('\n')
|
||||
.filter(
|
||||
(line) => line.trim() !== '' && !line.includes('{tools.removeLine}')
|
||||
)
|
||||
.join('\n')
|
||||
.replace(/\{tools.newLine\}/g, '\n');
|
||||
}
|
||||
|
||||
function modifier(
|
||||
mod: string,
|
||||
value: unknown,
|
||||
tzlocale?: string,
|
||||
check_true?: string,
|
||||
check_false?: string,
|
||||
_value?: ParseValue
|
||||
): string {
|
||||
mod = mod.toLowerCase();
|
||||
check_true = check_true?.slice(1, -1);
|
||||
check_false = check_false?.slice(1, -1);
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
switch (true) {
|
||||
case mod === 'join':
|
||||
return value.join(', ');
|
||||
case mod.startsWith('join(') && mod.endsWith(')'):
|
||||
// Extract the separator from join(separator)
|
||||
// e.g. join(' - ')
|
||||
const separator = mod
|
||||
.substring(5, mod.length - 1)
|
||||
.replace(/^['"]|['"]$/g, '');
|
||||
return value.join(separator);
|
||||
case mod == 'length':
|
||||
return value.length.toString();
|
||||
case mod == 'first':
|
||||
return value.length > 0 ? String(value[0]) : '';
|
||||
case mod == 'last':
|
||||
return value.length > 0 ? String(value[value.length - 1]) : '';
|
||||
case mod == 'random':
|
||||
return value.length > 0
|
||||
? String(value[Math.floor(Math.random() * value.length)])
|
||||
: '';
|
||||
case mod == 'sort':
|
||||
return [...value].sort().join(', ');
|
||||
case mod == 'reverse':
|
||||
return [...value].reverse().join(', ');
|
||||
case mod == 'exists': {
|
||||
if (typeof check_true !== 'string' || typeof check_false !== 'string')
|
||||
return `{unknown_array_modifier(${mod})}`;
|
||||
|
||||
if (_value) {
|
||||
return value.length > 0
|
||||
? parseString(check_true, _value) || check_true
|
||||
: parseString(check_false, _value) || check_false;
|
||||
}
|
||||
|
||||
return value.length > 0 ? check_true : check_false;
|
||||
}
|
||||
default:
|
||||
return `{unknown_array_modifier(${mod})}`;
|
||||
}
|
||||
} else if (typeof value === 'string') {
|
||||
switch (true) {
|
||||
case mod == 'upper':
|
||||
return value.toUpperCase();
|
||||
case mod == 'lower':
|
||||
return value.toLowerCase();
|
||||
case mod == 'title':
|
||||
return value.charAt(0).toUpperCase() + value.slice(1);
|
||||
case mod == 'length':
|
||||
return value.length.toString();
|
||||
case mod == 'reverse':
|
||||
return value.split('').reverse().join('');
|
||||
case mod == 'base64':
|
||||
return btoa(value);
|
||||
case mod == 'string':
|
||||
return value;
|
||||
case mod == 'exists': {
|
||||
if (typeof check_true !== 'string' || typeof check_false !== 'string')
|
||||
return `{unknown_str_modifier(${mod})}`;
|
||||
|
||||
if (_value) {
|
||||
return value != 'null' && value
|
||||
? parseString(check_true, _value) || check_true
|
||||
: parseString(check_false, _value) || check_false;
|
||||
}
|
||||
|
||||
return value != 'null' && value ? check_true : check_false;
|
||||
}
|
||||
case mod.startsWith('='): {
|
||||
if (typeof check_true !== 'string' || typeof check_false !== 'string')
|
||||
return `{unknown_str_modifier(${mod})}`;
|
||||
|
||||
const check = mod.replace('=', '');
|
||||
|
||||
if (!check) return `{unknown_str_modifier(${mod})}`;
|
||||
|
||||
if (_value) {
|
||||
return value.toLowerCase() == check
|
||||
? parseString(check_true, _value) || check_true
|
||||
: parseString(check_false, _value) || check_false;
|
||||
}
|
||||
|
||||
return value.toLowerCase() == check ? check_true : check_false;
|
||||
}
|
||||
case mod.startsWith('$'): {
|
||||
if (typeof check_true !== 'string' || typeof check_false !== 'string')
|
||||
return `{unknown_str_modifier(${mod})}`;
|
||||
|
||||
const check = mod.replace('$', '');
|
||||
|
||||
if (!check) return `{unknown_str_modifier(${mod})}`;
|
||||
|
||||
if (_value) {
|
||||
return value.toLowerCase().startsWith(check)
|
||||
? parseString(check_true, _value) || check_true
|
||||
: parseString(check_false, _value) || check_false;
|
||||
}
|
||||
|
||||
return value.toLowerCase().startsWith(check) ? check_true : check_false;
|
||||
}
|
||||
case mod.startsWith('^'): {
|
||||
if (typeof check_true !== 'string' || typeof check_false !== 'string')
|
||||
return `{unknown_str_modifier(${mod})}`;
|
||||
|
||||
const check = mod.replace('^', '');
|
||||
|
||||
if (!check) return `{unknown_str_modifier(${mod})}`;
|
||||
|
||||
if (_value) {
|
||||
return value.toLowerCase().endsWith(check)
|
||||
? parseString(check_true, _value) || check_true
|
||||
: parseString(check_false, _value) || check_false;
|
||||
}
|
||||
|
||||
return value.toLowerCase().endsWith(check) ? check_true : check_false;
|
||||
}
|
||||
case mod.startsWith('~'): {
|
||||
if (typeof check_true !== 'string' || typeof check_false !== 'string')
|
||||
return `{unknown_str_modifier(${mod})}`;
|
||||
|
||||
const check = mod.replace('~', '');
|
||||
|
||||
if (!check) return `{unknown_str_modifier(${mod})}`;
|
||||
|
||||
if (_value) {
|
||||
return value.toLowerCase().includes(check)
|
||||
? parseString(check_true, _value) || check_true
|
||||
: parseString(check_false, _value) || check_false;
|
||||
}
|
||||
|
||||
return value.toLowerCase().includes(check) ? check_true : check_false;
|
||||
}
|
||||
default:
|
||||
return `{unknown_str_modifier(${mod})}`;
|
||||
}
|
||||
} else if (typeof value === 'number') {
|
||||
switch (true) {
|
||||
case mod == 'comma':
|
||||
return value.toLocaleString();
|
||||
case mod == 'hex':
|
||||
return value.toString(16);
|
||||
case mod == 'octal':
|
||||
return value.toString(8);
|
||||
case mod == 'binary':
|
||||
return value.toString(2);
|
||||
case mod == 'bytes':
|
||||
return formatSize(value);
|
||||
case mod == 'string':
|
||||
return value.toString();
|
||||
case mod == 'time':
|
||||
return formatDuration(value);
|
||||
case mod.startsWith('>='): {
|
||||
if (typeof check_true !== 'string' || typeof check_false !== 'string')
|
||||
return `{unknown_int_modifier(${mod})}`;
|
||||
|
||||
const check = Number(mod.replace('>=', ''));
|
||||
|
||||
if (Number.isNaN(check)) return `{unknown_int_modifier(${mod})}`;
|
||||
|
||||
if (_value) {
|
||||
return value >= check
|
||||
? parseString(check_true, _value) || check_true
|
||||
: parseString(check_false, _value) || check_false;
|
||||
}
|
||||
|
||||
return value >= check ? check_true : check_false;
|
||||
}
|
||||
case mod.startsWith('>'): {
|
||||
if (typeof check_true !== 'string' || typeof check_false !== 'string')
|
||||
return `{unknown_int_modifier(${mod})}`;
|
||||
|
||||
const check = Number(mod.replace('>', ''));
|
||||
|
||||
if (Number.isNaN(check)) return `{unknown_int_modifier(${mod})}`;
|
||||
|
||||
if (_value) {
|
||||
return value > check
|
||||
? parseString(check_true, _value) || check_true
|
||||
: parseString(check_false, _value) || check_false;
|
||||
}
|
||||
|
||||
return value > check ? check_true : check_false;
|
||||
}
|
||||
case mod.startsWith('='): {
|
||||
if (typeof check_true !== 'string' || typeof check_false !== 'string')
|
||||
return `{unknown_int_modifier(${mod})}`;
|
||||
|
||||
const check = Number(mod.replace('=', ''));
|
||||
|
||||
if (Number.isNaN(check)) return `{unknown_int_modifier(${mod})}`;
|
||||
|
||||
if (_value) {
|
||||
return value == check
|
||||
? parseString(check_true, _value) || check_true
|
||||
: parseString(check_false, _value) || check_false;
|
||||
}
|
||||
|
||||
return value == check ? check_true : check_false;
|
||||
}
|
||||
case mod.startsWith('<='): {
|
||||
if (typeof check_true !== 'string' || typeof check_false !== 'string')
|
||||
return `{unknown_int_modifier(${mod})}`;
|
||||
|
||||
const check = Number(mod.replace('<=', ''));
|
||||
|
||||
if (Number.isNaN(check)) return `{unknown_int_modifier(${mod})}`;
|
||||
|
||||
if (_value) {
|
||||
return value <= check
|
||||
? parseString(check_true, _value) || check_true
|
||||
: parseString(check_false, _value) || check_false;
|
||||
}
|
||||
|
||||
return value <= check ? check_true : check_false;
|
||||
}
|
||||
case mod.startsWith('<'): {
|
||||
if (typeof check_true !== 'string' || typeof check_false !== 'string')
|
||||
return `{unknown_int_modifier(${mod})}`;
|
||||
|
||||
const check = Number(mod.replace('<', ''));
|
||||
|
||||
if (Number.isNaN(check)) return `{unknown_int_modifier(${mod})}`;
|
||||
|
||||
if (_value) {
|
||||
return value < check
|
||||
? parseString(check_true, _value) || check_true
|
||||
: parseString(check_false, _value) || check_false;
|
||||
}
|
||||
|
||||
return value < check ? check_true : check_false;
|
||||
}
|
||||
default:
|
||||
return `{unknown_int_modifier(${mod})}`;
|
||||
}
|
||||
} else if (typeof value === 'boolean') {
|
||||
switch (true) {
|
||||
case mod == 'istrue': {
|
||||
if (typeof check_true !== 'string' || typeof check_false !== 'string')
|
||||
return `{unknown_bool_modifier(${mod})}`;
|
||||
|
||||
if (_value) {
|
||||
return value
|
||||
? parseString(check_true, _value) || check_true
|
||||
: parseString(check_false, _value) || check_false;
|
||||
}
|
||||
|
||||
return value ? check_true : check_false;
|
||||
}
|
||||
case mod == 'isfalse': {
|
||||
if (typeof check_true !== 'string' || typeof check_false !== 'string')
|
||||
return `{unknown_bool_modifier(${mod})}`;
|
||||
|
||||
if (_value) {
|
||||
return !value
|
||||
? parseString(check_true, _value) || check_true
|
||||
: parseString(check_false, _value) || check_false;
|
||||
}
|
||||
|
||||
return !value ? check_true : check_false;
|
||||
}
|
||||
default:
|
||||
return `{unknown_bool_modifier(${mod})}`;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
typeof check_false == 'string' &&
|
||||
(['>', '>=', '=', '<=', '<', '~', '$', '^'].some((modif) =>
|
||||
mod.startsWith(modif)
|
||||
) ||
|
||||
['istrue', 'exists', 'isfalse'].includes(mod))
|
||||
) {
|
||||
if (_value) return parseString(check_false, _value) || check_false;
|
||||
return check_false;
|
||||
}
|
||||
|
||||
return `{unknown_modifier(${mod})}`;
|
||||
}
|
||||
|
||||
function replaceCharsFromString(
|
||||
str: string,
|
||||
replace: string,
|
||||
start: number,
|
||||
end: number
|
||||
): string {
|
||||
return str.slice(0, start) + replace + str.slice(end);
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
import { ParsedStream } from '@aiostreams/types';
|
||||
import { formatDuration, formatSize, languageToEmoji } from './utils';
|
||||
import { serviceDetails, Settings } from '@aiostreams/utils';
|
||||
|
||||
export function gdriveFormat(
|
||||
stream: ParsedStream,
|
||||
minimalistic: boolean = false
|
||||
): {
|
||||
name: string;
|
||||
description: string;
|
||||
} {
|
||||
let name: string = '';
|
||||
|
||||
if (stream.provider) {
|
||||
const cacheStatus = stream.provider.cached
|
||||
? '⚡'
|
||||
: stream.provider.cached === undefined
|
||||
? '❓'
|
||||
: '⏳';
|
||||
const serviceShortName =
|
||||
serviceDetails.find((service) => service.id === stream.provider!.id)
|
||||
?.shortName || stream.provider.id;
|
||||
name += `[${serviceShortName}${cacheStatus}] `;
|
||||
}
|
||||
|
||||
if (stream.torrent?.infoHash) {
|
||||
name += `[P2P] `;
|
||||
}
|
||||
|
||||
name += `${stream.addon.name} ${stream.personal ? '(Your Media) ' : ''}`;
|
||||
if (!minimalistic) {
|
||||
name += stream.resolution;
|
||||
} else {
|
||||
name += stream.resolution !== 'Unknown' ? stream.resolution + '' : '';
|
||||
}
|
||||
|
||||
// let description: string = `${stream.quality !== 'Unknown' ? '🎥 ' + stream.quality + ' ' : ''}${stream.encode !== 'Unknown' ? '🎞️ ' + stream.encode : ''}`;
|
||||
let description: string = '';
|
||||
if (
|
||||
stream.quality ||
|
||||
stream.encode ||
|
||||
(stream.releaseGroup && !minimalistic)
|
||||
) {
|
||||
description += stream.quality !== 'Unknown' ? `🎥 ${stream.quality} ` : '';
|
||||
description += stream.encode !== 'Unknown' ? `🎞️ ${stream.encode} ` : '';
|
||||
description +=
|
||||
stream.releaseGroup !== 'Unknown' && !minimalistic
|
||||
? `🏷️ ${stream.releaseGroup}`
|
||||
: '';
|
||||
description += '\n';
|
||||
}
|
||||
|
||||
if (stream.visualTags.length > 0 || stream.audioTags.length > 0) {
|
||||
description +=
|
||||
stream.visualTags.length > 0
|
||||
? `📺 ${stream.visualTags.join(' | ')} `
|
||||
: '';
|
||||
description +=
|
||||
stream.audioTags.length > 0 ? `🎧 ${stream.audioTags.join(' | ')}` : '';
|
||||
description += '\n';
|
||||
}
|
||||
if (
|
||||
stream.size ||
|
||||
(stream.torrent?.seeders && !minimalistic) ||
|
||||
(minimalistic && stream.torrent?.seeders && !stream.provider?.cached) ||
|
||||
stream.usenet?.age ||
|
||||
stream.duration
|
||||
) {
|
||||
description += `📦 ${formatSize(stream.size || 0)} `;
|
||||
description += stream.duration
|
||||
? `⏱️ ${formatDuration(stream.duration)} `
|
||||
: '';
|
||||
description +=
|
||||
(stream.torrent?.seeders !== undefined && !minimalistic) ||
|
||||
(minimalistic && stream.torrent?.seeders && !stream.provider?.cached)
|
||||
? `👥 ${stream.torrent.seeders} `
|
||||
: '';
|
||||
|
||||
description += stream.usenet?.age ? `📅 ${stream.usenet.age} ` : '';
|
||||
description +=
|
||||
stream.indexers && !minimalistic ? `🔍 ${stream.indexers}` : '';
|
||||
description += '\n';
|
||||
}
|
||||
|
||||
if (stream.languages.length !== 0) {
|
||||
let languages = stream.languages;
|
||||
if (minimalistic) {
|
||||
languages = languages.map(
|
||||
(language) => languageToEmoji(language) || language
|
||||
);
|
||||
}
|
||||
description += `🌎 ${languages.join(minimalistic ? ' / ' : ' | ')}`;
|
||||
description += '\n';
|
||||
}
|
||||
|
||||
if (!minimalistic && (stream.filename || stream.folderName)) {
|
||||
description += stream.folderName ? `📁 ${stream.folderName}\n` : '';
|
||||
description += stream.filename ? `📄 ${stream.filename}\n` : '📄 Unknown\n';
|
||||
}
|
||||
|
||||
if (stream.message) {
|
||||
description += `📢 ${stream.message}`;
|
||||
}
|
||||
|
||||
if (stream.proxied) {
|
||||
name = `🕵️♂️ ${name}`;
|
||||
} else if (Settings.SHOW_DIE) {
|
||||
name = `🎲 ${name}`;
|
||||
}
|
||||
|
||||
description = description.trim();
|
||||
name = name.trim();
|
||||
return { name, description };
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
import { ParsedStream } from '@aiostreams/types';
|
||||
import { formatDuration, formatSize } from './utils';
|
||||
|
||||
const imposters = [
|
||||
'Disney+',
|
||||
'Netflix',
|
||||
'HBO',
|
||||
'Amazon Prime Video',
|
||||
'Hulu',
|
||||
'Apple TV+',
|
||||
'Peacock',
|
||||
'Paramount+',
|
||||
];
|
||||
|
||||
export function imposterFormat(stream: ParsedStream): {
|
||||
name: string;
|
||||
description: string;
|
||||
} {
|
||||
let name: string = '';
|
||||
|
||||
if (stream.torrent?.infoHash) {
|
||||
name += `[P2P] `;
|
||||
}
|
||||
const chosenImposter =
|
||||
imposters[Math.floor(Math.random() * imposters.length)];
|
||||
name += `${chosenImposter} ${stream.personal ? '(Your Media) ' : ''}`;
|
||||
|
||||
name += stream.resolution !== 'Unknown' ? stream.resolution + '' : '';
|
||||
|
||||
let description: string = `${stream.quality !== 'Unknown' ? '🎥 ' + stream.quality + ' ' : ''}${stream.encode !== 'Unknown' ? '🎞️ ' + stream.encode : ''}`;
|
||||
|
||||
if (stream.visualTags.length > 0 || stream.audioTags.length > 0) {
|
||||
description += '\n';
|
||||
|
||||
description +=
|
||||
stream.visualTags.length > 0
|
||||
? `📺 ${stream.visualTags.join(' | ')} `
|
||||
: '';
|
||||
description +=
|
||||
stream.audioTags.length > 0 ? `🎧 ${stream.audioTags.join(' | ')}` : '';
|
||||
}
|
||||
if (
|
||||
stream.size ||
|
||||
stream.torrent?.seeders ||
|
||||
stream.usenet?.age ||
|
||||
stream.duration
|
||||
) {
|
||||
description += '\n';
|
||||
|
||||
description += `📦 ${formatSize(stream.size || 0)} `;
|
||||
description += stream.duration
|
||||
? `⏱️ ${formatDuration(stream.duration)} `
|
||||
: '';
|
||||
description += stream.torrent?.seeders
|
||||
? `👥 ${stream.torrent.seeders}`
|
||||
: '';
|
||||
|
||||
description += stream.usenet?.age ? `📅 ${stream.usenet.age}` : '';
|
||||
}
|
||||
|
||||
if (stream.languages.length !== 0) {
|
||||
let languages = stream.languages;
|
||||
description += `\n🔊 ${languages.join(' | ')}`;
|
||||
}
|
||||
|
||||
description += `\n📄 ${stream.filename ? stream.filename : 'Unknown'}`;
|
||||
if (stream.message) {
|
||||
description += `\n📢${stream.message}`;
|
||||
}
|
||||
return { name, description };
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
export * from './gdrive';
|
||||
export * from './utils';
|
||||
export * from './torrentio';
|
||||
export * from './torbox';
|
||||
export * from './imposter';
|
||||
export * from './custom';
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user