1
0

sections.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. require_once '../../../myMyPlex.inc';
  3. # Bail if we're not happy with the auth token in the URL
  4. $auth = '';
  5. if (array_key_exists('auth_token', $_GET) && strlen($_GET['auth_token'])) {
  6. $auth = preg_replace('/\W/', '', $_GET['auth_token']);
  7. }
  8. if ($auth == '' || $auth != $_GET['auth_token']) {
  9. header('HTTP/1.1 401 Authorization Required');
  10. die("Invalid auth token\n");
  11. }
  12. # Lookup the user
  13. $user = get_user('', $auth);
  14. if (! $user['username']) {
  15. header('HTTP/1.1 401 Authorization Required');
  16. die("Unknown auth token\n");
  17. }
  18. # Lookup all the user's servers
  19. $servers = get_server_list($user['username']);
  20. # Lookup all the sections in those servers
  21. $sections = array();
  22. foreach ($servers as $name) {
  23. $server = get_server($user['username'], $name);
  24. $sections[] = array(
  25. 'version' => $server['version'],
  26. 'title' => 'myMyMovies',
  27. 'port' => $server['port'],
  28. 'lang' => 'en',
  29. 'server' => $server['name'],
  30. 'id' => $server['id'],
  31. 'type' => 'movie',
  32. 'agent' => 'com.plexapp.agents.imdb',
  33. 'path' => '/library/sections/1',
  34. 'address' => $server['address'],
  35. 'scanner' => 'Plex Movie Scanner',
  36. );
  37. }
  38. # Build an XML response
  39. $doc = new DomDocument('1.0');
  40. $root = $doc->createElement('MediaContainer');
  41. $root = $doc->appendChild($root);
  42. $root->setAttribute('title1', 'myMyPlex Library');
  43. $root->setAttribute('identifier', 'com.plexapp.plugins.myplex');
  44. $root->setAttribute('friendlyName', 'myMyPlex');
  45. $root->setAttribute('size', count($sections));
  46. $root->setAttribute('machineIdentifier', '1');
  47. foreach ($sections as $sec) {
  48. $elm = $doc->createElement('Directory');
  49. $elm->setAttribute('address', $sec['address']);
  50. $elm->setAttribute('local', '0');
  51. $elm->setAttribute('serverVersion', $sec['version']);
  52. $elm->setAttribute('accessToken', '');
  53. $elm->setAttribute('title', $sec['title']);
  54. $elm->setAttribute('updatedAt', date('U'));
  55. $elm->setAttribute('port', $sec['port']);
  56. $elm->setAttribute('art', 'http://' . $sec['address'] . ':' . $sec['port'] . '/:/resources/show-fanart.jpg');
  57. $elm->setAttribute('language', $sec['lang']);
  58. $elm->setAttribute('serverName', $sec['server']);
  59. $elm->setAttribute('machineIdentifier', $sec['id']);
  60. $elm->setAttribute('type', $sec['type']);
  61. $elm->setAttribute('agent', $sec['agent']);
  62. $elm->setAttribute('path', $sec['path']);
  63. $elm->setAttribute('owned', '1');
  64. $elm->setAttribute('host', $sec['address']);
  65. $elm->setAttribute('unique', '0');
  66. $elm->setAttribute('key', 'http://' . $sec['address'] . ':' . $sec['port'] . $sec['path']);
  67. $elm->setAttribute('scanner', $sec['scanner']);
  68. $elm = $root->appendChild($elm);
  69. }
  70. # Send our XML to the client
  71. header('HTTP/1.1 200 OK');
  72. print $doc->saveXML();
  73. ?>