onursimsek/opensubtitles-api

OpenSubtitles REST API SDK for PHP

v2.0.1 2023-11-05 09:35 UTC

This package is auto-updated.

Last update: 2024-11-05 11:39:28 UTC


README

Latest Version on Packagist Software License Tests Quality Score Total Downloads

OpenSubtitle.com REST API SDK for PHP

Installation

You can install the package via composer:

composer require onursimsek/opensubtitles-api

Usage

Create a new instance with api key

$client = new OpenSubtitles();

Auth

// Login
$auth = $client->authentication->login(['username' => $username, 'password' => $password]);
// You can use short way
// $client->login($username, $password);

// Logout
$client->authentication->logout($auth->token);

Find Subtitles

// Find subtitles (for all parameters: https://opensubtitles.stoplight.io/docs/opensubtitles-api/open_api.json/paths/~1api~1v1~1subtitles/get)
$subtitles = $client->find([
    'id' => '',
    'query' => '',
    'imdb_id' => '',
    ...
]);

foreach ($subtitles->data as $subtitle) {
    echo $subtitle->id . PHP_EOL;
    echo $subtitle->attributes->language . PHP_EOL;
    echo $subtitle->attributes->feature_details->title . PHP_EOL;
    echo $subtitle->attributes->files[0]->file_id . PHP_EOL;
}

// Find subtitles by title
$subtitles = $client->subtitle->findByTitle('How i met your mother');

// Find subtitles by movie hash
$hash = (new \OpenSubtitles\Hash())->make(__DIR__ . '/../breakdance.avi');
$subtitles = $client->subtitle->findByMovieHash($hash);

Download Subtitle

$download = $client->download->download($auth->token, $subtitle->attributes->files[0]->file_id);

file_put_contents($subtitle->attributes->feature_details->title . $response->file_name, file_get_contents($response->link));