added basic movie search

redirect found movies to website
This commit is contained in:
lukas-heiligenbrunner 2020-03-01 11:02:28 +01:00
parent fad3fe019f
commit 2c1777c21c
5 changed files with 94 additions and 2 deletions

View File

@ -0,0 +1,22 @@
package eu.heili.hometheater.media
class Movie {
private var title: String = ""
private var url: String = ""
fun getTitle(): String {
return title
}
fun getUrl(): String {
return url
}
fun setTitle(title:String) {
this.title = title
}
fun setUrl(url: String) {
this.url = url
}
}

View File

@ -0,0 +1,43 @@
package eu.heili.hometheater.media;
import eu.heili.hometheater.basicutils.Log;
import java.io.File;
import java.util.ArrayList;
public class MovieHandler {
private static MovieHandler _this = new MovieHandler();
public static MovieHandler getInstance() {
return _this;
}
private MovieHandler() {
loadMovies();
}
ArrayList<Movie> movies = new ArrayList<>();
String moviepath = "./";
public void loadMovies() {
File folder = new File(moviepath);
if (folder.isDirectory()) {
for(File fl : folder.listFiles()){
if(fl.getName().endsWith(".mp4")) {
Movie tempi = new Movie();
tempi.setUrl(fl.getName());
tempi.setTitle(fl.getName().replace(".mp4",""));
movies.add(tempi);
System.out.println(fl.getName());
}
}
} else {
Log.Log.warning("moviepath is no folder!");
}
}
public ArrayList<Movie> getMovies(){
return movies;
}
}

View File

@ -3,6 +3,7 @@ package eu.heili.hometheater.website
import com.sun.net.httpserver.HttpServer import com.sun.net.httpserver.HttpServer
import eu.heili.hometheater.basicutils.Log.Log.criticalerror import eu.heili.hometheater.basicutils.Log.Log.criticalerror
import eu.heili.hometheater.basicutils.Log.Log.info import eu.heili.hometheater.basicutils.Log.Log.info
import eu.heili.hometheater.website.datarequests.MovieData
import eu.heili.hometheater.website.datarequests.TestData import eu.heili.hometheater.website.datarequests.TestData
import java.io.IOException import java.io.IOException
import java.net.BindException import java.net.BindException
@ -14,7 +15,7 @@ class Webserver {
try { try {
val server = HttpServer.create(InetSocketAddress(8080), 0) val server = HttpServer.create(InetSocketAddress(8080), 0)
server.createContext("/", MainPage()) server.createContext("/", MainPage())
server.createContext("/data/test", TestData()) server.createContext("/data/movie", MovieData())
// todo insert get and post request sites here! // todo insert get and post request sites here!
server.executor = java.util.concurrent.Executors.newCachedThreadPool() // creates a default executor server.executor = java.util.concurrent.Executors.newCachedThreadPool() // creates a default executor
server.start() server.start()

View File

@ -0,0 +1,26 @@
package eu.heili.hometheater.website.datarequests
import eu.heili.hometheater.media.MovieHandler
import eu.heili.hometheater.website.basicrequest.PostRequest
import java.util.HashMap
class MovieData : PostRequest() {
override fun request(params: HashMap<String, String>): String {
val temp = MovieHandler.getInstance()
val sb = StringBuilder()
sb.append("""{"status":"ok","movies":[""")
for (i in temp.movies){
sb.append("""{"title":"${i.getTitle()}", "url":"${i.getUrl()}"}""")
if (temp.movies.last() != i){
sb.append(",")
}
println(i.getTitle())
}
sb.append("]}")
return sb.toString()
}
}

View File

@ -1,5 +1,5 @@
Req.ready((event) => { Req.ready((event) => {
Req.post("/data/test","action=test",function (dta) { Req.post("/data/movie","action=getMovies",function (dta) {
console.log(dta); console.log(dta);
}); });
}); });