src/de/uhilger/mediaz/Server.java | ●●●●● patch | view | raw | blame | history | |
src/de/uhilger/mediaz/api/AbstractHandler.java | ●●●●● patch | view | raw | blame | history | |
src/de/uhilger/mediaz/api/JsonHelper.java | ●●●●● patch | view | raw | blame | history | |
src/de/uhilger/mediaz/api/ListFileHandler.java | ●●●●● patch | view | raw | blame | history | |
src/de/uhilger/mediaz/api/MediaSteuerung.java | ●●●●● patch | view | raw | blame | history | |
src/de/uhilger/mediaz/api/StorageHandler.java | ●●●●● patch | view | raw | blame | history | |
src/de/uhilger/mediaz/store/StorageFile.java | ●●●●● patch | view | raw | blame | history | |
src/mediaz_de_DE.properties | ●●●●● patch | view | raw | blame | history | |
www/ui/data/tpl/abs_sel.tpl | ●●●●● patch | view | raw | blame | history | |
www/ui/data/tpl/katalog_inhalt_liste.tpl | ●●●●● patch | view | raw | blame | history | |
www/ui/js/app.js | ●●●●● patch | view | raw | blame | history |
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)); 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 { 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 { 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()); } } src/de/uhilger/mediaz/api/MediaSteuerung.java
New file @@ -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 } 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(); 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; } } 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 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> 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> 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 ----------------------- */ /*