kesar/php-open-subtitles

phpOpenSubtitles is a PHP library for opensubtitles.org

dev-master 2017-05-30 21:09 UTC

This package is auto-updated.

Last update: 2024-04-11 13:48:29 UTC


README

Library to connect with opensubtitles.org

Build Status Scrutinizer Code Quality Code Coverage

Example

  1. Update your config/configuration.yml.dist with login from Open Subtitles

  2. run in console ``php console.php ```

<?php
/**
 * Example that use SubtitleManager in console
 *
 * @author  César Rodríguez <kesarr@gmail.com>
 * @example php console.php <filepath>
 */

use Symfony\Component\Yaml\Yaml;
use OpenSubtitlesApi\SubtitlesManager;
use OpenSubtitlesApi\FileGenerator;

require_once 'vendor/autoload.php';

$file = $argv[1];

if (empty($file)) {
    echo 'error! you must supply a file';

    return 1;
}
if (!is_file($file)) {
    echo 'error! file ' . $file . ' does not exist';

    return 1;
}

$config = Yaml::parse(file_get_contents(__DIR__ . '/config/configuration.yml.dist'));

if (empty($config)) {
    echo 'error! config file does not exist';

    return 1;
}

$manager   = new SubtitlesManager($config['username'], $config['password'], $config['language']);
$subtitles = $manager->get($file);

if (!empty($subtitles) && !empty($subtitles[0])) {
    $fileGenerator = new FileGenerator();
    $fileGenerator->downloadSubtitle($subtitles[0], $file);
} else {
    echo 'error! impossible to find the subtitle';
}