Commit Graph

458 Commits

Author SHA1 Message Date
Sucukdeluxe
bece2f3e85 Performance: prune long-lived caches, hoist regexes, idle chart redraws
Three low-risk optimizations that reduce CPU/memory footprint without
changing user-visible behavior:

1. Periodic cleanup of unbounded module-level Maps (24/7 stability):
   - debridLinkKeyCooldowns, debridLinkKeyCooldownDetails,
     debridLinkKeyRuntimeStatuses (debrid.ts)
   - megaDebridAccountCooldowns (debrid.ts)
   - allDebridHostInfoCache (download-manager.ts)
   - All pruned every 10 min via existing resetStaleRetryState() with a
     1h grace window for debugging
   - Without this, modules accumulated entries indefinitely over days
     of continuous server operation

2. Hoist regex literals in resolveArchiveItemsFromList() to module scope.
   Avoids 5 RegExp constructions per call. The function is called per
   archive set during extraction discovery — adds up on packages with
   many archives.

3. BandwidthChart: skip the 250ms redraw interval while the session is
   stopped or paused. The chart renders once on state change to show the
   latest history, then sleeps until downloads resume. Saves 4 canvas
   redraws per second when idle (renderer CPU).

No functional changes. All 565 tests green.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-19 12:32:38 +02:00
Sucukdeluxe
d4b98ad172 Better error logging for non-Administrator/headless server scenarios
Three improvements for users running on servers where the Windows account
is not "Administrator" or where the environment is headless (Service, RDP-
disconnected, no interactive desktop):

1. readSettingsFile / readSessionFile: distinguish ENOENT (normal first run)
   from EACCES/EPERM (permission problem). The latter logs an explicit
   message including the current Windows username so the user can spot
   misconfigured ACLs immediately.

2. ensureBaseDir: log EACCES/EPERM with the current username before re-
   throwing. Previously the error bubbled up without any hint why the
   AppData directory creation failed.

3. createTray: log a warning when Tray creation fails (typical on Windows
   Service / headless servers / RDP disconnected sessions). Previously the
   error was silently swallowed and minimize-to-tray would just not work
   without explanation.

These errors were silently swallowed before, making it impossible to
diagnose problems on servers with restricted user accounts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-19 11:53:07 +02:00
Sucukdeluxe
6e936cd5bc Bonus dir detection: normalize separators (Making.Of, Behind.The.Scenes)
The v1.7.130 BONUS_DIR_PATTERNS used substring matching with space-separated
patterns like "making of" and "behind the scenes", but real-world subfolder
names use dot/dash/underscore separators (e.g. "Breaking.Bad.S05.Making.Of").
These were NOT detected as bonus dirs, causing the safety net in v1.7.131 to
apply the source filename's episode token to the package name, producing
mislabeled bonus files like "Breaking.Bad.S05E10.GERMAN.BluRay.720p.TSCC".

Fix: normalize folder segments by stripping all separators ([._-\s]+) before
matching against BONUS_DIR_NORMALIZED_PATTERNS. "Breaking.Bad.S05.Making.Of"
normalizes to "breakingbads05makingof" which matches "makingof".

Also extend BONUS_FILENAME_RE with "inside-e\d+" and "making-of-e\d+" to
catch more filename variants from Breaking Bad BluRay extras.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 15:03:02 +02:00
Sucukdeluxe
1dfb486145 Auto-rename safety net: never strip valid SxxExx episode token
Real-world scenario from user logs: package "Drei.Meter.ueber.dem.Himmel.
S01GERMAN.DL.720P.WEB.X264-WAYNE" (note malformed S01GERMAN with no
separator) caused the auto-renamer to strip the source's S01E01..S01E08
episode tokens because SCENE_SEASON_ONLY_RE doesn't match a season followed
by an immediate letter (no separator).

Result: all 8 episodes in the season pack collapsed to the same target name
and collided in the MKV library with (2)(3)(4)(5)(6)(7)(8) suffixes.

Fix: After buildAutoRenameBaseNameFromFoldersWithOptions, check if the
source filename has a valid episode token. If yes:
  1. If target has NO episode token: try to insert it via regex replacement
     (Sxx<garbage> -> SxxExx.<garbage>), then via applyEpisodeTokenToFolderName.
     If both fail, skip the rename entirely (preserve source name).
  2. If target has a DIFFERENT episode token: skip the rename (mislabel risk).

This guard is the last line of defense against the helper's regex
limitations on malformed package names.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 11:45:41 +02:00
Sucukdeluxe
6713771144 Skip bonus/extras content in MKV collection and auto-rename
Bonus content (Featurettes, Behind-The-Scenes, Making-Of, Deleted Scenes,
etc.) was being moved into the flat MKV library with generic names like
"Schrotflinte.mkv" or "White.House.mkv", losing all show context. Auto-rename
also touched these files and would mislabel them with episode tokens.

Real-world impact: 397 bonus files from Breaking Bad S03/S04/S05 BluRay
extras subdirectories landed in the user's main library with nonsense names.

Fix:
- Add isInsideBonusDir() that walks the path from file to package root,
  checking each directory segment for bonus indicators (Extras, Bonus,
  Featurettes, Specials, Behind-The-Scenes, Making-Of, Deleted-Scenes, etc.)
- Add BONUS_FILENAME_RE to catch bonus indicators in filenames (making-of-e02,
  deleted-scene, alternate-ending, gag-reel, behind-the-scenes, etc.)
- Auto-rename: skip files matching either pattern
- MKV collection: skip files matching either pattern, log skipped count

Bonus files now stay in the package output directory with their original
names; only the actual episodes get moved to the flat library.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 11:28:44 +02:00
Sucukdeluxe
49efebd001 Extend hybrid companion stem matching to all archive types
The stem extraction regex for matching companion metadata files (.sfv,
.nfo) to their archives only handled RAR patterns. Now also covers
ZIP, 7z, tar, generic splits, and recovery volumes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 21:28:06 +02:00
Sucukdeluxe
711147fc10 Fix companion files stuck at extraction labels in hybrid mode
When all archive parts were already extracted in a prior hybrid round and
a companion file (.sfv, .nfo, .md5) downloads later, result.extracted is
0 so the companion's status was never updated from "Entpacken - Ausstehend"
or "Entpacken - Warten auf Parts".

Now companion metadata files are explicitly marked as "Entpackt (Metadaten)"
when no archives need extraction and no failures occurred, preventing them
from blocking package completion indefinitely.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 20:41:38 +02:00
Sucukdeluxe
ab5fcaf836 Clean up companion metadata files (.sfv, .nfo, .md5) with their archives
collectArchiveCleanupTargets() now includes companion files (.sfv, .nfo,
.md5, .sha1, .sha256, .crc, .srr) that share the same base stem as the
archive parts. Previously these were left as orphans after archive cleanup.

Applies to all archive types: multipart RAR, single RAR, ZIP, split ZIP,
7z, and split 7z.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 20:31:58 +02:00
Sucukdeluxe
021401e3b6 Mark companion metadata files (.sfv) as extracted during hybrid extraction
SFV files belong to the same archive set as the RAR parts but were not
included in hybridFileNames, causing them to stay stuck on "Entpacken -
Ausstehend" after the RAR parts were successfully extracted. This blocked
package completion in hybrid extraction mode.

Fix: collect archive base stems from extracted parts and match companion
metadata files (.sfv, .nfo, etc.) by stem, adding them to hybridFileNames
so they get marked as "Entpackt" together with their archive parts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 20:21:16 +02:00
Sucukdeluxe
9d611bd749 Accept small metadata files (.sfv, .nfo, .nzb) without retry loops
SFV checksum verification files are legitimately tiny (~128 bytes) but were
rejected by the "suspicious small download" detection, causing infinite
"Direktlink erneuern" retry loops that blocked package extraction.

- Add KNOWN_SMALL_FILE_RE for .sfv, .nfo, .nzb, .md5, .sha1, .sha256, .crc,
  .txt, .url, .lnk, .srr file extensions
- Skip suspicious-small-download rejection for known small files when they
  match their expected size (or have no size expectation)
- Skip tiny-download error detection for known small metadata files
- Add test: verifies .sfv file downloads without retries and completes

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 20:07:26 +02:00
Sucukdeluxe
650dafb535 Fix support bundle export freeze and resume prealloc recovery 2026-03-29 03:25:58 +02:00
Sucukdeluxe
653e756010 Harden download integrity, extraction safety, and update security 2026-03-28 16:27:21 +01:00
Sucukdeluxe
a1d72b6dbc Fix resume tail corruption after terminated streams 2026-03-28 02:30:30 +01:00
Sucukdeluxe
e8c6761bf0 Harden state persistence and fix provider abort handling
- Add safeJsonReplacer to all JSON.stringify calls in storage.ts to prevent
  NaN/Infinity values from corrupting state files and causing queue loss
- Fix LinkSnappy and 1Fichier retry loops: use sleepWithSignal() instead of
  sleep() so abort signals are respected during retry delays
- Fix Debrid-Link polling: replace raw setTimeout with sleepWithSignal() so
  URL generation polling can be cancelled
- Fix Mega-Debrid doConnectApi: clear token cache on 401/403 responses
  instead of caching invalid credentials for 20 minutes
- Add logging when normalizeLoadedSession removes orphaned items so data
  loss during startup is visible in logs

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 19:47:58 +01:00
Sucukdeluxe
5aeab9ecad Prevent queue loss during app updates
- Increase quit timeout from 900ms to 5000ms to ensure pending saves complete
- Add persistNowSync() called before update install to flush queue to disk
- Remove blockAllPersistence from shutdown save condition — shutdown must
  always persist to prevent data loss across restarts
- Add temp file recovery as last resort when both primary and backup
  session files are corrupted

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 19:34:48 +01:00
Sucukdeluxe
52bafed0b2 Add archive deobfuscation for hoster-mangled filenames
Some hosters/debrid services obfuscate downloaded archive filenames by
mutating characters and changing extensions (e.g. .part06.rar → .part06.mov,
star_crossed → star_crossfed). This breaks extraction since the extractor
relies on filename patterns to discover archive parts.

New deobfuscateArchiveFiles() method runs after download, before extraction:
- Reads magic bytes of non-archive files via detectArchiveSignature()
- If RAR/7z/ZIP signature found: corrects the extension
- Uses correctly-named sibling .rar files as reference to reconstruct
  the full correct filename including part number
- Updates item.fileName and item.targetPath after rename

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 13:28:40 +01:00
Sucukdeluxe
38179881f5 Fix Debrid-Link key rotation cascade failure, case-sensitive rename, and sample filter
- notDebrid (host-level) no longer burns all keys: stops rotation immediately
  with 5min cooldown instead of cycling through all 9 keys pointlessly
- Remove double provider-blockade: debrid_link_cooldown no longer stacks
  recordProviderFailure + applyProviderBusyBackoff on top of key cooldowns
- Detect timeout cascades: 2+ consecutive transport failures trigger 3min
  cooldown instead of burning remaining keys
- Case-sensitive rename: files with different casing (e.g. lowercase scene
  names) now get properly renamed instead of being skipped as "already matching"
- Extended sample filter: detect -s.mkv suffix and \Sample\ subdirectories
  in auto-rename (already worked in MKV-move)
- Add key status display with state pills in Debrid-Link key stats popup
- Add parseDebridLinkTerminalFailure for fast-fail on exhausted keys

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 13:04:42 +01:00
Sucukdeluxe
c5dd6f4f30 Harden Debrid-Link key failover and pending-state handling
- Add polling loop (5x 2s) in resolveDownloaderEntry when /add returns
  no downloadUrl — Debrid-Link sometimes needs seconds to generate links
- Classify missing/expired downloadUrl as temporary instead of fatal so
  key rotation kicks in before giving up
- Change notDebrid from fatal to temporary — "host may be down" is
  transient, all keys should be tried before failing
- Raise parseRetryAfterMs cap from 2min to 1h — floodDetected mandates
  "retry after 1 hour" per API docs

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 19:53:54 +01:00
Sucukdeluxe
2d9fbb07ea Revert daily-log and queue-scope changes back to v1.7.112 state
Remove daily-log module entirely (caused UI freezes due to sync I/O
even after async rewrite). Revert queue-scope stop() change (was for
a different project). All source files now match v1.7.112.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-24 10:15:28 +01:00
Sucukdeluxe
45310f0bf7 Fix daily-log freezes and revert unrelated queue scope change
- Rewrite daily-log from synchronous fs.writeSync to async buffered
  writes (500ms flush interval), matching the main logger's pattern.
  The sync writes blocked the event loop on every log line.
- Revert the stop() queue scope change from v1.7.114 which was
  intended for a different project.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-24 10:03:35 +01:00
Sucukdeluxe
c215fdd658 Preserve selected-only run scope across stop/start cycles
When startItems() was used with a subset of items (e.g. 2000 of 6020),
stopping and restarting would pick up ALL 6020 queued items instead of
just the original 2000. Now stop() marks items outside the run set as
"Gestoppt" so they are not automatically included in the next start().

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-24 09:29:01 +01:00
Sucukdeluxe
d7149829ea Add daily log rotation with monthly folder structure
All log output is now additionally written to daily log files:
  daily-logs/YYYY-MM/YYYY-MM-DD.log (main log)
  daily-logs/YYYY-MM/YYYY-MM-DD-rename.log (rename log)

Automatic cleanup of daily logs older than 30 days. The existing
rd_downloader.log and rename.log continue to work as before.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-24 09:16:24 +01:00
Sucukdeluxe
180397f10a Revert post-MKV-move auto-rename that corrupted other packages
The post-MKV-move rename pass added in v1.7.107 ran on the shared
mkvLibraryDir (Entpackt/), causing files from OTHER packages to be
renamed to the current package's name. For example, Orange.Is.The.New.Black
files were renamed to Ted.S02E13...SAUERKRAUT.mkv.

Remove the post-MKV-move rename entirely. The original hybrid race
condition (1 file per season not renamed) is far less damaging than
cross-package corruption.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-24 08:58:07 +01:00
Sucukdeluxe
65650737b1 Refactor Mega-Debrid account UI from textarea to proper account list
Replace the raw login:password textarea with a proper form-based UI:
- Individual Login + Password input fields with "Hinzufügen" button
- List of configured accounts with masked logins and "Entfernen" button
- Duplicate login detection
- Storage format unchanged (megaCredentials stays login:password pairs)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 21:35:17 +01:00
Sucukdeluxe
6df0834b67 Add Mega-Debrid multi-account support with automatic fallback
Multiple Mega-Debrid accounts can now be configured as login:password
pairs (one per line). When an account hits Fair-Use limits or errors,
the next account is tried automatically.

- New parser module mega-debrid-accounts.ts (parse, ID generation,
  masking, serialization)
- Per-account daily limits, usage tracking, enable/disable
- Account rotation with per-mode cooldowns (API failures don't
  block Web attempts)
- Backward compatible: existing single megaLogin/megaPassword
  is auto-migrated to the new format
- UI: textarea for credentials, account list with masked logins

Follows the existing Debrid-Link multi-key pattern.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 20:12:51 +01:00
Sucukdeluxe
d91621bd6d Handle SxxSxx scene typo in episode token extraction
Scene releases occasionally use SxxSxx (e.g. s05s01) instead of
SxxExx — the second S is a typo for E. Add a fallback regex to
detect this pattern and correctly interpret it as S05E01.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 18:03:45 +01:00
Sucukdeluxe
79c178eb0d Skip sample files during auto-rename to prevent (2) MKV duplicates
Sample files like wayne-sample.mkv were renamed by auto-rename which
stripped the -sample suffix. After rename they were indistinguishable
from the main MKV, causing MKV collection to create (2) copies
(e.g. Messiah.Superstar.S01E01...WAYNE (2).mkv at 17 MB alongside
the real 470 MB episode).

Auto-rename now skips files with a "sample" token in their name,
matching the same detection used by MKV collection's sample filter.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 12:06:41 +01:00
Sucukdeluxe
87c097c822 Fix auto-rename race in hybrid extraction missing MKV files
During hybrid extraction, files can finish extracting between the
auto-rename scan and MKV-move, causing them to be moved to the MKV
library dir with their original scene names (e.g. awa-diethundermans03e21hd.mkv).

Add a post-MKV-move auto-rename pass on the MKV library directory to
catch these stragglers and rename them to the proper folder-based name.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 11:53:51 +01:00
Sucukdeluxe
7b764be769 Fix auto-rename episode range folders producing duplicate MKV names
Folder names with episode ranges like S01E01-E08 (common in season
packs from debrid servers) were returned unchanged as target name,
causing all episodes to get the same filename and producing (2)(3)(4)
suffixes during MKV collection.

- Detect episode ranges (S01E01-E08, S01E01-08) in folder names and
  replace them with the source file's specific episode token
- Extend applyEpisodeTokenToFolderName regex to match and replace
  full episode ranges instead of only single episode tokens

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 11:25:10 +01:00
Sucukdeluxe
78fef627bb Fix auto-rename episode pollution and deferred nested extraction abort
- Fix episode-token pollution: packageExtraCandidates included ALL item
  filenames, causing resolveEpisodeTokenForAutoRename to pick up episode
  tokens from unrelated files (e.g. S01E07 from 4sf-...-s01e07 applied
  to all hrs-...-101/102/103 files). This also caused (2)(3) MKV
  suffixes when multiple files were renamed to the same wrong episode.
  Now only the package name (outputDir) is used as extra candidate.
- Fix deferred nested extraction missing abort signal: the nested
  extractPackageArchives call in runDeferredPostExtraction did not
  receive deferredController.signal, making it unabortable on
  stop/cancel/restart.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-22 16:20:47 +01:00
Sucukdeluxe
30a5832498 Fix auto-rename mixed scene group suffixes 2026-03-11 20:05:12 +01:00
Sucukdeluxe
99455eca94 Fix auto-rename raw episode folder selection 2026-03-11 14:17:51 +01:00
Sucukdeluxe
d9170f4167 Refactor: Extractor in 18 Sektionen reorganisiert 2026-03-10 23:47:02 +01:00
Sucukdeluxe
1a0f49b29c Rebuild download completion verification 2026-03-10 20:22:19 +01:00
Sucukdeluxe
83640b8f1f Honor configured parallel extraction slots 2026-03-10 20:08:43 +01:00
Sucukdeluxe
fbae8a1496 Fix cleanup after partial extraction failures 2026-03-10 19:57:26 +01:00
Sucukdeluxe
113b34fadf Fix parallel extraction false positives 2026-03-10 19:34:42 +01:00
Sucukdeluxe
a054eface5 Improve extraction failure diagnostics 2026-03-10 19:14:21 +01:00
Sucukdeluxe
722fe071cc Harden Debrid-Link completion recovery 2026-03-10 18:27:26 +01:00
Sucukdeluxe
c1a4d8037f Fix Debrid-Link retry recovery 2026-03-10 18:20:19 +01:00
Sucukdeluxe
0a724aed71 Fix BSOD MEMORY_MANAGEMENT on low-RAM servers
- Dynamically compute JVM -Xmx based on system RAM instead of hardcoded 32g
- Reduce peak memory during session loading (inline JSON string, skip redundant clone)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 14:19:49 +01:00
Sucukdeluxe
6c7b1bb088 Keep failed packages out of package cleanup 2026-03-10 12:30:43 +01:00
Sucukdeluxe
17e947fc6b Harden type safety and recovery guards 2026-03-10 05:54:19 +01:00
Sucukdeluxe
17604910b5 Harden startup recovery and stats edge cases 2026-03-10 01:50:16 +01:00
Sucukdeluxe
6d7b3686dc Add AVI video-library support and startup recovery fixes 2026-03-10 00:43:51 +01:00
Sucukdeluxe
b41bb0aeb5 Fix deferred cleanup after MKV move 2026-03-09 23:48:28 +01:00
Sucukdeluxe
ecb5df0a31 Fix startup duplicate archive recovery 2026-03-09 20:38:23 +01:00
Sucukdeluxe
e6b8ea0abe Fix stale extract pending states 2026-03-09 20:14:35 +01:00
Sucukdeluxe
446c41a9b3 Fix extract error status bleed 2026-03-09 19:43:35 +01:00
Sucukdeluxe
51d4e2100f Rename backup menu actions 2026-03-09 18:16:30 +01:00