Most IPTV providers can tell you they carry "thousands of channels". Very few can show you which ones, in a way a normal person can search. When we decided to publish a full channel list for a Canadian IPTV service, the raw data turned out to be the hard part, not the web page.
This post walks through what the data looked like, the cleaning rules that made it usable, and a couple of design decisions that mattered more than the code.
Where the data comes from
Most IPTV backends expose an Xtream Codes–compatible API. Two calls give you everything you need for a live channel list:
import requests BASE = "https://provider.example/player_api.php" AUTH = {"username": USER, "password": PASSWORD} def call(action, timeout=60): r = requests.get(BASE, params={**AUTH, "action": action}, timeout=timeout) r.raise_for_status() return r.json() categories = call("get_live_categories") streams = call("get_live_streams") There is usually a third option, the classic M3U playlist from get.php. On our line it answered with a non-standard HTTP status (884) and an empty body, so we rebuilt everything from player_api.php instead. If you depend on M3U exports, check the status code, not just whether the request "worked".
The first snapshot held roughly 58,000 live streams spread across 921 categories. The get_live_streams response alone took between 6 and 40 seconds depending on the day, so the build runs offline and the website only reads the result.
What the raw names look like
Category names follow a loose convention: a country or language prefix, a pipe, then a label.
CA| CANADA IN| HINDI UK| SPORTS ᴴᴰ AT| AUSTRIA ⱽᴵᴾ Stream names are messier. The same channel can appear five times with different quality tags, backup numbers or decorative Unicode. And on sports-heavy categories, a large share of "channels" are not channels at all, but placeholders for single events:
TSN+ 03 : Team A @ Team B Sep 27 05pm Cardinals at 49ers No Scheduled Event Publishing those as channels would be wrong twice: they disappear within hours, and they make the list look padded.
Rule 1: group by prefix, not by category
Categories are too granular to browse (921 of them), so we group on the prefix before the pipe:
import re PREFIX = re.compile(r"^\s*([A-Z]{2,4})\s*\|") def country_of(category_name): m = PREFIX.match(category_name) return m.group(1) if m else None That collapses 921 categories into 74 prefixes. A small mapping table then turns prefixes into readable names (IN → India, EXYU → Ex-Yugoslavia) and merges a few that describe the same audience.
Watch out for prefixes that look like a country but are not. One category labelled CH| CHINA was really Chinese-language channels sitting under the Switzerland code. A quick manual review of every prefix with its three largest categories catches these.
Rule 2: drop event placeholders
Event streams share a few signatures: a time, an "@" or "at" between two team names, a date, or an explicit "no event" label.
EVENT = re.compile( r"(\b\d{1,2}(:\d{2})?\s?(am|pm)\b)" # 05pm, 7:30 PM r"|(\s@\s)" # Team A @ Team B r"|(\b(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\s\d{1,2}\b)" r"|(no scheduled event)", re.IGNORECASE, ) def is_event(name): return bool(EVENT.search(name)) This is deliberately conservative. A regex that is too clever starts deleting real channels with numbers in their names. After every build we print every name that still contains a time or a date and read the list by eye. It takes two minutes and has caught a new pattern more than once.
Rule 3: deduplicate on a normalised name
Quality tags and decorative characters are stripped before comparing names, so "SPORTS 1 FHD", "Sports 1 ᴴᴰ" and "SPORTS 1 (backup 2)" count as one channel:
import unicodedata NOISE = re.compile(r"\b(uhd|fhd|hd|sd|4k|hevc|raw|backup\s*\d*)\b|[()\[\]]", re.I) def normalise(name): name = unicodedata.normalize("NFKC", name) # turns ᴴᴰ-style glyphs into plain letters name = NOISE.sub(" ", name) return re.sub(r"\s+", " ", name).strip().casefold() NFKC normalisation does a surprising amount of the work: many "fancy" letters used in IPTV labels are compatibility characters that collapse to ordinary ASCII.
After all three rules, the list went from about 58,000 raw entries to about 42,000 distinct channel names in 111 countries and languages. Adult categories are excluded from the public list entirely.
The decisions that mattered more than the code
Order is a product decision. Alphabetical order puts Afghanistan first and Canada somewhere in the middle. For a Canadian audience we show Canada, then the USA, then the other English-speaking markets (UK, Ireland, Australia, New Zealand), then everything else A–Z. Most visitors find what they came for without scrolling.
Not everything belongs in the first HTML response. The full dataset is a few megabytes of JSON. The page renders a small summary server-side (country names, counts and the Canadian section), and the complete list loads only when someone opens a country. Search engines still get real, readable content in the HTML, and phones are not forced to download 42,000 names on page load.
Deep links per country. Each country gets an anchor such as #india or #usa. That sounds minor, but it is what lets a support agent answer "do you have Tamil channels?" with a single link instead of a paragraph.
You can see the result in practice in this searchable channel directory, which is rebuilt monthly from the provider's API with exactly these rules.
What I would do differently
- Snapshot the raw API responses before cleaning, with a date in the filename. When a channel disappears, you want to know whether the provider removed it or your regex did.
- Write the event filter as data, not code. A list of patterns in a JSON file is easier to extend than a regex that keeps growing.
- Count before and after every rule and log the numbers. The day a rule suddenly removes 30 % more names than usual is the day the upstream format changed.
None of this is sophisticated. It is mostly the unglamorous work of reading thousands of strings until the patterns become obvious. But it is the difference between a channel count on a sales page and a list people can actually check.
I work on IPTV4Canadian, an IPTV service focused on Canadian and international channels for immigrant families.

