Skip to content

Custom Source Patterns

Andrew S edited this page Aug 30, 2024 · 2 revisions

The Problem

FastStream can only detect video sources by inspecting network traffic for URLS that end in specific file extensions, such as .mp4, .m3u8, and .mpd. When websites don't include file extensions in the URL, FastStream is unable to detect video sources automatically. Solving this issue will necessitate having a list of hardcoded URL patterns for specific websites. Such a list will require constant maintenance and updates as websites change, it would be akin to Adblock filter lists. But I'm not in a position to spend all my time doing that, so this option is not feasible for FastStream.

The Solution

FastStream allows the user (you) to define custom source url patterns that are used to guide FastStream's source detection algorithm. These are set in the extension options/settings page. The format is as follows

# This is a comment
// This is also a comment
[file extension] /[regex]/[flags]

The [file extension] determines what mode FastStream uses to play the video source. Here are some common values it can take:

m3u8 - Accelerated HLS
mpd - Accelerated DASH
mp4 - Accelerated MP4
vtt - Subtitle track

The /[regex]/[flags] parameter tells FastStream when to apply the file extension override.

Example

This system was instituted because of issue #51. The website in question is ok.ru. Their manifest URLS are encoded using the following URL format:

https://vd343.mycdn.me/?expires=1702952511283&srcIp=[redacted]&pr=10&srcAg=CHROME_MAC&ms=[redacted]&type=1&sig=kThi2hIuDQE&ct=6&urls=[redacted]&clientType=0&zs=43&id=5978708576784

I identified this URL by looking at the network tab in Chrome's developer tools. This network request happens right before the video fragments begin to load, and also results in an XML file. This indicated that it was a DASH manifest file. I added this rule to make FastStream recognize the URL as a video source:

# Custom pattern for ok.ru/video/
mpd /^https:\/\/vd[0-9]*\.mycdn\.me\/\?.*&type=1&/

In a nutshell, this regex matches any request going to their video servers with the type=1 URL parameter set. The process to select this particular pattern is arbitrary, but ideally, the pattern should:

  1. Match as many videos on the website as possible
  2. Avoid matching URLs that are not video sources

Performance

Because these regexes are tested on every request you make, it is important to make them as performant as possible. I suggest using regex101 to check the number of steps the regex requires. In the future, I will consider adding some optimizations (similar to the way adblockers work) in case people need large amounts of custom source pattern rules. Let me know if you are having problems with performance so I can gauge how important it is to fix.

Clone this wiki locally