CouchPotato.php 33 KB

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