Advertisement
pegatron

Untitled

Mar 14th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1. <?php
  2. // PHP script to get status of vlc because javascript is shit
  3. $username = '';
  4. $password = '1234';
  5. $server = 'localhost:8080/requests/status.xml';
  6. $fullscreenurl = 'localhost:8080/requests/status.xml?command=fullscreen';
  7. $clearplurl = 'localhost:8080/requests/status.xml?command=pl_empty';
  8. $stopurl = 'localhost:8080/requests/status.xml?command=pl_pause';
  9. $playurl = 'localhost:8080/requests/status.xml?command=in_play&input=';
  10. $filelocation = '\\\\NasDrive\\Library\\';
  11.  
  12. $context = stream_context_create(array( //needed to authorise VLC
  13. 'http' => array(
  14. 'header' => "Authorization: Basic " . base64_encode("$username:$password")
  15. )
  16. )
  17. );
  18.  
  19. //Checks status
  20. $data = file_get_contents("http://$server", false, $context);
  21. $xml=simplexml_load_string($data);
  22. if($_POST['action'] == 'checkit') {
  23. if ($xml === false) {
  24. echo "Failed loading XML: Check Password and make sure VLC is running ";
  25. foreach(libxml_get_errors() as $error) {
  26. echo "<br>", $error->message;
  27. }
  28. } else {
  29. $data = file_get_contents("http://$server", false, $context);
  30. $xml=simplexml_load_string($data);
  31. $fullscreenstatus = $xml->fullscreen; //States from the xml
  32. $vlcstate = $xml->state;
  33. //$videoplaying = $xml->information->category['filename'];
  34. $videoloop = $xml->loop;
  35.  
  36.  
  37. echo "<u><b>Status</u>: </b><i>" . $vlcstate . " - Filename.mp4</i><a href='' onclick='checkvlcstatus()'><img src='refresh.png' alt='Toggle Fullscreen'></a> </br> <b><u>Fullscreen</u>:</b><i> ". $fullscreenstatus ."</i> <a href='#' onclick='fullscreen()'><img src='power.png' alt='Toggle Fullscreen'></a> </br> <b><u>Loop</u>:</b><i> ".$videoloop." </i><a href='#' onclick='fullscreen()'><img src='power.png' alt='Toggle Fullscreen'></a></br><b><u>Spreadsheet</u>: </b><a href='http://www.google.com'><img src='go.png' alt='Toggle Fullscreen'></a>";
  38. }
  39. }
  40. // Toggles fullscreen
  41. if($_POST['action'] == 'fullscreen') {
  42. if ($xml === false) {
  43. echo "Failed loading XML: Check Password and make sure VLC is running ";
  44. foreach(libxml_get_errors() as $error) {
  45. echo "<br>", $error->message;
  46. }
  47. } else {
  48. $data = file_get_contents("http://$fullscreenurl", false, $context);
  49. $xml=simplexml_load_string($data);
  50. }
  51. }
  52.  
  53. //Will play something
  54. if($_POST['action'] == 'playit') {
  55. if ($xml === false) {
  56. echo "Failed loading XML: Check Password and make sure VLC is running ";
  57. foreach(libxml_get_errors() as $error) {
  58. echo "<br>", $error->message;
  59. }
  60. } else {
  61.  
  62. //Build URL in here return filename & update status
  63. $vlcfilename = $_POST['filename'];
  64. $fullvlcplayurl = $playurl . $filelocation . $vlcfilename;
  65. $stopdata = file_get_contents("http://$stopurl", false, $context);
  66. $cleardata = file_get_contents("http://$clearplurl", false, $context);
  67. $playdata = file_get_contents("http://$fullvlcplayurl", false, $context);
  68. //sleep(1); Wont go into full screen unless delayed for a second. Will sort a if statement out with the xml
  69. //$fullscreendata = file_get_contents("http://$fullscreenurl", false, $context);
  70. sleep(1);
  71. $finalstatus = file_get_contents("http://$server", false, $context);
  72. $xmlnew=simplexml_load_string($finalstatus);
  73. $fullscreenstatus = $xmlnew->fullscreen; //States from the xml
  74. $vlcstate = $xml->state;
  75. echo "VLC is currently " . $vlcstate . ". Fullscreen? ". $fullscreenstatus ."!";
  76. }
  77. }
  78.  
  79.  
  80. //Deletes requested file - forever
  81. if($_POST['action'] == 'deleteit') {
  82. $filenamedelete = $_POST['filename'];
  83. $filenamedelete1= str_replace("%20"," ",$filenamedelete);
  84. $deletepath = $filelocation . $filenamedelete1;
  85.  
  86. if (!unlink($deletepath))
  87. {
  88. echo ("Error deleting $deletepath Check permissions and try again.");
  89. }
  90. else
  91. {
  92. echo ("Success page will reload");
  93. }
  94.  
  95. }
  96.  
  97.  
  98.  
  99.  
  100.  
  101. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement