Function
The lesson's source URL, in any form
The video id, or undefined when the source is not a YouTube link
A VideoLesson.source is an opaque URL: the project hosts most lectures as
MP4 files, but some are published on YouTube. This is the one place that
tells the two apart, so the player can pick a provider without a vendor
conditional spreading through the component tree.
Returns undefined, not null, and never throws. A source that is not
a YouTube link is the ordinary case — most lessons — not a failure, so
there is no error to model. The codebase's Result<T, DomainError>
convention governs use cases; this is a pure classifier at the delivery
edge, and a discriminated union here would be ceremony with no caller for
its error arm.
Parsed with URL, not matched with a regex. The host has to be matched
exactly: https://cdn.example.com/youtube.com/watch?v=x.mp4 is a
self-hosted file whose path mentions YouTube, and any pattern that scans
the whole string for youtube.com would hand it to the wrong provider.
Parsing also yields searchParams and a normalized pathname for free. A
malformed source makes the constructor throw; that is caught and reported
as "not YouTube", so bad data degrades to the direct-source path instead of
breaking the lesson page.
Extra query parameters (si, list, t) are discarded. The provider owns
the embed URL it builds, and the starting position is the stored playback
position applied by a seek — not something encoded in a link.
Extracts the YouTube video id from a lesson's
source, when that source is a YouTube link.