Skip to content

Instantly share code, notes, and snippets.

@LiamKenyon
Forked from andey/IPTV M3U filter
Created May 8, 2019 14:41
Show Gist options
  • Save LiamKenyon/a1f197938b01d0e2b58fde7e22fddcbb to your computer and use it in GitHub Desktop.
Save LiamKenyon/a1f197938b01d0e2b58fde7e22fddcbb to your computer and use it in GitHub Desktop.
Filter out the garbage channels, and only show me what I want to see
<?php
// download the file
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "<M3U_LINK>");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close ($ch);
// write to file
$fp = fopen('tv_channels.m3u', 'w');
fwrite($fp, $result);
fclose($fp);
// filter the file
echo "#EXTM3U\n";
exec('grep -E "^#EXTINF.*tvg\-name=\"([^#])*\".*group\-title=\"(NHL|NBA|Canada|USA Entertainment|USA Docs & News|Latino|USA Sports)\"" -A 1 tv_channels.m3u | sed "/^--$/d"', $out);
foreach($out as $line) {
echo $line."\n";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment