Advertisement
Guest User

Untitled

a guest
Dec 8th, 2020
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. * @ This file is created by http://DeZender.Net
  5. * @ deZender (PHP7 Decoder for ionCube Encoder)
  6. *
  7. * @ Version : 4.1.0.1
  8. * @ Author : DeZender
  9. * @ Release on : 29.08.2020
  10. * @ Official site : http://DeZender.Net
  11. *
  12. */
  13.  
  14. class EmbyApiClient
  15. {
  16. private $serverAddress;
  17. private $username;
  18. private $password;
  19. private $headers = [];
  20. public $accessToken;
  21.  
  22. public function __construct($serverAddress = '', $username = '', $pwd = '')
  23. {
  24. $this->serverAddress = $serverAddress;
  25. $this->username = $username;
  26. $this->password = $pwd;
  27. $this->accessToken = $this->getAccessToken();
  28. }
  29.  
  30. public function setRequestHeaders()
  31. {
  32. if ($this->accessToken) {
  33. $this->headers['token'] = 'X-MediaBrowser-Token: ' . $this->accessToken;
  34. }
  35.  
  36. $this->headers['type'] = 'Content-Type: application/json';
  37. $this->headers['auth'] = 'X-Emby-Authorization: MediaBrowser Client=Android, Device=Samsung Galaxy SIII, DeviceId=xxx, Version=1.0.0.0';
  38. }
  39.  
  40. public function getAccessToken()
  41. {
  42. $token = '';
  43. $res = $this->authenticateUser($this->username, $this->password);
  44. if (isset($res['response']['AccessToken']) && !empty($res['response']['AccessToken'])) {
  45. $token = $res['response']['AccessToken'];
  46. }
  47.  
  48. return $token;
  49. }
  50.  
  51. public function getUrl($name, $params = [])
  52. {
  53. $this->url = $this->serverAddress . '/emby/';
  54. $this->url = $this->url . $name;
  55.  
  56. if (!empty($params)) {
  57. $this->url = $this->url . '?' . implode('&', $params);
  58. }
  59.  
  60. return $this->url;
  61. }
  62.  
  63. public function createUser($name)
  64. {
  65. $this->params = ['url' => $this->getUrl('Users/New'), 'name' => $name];
  66. return $this->curlPostRequest($this->params);
  67. }
  68.  
  69. public function setUserPassword($userid, $newpw, $currentpw = '')
  70. {
  71. if (empty($userid) || empty($newpw)) {
  72. return ['status' => 'error', 'message' => 'Required params are missing.'];
  73. }
  74.  
  75. $url = 'Users/' . $userid . '/Password';
  76. $this->params = ['url' => $this->getUrl($url), 'CurrentPw' => $currentpw, 'NewPw' => $newpw];
  77. return $this->curlPostRequest($this->params);
  78. }
  79.  
  80. public function deleteUser($userId)
  81. {
  82. if (empty($userId)) {
  83. return ['status' => 'error', 'message' => 'Userid is required.'];
  84. }
  85.  
  86. $url = 'Users/' . $userId;
  87. $this->params = ['url' => $this->getUrl($url)];
  88. return $this->curlDeleteRequest($this->params);
  89. }
  90.  
  91. public function updateUserPolicy($userId, $policies)
  92. {
  93. if (empty($userId)) {
  94. return ['status' => 'error', 'message' => 'Userid is required.'];
  95. }
  96.  
  97. if (empty($policies)) {
  98. return ['status' => 'error', 'message' => 'Required params are empty.'];
  99. }
  100.  
  101. $url = 'Users/' . $userId . '/Policy';
  102. $this->params = array_merge(['url' => $this->getUrl($url)], $policies);
  103. .....................................................................
  104. .............................................
  105. ...................
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement