Skip to content

Latest commit

 

History

History
71 lines (52 loc) · 2.29 KB

README.md

File metadata and controls

71 lines (52 loc) · 2.29 KB

OpenSubtitles SDK

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));