Skip to content
This repository has been archived by the owner on Aug 6, 2020. It is now read-only.

Commit

Permalink
Catch all exception that can occur while calling OpenSubtitles API (#12)
Browse files Browse the repository at this point in the history
* Catch all exception that can occur while calling OpenSubtitles API

* Update README
  • Loading branch information
jonag authored Jan 8, 2017
1 parent b3e8894 commit 640ffe7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,22 @@ This application organize your downloaded tv shows and can download their subtit
The subtitles are downloaded thanks to the [OpenSubtitles](http://www.opensubtitles.org/) API.

## Usage
1. Move episodes to the tv shows directory
- Move episodes to the tv shows directory

``` sh
$ bin/episodes episodes:move
```
- Search subtitles for a specific file

``` sh
$ bin/episodes subtitles:search path_to_file.mkv
```

- Search all missing subtitles (stored in the database)

``` sh
$ bin/episodes subtitles:missing
```

## Installation
1. Download the [`composer.phar`](https://getcomposer.org/composer.phar) executable or use the installer.
Expand All @@ -21,7 +32,7 @@ The subtitles are downloaded thanks to the [OpenSubtitles](http://www.opensubtit
2. Install the dependencies

``` sh
$ php composer.phar install
$ php composer.phar install --no-dev
```

3. Edit the configuration file (settings.yml)
Expand Down
2 changes: 1 addition & 1 deletion bin/episodes
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set_time_limit(0);
*/
$loader = require __DIR__.'/../vendor/autoload.php';

$application = new \jonag\Episodes\Application('Episodes', '2.1.1');
$application = new \jonag\Episodes\Application('Episodes', '2.1.2');

$container = $application->getContainer();
$container['pdo'] = function () {
Expand Down
2 changes: 1 addition & 1 deletion src/jonag/Episodes/Command/SearchSubtitlesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
try {
$subtitles = $osClient->getSubtitles('eng', $searchOptions);
$progressBar->advance();
} catch (OpenSubtitlesException $e) {
} catch (\Exception $e) {
$progressBar->finish();
$io->error(sprintf('An error occured while calling the OpenSubtitles API %s', $e->getMessage()));

Expand Down
6 changes: 2 additions & 4 deletions src/jonag/OpenSubtitlesSDK/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function serverInfo()
public function getToken()
{
if ($this->token === null) {
$result = $this->call('LogIn', ['', '', 'en', 'jonag\episodes v2.1.1']);
$result = $this->call('LogIn', ['', '', 'en', 'jonag\episodes v2.1.2']);
$this->token = $result['token'];
}

Expand Down Expand Up @@ -92,7 +92,7 @@ public function getSubtitles($language, $options)
* @return mixed|null
* @throws \jonag\OpenSubtitlesSDK\Exception\OpenSubtitlesException
*/
private function call($methodName, $params = [])
private function call($methodName, array $params = [])
{
if ($this->xmlRpcClient === null) {
$this->xmlRpcClient = new RpcClient('http://api.opensubtitles.org/xml-rpc');
Expand All @@ -111,14 +111,12 @@ private function call($methodName, $params = [])

case UnauthorizedException::CODE:
throw new UnauthorizedException($result['status']);
break;

case MethodNotFoundException::CODE:
throw new MethodNotFoundException($result['status']);

default:
throw new OpenSubtitlesException($result['status']);
break;
}
}
}

0 comments on commit 640ffe7

Please sign in to comment.