XMLTV Generator
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
src Fix style Jan 1, 2017
tests Handle programme <new/> element Jan 1, 2017
.coveralls.yml Fix Coveralls conf Dec 30, 2016
.gitignore Initial commit Dec 23, 2016
.travis.yml Fix Travis conf Dec 30, 2016
LICENSE Initial commit Dec 23, 2016
README.md Doc Jan 2, 2017
composer.json Bump version 1.0.0 Jan 1, 2017
composer.lock Fix composer dependencies Dec 30, 2016
phpunit.xml Add coveralls Dec 30, 2016


Latest Stable Version Build Status Coverage Status StyleCI

XMLTV Generator

XMLTV Format PHP generator.


  • PHP 5.6
  • libxml


The library is PSR-4 compliant and the simplest way to install it is via composer:

 composer require b-alidra/xmltv


Create a new XMLTV document root node

$xmltv = new XMLTV();

Set the document root node ttributes (optional)


Add a channel

$xmltv->addChannel(function (&$channel) {
        // Required attribute
        // Optional children
        ->addDisplayname(['lang' => 'en'], 'The One')
        ->addIcon(['width' => '80', 'height' => 120, 'src' => 'https://b-alidra.com/icon.png'])

Add a programme

        // Required attributes
        'channel'          => 'test-channel',
        'start'            => '20161223184000',
        // Optional attributes
        'stop'             => '20161223194000',
        'pdc-start'        => '20161223184000',
        'vps-start'        => '20161223184000',
        'showview'         => '???',
        'videoplus'        => '???',
        'clumpidx'         => '1'
    ], function (&$program) {
            // Required child
            ->addTitle(['lang' => 'en'], 'Test channel')
            // Optional children
            ->addSubtitle(['lang' => 'en'], 'Test channel second title')
            ->addDesc(['lang' => 'en'], 'Test channel description')
            ->addCredits(function (&$credits) {
                    ->addActor('Test actor')
                    ->addAdapter('Test adapter')
                    ->addCommentator('Test commentator')
                    ->addComposer('Test composer')
                    ->addDirector('Test director')
                    ->addEditor('Test editor')
                    ->addGuest('Test guest')
                    ->addPresenter('Test presenter')
                    ->addProducer('Test producer')
                    ->addWriter('Test writer');
            ->addCategory(['lang' => 'en'], 'Horror')
            ->addKeyword(['lang' => 'en'], 'Fantastic')
            ->addLength(['units' => 'minutes'], 120)
            ->addIcon(['src' => 'https://b-alidra.com/icon.png'])
            ->addVideo(function (&$video) {
            ->addAudio(function (&$audio) {
            ->addSubtitles(function (&$subtitles) {
            ->addRating(function (&$rating) {
                    ->addIcon(['src' => 'https://b-alidra.com/icon.png']);
            ->addStarrating(function (&$starrating) {
                    ->addIcon(['src' => 'https://b-alidra.com/icon.png']);
                'type'     => 'text',
                'source'   => 'Web',
                'reviewer' => 'Belkacem Alidra',
                'lang'     => 'en'

Check validation against the DTD


Get the XML

$output = $xmltv->toXml();

Will produce the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tv PUBLIC "SYSTEM" "http://xmltv.cvs.sourceforge.net/viewvc/xmltv/xmltv/xmltv.dtd">
<tv date="2016-12-26" source-info-url="https://b-alidra.com/xmltv" source-info-name="XMLTV" source-data-url="https://b-alidra.com/xmltv" generator-info-name="XMLTV" generator-info-url="https://b-alidra.com/xmltv">
  <channel id="test-channel">
    <display-name lang="en">The One</display-name>
    <icon width="80" height="120" src="https://b-alidra.com/icon.png"/>
    <icon width="80" height="120" src="https://b-alidra.com/icon2.png"/>
  <programme channel="test-channel" start="20161223184000" stop="20161223194000" pdc-start="20161223184000" vps-start="20161223184000" showview="???" videoplus="???" clumpidx="1">
    <title lang="en">Test channel</title>
    <sub-title lang="en">Test channel second title</sub-title>
    <desc lang="en">Test channel description</desc>
      <director>Test director</director>
      <actor>Test actor</actor>
      <writer>Test writer</writer>
      <adapter>Test adapter</adapter>
      <producer>Test producer</producer>
      <composer>Test composer</composer>
      <editor>Test editor</editor>
      <presenter>Test presenter</presenter>
      <commentator>Test commentator</commentator>
      <guest>Test guest</guest>
    <category lang="en">Horror</category>
    <keyword lang="en">Fantastic</keyword>
    <length units="minutes">120</length>
    <icon src="https://b-alidra.com/icon.png"/>
      <icon src="https://b-alidra.com/icon.png"/>
      <icon src="https://b-alidra.com/icon.png"/>
    <review type="text" source="Web" reviewer="Belkacem Alidra" lang="en"/>

Implementation notes

Magic methods are used to set element attributes and to add an element child.

To set an id attribute (for example), use


To add a display-name child, use

$element->addDisplayname($attributes = [], $value = '', $callback)


To run the test suite, first install the dependencies, then run phpunit:

$ composer install
$ phpunit

For a test coverage report, look atbuild/report



Latest Stable Version Build Status Coverage Status StyleCI