diff --git a/README.md b/README.md index d687a08..715e7ae 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,13 @@ # ytm-webremote -YTMDesktop php web remote + +YTMDesktop PHP web remote. Deploy on local server or use from ytm.hassing.org. + +## FAQ + +_Q: Why not call the YTMDesktop API directly from javascript?_ + +Browsers like Chrome no longer allows calling HTTP and will automatically redirect to HTTPS. The YTMDesktop API is HTTP only. + +_Q: I can't connect to [lan-ip]:9863?_ + +The API port must be forwarded on your router to allow access from the internet to use it from ytm.hassing.org. Install on a local server to use it without opening for internet trafic. diff --git a/index.php b/index.php new file mode 100644 index 0000000..0fc557c --- /dev/null +++ b/index.php @@ -0,0 +1,319 @@ + $_POST["command"]]; + if(isset($_POST["value"])) { + $data["value"] = $_POST["value"]; + } + + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, "http://".$_POST["server"]."/".$url); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_HTTPHEADER, ["Authorization: Bearer ".$_POST["auth"]]); + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); + + $result = curl_exec($curl); + curl_close($curl); + + return $data; +} + +if(isset($_POST["auth"]) && isset($_POST["server"])) { + if(preg_match("/^[a-z0-9\.\:\-]+$/i", $_POST["server"]) == false) { + header("Location: /?error=1"); + exit(); + } + + if(isset($_POST["type"])) { + if($_POST["type"] == "data") { + $data = getData("query"); + if($data == null) { + echo json_encode(["player" => ["hasSong" => false]]); + exit(); + } + echo json_encode($data); + exit(); + } else if($_POST["type"] == "queue") { + $data = getData("query/queue"); + if($data == null) { + echo json_encode(["currentIndex" => 0,"list" => []]); + exit(); + } + echo json_encode($data); + exit(); + } else if($_POST["type"] == "command") { + echo json_encode(["status" => postCommand("query")]); + } + + exit(); + } else { + if(getData("query") == null) { + header("Location: /?error=1"); + exit(); + } + + if(isset($_POST["remember"])) { + setcookie("server", $_POST["server"], time()+60*60*24*365); + setcookie("auth", $_POST["auth"], time()+60*60*24*365); + } + } +} + + +?> + + +
+ +
+ Not playing ...
+ [DISLIKE
+ /
+ LIKE]
+ -
+
+ [BACK]
+ [PLAY / PAUSE]
+ [NEXT]
+
+
+ [LOGOUT]
+
FAILED TO CONNECT!
+ + + + +