Building an M3U Playlist in PHP!

Since my last post about using HDHR in VLC, I've upgraded the firmware to 2013-12-12 (the latest as of this writing). This new firmware seems to be a lot more stable for http streaming. If that's the case, why not build out an .m3u playlist listing all of the channels I subscribe to that pulls in what's playing on open? Give this a try by pressing CMD N in VLC and typing your HDHR Prime's IP in the box as well as the channel you want to stream.

This should send a beautifully stable stream of television to VLC.

Cool. Let's build out a playlist using PHP. The format needs to look like this:

#EXTM3U

#EXTINF:-1,Channel Number - Call Sign Program Title
http://

#EXTINF:-1,Channel Number - Call Sign Program Title
http://

This will translate to something like this:

You will obviously need to connect to the MythTV database and may potentially violate your TOS for your listings provider if you add the program that is playing (there are many sources for retrieving your channels and call signs). I like to use PHPLib to connect to a database, but there are many ways.

query($q);
$out=array("#EXTM3U".$lb);

while ($db->next_record()){
	$r=$db->Record;
	$o= "#EXTINF: -1, ". $r['channum'] ." - ".$r['callsign']." ".$r['title'];
	if ($r['subtitle']) { $o.=" -- ". $r['subtitle']; }
	$o.=$lb."http://< hdhr ip >:5004/tuner0/v".$r['channum']."?duration=100".$lb;
	$out[]=$o;
}

print implode("\r\n", $out);
?>