Skip to content

feat: drm validation#23

Merged
jvillegasd merged 7 commits intomainfrom
feat/drm-validation
Dec 2, 2025
Merged

feat: drm validation#23
jvillegasd merged 7 commits intomainfrom
feat/drm-validation

Conversation

@jvillegasd
Copy link
Owner

This pull request introduces robust DRM detection and handling for HLS and M3U8 downloads, along with improved filename sanitization throughout the downloader modules. It enhances user safety by preventing downloads of DRM-protected or undecryptable content, and ensures that filenames used in downloads are always valid and safe for the filesystem. Additionally, it improves error handling and user feedback in the UI regarding DRM and encryption issues.

DRM Detection and Enforcement:

  • Added a new utility module drm-utils.ts to detect DRM in HLS manifests, check for supported encryption methods, and enforce download restrictions by throwing errors when DRM or unsupported encryption is detected. (src/core/utils/drm-utils.ts)
  • Integrated DRM detection and decryption checks into the HLS, M3U8, and direct download handlers to prevent downloads when content is protected or cannot be decrypted. (src/core/detection/hls/hls-detection-handler.ts, src/core/downloader/hls/hls-download-handler.ts, src/core/downloader/m3u8/m3u8-download-handler.ts) [1] [2] [3] [4] [5] [6] [7] [8]

Metadata and UI Feedback:

  • Extended the VideoMetadata interface to include hasDrm and unsupported fields, allowing the UI and logic to distinguish between DRM-protected and undecryptable content. (src/core/types.ts)
  • Added new status badge styles for .status-drm and .status-undecrypted in the popup UI for clearer user feedback about DRM or unsupported encryption issues. (src/popup/popup.html) [1] [2]

Filename Sanitization:

  • Improved and exported the sanitizeFilename utility to remove invisible and bidirectional Unicode characters, in addition to standard invalid characters. (src/core/utils/file-utils.ts)
  • Applied filename sanitization across all download handlers, ensuring that downloads always use valid filenames and providing fallbacks if sanitization results in an empty name. (src/core/downloader/direct/direct-download-handler.ts, src/core/downloader/hls/hls-download-handler.ts, src/core/downloader/m3u8/m3u8-download-handler.ts) [1] [2] [3] [4] [5]

Error Handling and Logging:

  • Enhanced error handling in download handlers to log and surface Chrome API errors and DRM/encryption issues more clearly. (src/core/downloader/hls/hls-download-handler.ts)

These changes collectively make the downloader safer, more robust, and user-friendly when dealing with protected or problematic content.

…loads

- Added a new utility for detecting DRM protection in HLS manifests, preventing downloads of DRM-protected content.
- Updated HlsDetectionHandler and HlsDownloadHandler to check for DRM in playlists and handle errors accordingly.
- Enhanced UI to display warnings for DRM-protected content in the popup, disabling download options when necessary.
- Refactored related functions to integrate DRM checks across video metadata extraction and download processes.
- Added `sanitizeFilename` utility to remove invalid characters from filenames in Direct, HLS, and M3U8 download handlers.
- Updated download handlers to use sanitized filenames for improved file handling and to prevent errors during downloads.
- Implemented fallback logic for empty or invalid base filenames, ensuring robust filename generation.
…S and M3U8 manifests

- Updated HlsDownloadHandler and M3u8DownloadHandler to use `canDownloadHLSManifest` for validating if playlists can be downloaded, replacing the previous DRM checks.
- Refactored `drm-utils` to separate DRM detection from download validation, enhancing clarity and maintainability of the code.
- Improved error handling by throwing appropriate exceptions for unsupported encryption methods and DRM-protected content.
…nifests

- Enhanced VideoMetadata interface to include `cannotDecrypt` property, indicating unsupported encryption methods.
- Updated HlsDetectionHandler to set `cannotDecrypt` based on manifest analysis.
- Introduced UI elements in the popup to display warnings for content that cannot be decrypted, improving user feedback.
- Modified rendering logic in popup.ts to handle the new decryption status, disabling download options accordingly.
…loadHandler

- Updated HlsDownloadHandler to fetch and validate master, video, and audio playlists more efficiently.
- Removed redundant fetching of master playlist when quality preferences are provided, enhancing performance.
- Improved handling of video and audio playlists by checking if they have already been fetched before making requests.
- Enhanced code clarity by consolidating playlist validation logic, ensuring better maintainability.
…nsupported encryption detection

- Updated VideoMetadata interface to replace `cannotDecrypt` with `unsupported` for better clarity on encryption status.
- Modified HlsDetectionHandler to reflect the new property name when checking decryption capability.
- Adjusted UI elements in popup.html and popup.ts to display warnings for unsupported encryption methods, improving user feedback.
- Enhanced the canDecrypt function to better match unsupported encryption patterns, ensuring accurate detection.
@jvillegasd jvillegasd self-assigned this Dec 2, 2025
@github-actions github-actions bot changed the title Feat/drm validation feat: drm validation Dec 2, 2025
- Updated popup.html and popup.ts to replace instances of "undecrypted" with "unsupported" for better clarity regarding encryption status.
- Adjusted related UI elements and logic to ensure consistent messaging for unsupported encryption methods, enhancing user feedback.
@jvillegasd jvillegasd merged commit d8f5acb into main Dec 2, 2025
@jvillegasd jvillegasd deleted the feat/drm-validation branch December 2, 2025 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant