PHPackages                             b-alidra/xmltv - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. b-alidra/xmltv

ActiveLibrary

b-alidra/xmltv
==============

XMLTV generator

1.0.0(9y ago)4117↓100%1[1 issues](https://github.com/b-alidra/XMLTV-Generator/issues)1MITPHPPHP &gt;=5.6

Since Jan 1Pushed 9y ago2 watchersCompare

[ Source](https://github.com/b-alidra/XMLTV-Generator)[ Packagist](https://packagist.org/packages/b-alidra/xmltv)[ RSS](/packages/b-alidra-xmltv/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (2)Versions (2)Used By (1)

[![Latest Stable Version](https://camo.githubusercontent.com/ab9490d4ea6364942e7b3eac0936112155e914e7594a26eee95e517c87fe8aa0/68747470733a2f2f706f7365722e707567782e6f72672f622d616c696472612f786d6c74762f762f737461626c65)](https://packagist.org/packages/b-alidra/xmltv)[![Build Status](https://camo.githubusercontent.com/e59221094234c80f0aff8665d6d3743778da98ef3937d6b9ee07bdf05198e655/68747470733a2f2f7472617669732d63692e6f72672f622d616c696472612f584d4c54562d47656e657261746f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/b-alidra/XMLTV-Generator)[![Coverage Status](https://camo.githubusercontent.com/2c202934070e294e6492e9a3d52e6234bc4118d86f15604fbc181ebfc17b8033/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f622d616c696472612f584d4c54562d47656e657261746f722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/b-alidra/XMLTV-Generator?branch=master)[![StyleCI](https://camo.githubusercontent.com/2e239a8abff6f4b897676974f0fa5fd8cbbc73e872469a6e4b9348ab4f46f954/68747470733a2f2f7374796c6563692e696f2f7265706f732f37373635333133362f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/77653136)

XMLTV Generator
===============

[](#xmltv-generator)

[XMLTV Format](http://xmltv.cvs.sourceforge.net/viewvc/xmltv/xmltv/xmltv.dtd) PHP generator.

Requirements:
-------------

[](#requirements)

- PHP 5.6
- libxml

Installation:
-------------

[](#installation)

The library is [PSR-4 compliant](http://www.php-fig.org/psr/psr-4)and the simplest way to install it is via composer:

```
 composer require b-alidra/xmltv

```

Usage
-----

[](#usage)

### Create a new XMLTV document root node

[](#create-a-new-xmltv-document-root-node)

```
$xmltv = new XMLTV();
```

### Set the document root node ttributes (optional)

[](#set-the-document-root-node-ttributes-optional)

```
$xmltv
    ->setDate('2016-12-26')
    ->setSourceinfourl('https://b-alidra.com/xmltv')
    ->setSourceinfoname('XMLTV')
    ->setSourcedataurl('https://b-alidra.com/xmltv')
    ->setGeneratorinfoname('XMLTV')
    ->setGeneratorinfourl('https://b-alidra.com/xmltv');
```

### Add a channel

[](#add-a-channel)

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

### Add a programme

[](#add-a-programme)

```
$xmltv->addProgramme([
        // Required attributes
        'channel'          => 'test-channel',
        'start'            => '20161223184000',
        // Optional attributes
        'stop'             => '20161223194000',
        'pdc-start'        => '20161223184000',
        'vps-start'        => '20161223184000',
        'showview'         => '???',
        'videoplus'        => '???',
        'clumpidx'         => '1'
    ], function (&$program) {
        $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) {
                $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');
            })
            ->addDate('20160615')
            ->addCategory(['lang' => 'en'], 'Horror')
            ->addKeyword(['lang' => 'en'], 'Fantastic')
            ->addLanguage('en')
            ->addOriglanguage('en')
            ->addLength(['units' => 'minutes'], 120)
            ->addIcon(['src' => 'https://b-alidra.com/icon.png'])
            ->addUrl('https://b-alidra.com')
            ->addCountry('GB')
            ->addEpisodenum('0.0.0/1')
            ->addVideo(function (&$video) {
                $video
                    ->addAspect('')
                    ->addColour('')
                    ->addPresent('yes')
                    ->addQuality('');
            })
            ->addAudio(function (&$audio) {
                $audio->addPresent('yes');
            })
            ->addPreviouslyshown([])
            ->addPremiere('')
            ->addLastchance('')
            ->addNew()
            ->addSubtitles(function (&$subtitles) {
                $subtitles->addLanguage('English');
            })
            ->addRating(function (&$rating) {
                $rating
                    ->addValue('1/5')
                    ->addIcon(['src' => 'https://b-alidra.com/icon.png']);
            })
            ->addStarrating(function (&$starrating) {
                $starrating
                    ->addValue('1/5')
                    ->addIcon(['src' => 'https://b-alidra.com/icon.png']);
            })
            ->addReview([
                'type'     => 'text',
                'source'   => 'Web',
                'reviewer' => 'Belkacem Alidra',
                'lang'     => 'en'
            ]);
        });
    });
```

### Check validation against the [DTD](http://xmltv.cvs.sourceforge.net/viewvc/xmltv/xmltv/xmltv.dtd)

[](#check-validation-against-the-dtd)

```
$xmltv->validate();

```

### Get the XML

[](#get-the-xml)

```
$output = $xmltv->toXml();
```

Will produce the following XML:

```

DOCTYPE tv PUBLIC "SYSTEM" "http://xmltv.cvs.sourceforge.net/viewvc/xmltv/xmltv/xmltv.dtd">

    The One

    https://b-alidra.com

    Test channel
    Test channel second title
    Test channel description

      Test director
      Test actor
      Test writer
      Test adapter
      Test producer
      Test composer
      Test editor
      Test presenter
      Test commentator
      Test guest

    20160615
    Horror
    Fantastic
    en
    en
    120

    https://b-alidra.com
    GB
    0.0.0/1

      yes

      yes

      English

      1/5

      1/5

```

Implementation notes
--------------------

[](#implementation-notes)

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

To set an **id** attribute (for example), use

```
$element->setId($value)
```

To add a **display-name** child, use

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

Tests
-----

[](#tests)

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

```
$ composer install
$ phpunit
```

For a test coverage report, look at`build/report`

License
-------

[](#license)

[MIT](LICENSE)

[![Latest Stable Version](https://camo.githubusercontent.com/ab9490d4ea6364942e7b3eac0936112155e914e7594a26eee95e517c87fe8aa0/68747470733a2f2f706f7365722e707567782e6f72672f622d616c696472612f786d6c74762f762f737461626c65)](https://packagist.org/packages/b-alidra/xmltv)[![Build Status](https://camo.githubusercontent.com/e59221094234c80f0aff8665d6d3743778da98ef3937d6b9ee07bdf05198e655/68747470733a2f2f7472617669732d63692e6f72672f622d616c696472612f584d4c54562d47656e657261746f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/b-alidra/XMLTV-Generator)[![Coverage Status](https://camo.githubusercontent.com/2c202934070e294e6492e9a3d52e6234bc4118d86f15604fbc181ebfc17b8033/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f622d616c696472612f584d4c54562d47656e657261746f722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/b-alidra/XMLTV-Generator?branch=master)[![StyleCI](https://camo.githubusercontent.com/2e239a8abff6f4b897676974f0fa5fd8cbbc73e872469a6e4b9348ab4f46f954/68747470733a2f2f7374796c6563692e696f2f7265706f732f37373635333133362f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/77653136)

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3417d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c0633c829b16c9938891674bfdb99fe31522288480fa2fda96232cabe8cd7c54?d=identicon)[b-alidra](/maintainers/b-alidra)

---

Top Contributors

[![b-alidra](https://avatars.githubusercontent.com/u/372249?v=4)](https://github.com/b-alidra "b-alidra (40 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/b-alidra-xmltv/health.svg)

```
[![Health](https://phpackages.com/badges/b-alidra-xmltv/health.svg)](https://phpackages.com/packages/b-alidra-xmltv)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
