PHP code example of ecourty / kodi-nfo-parser

1. Go to this page and download the library: Download ecourty/kodi-nfo-parser library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ecourty / kodi-nfo-parser example snippets


use Ecourty\KodiNfoParser\NfoParser;
use Ecourty\KodiNfoParser\Model\MovieNfo;

$parser = new NfoParser();
$nfo = $parser->parseFile('/path/to/movie.nfo');

if ($nfo instanceof MovieNfo) {
    echo $nfo->title;       // "Inception"
    echo $nfo->year;        // 2010
    echo $nfo->plot;        // "A thief who steals..."
}

$nfo = $parser->parseString(file_get_contents('tvshow.nfo'));

use Ecourty\KodiNfoParser\Model\EpisodeNfo;

$nfo = $parser->parseFile('s01e01e02.nfo');

if ($nfo instanceof EpisodeNfo) {
    foreach ($nfo->episodes as $episode) {
        echo $episode->title;   // each episode's title
        echo $episode->season;  // season number
        echo $episode->episode; // episode number
    }
}

$nfo = $parser->parseParsingNfo('https://www.imdb.com/title/tt1375666/');

echo $nfo->scraperUrl; // "https://www.imdb.com/title/tt1375666/"

use Ecourty\KodiNfoParser\NfoSerializer;
use Ecourty\KodiNfoParser\Model\MovieNfo;

$serializer = new NfoSerializer();

$movie = new MovieNfo(
    title: 'Inception',
    year: 2010,
    plot: 'A thief who steals corporate secrets...',
);

$xml = $serializer->serialize($movie);
file_put_contents('movie.nfo', $xml);

use Ecourty\KodiNfoParser\Exception\NfoException;
use Ecourty\KodiNfoParser\Exception\NfoFileNotFoundException;

try {
    $nfo = $parser->parseFile('/path/to/file.nfo');
} catch (NfoFileNotFoundException $e) {
    // file missing
} catch (NfoException $e) {
    // any other NFO-related error
}