From b56bb3e0be136a9465589df74dd443b2bc063f90 Mon Sep 17 00:00:00 2001 From: ulrich Date: Fri, 09 Apr 2021 17:22:54 +0000 Subject: [PATCH] Abspielen in Arbeit --- src/de/uhilger/mediaz/api/StorageHandler.java | 89 ----------------- src/de/uhilger/mediaz/store/StorageFile.java | 2 www/ui/data/tpl/abs_sel.tpl | 2 src/mediaz_de_DE.properties | 1 src/de/uhilger/mediaz/Server.java | 3 src/de/uhilger/mediaz/api/MediaSteuerung.java | 111 ++++++++++++++++++++++ www/ui/js/app.js | 22 ++++ src/de/uhilger/mediaz/api/JsonHelper.java | 21 +++ src/de/uhilger/mediaz/api/ListFileHandler.java | 6 + src/de/uhilger/mediaz/api/AbstractHandler.java | 21 +++ www/ui/data/tpl/katalog_inhalt_liste.tpl | 6 + 11 files changed, 181 insertions(+), 103 deletions(-) diff --git a/src/de/uhilger/mediaz/Server.java b/src/de/uhilger/mediaz/Server.java index 69228eb..f662f2f 100644 --- a/src/de/uhilger/mediaz/Server.java +++ b/src/de/uhilger/mediaz/Server.java @@ -21,6 +21,7 @@ import de.uhilger.mediaz.api.FileHandler; import de.uhilger.mediaz.api.ListFileHandler; import de.uhilger.mediaz.api.ListHandler; +import de.uhilger.mediaz.api.MediaSteuerung; import de.uhilger.mediaz.api.StopServerHandler; import de.uhilger.mediaz.api.StorageHandler; import de.uhilger.mediaz.store.FileStorage; @@ -49,6 +50,7 @@ public static final String RB_SERVER_START_MSG = "msgServerStart"; public static final String RB_WEBROOT = "webroot"; public static final String RB_STORE = "store"; + public static final String RB_STRG = "strg"; public static final String RB_ALIST= "alist"; //public static final String RB_UI_ROOT = "uiroot"; public static final String RB_STOP_SERVER = "stopServer"; @@ -111,6 +113,7 @@ server.createContext(ctx + App.getRs(RB_WEBROOT), new FileHandler(wwwDir.getAbsolutePath())); ablageorteEinklinken(server); server.createContext(ctx + App.getRs(RB_STORE), new StorageHandler()); + server.createContext(ctx + App.getRs(RB_STRG), new MediaSteuerung()); server.createContext(ctx + App.getRs(RB_ALIST), new ListHandler()); server.createContext(ctx + App.getRs(RB_STOP_SERVER), new StopServerHandler()); server.setExecutor(Executors.newFixedThreadPool(20)); diff --git a/src/de/uhilger/mediaz/api/AbstractHandler.java b/src/de/uhilger/mediaz/api/AbstractHandler.java index 45befae..038b647 100644 --- a/src/de/uhilger/mediaz/api/AbstractHandler.java +++ b/src/de/uhilger/mediaz/api/AbstractHandler.java @@ -1,7 +1,19 @@ /* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. + Mediazentrale - Personal Media Center + Copyright (C) 2021 Ulrich Hilger + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. */ package de.uhilger.mediaz.api; @@ -17,7 +29,8 @@ /** * - * @author ulrich + * @author Ulrich Hilger + * @version 1, 8.4.2021 */ public abstract class AbstractHandler extends JsonHelper implements HttpHandler { diff --git a/src/de/uhilger/mediaz/api/JsonHelper.java b/src/de/uhilger/mediaz/api/JsonHelper.java index b84c51e..21b323e 100644 --- a/src/de/uhilger/mediaz/api/JsonHelper.java +++ b/src/de/uhilger/mediaz/api/JsonHelper.java @@ -1,7 +1,19 @@ /* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. + Mediazentrale - Personal Media Center + Copyright (C) 2021 Ulrich Hilger + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. */ package de.uhilger.mediaz.api; @@ -9,7 +21,8 @@ /** * - * @author ulrich + * @author Ulrich Hilger + * @version 1, 9.4.2021 */ public class JsonHelper { diff --git a/src/de/uhilger/mediaz/api/ListFileHandler.java b/src/de/uhilger/mediaz/api/ListFileHandler.java index cb9e9b4..3b01afe 100644 --- a/src/de/uhilger/mediaz/api/ListFileHandler.java +++ b/src/de/uhilger/mediaz/api/ListFileHandler.java @@ -85,6 +85,7 @@ StorageFile sf = new StorageFile(); String fname = file.getName(); sf.setName(fname); + sf.setTitelAnzName(fname); if(file.isDirectory()) { sf.setTyp(StorageFile.TYP_FOLDER); } else { @@ -117,7 +118,10 @@ if(sf.getTyp().equalsIgnoreCase(StorageFile.TYP_AUDIO)) { Track track = new Track(file); sf.setInterpret(track.getArtist()); - sf.setTitelAnzName(track.getTitle()); + String trackTitel = track.getTitle(); + if(trackTitel != null && trackTitel.length() > 0) { + sf.setTitelAnzName(trackTitel); + } sf.setAlbum(track.getAlbum()); } } diff --git a/src/de/uhilger/mediaz/api/MediaSteuerung.java b/src/de/uhilger/mediaz/api/MediaSteuerung.java new file mode 100644 index 0000000..f697353 --- /dev/null +++ b/src/de/uhilger/mediaz/api/MediaSteuerung.java @@ -0,0 +1,111 @@ +/* + Mediazentrale - Personal Media Center + Copyright (C) 2021 Ulrich Hilger + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + */ +package de.uhilger.mediaz.api; + +import com.sun.net.httpserver.HttpExchange; +import de.uhilger.mediaz.App; +import de.uhilger.mediaz.Server; +import de.uhilger.mediaz.entity.Abspieler; +import de.uhilger.mediaz.entity.Abspielliste; +import de.uhilger.mediaz.entity.Entity; +import de.uhilger.mediaz.entity.Titel; +import de.uhilger.mediaz.store.FileStorage; +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Logger; + +/** + * Die MediaSteuerung verarbeitet HTTP-Signale zur Steuerung von Media-Operationen + * wie z.B. dem Spielen einer Abspielliste oder dem Starten oder Stoppen eines Videos + * auf einem entfernten Abspielgeraet. + * + * HTTP GET /mz/api/strg/abspieler/play/liste/[name] + * HTTP GET /mz/api/strg/abspieler/play/[titel-url] + * HTTP GET /mz/api/strg/abspieler/pause + * HTTP GET /mz/api/strg/abspieler/stop + * HTTP GET /mz/api/strg/abspieler/weiter + * + * + * @author Ulrich Hilger + * @version 1, 9.4.2021 + */ +public class MediaSteuerung extends AbstractHandler { + + private static final Logger logger = Logger.getLogger(MediaSteuerung.class.getName()); + + private Map spielt = new HashMap(); + + @Override + protected String get(HttpExchange e) { + String response = "in Arbeit.."; + String path = e.getRequestURI().toString(); + String[] elems = path.split(App.getRs(Server.RB_SLASH)); + // 4 Player name, 7 listenname + switch(elems.length) { + case 8: + response = play(e, elems[4], elems[7]); + break; + } + return response; + } + + @Override + protected String put(HttpExchange e) throws IOException { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + protected String post(HttpExchange e) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + protected boolean delete(HttpExchange e) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + private String play(HttpExchange e, String aName, String lName) { + FileStorage fs = new FileStorage(App.getInitParameter(App.getRs(App.RB_AP_CONF))); + Entity entity = fs.read(FileStorage.ST_ABSPIELER, aName); + if(entity instanceof Abspieler) { + Abspieler abspieler = (Abspieler) entity; + String aUrl = abspieler.getUrl(); + entity = fs.read(FileStorage.ST_ABSPIELLISTE, lName); + if(entity instanceof Abspielliste) { + Abspielliste liste = (Abspielliste) entity; + Titel titel = liste.getTitel().get(0); + spielt.put(aName, (int) 0); + String titelUrl = titel.getKatalogUrl() + titel.getPfad() + titel.getName(); + logger.info("abspielen von " + titelUrl + " auf " + aUrl); + } + } + String response = "Abspielen der Liste " + lName + " auf Abspieler " + aName + " gestartet."; + return response; + } + + private String kommando() { + return "avd/play?th=60&ti=60&o=local&titel="; + } + + // rpi4-az:9090/avd/play?titel=/Filme/S/sound_city.m4v&th=60&ti=60&o=local + // aUrl http://rpi4-wz:9090/ + // titelUrl /media/test/A/The-Alan-Parsons-Project/I-Robot/02-I-Wouldnt-Want-to-Be-Like-You.mp3 + +} diff --git a/src/de/uhilger/mediaz/api/StorageHandler.java b/src/de/uhilger/mediaz/api/StorageHandler.java index aea2ffc..e6521bc 100644 --- a/src/de/uhilger/mediaz/api/StorageHandler.java +++ b/src/de/uhilger/mediaz/api/StorageHandler.java @@ -40,95 +40,6 @@ private static final Logger logger = Logger.getLogger(StorageHandler.class.getName()); - - /* - Das REST-Muster fuer die Mediazentrale (Beispiel Ablageort): - - 1. HTTP GET Ablageort/[Name] - Liefere den Ablageort namens [Name] - 2. HTTP GET Ablageort/liste/ - Liefere eine Liste mit Namen aller Ablageorte - Es duerfen keine Elemente namens "liste" angelegt werden - 3. HTTP GET Ablageort/ - Liefere eine Liste aller Ablageort-Objekte als JSON - 4. HTTP PUT Ablageort/[Name] - Der Ablageort wird angelegt. Wenn er bereits existiert, - wird er geändert. (im Falle einer Aenderung des Namens - muss der alte Name im URL stehen und im Body die Aenderung) - 5. HTTP DELETE - loesche den Ablageort - - Beispiele: - - HTTP GET /mz/api/store/Ablageort/ - liefert alle Ablageort-Objekte - - HTTP GET /mz/api/store/Ablageort/liste/ - liefert eine Liste der Namen vorhandener Ablageorte - - HTTP GET /mz/api/store/Ablageort/[Name] - liest den Ablageort namens [Name] - - HTTP PUT /mz/api/store/Ablageort/[Name] - wenn [Name] existiert: Aenderung, sonst neu anlegen - - HTTP DELETE /mz/api/store/Ablageort/[Name] - löscht den Ablageort namens [Name] - - */ - - /** Name der HTTP Methode GET */ - //public static final String HTTP_GET = "GET"; - - /** Name der HTTP Methode PUT */ - //public static final String HTTP_PUT = "PUT"; - - /** Name der HTTP Methode POST */ - //public static final String HTTP_POST = "POST"; - - /** Name der HTTP Methode DELETE */ - //public static final String HTTP_DELETE = "DELETE"; - - //public static final String EP_LISTE = "liste/"; - - /* - @Override - public void handle(HttpExchange e) throws IOException { - String method = e.getRequestMethod(); - String response = ""; - int code = 200; - switch(method) { - case HTTP_GET: - String json = lesen(e); - if(json != null) { - response = json; - } else { - response = "nicht gefunden"; - code = 404; - } - break; - - case HTTP_PUT: - response = put(e); - break; - - case HTTP_POST: - response = "nicht unterstuertzt."; - code = 404; - break; - - case HTTP_DELETE: - boolean geloescht = loeschen(e); - if(geloescht) { - response = "geloescht"; - } else { - response = "nicht geloescht"; - } - break; - } - logger.fine(response); - e.sendResponseHeaders(code, response.length()); - OutputStream os = e.getResponseBody(); - os.write(response.getBytes()); - os.close(); - } - */ - @Override protected String put(HttpExchange e) throws IOException { String path = e.getRequestURI().toString(); diff --git a/src/de/uhilger/mediaz/store/StorageFile.java b/src/de/uhilger/mediaz/store/StorageFile.java index 8c183c5..2e1a7bb 100644 --- a/src/de/uhilger/mediaz/store/StorageFile.java +++ b/src/de/uhilger/mediaz/store/StorageFile.java @@ -67,7 +67,7 @@ public void setTitelAnzName(String tan) { if(tan != null) { - this.titelAnzName = tan; + this.titelAnzName = tan; } } diff --git a/src/mediaz_de_DE.properties b/src/mediaz_de_DE.properties index ec16c5d..f5f7892 100644 --- a/src/mediaz_de_DE.properties +++ b/src/mediaz_de_DE.properties @@ -11,6 +11,7 @@ # uiroot=/ui store=/api/store alist=/api/alist +strg=/api/strg epliste=liste stopServer=/api/server/stop testAblage=/api/test/ablage diff --git a/www/ui/data/tpl/abs_sel.tpl b/www/ui/data/tpl/abs_sel.tpl index b42a2ea..5a36ab4 100644 --- a/www/ui/data/tpl/abs_sel.tpl +++ b/www/ui/data/tpl/abs_sel.tpl @@ -1,5 +1,5 @@ <select class="u-full-width ctrl-item ctrl-select" id="abspieler" title="Abspieler"> {{#ArrayList}} - <option value="{{url}}">{{name}}</option> + <option value="{{.}}">{{.}}</option> {{/ArrayList}} </select> \ No newline at end of file diff --git a/www/ui/data/tpl/katalog_inhalt_liste.tpl b/www/ui/data/tpl/katalog_inhalt_liste.tpl index 0bbda60..b62cf46 100644 --- a/www/ui/data/tpl/katalog_inhalt_liste.tpl +++ b/www/ui/data/tpl/katalog_inhalt_liste.tpl @@ -6,7 +6,11 @@ <ul class='entity-liste'> {{#Medialiste}} <li class='entity-eintrag entity-typ-{{typ}}' - interpret='{{interpret}}' album='{{album}}' titelAnzName='{{titelAnzName}}'>{{name}}</li> + typ='{{typ}}' + interpret='{{interpret}}' + album='{{album}}' + titelAnzName='{{titelAnzName}}' + dateiName='{{name}}'>{{titelAnzName}}</li> {{/Medialiste}} </ul> </div> diff --git a/www/ui/js/app.js b/www/ui/js/app.js index 87f417d..87fdf6b 100644 --- a/www/ui/js/app.js +++ b/www/ui/js/app.js @@ -194,7 +194,7 @@ }; this.abspieler_auswahl_fuellen = function() { - self.http_get('../api/store/Abspieler/', function (responseText) { + self.http_get('../api/store/Abspieler/liste/', function (responseText) { self.vorlage_laden_und_fuellen("data/tpl/abs_sel.tpl", JSON.parse(responseText), function (html) { document.querySelector(".abs-sel").innerHTML = html; }); @@ -205,13 +205,17 @@ self.http_get('../api/store/Abspielliste/', function (responseText) { self.vorlage_laden_und_fuellen("data/tpl/pl_sel.tpl", JSON.parse(responseText), function (html) { document.querySelector(".pl-sel").innerHTML = html; + self.addEvtListener('#playlist', 'change', function() { + self.titel_liste(); + }); }); }); }; this.addSelectedTitel = function() { var elem = document.querySelector(".selected"); - var titelName = elem.textContent; + //var titelName = elem.textContent; + var titelName = elem.attributes.dateiName.nodeValue; var album = elem.attributes.album.nodeValue; var interpret = elem.attributes.interpret.nodeValue; var anzName = elem.attributes.titelAnzName.nodeValue; @@ -237,6 +241,7 @@ self.abspieler_auswahl_fuellen(); self.abspielliste_auswahl_fuellen(); self.addEvtListener('#dazu-btn', 'click', self.addSelectedTitel); + self.addEvtListener('#play-btn', 'click', self.play); self.media_liste(); }); }; @@ -258,6 +263,19 @@ }); }; + /* ------------- Media-Steuerung ------------------------- */ + + this.play = function() { + var abs = document.querySelector('#abspieler').value; + var lst = document.querySelector('#playlist').value; + console.log( + "play playlist.value: " + document.querySelector('#playlist').value + + ", abspieler.value: " + document.querySelector('#abspieler').value); + self.http_get('../api/strg/' + abs + '/play/liste/' + lst, function(responseText) { + self.meldung_mit_timeout(responseText, 1500); + }); + }; + /* ------------- Helfer fuer Entitaets-Formulare ----------------------- */ /* -- Gitblit v1.9.3