PHP Classes

Easy Subtitle Downloader: Download movie subtitles with EasySubtitles API

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 150 All time: 9,086 This week: 81Up
Version License PHP version Categories
easysubtitledownload 1.000.000GNU General Publi...5PHP 5, Web services, Video
Description 

Author

This package can download movie subtitles with EasySubtitles API.

It can send HTTP requests to the EasySubtitles API Web server to obtain subtitles for a given movie.

The downloaded subtitles are returned as a string.

Innovation Award
PHP Programming Innovation award nominee
January 2018
Number 5
This package can download movie subtitles with EasySubtitles API.

It can send HTTP requests to the EasySubtitles API Web server to obtain subtitles for a given movie.

The downloaded subtitles are returned as a string.

Manuel Lemos
Picture of Alexandre Sinício
  Performance   Level  
Name: Alexandre Sinício <contact>
Classes: 7 packages by
Country: Brazil Brazil
Age: 40
All time rank: 2095136 in Brazil Brazil
Week rank: 49 Up4 in Brazil Brazil Up
Innovation award
Innovation award
Nominee: 3x

Example

<?php

use alesinicio\Easysubtitle\EasysubtitleDownloader;

require
'./vendor/alesinicio/Easysubtitle/EasysubtitleDownloader.php';

$sub = new EasysubtitleDownloader();

//THE WHOLE THING THROWS EXCEPTIONS ON ERRORS, SO KEEP EVERYTHING IN A TRY/CATCH BLOCK.
try {
   
//SETS THE PATH TO THE VIDEO FILE
   
$sub->setVideofile(__DIR__.'/tests/alesinicio/Easysubtitle/justified.mp4');
   
   
//SETS THE USER AGENT FOR THE API CALL -- USE YOUR OWN PROJECT DATA
   
$sub->setUserAgent('SubDB/1.0 (YOUR_NAME/VERSION; PROJECT_URL)');
   
   
//SETS WHAT ARE YOUR PREFERRED LANGUAGES FOR THE SUBTITLE -- EITHER AN ARRAY OR COMMA-SEPARATED VALUES
   
$sub->setPreferredLanguages('pt,en');
   
   
//CALLS THE API AND GET WHAT SUBTITLES ARE AVAILABLE FOR THAT VIDEO FILE
   
$strSubtitlesAvailable = $sub->getAvailableSubtitles();
   
   
//GIVEN THE AVAILABLE SUBTITLES, GETS THE BEST CHOICE BASED ON YOUR PREFERENCES
   
$bestAvailableSubtitle = $sub->searchForPreferredSubtitle($strSubtitlesAvailable);
   
   
//DOWNLOADS THE SUBTITLE TO THE SAME FOLDER OF THE VIDEO FILE
   
$sub->downloadSubtitle($bestAvailableSubtitle);
   
    echo
"Subtitle in language `{$bestAvailableSubtitle}` downloaded!";
} catch (
Exception $e) {
    die(
$e->getMessage());
}


Details

EasysubtitleDownloader

PHP implementation for the easysubtitles.com REST API.

Downloads subtitles for video files given preferred language.

Can be used in an object-oriented fashion or in procedural format.

The file 'tests.php' runs unit-tests for most common situations.

Feel free to contribute.

Examples

Object-oriented style

try {
	$sub = new EasysubtitleDownloader();

	//SETS THE PATH TO THE VIDEO FILE
	$sub->setVideofile(__DIR__.'/tests/alesinicio/Easysubtitle/justified.mp4');
	
	//SETS THE USER AGENT FOR THE API CALL -- USE YOUR OWN PROJECT DATA
	$sub->setUserAgent('SubDB/1.0 (YOUR_NAME/VERSION; PROJECT_URL)');
	
	//SETS WHAT ARE YOUR PREFERRED LANGUAGES FOR THE SUBTITLE -- EITHER AN ARRAY OR COMMA-SEPARATED VALUES
	$sub->setPreferredLanguages('pt,en');
	
	//CALLS THE API AND GET WHAT SUBTITLES ARE AVAILABLE FOR THAT VIDEO FILE
	$strSubtitlesAvailable = $sub->getAvailableSubtitles();
	
	//GIVEN THE AVAILABLE SUBTITLES, GETS THE BEST CHOICE BASED ON YOUR PREFERENCES
	$bestAvailableSubtitle = $sub->searchForPreferredSubtitle($strSubtitlesAvailable);
	
	//DOWNLOADS THE SUBTITLE TO THE SAME FOLDER OF THE VIDEO FILE
	$sub->downloadSubtitle($bestAvailableSubtitle);
	
	echo "Subtitle in language `{$bestAvailableSubtitle}` downloaded!";
} catch (Exception $e) {
	die($e->getMessage());
}

Procedural styles

try {
	//SETS THE PATH TO THE VIDEO FILE
	$strVideofile		= __DIR__.'/tests/alesinicio/Easysubtitle/justified.mp4';
	
	//SETS THE USER AGENT FOR THE API CALL -- USE YOUR OWN PROJECT DATA
	$strUserAgent		= 'SubDB/1.0 (YOUR_NAME/VERSION; PROJECT_URL)';
	
	//SETS WHAT ARE YOUR PREFERRED LANGUAGES FOR THE SUBTITLE -- EITHER AN ARRAY OR COMMA-SEPARATED VALUES
	$preferredLanguages	= ['pt','en'];

	//TRIES TO DOWNLOAD THE SUBTITLE
	$result = EasysubtitleDownloader::downloadSubtitleForVideoFile($strUserAgent, $strVideofile, $preferredLanguages);

	//PARSES THE RESULT OF THE DOWNLOAD ATTEMPT
	if ($result['code'] == 1) {
		echo "Subtitle downloaded!";
	} else {
		die('Error > '.$result['message']);
	}
} catch (Exception $e) {
	die($e->getMessage());
}

  Files folder image Files (6)  
File Role Description
Files folder imagetests (1 directory)
Files folder imagevendor (1 directory)
Accessible without login Plain text file example_01_oop.php Example Example script
Accessible without login Plain text file example_02_procedural.php Example Example script
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file tests.php Example Example script

  Files folder image Files (6)  /  tests  
File Role Description
Files folder imagealesinicio (1 directory)

  Files folder image Files (6)  /  tests  /  alesinicio  
File Role Description
Files folder imageEasysubtitle (1 file)

  Files folder image Files (6)  /  tests  /  alesinicio  /  Easysubtitle  
File Role Description
  Plain text file EasysubtitleDownloader.test.php Class Class source

  Files folder image Files (6)  /  vendor  
File Role Description
Files folder imagealesinicio (1 directory)

  Files folder image Files (6)  /  vendor  /  alesinicio  
File Role Description
Files folder imageEasysubtitle (1 file)

  Files folder image Files (6)  /  vendor  /  alesinicio  /  Easysubtitle  
File Role Description
  Plain text file EasysubtitleDownloader.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:150
This week:0
All time:9,086
This week:81Up