CouchPotato.php 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  1. <?php
  2. namespace Kryptonit3\CouchPotato;
  3. use GuzzleHttp\Client;
  4. use Kryptonit3\CouchPotato\Exceptions\InvalidException;
  5. class CouchPotato
  6. {
  7. protected $url;
  8. protected $apiKey;
  9. protected $httpAuthUsername;
  10. protected $httpAuthPassword;
  11. public $options;
  12. public function __construct($url, $apiKey, $httpAuthUsername = null, $httpAuthPassword = null, $options = [])
  13. {
  14. $this->url = rtrim($url, '/\\'); // Example: http://127.0.0.1:5050 (no trailing forward-backward slashes)
  15. $this->apiKey = $apiKey;
  16. $this->httpAuthUsername = $httpAuthUsername;
  17. $this->httpAuthPassword = $httpAuthPassword;
  18. $this->options = $options;
  19. }
  20. /**
  21. * Check if app available.
  22. *
  23. * @return string
  24. * @throws InvalidException
  25. */
  26. public function getAppAvailable()
  27. {
  28. $uri = 'app.available';
  29. try {
  30. $response = $this->_request(
  31. [
  32. 'uri' => $uri,
  33. 'type' => 'get',
  34. 'data' => []
  35. ]
  36. );
  37. } catch (\Exception $e) {
  38. throw new InvalidException($e->getMessage());
  39. }
  40. return $response->getBody()->getContents();
  41. }
  42. /**
  43. * Restart the app.
  44. *
  45. * @return string
  46. * @throws InvalidException
  47. */
  48. public function getAppRestart()
  49. {
  50. $uri = 'app.restart';
  51. try {
  52. $response = $this->_request(
  53. [
  54. 'uri' => $uri,
  55. 'type' => 'get',
  56. 'data' => []
  57. ]
  58. );
  59. } catch (\Exception $e) {
  60. throw new InvalidException($e->getMessage());
  61. }
  62. return $response->getBody()->getContents();
  63. }
  64. /**
  65. * Shutdown the app.
  66. *
  67. * @return string
  68. * @throws InvalidException
  69. */
  70. public function getAppShutdown()
  71. {
  72. $uri = 'app.shutdown';
  73. try {
  74. $response = $this->_request(
  75. [
  76. 'uri' => $uri,
  77. 'type' => 'get',
  78. 'data' => []
  79. ]
  80. );
  81. } catch (\Exception $e) {
  82. throw new InvalidException($e->getMessage());
  83. }
  84. return $response->getBody()->getContents();
  85. }
  86. /**
  87. * Get version.
  88. *
  89. * @return string
  90. * @throws InvalidException
  91. */
  92. public function getAppVersion()
  93. {
  94. $uri = 'app.version';
  95. try {
  96. $response = $this->_request(
  97. [
  98. 'uri' => $uri,
  99. 'type' => 'get',
  100. 'data' => []
  101. ]
  102. );
  103. } catch (\Exception $e) {
  104. throw new InvalidException($e->getMessage());
  105. }
  106. return $response->getBody()->getContents();
  107. }
  108. /**
  109. * List all available categories
  110. *
  111. * @return string
  112. * @throws InvalidException
  113. */
  114. public function getCategoryList()
  115. {
  116. $uri = 'category.list';
  117. try {
  118. $response = $this->_request(
  119. [
  120. 'uri' => $uri,
  121. 'type' => 'get',
  122. 'data' => []
  123. ]
  124. );
  125. } catch (\Exception $e) {
  126. throw new InvalidException($e->getMessage());
  127. }
  128. return $response->getBody()->getContents();
  129. }
  130. /**
  131. * Return the directory list of a given directory
  132. *
  133. * @param null $path
  134. * @param bool|true $showHidden
  135. * @return string
  136. * @throws InvalidException
  137. */
  138. public function getDirectoryList($path = null, $showHidden = true)
  139. {
  140. $uri = 'directory.list';
  141. $uriData = [];
  142. if ($path) {
  143. $uriData['path'] = $path;
  144. }
  145. if ($showHidden) {
  146. $uriData['show_hidden'] = true;
  147. }
  148. try {
  149. $response = $this->_request(
  150. [
  151. 'uri' => $uri,
  152. 'type' => 'get',
  153. 'data' => $uriData
  154. ]
  155. );
  156. } catch (\Exception $e) {
  157. throw new InvalidException($e->getMessage());
  158. }
  159. return $response->getBody()->getContents();
  160. }
  161. /**
  162. * Remove all the log files
  163. *
  164. * @return string
  165. * @throws InvalidException
  166. */
  167. public function getLoggingClear()
  168. {
  169. $uri = 'logging.clear';
  170. try {
  171. $response = $this->_request(
  172. [
  173. 'uri' => $uri,
  174. 'type' => 'get',
  175. 'data' => []
  176. ]
  177. );
  178. } catch (\Exception $e) {
  179. throw new InvalidException($e->getMessage());
  180. }
  181. return $response->getBody()->getContents();
  182. }
  183. /**
  184. * Get the full log file by number
  185. *
  186. * @param int $nr Number of the log to get.
  187. * @return string
  188. * @throws InvalidException
  189. */
  190. public function getLoggingGet($nr = 0)
  191. {
  192. $uri = 'logging.get';
  193. $uriData = [
  194. 'nr' => $nr
  195. ];
  196. try {
  197. $response = $this->_request(
  198. [
  199. 'uri' => $uri,
  200. 'type' => 'get',
  201. 'data' => $uriData
  202. ]
  203. );
  204. } catch (\Exception $e) {
  205. throw new InvalidException($e->getMessage());
  206. }
  207. return $response->getBody()->getContents();
  208. }
  209. /**
  210. * @param string $type Type of logging, default "error" | info, debug
  211. * @param array $args All other params will be printed in the log string.
  212. * @return string
  213. * @throws InvalidException
  214. */
  215. public function getLoggingLog($type = 'error', array $args)
  216. {
  217. $uri = 'logging.log';
  218. $uriData = [
  219. 'type' => $type,
  220. 'args' => array_flatten($args)
  221. ];
  222. try {
  223. $response = $this->_request(
  224. [
  225. 'uri' => $uri,
  226. 'type' => 'get',
  227. 'data' => $uriData
  228. ]
  229. );
  230. } catch (\Exception $e) {
  231. throw new InvalidException($e->getMessage());
  232. }
  233. return $response->getBody()->getContents();
  234. }
  235. /**
  236. * Get a partial log
  237. *
  238. * @param int $lines Number of lines. Last to first. Default 30
  239. * @param string $type Type of log | all(default), error, info, debug
  240. * @return string
  241. * @throws InvalidException
  242. */
  243. public function getLoggingPartial($lines = 30, $type = 'all')
  244. {
  245. $uri = 'logging.partial';
  246. $uriData = [
  247. 'lines' => $lines,
  248. 'type' => $type
  249. ];
  250. try {
  251. $response = $this->_request(
  252. [
  253. 'uri' => $uri,
  254. 'type' => 'get',
  255. 'data' => $uriData
  256. ]
  257. );
  258. } catch (\Exception $e) {
  259. throw new InvalidException($e->getMessage());
  260. }
  261. return $response->getBody()->getContents();
  262. }
  263. /**
  264. * Get the progress of current manage update
  265. *
  266. * @return string
  267. * @throws InvalidException
  268. */
  269. public function getManageProgress()
  270. {
  271. $uri = 'manage.progress';
  272. try {
  273. $response = $this->_request(
  274. [
  275. 'uri' => $uri,
  276. 'type' => 'get',
  277. 'data' => []
  278. ]
  279. );
  280. } catch (\Exception $e) {
  281. throw new InvalidException($e->getMessage());
  282. }
  283. return $response->getBody()->getContents();
  284. }
  285. /**
  286. * Update the library by scanning for new movies
  287. *
  288. * @param bool|false $full Do a full update or just recently changed/added movies.
  289. * @return string
  290. * @throws InvalidException
  291. */
  292. public function getManageUpdate($full = false)
  293. {
  294. $uri = 'manage.update';
  295. $uriData = [];
  296. if ($full) {
  297. $uriData['full'] = true;
  298. }
  299. try {
  300. $response = $this->_request(
  301. [
  302. 'uri' => $uri,
  303. 'type' => 'get',
  304. 'data' => []
  305. ]
  306. );
  307. } catch (\Exception $e) {
  308. throw new InvalidException($e->getMessage());
  309. }
  310. return $response->getBody()->getContents();
  311. }
  312. /**
  313. * Delete a media from the wanted list
  314. *
  315. * @param int $id media ID(s) you want to delete. (comma separated)
  316. * @param string $deleteFrom all (default), wanted, manage
  317. * @return string
  318. * @throws InvalidException
  319. */
  320. public function getMediaDelete($id, $deleteFrom = 'all')
  321. {
  322. $uri = 'media.delete';
  323. $uriData = [
  324. 'id' => $id,
  325. 'delete_from' => $deleteFrom
  326. ];
  327. try {
  328. $response = $this->_request(
  329. [
  330. 'uri' => $uri,
  331. 'type' => 'get',
  332. 'data' => $uriData
  333. ]
  334. );
  335. } catch (\Exception $e) {
  336. throw new InvalidException($e->getMessage());
  337. }
  338. return $response->getBody()->getContents();
  339. }
  340. /**
  341. * Get media by id
  342. *
  343. * @param int $id The id of the media
  344. * @return string
  345. * @throws InvalidException
  346. */
  347. public function getMediaGet($id)
  348. {
  349. $uri = 'media.get';
  350. $uriData = [
  351. 'id' => $id
  352. ];
  353. try {
  354. $response = $this->_request(
  355. [
  356. 'uri' => $uri,
  357. 'type' => 'get',
  358. 'data' => $uriData
  359. ]
  360. );
  361. } catch (\Exception $e) {
  362. throw new InvalidException($e->getMessage());
  363. }
  364. return $response->getBody()->getContents();
  365. }
  366. /**
  367. * List media
  368. *
  369. * OPTIONAL PARAMETERS
  370. * status (array or csv) Filter media by status. Example:"active,done"
  371. * search (string) Search media title
  372. * release_status (array or csv) Filter media by status of its releases. Example:"snatched,available"
  373. * limit_offset (string) Limit and offset the media list. Examples: "50" or "50,30"
  374. * type (string) Media type to filter on.
  375. * starts_with (string) Starts with these characters. Example: "a" returns all media starting with the letter "a"
  376. *
  377. * @param array $params
  378. * @return string
  379. * @throws InvalidException
  380. */
  381. public function getMediaList(array $params = [])
  382. {
  383. $uri = 'media.list';
  384. $uriData = [];
  385. if (array_key_exists('status', $params)) {
  386. $uriData['status'] = $params['status'];
  387. }
  388. if (array_key_exists('search', $params)) {
  389. $uriData['search'] = $params['search'];
  390. }
  391. if (array_key_exists('release_status', $params)) {
  392. $uriData['release_status'] = $params['release_status'];
  393. }
  394. if (array_key_exists('limit_offset', $params)) {
  395. $uriData['limit_offset'] = $params['limit_offset'];
  396. }
  397. if (array_key_exists('type', $params)) {
  398. $uriData['type'] = $params['type'];
  399. }
  400. if (array_key_exists('starts_with', $params)) {
  401. $uriData['starts_with'] = $params['starts_with'];
  402. }
  403. try {
  404. $response = $this->_request(
  405. [
  406. 'uri' => $uri,
  407. 'type' => 'get',
  408. 'data' => $uriData
  409. ]
  410. );
  411. } catch (\Exception $e) {
  412. throw new InvalidException($e->getMessage());
  413. }
  414. return $response->getBody()->getContents();
  415. }
  416. /**
  417. * Refresh a any media type by ID
  418. *
  419. * @param int $id Movie, Show, Season or Episode ID(s) you want to refresh. (comma separated)
  420. * @return string
  421. * @throws InvalidException
  422. */
  423. public function getMediaRefresh($id)
  424. {
  425. $uri = 'media.refresh';
  426. $uriData = [
  427. 'id' => $id
  428. ];
  429. try {
  430. $response = $this->_request(
  431. [
  432. 'uri' => $uri,
  433. 'type' => 'get',
  434. 'data' => $uriData
  435. ]
  436. );
  437. } catch (\Exception $e) {
  438. throw new InvalidException($e->getMessage());
  439. }
  440. return $response->getBody()->getContents();
  441. }
  442. /**
  443. * Add new movie to the wanted list
  444. *
  445. * PARAMETERS
  446. * profile_id (string) ID of quality profile you want the add the movie in. If empty will use the default profile.
  447. * title (string) Movie title to use for searches. Has to be one of the titles returned by movie.search.
  448. * identifier (string) IMDB id of the movie your want to add.
  449. * category_id (string) ID of category you want the add the movie in. If empty will use no category.
  450. * force_readd (string) Force re-add even if movie already in wanted or manage. Default: True
  451. *
  452. * @param array $params
  453. * @return string
  454. * @throws InvalidException
  455. */
  456. public function getMovieAdd(array $params)
  457. {
  458. $uri = 'movie.add';
  459. $uriData = [];
  460. if (array_key_exists('profile_id', $params)) {
  461. $uriData['profile_id'] = $params['profile_id'];
  462. }
  463. if (array_key_exists('title', $params)) {
  464. $uriData['title'] = $params['title'];
  465. }
  466. if (array_key_exists('identifier', $params)) {
  467. $uriData['identifier'] = $params['identifier'];
  468. }
  469. if (array_key_exists('category_id', $params)) {
  470. $uriData['category_id'] = $params['category_id'];
  471. }
  472. if (array_key_exists('force_readd', $params)) {
  473. $uriData['force_readd'] = $params['force_readd'];
  474. }
  475. try {
  476. $response = $this->_request(
  477. [
  478. 'uri' => $uri,
  479. 'type' => 'get',
  480. 'data' => $uriData
  481. ]
  482. );
  483. } catch (\Exception $e) {
  484. throw new InvalidException($e->getMessage());
  485. }
  486. return $response->getBody()->getContents();
  487. }
  488. /**
  489. * Delete a movie from the wanted list
  490. *
  491. * @param int $id Movie ID(s) you want to delete. (comma separated)
  492. * @param string $deleteFrom Delete movie from this page all (default), wanted, manage
  493. * @return string
  494. * @throws InvalidException
  495. */
  496. public function getMovieDelete($id, $deleteFrom = 'all')
  497. {
  498. $uri = 'movie.delete';
  499. $uriData = [
  500. 'id' => $id,
  501. 'delete_from' => $deleteFrom
  502. ];
  503. try {
  504. $response = $this->_request(
  505. [
  506. 'uri' => $uri,
  507. 'type' => 'get',
  508. 'data' => $uriData
  509. ]
  510. );
  511. } catch (\Exception $e) {
  512. throw new InvalidException($e->getMessage());
  513. }
  514. return $response->getBody()->getContents();
  515. }
  516. /**
  517. * Edit Movies
  518. *
  519. * PARAMETERS
  520. * profile_id (string) ID of quality profile you want the edit the movie to.
  521. * default_title (string) Movie title to use for searches. Has to be one of the titles returned by movie.search.
  522. * id (string) Movie ID(s) you want to edit. (comma separated)
  523. * category_id (string) ID of category you want the add the movie in. If empty will use no category.
  524. *
  525. * @param array $params
  526. * @return string
  527. * @throws InvalidException
  528. */
  529. public function getMovieEdit(array $params)
  530. {
  531. $uri = 'movie.edit';
  532. $uriData = [];
  533. if (array_key_exists('profile_id', $params)) {
  534. $uriData['profile_id'] = $params['profile_id'];
  535. }
  536. if (array_key_exists('default_title', $params)) {
  537. $uriData['default_title'] = $params['default_title'];
  538. }
  539. if (array_key_exists('id', $params)) {
  540. $uriData['id'] = $params['id'];
  541. }
  542. if (array_key_exists('category_id', $params)) {
  543. $uriData['category_id'] = $params['category_id'];
  544. }
  545. try {
  546. $response = $this->_request(
  547. [
  548. 'uri' => $uri,
  549. 'type' => 'get',
  550. 'data' => $uriData
  551. ]
  552. );
  553. } catch (\Exception $e) {
  554. throw new InvalidException($e->getMessage());
  555. }
  556. return $response->getBody()->getContents();
  557. }
  558. /**
  559. * List Movies
  560. *
  561. * OPTIONAL PARAMETERS
  562. * status (array or csv) Filter movie by status. Example:"active,done"
  563. * search (string) Search movie title
  564. * release_status (array or csv) Filter movie by status of its releases. Example:"snatched,available"
  565. * limit_offset (string) Limit and offset the movie list. Examples: "50" or "50,30"
  566. * starts_with (string) Starts with these characters. Example: "a" returns all movies starting with the letter "a"
  567. *
  568. * @param array $params
  569. * @return string
  570. * @throws InvalidException
  571. */
  572. public function getMovieList(array $params = [])
  573. {
  574. $uri = 'movie.list';
  575. $uriData = [];
  576. if (array_key_exists('status', $params)) {
  577. $uriData['status'] = $params['status'];
  578. }
  579. if (array_key_exists('search', $params)) {
  580. $uriData['search'] = $params['search'];
  581. }
  582. if (array_key_exists('release_status', $params)) {
  583. $uriData['release_status'] = $params['release_status'];
  584. }
  585. if (array_key_exists('limit_offset', $params)) {
  586. $uriData['limit_offset'] = $params['limit_offset'];
  587. }
  588. if (array_key_exists('starts_with', $params)) {
  589. $uriData['starts_with'] = $params['starts_with'];
  590. }
  591. try {
  592. $response = $this->_request(
  593. [
  594. 'uri' => $uri,
  595. 'type' => 'get',
  596. 'data' => $uriData
  597. ]
  598. );
  599. } catch (\Exception $e) {
  600. throw new InvalidException($e->getMessage());
  601. }
  602. return $response->getBody()->getContents();
  603. }
  604. /**
  605. * Starts a full search for all wanted movies
  606. *
  607. * @return string
  608. * @throws InvalidException
  609. */
  610. public function getMovieSearcherFull()
  611. {
  612. $uri = 'movie.searcher.full_search';
  613. try {
  614. $response = $this->_request(
  615. [
  616. 'uri' => $uri,
  617. 'type' => 'get',
  618. 'data' => []
  619. ]
  620. );
  621. } catch (\Exception $e) {
  622. throw new InvalidException($e->getMessage());
  623. }
  624. return $response->getBody()->getContents();
  625. }
  626. /**
  627. * Get the progress of current full search
  628. *
  629. * @return string
  630. * @throws InvalidException
  631. */
  632. public function getMovieSearcherProgress()
  633. {
  634. $uri = 'movie.searcher.progress';
  635. try {
  636. $response = $this->_request(
  637. [
  638. 'uri' => $uri,
  639. 'type' => 'get',
  640. 'data' => []
  641. ]
  642. );
  643. } catch (\Exception $e) {
  644. throw new InvalidException($e->getMessage());
  645. }
  646. return $response->getBody()->getContents();
  647. }
  648. /**
  649. * Marks the snatched results as ignored and try the next best release
  650. *
  651. * @param int $id The id of the media
  652. * @return string
  653. * @throws InvalidException
  654. */
  655. public function getMovieSearcherTryNext($id)
  656. {
  657. $uri = 'movie.searcher.try_next';
  658. $uriData = [
  659. 'id' => $id
  660. ];
  661. try {
  662. $response = $this->_request(
  663. [
  664. 'uri' => $uri,
  665. 'type' => 'get',
  666. 'data' => $uriData
  667. ]
  668. );
  669. } catch (\Exception $e) {
  670. throw new InvalidException($e->getMessage());
  671. }
  672. return $response->getBody()->getContents();
  673. }
  674. /**
  675. * Get list of notifications
  676. *
  677. * @param string|null $limit Limit and offset the notification list. Examples: "50" or "50,30"
  678. * @return string
  679. * @throws InvalidException
  680. */
  681. public function getNotificationList($limit = null)
  682. {
  683. $uri = 'notification.list';
  684. $uriData = [];
  685. if ( $limit ) { $uriData['limit_offset'] = $limit; }
  686. try {
  687. $response = $this->_request(
  688. [
  689. 'uri' => $uri,
  690. 'type' => 'get',
  691. 'data' => $uriData
  692. ]
  693. );
  694. } catch (\Exception $e) {
  695. throw new InvalidException($e->getMessage());
  696. }
  697. return $response->getBody()->getContents();
  698. }
  699. /**
  700. * Mark notifications as read
  701. *
  702. * @param int $id Notification id you want to mark as read. All if ids is empty.
  703. * @return string
  704. * @throws InvalidException
  705. */
  706. public function getNotificationMarkRead($id = null)
  707. {
  708. $uri = 'notification.markread';
  709. $uriData = [];
  710. if ( $id ) { $uriData['id'] = $id; }
  711. try {
  712. $response = $this->_request(
  713. [
  714. 'uri' => $uri,
  715. 'type' => 'get',
  716. 'data' => $uriData
  717. ]
  718. );
  719. } catch (\Exception $e) {
  720. throw new InvalidException($e->getMessage());
  721. }
  722. return $response->getBody()->getContents();
  723. }
  724. /**
  725. * List all available profiles
  726. *
  727. * @return string
  728. * @throws InvalidException
  729. */
  730. public function getProfileList()
  731. {
  732. $uri = 'profile.list';
  733. try {
  734. $response = $this->_request(
  735. [
  736. 'uri' => $uri,
  737. 'type' => 'get',
  738. 'data' => []
  739. ]
  740. );
  741. } catch (\Exception $e) {
  742. throw new InvalidException($e->getMessage());
  743. }
  744. return $response->getBody()->getContents();
  745. }
  746. /**
  747. * List all available qualities
  748. *
  749. * @return string
  750. * @throws InvalidException
  751. */
  752. public function getQualityList()
  753. {
  754. $uri = 'quality.list';
  755. try {
  756. $response = $this->_request(
  757. [
  758. 'uri' => $uri,
  759. 'type' => 'get',
  760. 'data' => []
  761. ]
  762. );
  763. } catch (\Exception $e) {
  764. throw new InvalidException($e->getMessage());
  765. }
  766. return $response->getBody()->getContents();
  767. }
  768. /**
  769. * Delete releases
  770. *
  771. * @param int $id ID of the release object in release-table
  772. * @return string
  773. * @throws InvalidException
  774. */
  775. public function getReleaseDelete($id)
  776. {
  777. $uri = 'release.delete';
  778. $uriData = [
  779. 'id' => $id
  780. ];
  781. try {
  782. $response = $this->_request(
  783. [
  784. 'uri' => $uri,
  785. 'type' => 'get',
  786. 'data' => $uriData
  787. ]
  788. );
  789. } catch (\Exception $e) {
  790. throw new InvalidException($e->getMessage());
  791. }
  792. return $response->getBody()->getContents();
  793. }
  794. /**
  795. * Toggle ignore, for bad or wrong releases
  796. *
  797. * @param int $id ID of the release object in release-table
  798. * @return string
  799. * @throws InvalidException
  800. */
  801. public function getReleaseIgnore($id)
  802. {
  803. $uri = 'release.ignore';
  804. $uriData = [
  805. 'id' => $id
  806. ];
  807. try {
  808. $response = $this->_request(
  809. [
  810. 'uri' => $uri,
  811. 'type' => 'get',
  812. 'data' => $uriData
  813. ]
  814. );
  815. } catch (\Exception $e) {
  816. throw new InvalidException($e->getMessage());
  817. }
  818. return $response->getBody()->getContents();
  819. }
  820. /**
  821. * Send a release manually to the downloaders
  822. *
  823. * @param int $id ID of the release object in release-table
  824. * @return string
  825. * @throws InvalidException
  826. */
  827. public function getReleaseManualDownload($id)
  828. {
  829. $uri = 'release.manual_download';
  830. $uriData = [
  831. 'id' => $id
  832. ];
  833. try {
  834. $response = $this->_request(
  835. [
  836. 'uri' => $uri,
  837. 'type' => 'get',
  838. 'data' => $uriData
  839. ]
  840. );
  841. } catch (\Exception $e) {
  842. throw new InvalidException($e->getMessage());
  843. }
  844. return $response->getBody()->getContents();
  845. }
  846. /**
  847. * Get the progress of current renamer scan
  848. *
  849. * @return string
  850. * @throws InvalidException
  851. */
  852. public function getRenamerProgress()
  853. {
  854. $uri = 'renamer.progress';
  855. try {
  856. $response = $this->_request(
  857. [
  858. 'uri' => $uri,
  859. 'type' => 'get',
  860. 'data' => []
  861. ]
  862. );
  863. } catch (\Exception $e) {
  864. throw new InvalidException($e->getMessage());
  865. }
  866. return $response->getBody()->getContents();
  867. }
  868. /**
  869. * For the renamer to check for new files to rename in a folder
  870. *
  871. * OPTIONAL PARAMETERS
  872. * files (string) Provide the release files if more releases are in the same media_folder, delimited with a '|'. Note that no dedicated release folder is expected for releases with one file.
  873. * base_folder (string) The folder to find releases in. Leave empty for default folder.
  874. * download_id (string) The nzb/torrent ID of the release in media_folder. 'downloader' is required with this option.
  875. * status (string) The status of the release: 'completed' (default) or 'seeding'
  876. * to_folder (string) The folder to move releases to. Leave empty for default folder.
  877. * async (int) Set to 1 if you dont want to fire the renamer.scan asynchronous.
  878. * media_folder (string) The folder of the media to scan. Keep empty for default renamer folder.
  879. * downloader (string) The downloader the release has been downloaded with. 'download_id' is required with this option.
  880. *
  881. * @param array $params
  882. * @return string
  883. * @throws InvalidException
  884. */
  885. public function getRenamerScan(array $params = [])
  886. {
  887. $uri = 'renamer.scan';
  888. $uriData = [];
  889. if (array_key_exists('files', $params)) {
  890. $uriData['files'] = $params['files'];
  891. }
  892. if (array_key_exists('base_folder', $params)) {
  893. $uriData['base_folder'] = $params['base_folder'];
  894. }
  895. if (array_key_exists('download_id', $params)) {
  896. $uriData['download_id'] = $params['download_id'];
  897. }
  898. if (array_key_exists('status', $params)) {
  899. $uriData['status'] = $params['status'];
  900. }
  901. if (array_key_exists('to_folder', $params)) {
  902. $uriData['to_folder'] = $params['to_folder'];
  903. }
  904. if (array_key_exists('async', $params)) {
  905. $uriData['async'] = $params['async'];
  906. }
  907. if (array_key_exists('media_folder', $params)) {
  908. $uriData['media_folder'] = $params['media_folder'];
  909. }
  910. if (array_key_exists('downloader', $params)) {
  911. $uriData['downloader'] = $params['downloader'];
  912. }
  913. try {
  914. $response = $this->_request(
  915. [
  916. 'uri' => $uri,
  917. 'type' => 'get',
  918. 'data' => $uriData
  919. ]
  920. );
  921. } catch (\Exception $e) {
  922. throw new InvalidException($e->getMessage());
  923. }
  924. return $response->getBody()->getContents();
  925. }
  926. /**
  927. * Search the info in providers for a movie
  928. *
  929. * @param string $query The (partial) movie name you want to search for
  930. * @param string|null $type Search for a specific media type. Leave empty to search all.
  931. * @return string
  932. * @throws InvalidException
  933. */
  934. public function getSearch($query, $type = null)
  935. {
  936. $uri = 'search';
  937. $uriData = [
  938. 'q' => $query
  939. ];
  940. if ( $type ) { $uriData['type'] = $type; }
  941. try {
  942. $response = $this->_request(
  943. [
  944. 'uri' => $uri,
  945. 'type' => 'get',
  946. 'data' => $uriData
  947. ]
  948. );
  949. } catch (\Exception $e) {
  950. throw new InvalidException($e->getMessage());
  951. }
  952. return $response->getBody()->getContents();
  953. }
  954. /**
  955. * Starts a full search for all media
  956. *
  957. * @return string
  958. * @throws InvalidException
  959. */
  960. public function getSearcherFull()
  961. {
  962. $uri = 'searcher.full_search';
  963. try {
  964. $response = $this->_request(
  965. [
  966. 'uri' => $uri,
  967. 'type' => 'get',
  968. 'data' => []
  969. ]
  970. );
  971. } catch (\Exception $e) {
  972. throw new InvalidException($e->getMessage());
  973. }
  974. return $response->getBody()->getContents();
  975. }
  976. /**
  977. * Get the progress of all media searches
  978. *
  979. * @return string
  980. * @throws InvalidException
  981. */
  982. public function getSearcherProgress()
  983. {
  984. $uri = 'searcher.progress';
  985. try {
  986. $response = $this->_request(
  987. [
  988. 'uri' => $uri,
  989. 'type' => 'get',
  990. 'data' => []
  991. ]
  992. );
  993. } catch (\Exception $e) {
  994. throw new InvalidException($e->getMessage());
  995. }
  996. return $response->getBody()->getContents();
  997. }
  998. /**
  999. * Return the options and its values of settings.conf.
  1000. * Including the default values and group ordering used on the settings page.
  1001. *
  1002. * @return string
  1003. * @throws InvalidException
  1004. */
  1005. public function getSettings()
  1006. {
  1007. $uri = 'settings';
  1008. try {
  1009. $response = $this->_request(
  1010. [
  1011. 'uri' => $uri,
  1012. 'type' => 'get',
  1013. 'data' => []
  1014. ]
  1015. );
  1016. } catch (\Exception $e) {
  1017. throw new InvalidException($e->getMessage());
  1018. }
  1019. return $response->getBody()->getContents();
  1020. }
  1021. /**
  1022. * Save setting to config file (settings.conf)
  1023. *
  1024. * @param string $section The section name in settings.conf
  1025. * @param string $name The option name
  1026. * @param string $value The value you want to save
  1027. * @return string
  1028. * @throws InvalidException
  1029. */
  1030. public function getSettingsSave($section, $name, $value)
  1031. {
  1032. $uri = 'settings.save';
  1033. $uriData = [
  1034. 'section' => $section,
  1035. 'name' => $name,
  1036. 'value' => $value
  1037. ];
  1038. try {
  1039. $response = $this->_request(
  1040. [
  1041. 'uri' => $uri,
  1042. 'type' => 'get',
  1043. 'data' => $uriData
  1044. ]
  1045. );
  1046. } catch (\Exception $e) {
  1047. throw new InvalidException($e->getMessage());
  1048. }
  1049. return $response->getBody()->getContents();
  1050. }
  1051. /**
  1052. * Check for available update
  1053. *
  1054. * @return string
  1055. * @throws InvalidException
  1056. */
  1057. public function getUpdaterCheck()
  1058. {
  1059. $uri = 'updater.check';
  1060. try {
  1061. $response = $this->_request(
  1062. [
  1063. 'uri' => $uri,
  1064. 'type' => 'get',
  1065. 'data' => []
  1066. ]
  1067. );
  1068. } catch (\Exception $e) {
  1069. throw new InvalidException($e->getMessage());
  1070. }
  1071. return $response->getBody()->getContents();
  1072. }
  1073. /**
  1074. * Get updater information
  1075. *
  1076. * @return string
  1077. * @throws InvalidException
  1078. */
  1079. public function getUpdaterInfo()
  1080. {
  1081. $uri = 'updater.info';
  1082. try {
  1083. $response = $this->_request(
  1084. [
  1085. 'uri' => $uri,
  1086. 'type' => 'get',
  1087. 'data' => []
  1088. ]
  1089. );
  1090. } catch (\Exception $e) {
  1091. throw new InvalidException($e->getMessage());
  1092. }
  1093. return $response->getBody()->getContents();
  1094. }
  1095. /**
  1096. * Process requests with Guzzle
  1097. *
  1098. * @param array $params
  1099. * @return \Psr\Http\Message\ResponseInterface
  1100. */
  1101. protected function _request(array $params)
  1102. {
  1103. $client = new Client($this->options);
  1104. if ( $params['type'] == 'get' ) {
  1105. $url = $this->url . '/api/' . $this->apiKey . '/' . $params['uri'] . '?' . http_build_query($params['data']);
  1106. $options = [];
  1107. if ( $this->httpAuthUsername && $this->httpAuthPassword ) {
  1108. $options['auth'] = [
  1109. $this->httpAuthUsername,
  1110. $this->httpAuthPassword
  1111. ];
  1112. }
  1113. return $client->get($url, $options);
  1114. }
  1115. }
  1116. }