Commit graph

221 commits

Author SHA1 Message Date
LimeDrive
cdc3d0834b refactor(debrid): switch to DLToken/EDToken/OCCredentials/PPCredentials 2026-04-04 12:14:45 +02:00
LimeDrive
16ac08423e feat(settings): hotfix yggflix 2026-04-04 02:49:53 +02:00
LimeDrive
e79d5874d7 feat(admin): améliorer l'interface du tableau de bord avec des sections et des informations sur les torrents 2026-04-03 17:04:09 +02:00
LimeDrive
e8b0976332 refactor(logging): switch info/debug logs to trace across modules
convert info/debug logs to trace across modules for deeper diagnostics
without changing behavior
2026-04-03 12:09:26 +02:00
LimeDrive
09adc19273 feat(tmdb_matcher): implement orphan matcher with history
- add TMDB orphan matcher backend (orphan_matcher.py) and search client (tmdb_search.py)
- introduce Redis-backed run history tracker (history.py) for matcher runs
- extend TorrentItemModel with tmdb_match_attempted_at and index
- add Alembic migration to create tmdb_match_attempted_at and its index
- integrate new tmdb_orphan_matching job into scheduler; expose in UI
- add admin UI: tmdb_matcher.html, history/revert endpoints, and nav entry
- wire settings: scheduler_tmdb_match_interval_hours and batch size
- enhance title normalizer: strip possessive s and remove technical brackets/tokens
- update admin docs to reflect new matcher and deprecation of old cleanup
- update admin base navigation and scheduled tasks page accordingly
2026-04-02 20:43:36 +02:00
LimeDrive
acef8f2516 feat(torrent-group): add initial grouping framework for torrents
introduce initial torrent grouping: add torrent_groups table and
group_id on torrent_items. include migrations, ORM models, and DAOs.
expose admin/web endpoints to group by info_hash and by title/size.
propagate tmdb_id across grouped items. non-destructive and backwards
compatible with existing data
2026-04-02 16:13:09 +02:00
LimeDrive
3d3372a4bd feat: add scheduled tasks admin page with auto-refresh and job management
- Implemented a new HTML page for managing scheduled tasks in the admin panel.
- Added JavaScript functionality for auto-refreshing job statuses and triggering jobs manually.
- Enhanced job result display with relative time and duration formatting.
- Introduced a toast notification system for user feedback on job actions.

fix: update Redis cache key generation to include a prefix

- Modified the Redis cache key generation to prepend "search:" to the hashed key for better organization.

refactor: improve Yggflix API search functionality

- Added an optional parameter to the search_movie method to specify the search type.
- Implemented a fallback mechanism to broaden search if initial results are insufficient.

chore: enhance Yggflix service with improved result handling

- Introduced a threshold for retrying searches with a broader query type based on result ratios.
- Increased the limit for sorted results from 50 to 100.

feat: add maintenance endpoints for managing expired API and peer keys

- Created endpoints to disable expired API keys and peer keys in the admin panel.
- Added functionality to clean orphan torrent items based on a specified age.

feat: integrate scheduler into the application lifecycle

- Initialized a database cleanup scheduler during application startup.
- Ensured proper shutdown of the scheduler during application termination.
2026-04-02 00:52:11 +02:00
LimeDrive
31cd83e9cb refactor(debrid): adjust not_cached ttl and remove series file_index path
extend not_cached ttl from 20m to 3h to reduce re-checks
of not cached items

remove the file_index shortcut for series in Torbox
and rely on season/episode parsing
2026-04-01 22:34:48 +02:00
LimeDrive
76bb5ab8aa feat: améliorer la gestion des filtres et ajuster le délai de rafraîchissement en arrière-plan 2026-04-01 18:10:22 +02:00
LimeDrive
d65366cce2 feat: Ajouter la gestion du cache local Postgres avec des paramètres de résultats minimum et de durée de validité 2026-04-01 15:37:54 +02:00
LimeDrive
15f3d1facb feat: Refactor torrent filtering and TMDB ID assignment logic for improved accuracy 2026-04-01 13:25:37 +02:00
LimeDrive
94c0e26f62 feat(normalizer): add title extraction and boundary detection logic 2026-04-01 12:00:41 +02:00
LimeDrive
fa68cb2c6b feat: Implement title matching and language rules management
- Refactored title filtering logic in `filter_results.py` to utilize a new title matching module.
- Introduced normalization functions for search queries in `jackett_service.py` and `yggflix_service.py`.
- Added new endpoints for managing title and language normalization rules in the admin views.
- Implemented loading and reloading of title matching and language rules in the application lifecycle.
- Enhanced release group extraction and language detection in `parser_utils.py` using the new title matching module.
2026-04-01 11:04:04 +02:00
LimeDrive
c71e301dfb fix(filter): skip year filtering when year is not provided 2026-03-31 16:30:59 +02:00
LimeDrive
a9c2ce268e feat(ygg): add fallback search and pagination for movie queries
Refactor search_movie method to remove tmdb_id parameter and add offset support for pagination. Implement automatic fallback to search type when movie type returns empty results, improving result coverage. Add intelligent page 2 fetching in service layer based on title pre-filter ratio threshold to avoid unnecessary API calls.
2026-03-31 15:18:52 +02:00
LimeDrive
204daee1a0 feat: ajouter une action pour vider le cache de recherche et mettre à jour la logique de filtrage des modèles autorisés 2026-03-31 03:18:04 +02:00
LimeDrive
76afe6ed15 feat: enhance json_response method to support json data and add new torrent management features in Torbox 2026-03-31 03:06:07 +02:00
LimeDrive
5b07696526 feat: add warning for non-series media context in TorrentSmartContainer 2026-03-31 01:23:00 +02:00
LimeDrive
099132d9c4 feat: add background caching for magnets/torrents in AllDebrid 2026-03-30 23:52:50 +02:00
LimeDrive
fb019a85bf feat(search): add configurable indexer search phases and RealDebrid optimization
Introduce a 4-phase search system where private indexers are grouped by priority:
- Phase 1 (priority_private): always queried first
- Phase 2 (intermediary_private): queried only if private results < minCachedResults
- Phase 3 (fallback_private): queried only if still insufficient
- Phase 4 (public): Yggflix relay position controlled by yggflixPriority toggle

Add rdMinCachedBeforeCheck setting to skip RealDebrid if prior services already found enough cached results, since RD API is slow (~3s) and rate-limited. Default to 3.

Non-blocking magnet cleanup in AllDebrid availability checks via background task. G3MINI now computes info_hash from .torrent files when API omits it. Public indexer results are excluded from final matches unless already cached by a debrid service.
2026-03-30 17:49:18 +02:00
LimeDrive
0d0c238383 feat(trackers): add support for ABN, G3MINI, and TheOldSchool UNIT3D indexers
Remove deprecated Sharewood tracker integration and add three new private trackers:
- ABN (Abnormal): keyword-based search with name filtering
- G3MINI (Gemini Tracker): TMDB/IMDB ID-based filtering
- TheOldSchool: TMDB/IMDB ID-based filtering

Includes new API clients, result parsers, and service layers. Updates frontend UI, settings configuration, and credential handling to support the new indexers with proper passkey management.
2026-03-30 14:23:20 +02:00
LimeDrive
7755a78842 feat(security): add Fernet encryption for config tokens and CSRF protection
- Implement Fernet encryption for configuration URLs to protect sensitive user settings
- Add CONFIG_SECRET_KEY environment variable for key derivation
- Add server-side /api/config/encode endpoint for secure config token generation
- Add CSRF token generation and validation for all admin POST routes
- Auto-inject CSRF tokens into admin forms and AJAX requests via JavaScript
- Update frontend to use async server encoding instead of client-side Base64
- Add localStorage fallback for config restoration on /configure pages
- Maintain backward compatibility with existing Base64-encoded URLs
- Log warning at startup if CONFIG_SECRET_KEY is not configured
- Convert debug logs to trace level in TorrentSmartContainer for reduced noise
2026-03-30 01:18:08 +02:00
LimeDrive
8468bae024 feat(admin): add metadata mappings table and complete admin UI redesign
Introduce a metadata_mappings table with DAO/model layers for admin-managed
IMDB→TMDB/title overrides, and overhaul the admin panel with a modern
Bootstrap 5 sidebar UI.

- Add metadata_mappings table with migrations (search_titles, year_override)
- Add MetadataMappingDAO with standalone session helpers for use outside FastAPI
- Add new admin pages: dashboard, mappings CRUD, maintenance, config, hash/TMDB search
- Integrate DB mapping lookups into Cinemeta and TMDB metadata providers
- Update catalog views to use DB mappings before hitting external APIs
- Rewrite all admin templates with Bootstrap 5, sidebar navigation, French labels
- Add session-based auth for admin routes with Redis session store
2026-03-29 04:46:51 +02:00
LimeDrive
ab70ea53a5 feat(debrid): add allow_debrid_download setting and TorBox preference for French indexers
Add `allow_debrid_download` setting to control whether non-cached download streams are visible in Stremio results. When disabled, only instantly available streams are shown. Additionally, automatically prefer TorBox for downloads from special French indexers (C411, Torr9, LaCale, GenerationFree) when TorBox is configured, overriding the user's default debrid service selection.
2026-03-28 15:53:57 +01:00
LimeDrive
b64c14200d docs(debrid): document optional enrichment hook in caching strategy 2026-03-28 05:15:57 +01:00
LimeDrive
0aba81abb2 feat(peer): add authenticated peer-to-peer cache sharing
Introduces a secure peer-to-peer cache sharing system using HMAC-SHA256 request signatures and Fernet (AES-128-CBC) response encryption.

- New peer_keys table for per-peer credential management (key_id, secret)
- New /api/peer/check endpoint returns encrypted debrid availability data
- New /api/peer/items endpoint returns encrypted torrent metadata
- Rate limiting per peer key with configurable limits and windows
- Admin UI for creating, viewing, revoking, and deleting peer keys
- Peer cache enrichment integrated into BaseDebrid L2.5 lookup pipeline
- StremThruDebrid override with cross-service PG L2 check + peer cache
- Removed old /api/share/cache endpoint (replaced by /api/peer/*)
- Added cryptography package dependency

BREAKING CHANGE: The /api/share/cache endpoint has been removed and replaced with /api/peer/check. Clients must update to use HMAC authentication with X-Peer-Key-Id, X-Peer-Timestamp, and X-Peer-Signature headers.
2026-03-28 05:07:40 +01:00
LimeDrive
0c1d305784 feat(debrid): add PostgreSQL L2 cache for persistent debrid availability
Add a two-level caching architecture for debrid service availability lookups:
- L1: Redis (existing) with 10-day TTL for fast in-memory access
- L2: PostgreSQL with 30-day TTL for persistent caching across Redis restarts

Changes:
- Add `debrid_cache` table with unique constraint on (info_hash, service) and indexes for efficient queries
- Create `DebridCacheDAO` with batch get/upsert and invalidation methods
- Add pgCron job to periodically clean up expired cache entries
- Extend `get_availability_bulk_cached` to check PG on Redis miss, warm Redis from PG hits, and write confirmed-cached results to PG
- Add `invalidate_availability_cache` method to remove false positives from both caches when NO_CACHE_VIDEO_URL is returned during playback
- Integrate `db_session` dependency into playback and search views
- Add retry handling to Yggflix API (3 retries, ignore Retry-After headers) and rate-limiting delay (0.3s) between consecutive queries
2026-03-26 15:47:37 +01:00
LimeDrive
9203464680 refactor(logging): downgrade verbose log levels from info to debug/trace
Lower log verbosity across the codebase by converting info-level logs to debug
and debug-level logs to trace. This reduces noise in production while keeping
detailed information available for debugging when needed.

Affected modules: API key DAO, Real Debrid token manager, C411/Torr9/YGG
indexers, debrid services, torrent container, playback/stream handlers,
search views, and utility modules.
2026-03-26 13:49:57 +01:00
LimeDrive
709fb805b2 refactor(logging): use trace level for verbose internal logging
Downgrade debug logs to trace level for internal processing details that are too verbose for normal debugging. Affects c411, lacale, sharewood, and torr9 services.
2026-03-26 13:07:56 +01:00
LimeDrive
26ec572e45 refactor(playback): use hashed cache keys and add rate limiting
Refactor playback stream caching to use deterministic hash-based keys for user and content identifiers, removing plain-text API keys and query data from Redis keys.

Key changes:
- Add fixed-window rate limiting (60 requests per 60 seconds per user)
- Replace cache keys using hashed user/content identifiers instead of raw API keys
- Extend TTLs from 20 minutes to 6 hours for stream links and direct links
- Fix tracker credential leak by skipping credentials when file is cached on debrid service
- Simplify get_stream_link by removing series-specific caching logic
2026-03-26 12:56:26 +01:00
LimeDrive
8739513ced refactor(realdebrid): improve availability checking with direct RD API
Replaced StremThru-dependent availability check with a two-step approach:
- Step 1: Use StremThru community cache when available
- Step 2: Fall back to direct RD API checks via anonymous magnet adds

Added _check_availability_direct method to check RD cache by:
- Marking already-cached hashes from existing account torrents
- Adding anonymous magnets for remaining hashes (0.5s rate limit)
- Checking status of newly added torrents
- Performing background cleanup of temp torrents

Added _add_magnet_probe helper for low-level magnet addition with retry logic for rate limits, and _delete_torrents_background for non-blocking cleanup.

Changed return type from object wrapper to flat array, moved regex import to module level, and added deduplication of input hashes. Also fixed logging style by removing unnecessary f-string formatting.
2026-03-26 01:22:38 +01:00
LimeDrive
62fb267622 refactor(logging): optimize log levels and enhance secret redaction
Convert verbose debug messages to trace level for cleaner production logs, improve secret redaction patterns to handle JWT tokens and API key parameters while preserving parameter names, and standardize log messages to English for consistency across the codebase.
2026-03-25 16:56:32 +01:00
LimeCat on the Hub's
1be159afb3
Merge pull request #86 from LimeHubs/limedrive/develop
Refactor filtering logic and improve performance with caching
2026-03-25 05:13:32 +01:00
LimeDrive
dbd050e226 refactor: Enhance filtering logic and improve performance with caching 2026-03-25 05:05:53 +01:00
LimeDrive
ce2e88a24d refactor: Supprimer le cache public et les références associées 2026-03-25 03:36:36 +01:00
LimeDrive
7074387c3a feat: Implement StremThruDebrid integration with new SDK
- Added StremThruDebrid class for handling debrid operations using StremThru as backend.
- Introduced StremThruSDK for API interactions, including health checks and request handling.
- Created error handling with StremThruError for better error management.
- Updated torrent_smart_container to use the new StremThruDebrid class.
- Added necessary utility functions and data structures for managing magnet and torrent data.
- Implemented caching and session management for improved performance and reliability.
2026-03-25 02:23:56 +01:00
LimeDrive
6a973e1574 refactor: change logger level from info to debug for detailed request and filtering logs 2026-03-25 00:12:00 +01:00
LimeDrive
c9e4ad79a8 refactor: improve search functionality and logging in C411API and C411Service 2026-03-24 21:52:38 +01:00
LimeDrive
310b20de6e perf: async cleanup and small parallelization improvements
- torrent_smart_container: remove redundant threading.Thread from
  cache_container_items() — already runs via asyncio.to_thread() at
  call sites, internal thread was a no-op double-wrap
- catalog/views.py: parallelize get_tv_details() + Redis IMDB cache
  lookup in process_one() with asyncio.gather() (independent calls)
- torr9_service.py: replace hardcoded "fr-FR" with settings.tmdb_language

Note: alldebrid delete_magnets and realdebrid _get_cached_torrent_info
kept sequential intentionally — API rate limits make parallelization risky.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-24 19:34:20 +01:00
LimeDrive
5e183c48a0 refactor: async fixes, security hardening, and code deduplication
Async correctness:
- Wrap blocking time.sleep/requests.get calls with asyncio.to_thread()
  in torrent_service.py and torr9_service.py
- Run cache_container_items() as fire-and-forget background task via
  asyncio.create_task(asyncio.to_thread(...)) in search/views.py
- Make RDTokenManager.get_access_token() and new_access_token() async,
  replace requests.post with aiohttp (token_manager.py)
- Make RealDebrid.get_headers() async, await all callers (realdebrid.py)

Security:
- Remove API key, device code, and PIN values from log output
  (auth/views.py, admin/views.py)
- Add WARNING on startup when SESSION_KEY uses the insecure default
  value (settings.py)
- Make admin template dir configurable via settings.admin_template_dir

Performance:
- Parallelize TMDB metadata fetches with asyncio.gather() (catalog/views.py)
- Add tmdb_language setting instead of hardcoded "fr-FR"

Deduplication:
- Extract ensure_uuid() to stream_fusion/web/api/utils.py
- Extract get_client_ip() to stream_fusion/web/utils.py
- Replace 8-way if/elif debrid factory with _SERVICE_MAP dict +
  _build_service() helper (get_debrid_service.py)
- Extract _model_to_schema() in APIKeyDAO to remove 6 repeated blocks
- Simplify ProxyStreamer: remove manual BytesIO buffer, stream directly
  via iter_any() (stream/views.py)

Inspired by commits 823bc77 and e306eb5 from limedrive/develop.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-24 19:05:33 +01:00
LimeDrive
93ec64eb4a fix: update StremThru handling and improve torrent file processing in cache pre-fetch 2026-03-24 17:16:30 +01:00
LimeDrive
92db524f70 fix: update .gitignore and dev-compose.yml for environment configuration; add StremThru response handling methods 2026-03-24 15:54:46 +01:00
LimeDrive
dfc8182960 feat: shared Redis availability cache for all debrid providers (issue #77)
Implements a generic caching layer in BaseDebrid that wraps every provider's
get_availability_bulk() with a shared Redis cache, reducing API calls and
cross-user redundancy.

Key changes:
- base_debrid.py: add get_availability_bulk_cached(), _sanitize_for_cache(),
  _index_results_by_hash(), _reconstruct_response(), service_name property.
  Cache keys: debrid_avail:{service}:{hash}. TTL: 3d (cached), 10min (not cached).
  Security: _sanitize_for_cache() strips private links/tokens before shared storage.
- alldebrid.py: remove fragile cache helpers (_cache_get_json, _cache_set_json,
  _lookup_local_cache, _write_local_cache); add provider overrides for #77;
  fix rate limiter attribute names (global_limit/period, was silently ignored);
  remove statusCode==4 fallback (field absent from /magnet/upload response);
  re-comment in English; StremThru results no longer cached locally.
- realdebrid.py, torbox.py, premiumize.py, stremthru.py: add provider overrides.
- views.py: replace get_availability_bulk() → get_availability_bulk_cached()
  at both call sites (prefetch + stream_processing).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 23:03:47 +01:00
laster13
5b7def748c
Merge branch 'develop' into pr-limehubs-develop 2026-03-23 18:24:45 +01:00
laster13
7ed11a1fea fix: stabilize StremThru/AllDebrid cache checks, playback, and stream caching 2026-03-23 16:54:59 +00:00
LimeDrive
6f674a88db fix: cache MAGNET_INVALID_URI as confirmed not-cached (1h TTL)
MAGNET_INVALID_URI on a valid 40-char hash means AD doesn't have it
in cache — treat as a confirmed negative and store in Redis for 1h.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 03:06:20 +01:00
LimeDrive
cd3e2c4059 fix: handle error responses from AD upload (no hash field + no Redis cache)
Error responses (e.g. MAGNET_INVALID_URI) contain "magnet" not "hash".
Fall back to m.get("magnet") so the hash is not silently dropped.

MAGNET_INVALID_URI on a valid 40-char hash likely means AD cannot verify
an unknown hash without trackers — not a confirmed "not in cache" state.
These results are marked instant:False locally but NOT stored in Redis
to avoid caching a false negative caused by the trackless format.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 03:04:47 +01:00
LimeDrive
01ff4c2495 fix: remove statusCode check from upload response (field not present)
statusCode is only returned by /v4.1/magnet/status, not by /v4/magnet/upload.
The upload response only contains `ready: bool` to indicate cache status.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 02:56:48 +01:00
LimeDrive
3cdf5928cf fix: do not cache StremThru results in Redis
StremThru manages its own community cache and keeps it up to date.
Caching its responses locally would serve stale data and bypass
its real-time updates. Only direct AD API responses are cached.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 02:46:25 +01:00
LimeDrive
5a0dd36caa feat: shared Redis cache for AD availability check (7d/1h TTL)
Add a shared Redis availability cache keyed by hash (debrid:availability:ad:{hash})
so all users benefit from previous checks without hitting the AD API again.

TTLs:
- Confirmed cached (instant:True)  → 7 days
- Confirmed not cached (instant:False) → 1 hour

Anti-pollution safety rules:
- False is only cached when the AD API returned status:success AND the hash
  was present in the response (confirmed by AD itself)
- API errors, MAGNET_TOO_MANY_ACTIVE, exceptions and missing hashes
  never produce a cache entry → a misconfigured token cannot pollute
  the shared cache for other users
- StremThru confirmed results are also stored (always True, 7 days)
- Redis lookup uses mget (single round-trip for all hashes)
- Redis writes use pipeline (single round-trip per batch)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 02:41:50 +01:00