From 640ffe7eac36a8680bb53f1f8d912e5106daf45e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Gon=C3=A7alves?= Date: Sun, 8 Jan 2017 13:03:51 +0100 Subject: [PATCH] Catch all exception that can occur while calling OpenSubtitles API (#12) * Catch all exception that can occur while calling OpenSubtitles API * Update README --- README.md | 15 +++++++++++++-- bin/episodes | 2 +- .../Episodes/Command/SearchSubtitlesCommand.php | 2 +- src/jonag/OpenSubtitlesSDK/Client.php | 6 ++---- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 291085e..0f3afd5 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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) diff --git a/bin/episodes b/bin/episodes index 22e17c2..6985095 100644 --- a/bin/episodes +++ b/bin/episodes @@ -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 () { diff --git a/src/jonag/Episodes/Command/SearchSubtitlesCommand.php b/src/jonag/Episodes/Command/SearchSubtitlesCommand.php index 3beb464..15e7358 100644 --- a/src/jonag/Episodes/Command/SearchSubtitlesCommand.php +++ b/src/jonag/Episodes/Command/SearchSubtitlesCommand.php @@ -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())); diff --git a/src/jonag/OpenSubtitlesSDK/Client.php b/src/jonag/OpenSubtitlesSDK/Client.php index 14845a7..de8c820 100644 --- a/src/jonag/OpenSubtitlesSDK/Client.php +++ b/src/jonag/OpenSubtitlesSDK/Client.php @@ -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']; } @@ -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'); @@ -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; } } }