How Stream URLs Are Validated Before Inclusion in IPTV Playlists
The Free-TV/IPTV repository performs minimal validation on stream URLs, extracting them solely through basic string slicing without verifying protocols, hostnames, or reachability.
The Free-TV/IPTV project aggregates television streams into M3U playlists from markdown source files. While the generator processes channel entries to populate playlist metadata, the validation performed on stream URLs before inclusion is limited to stripping whitespace and extracting text between parentheses.
URL Extraction in make_playlist.py
The parsing logic resides in make_playlist.py, specifically lines 102-103. When the script encounters a channel line (identified by the [>] marker), it splits the line by pipe delimiters and extracts the URL from the fourth field:
self.url = parts[3].strip() # 102
self.url = self.url[self.url.find("(")+1:self.url.rfind(")")] # 103
This operation merely locates the first opening parenthesis and the last closing parenthesis in the string, returning the substring between them. No regex matching or URL parsing libraries are invoked.
Example Extraction Flow
Given a raw markup line:
line = '[>] Channel 101 | My Channel | (http://example.com/stream.m3u8) | <img src="logo.png">'
The script processes it as:
parts = line.split('|')
url_part = parts[3].strip() # '(http://example.com/stream.m3u8)'
url = url_part[url_part.find('(')+1:url_part.rfind(')')]
# Result: 'http://example.com/stream.m3u8'
Missing Validation Checks
The extraction logic does not enforce any of the following:
- Protocol verification: No check for valid schemes like
http,https,rtmp, orrtsp - Hostname validation: No DNS resolution or syntax verification
- Network reachability: No HTTP HEAD requests or connectivity testing
- Content-type inspection: No verification that the endpoint returns valid stream data
As implemented in Free-TV/IPTV, any string between the outermost parentheses passes through to the final playlist regardless of format.
Playlist Generation Pipeline
After extraction, the URL is embedded directly into the generated M3U file. According to the source code at lines 118-120 of make_playlist.py, the raw URL string is written to the playlist output without additional sanitization or encoding.
The pipeline flows as follows:
- Source: Markdown files in the
lists/directory (e.g.,lists/usa.md) contain channel definitions - Processing:
make_playlist.pyparses each line and extracts the URL via substring slicing - Output: Generated playlists in
playlists/(e.g.,playlists/playlist_usa.m3u8) contain the unvalidated URLs
Implementing Strict URL Validation
If you require robust validation, you could extend the extraction logic with regex pattern matching. For example:
import re
URL_REGEX = re.compile(
r'^(https?|rtmp|rtsp)://' # scheme
r'[\w.-]+' # host
r'(?::\d+)?' # optional port
r'(?:/[\w./?%&=-]*)?$' # path/query
)
if not URL_REGEX.match(url):
raise ValueError(f'Invalid stream URL: {url}')
This would enforce protocol restrictions and hostname syntax before inclusion, though the current Free-TV/IPTV codebase does not implement such checks.
Summary
- Minimal validation: The script only extracts text between parentheses via
find()andrfind()operations inmake_playlist.py - No format enforcement: URL schemes, domain validity, and path structure are not verified
- Direct embedding: Extracted strings pass directly from lines 102-103 to the M3U output at lines 118-120
- Source files: Channel data originates in markdown files under
lists/and outputs toplaylists/
Frequently Asked Questions
Does Free-TV/IPTV check if stream URLs are accessible?
No. The make_playlist.py script does not perform HTTP requests, DNS lookups, or connectivity tests. It extracts the URL string mechanically and writes it to the playlist file without verifying if the endpoint is online or streaming.
What URL formats does the playlist generator accept?
The generator accepts any string between the first opening parenthesis and last closing parenthesis in the fourth field of a channel line. While the repository typically contains http and https URLs, the code itself imposes no restrictions on protocols like rtmp or rtsp, nor does it validate URL structure.
Where in the codebase is URL extraction handled?
URL extraction occurs in make_playlist.py at lines 102-103. Line 102 strips whitespace from the fourth pipe-delimited field, and line 103 slices the string between the outermost parentheses to isolate the URL.
Can I add validation to reject malformed URLs?
Yes. You could modify make_playlist.py to import the re module and validate the extracted string against a URL pattern regex before assignment. However, the current upstream implementation intentionally omits such validation to support diverse streaming protocols and edge cases.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →