=== Secure Video for WooCommerce ===
Contributors: teckform
Tags: video, woocommerce, hls, streaming, protected video
Requires at least: 6.5
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.5.0
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Protected video streaming for WooCommerce customers, from Bunny Stream or your own server. Secure streaming - not Widevine/FairPlay DRM.

== Description ==

Sell access to videos and courses through WooCommerce and stream them with layered protection.

**Two ways to host the videos**

* **Bunny Stream** (recommended): upload an MP4 / MOV / M4V on the video's edit screen and it goes straight from your browser to your Bunny Stream library. Bunny converts and streams it; your hosting's upload limits and CPU are not involved. Requires a Bunny Stream account (paid by usage).
* **Self-hosted HLS**: the video stays on your own server as AES-128 encrypted HLS. Convert it automatically on the server (when FFmpeg is available), upload a prepared HLS ZIP, or convert it on your computer.

**Protection**

* WooCommerce purchase verification on the server for every playback start and renewal
* concurrent-session limits and optional device limits
* moving watermark with the customer's name, e-mail and/or order number
* self-hosted: AES-128 encrypted segments, short-lived HMAC-SHA256 signed playback tokens in an HttpOnly cookie, authenticated key delivery (the key is never in HTML, JavaScript or a public URL), and protected storage delivered by LiteSpeed, Nginx, Apache or a PHP fallback, with a built-in delivery test
* Bunny: a signed, expiring player link is created only after the purchase and session checks
* security log with automatic retention

**Customer library**

* My Library, Courses, course and lesson pages inside WooCommerce My Account, with a full-screen sidebar design and a mobile menu
* watch progress, resume, "Continue" section and course progress
* courses sold by one WooCommerce product, with "any lesson" or sequential access
* a PDF per video, downloadable only by customers who may watch it

= Important limitations =

This plugin is NOT Widevine, FairPlay or PlayReady DRM and does not make videos impossible to download.

It protects against casual downloads, simple URL sharing, direct MP4 downloading, unauthorized playback and permanent shared links.

It cannot completely prevent advanced stream extraction by an authorized customer, screen recording, external camera recording, or a sufficiently determined authorized attacker. The watermark deters these and identifies the source of a leak.

With Bunny Stream, a player link that was already handed out works for anyone who has it until it expires. Keep its lifetime short and allow only your own domain in the Bunny library's security settings.

Full documentation is in the plugin's docs/ folder: SECURITY.md, automatic-processing.md, ffmpeg-hls.md, litespeed-apache.md and nginx-example.conf.

== External services ==

The plugin connects to these services only when you use the feature that needs them.

**Bunny Stream** (bunny.net), when "Enable Bunny Stream" is on:

* Your server calls the Bunny Stream API (`video.bunnycdn.com`) with your library ID and API key to create videos, check their processing status and delete them.
* When you upload a video, the file is sent from your browser to Bunny (`video.bunnycdn.com/tusupload`).
* When a customer watches a video, their browser loads Bunny's player (`player.mediadelivery.net`, `assets.mediadelivery.net`) and the video from Bunny's CDN. Bunny then receives the viewer's IP address and browser details.

Bunny's terms: https://bunny.net/tos/
Bunny's privacy policy: https://bunny.net/privacy/

**Google Fonts**, only when "Load the library fonts (Playfair Display, Poppins) from Google Fonts" is on (off by default): the customer library loads Playfair Display and Poppins from `fonts.googleapis.com`, so visitors' browsers contact Google.

Google's privacy policy: https://policies.google.com/privacy

Self-hosted HLS needs no external service.

== Installation ==

1. Plugins > Add Plugin > Upload Plugin, choose the zip, install and activate. WooCommerce must be active.
2. Recommended: add `define( 'SECURE_VIDEO_SIGNING_KEY', '64+ random characters' );` to wp-config.php.
3. **Bunny Stream:** Secure Video > Settings > Bunny Stream: enter the Video Library ID, the library API key and the token authentication key, then Test connection. In the Bunny dashboard, add your domain under the library's Allowed domains and turn on embed view and CDN token authentication.
4. **Self-hosted:** Secure Video > Settings: choose the delivery mode for your server (LiteSpeed, Nginx, Apache or PHP). The plugin tests it and falls back to PHP automatically if it is unsupported.
5. Secure Video > Add Video: choose the WooCommerce product, upload the video file and publish.
6. Add `[secure_video id="123"]` to a page, or let customers watch from My Account > My Library.

== Frequently Asked Questions ==

= Is this DRM? =

No. It is protected streaming. See "Important limitations".

= Do customers need an account? =

Yes. Access is tied to the WordPress user who placed the order. Disable guest checkout or let customers create an account during checkout.

= Does my server need FFmpeg? =

No. With Bunny Stream, Bunny converts the videos. For self-hosted videos the plugin converts them automatically when the server has FFmpeg; otherwise you can upload a prepared HLS ZIP or convert the video on your own computer (docs/ffmpeg-hls.md).

= Will it slow down my site? =

During playback the plugin performs one small database write per viewer every 30-60 seconds. With Bunny, or with LiteSpeed/Nginx delivery, PHP only authorizes each request; the video bytes come from Bunny or the web server.

= What happens to my data when I deactivate or delete the plugin? =

Nothing is deleted unless you enabled "Delete plugin data when uninstalled" (off by default). Video files are never deleted automatically.

== Changelog ==

= 1.5.0 =
* Security: the automatic Bunny player link lifetime is now the video length + 20 minutes (30 minutes to 6 hours; was + 1 hour, up to 12 hours). New fixed option: 30 minutes.
* Security: Settings > Bunny Stream now warns clearly that the library's Allowed domains must list your site; docs/SECURITY.md explains what a Bunny player link can and cannot do.
* Privacy: the customer library no longer loads Google Fonts unless you switch on "Load the library fonts (Playfair Display, Poppins) from Google Fonts" (Settings > Customer library).
* Design: new neutral default colours for the customer library. Every colour is a CSS custom property a theme can override.
* readme: describes Bunny Stream and lists the external services.

= 1.4.1 =
* Design: new default look for My Library (and Courses / Profile, which share it): side panel, active menu item, section bands, card borders, progress line, "Continue" card and keyboard focus ring. The phone top bar and menu follow the same colours. Every colour is a CSS custom property, so a theme can re-skin the library. The sidebar logo is set in Settings > Customer library > Sidebar logo.

= 1.4.0 =
* New: a PDF per video (edit screen > "5. PDF for Buyers"). Everyone who may watch the video sees a "Download PDF" button under the player (shortcode and My Library). The PDF is kept in the protected storage folder, not in the public media library, and every download re-runs the purchase check; download links are personal (bound to the logged-in customer).
* New: switching Bunny accounts. Changing the Video Library ID without entering that library's keys clears the old keys (Settings shows "not complete" instead of playback silently failing). Videos uploaded to a previous library are listed in Settings > Bunny Stream, marked on the Videos list and the edit screen, fall back to their local HLS copy if they have one, and are uploaded again with the normal Upload to Bunny button. The plugin never calls the old library with the new keys.

= 1.3.3 =
* Fix: the mobile menu bar of the customer library was hidden by header-builder plugins that hide every "header" element of the page. The menu drawer now also opens above a sticky site header.

= 1.3.2 =
* New: Settings > Customer library > "Extra sidebar pages". Add and remove your own pages in the customer sidebar (shown after "Browse More").

= 1.3.0 =
* New: Bunny Stream as the media backend for new videos. Add Video > choose product > choose MP4/MOV/M4V > Upload to Bunny > Ready > Publish.
* New: the file is uploaded from the admin browser directly to Bunny (resumable TUS) - never through PHP, so hosting upload limits do not apply.
* New: Settings > Bunny Stream (Library ID, library API key, token authentication key, Test connection). Keys are stored encrypted or come from wp-config.php (SVWC_BUNNY_API_KEY, SVWC_BUNNY_TOKEN_KEY) and never reach the browser.
* Playback: the existing entitlement / session / device checks run first; only then a signed, expiring Bunny player link is created. Progress, resume, My Library, courses and the dynamic watermark keep working.
* Self-hosted HLS (LiteSpeed delivery, HLS ZIP, AES keys, FFmpeg conversion) is unchanged and remains available as a legacy fallback. No migration needed.

= 1.2.0 =
* New: customer library inside WooCommerce My Account (My Library, Courses, course page, lesson page) with a full-screen sidebar design and mobile drawer.
* New: Courses (Secure Video > Courses) - an ordered list of existing protected videos sold by one WooCommerce product; "Any lesson" or server-enforced "Sequential" access.
* New: watch progress, resume / start over, completion threshold (default 90%), Continue section, course progress.
* New: REST routes /library, /course/{id}, /progress/{video}, /progress, /progress/complete (current user only, entitlement re-checked on every request).
* Entitlement is still decided in one place; a video can now also be unlocked by the product of a course that contains it.
* Database version 3: adds the secure_video_progress table. No existing table, setting, video, key or package is changed.
* Playback, tokens, sessions, watermark and LiteSpeed delivery are unchanged.

= 1.1.0 =
* New: simple "Video file" workflow - upload a normal MP4 / MOV / M4V; the plugin creates the AES-128 key, converts to adaptive encrypted HLS in the background (FFmpeg), validates, publishes atomically under an opaque package name and shows real progress. Retry, cancel and replace are supported.
* New: chunked, resumable uploads (not limited by upload_max_filesize / post_max_size), plus import from a private "_incoming" folder for SFTP / File Manager uploads. Prepared HLS ZIPs can now also be uploaded in chunks (any size).
* New: server capability detection and "Automatic processing diagnostics" (FFmpeg / FFprobe path and version, exec / proc_open, disable_functions, disk space, PHP limits, background runner). When the server cannot convert videos the plugin says so and offers the ZIP / manual fallbacks - it never downloads or bundles FFmpeg.
* New: settings for automatic processing (on/off, maximum resolution, segment duration, source retention, concurrency, maximum source size).
* Changed: package folder, master playlist, key management and ZIP import moved into a collapsed "Advanced / Manual HLS import" section. Existing videos keep working unchanged and are labelled "Manual HLS package".
* Database: new table wp_secure_video_jobs (schema version 2, created automatically).
* Unchanged: LiteSpeed delivery, ORG_REQ_URI protection, REST routes, tokens, sessions, entitlement, key delivery, watermarking, player.

= 1.0.1 =
* Fix: LiteSpeed delivery (X-LiteSpeed-Location) failed its test because the protected folder's .htaccess refused the internal redirect as well as direct requests. The rules now use LiteSpeed's %{ORG_REQ_URI} variable: direct requests stay blocked, the plugin's own internal redirect is allowed. Fail-closed on servers that do not support the variable.
* Fix: the redirect URI is calculated from the server's document root (authoritative) instead of the WordPress path.
* New: LiteSpeed delivery diagnostics on the Settings screen (document root, protected path and URI, header value, direct / internal HTTP status, per-profile results, current .htaccess).
* Hardening: the delivery test also probes //, /./, %XX and query-string variants of the direct URL.

= 1.0.0 =
* Initial release.
