commit | author | age
|
b56bb3
|
1 |
/* |
U |
2 |
Mediazentrale - Personal Media Center |
|
3 |
Copyright (C) 2021 Ulrich Hilger |
|
4 |
|
|
5 |
This program is free software: you can redistribute it and/or modify |
|
6 |
it under the terms of the GNU Affero General Public License as |
|
7 |
published by the Free Software Foundation, either version 3 of the |
|
8 |
License, or (at your option) any later version. |
|
9 |
|
|
10 |
This program is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
GNU Affero General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU Affero General Public License |
|
16 |
along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
17 |
*/ |
|
18 |
package de.uhilger.mediaz.api; |
|
19 |
|
|
20 |
import com.sun.net.httpserver.HttpExchange; |
|
21 |
import de.uhilger.mediaz.App; |
|
22 |
import de.uhilger.mediaz.Server; |
|
23 |
import de.uhilger.mediaz.entity.Abspieler; |
|
24 |
import de.uhilger.mediaz.entity.Abspielliste; |
|
25 |
import de.uhilger.mediaz.entity.Entity; |
|
26 |
import de.uhilger.mediaz.entity.Titel; |
|
27 |
import de.uhilger.mediaz.store.FileStorage; |
|
28 |
import java.io.IOException; |
|
29 |
import java.util.HashMap; |
|
30 |
import java.util.List; |
|
31 |
import java.util.Map; |
|
32 |
import java.util.logging.Logger; |
|
33 |
|
|
34 |
/** |
|
35 |
* Die MediaSteuerung verarbeitet HTTP-Signale zur Steuerung von Media-Operationen |
|
36 |
* wie z.B. dem Spielen einer Abspielliste oder dem Starten oder Stoppen eines Videos |
|
37 |
* auf einem entfernten Abspielgeraet. |
|
38 |
* |
|
39 |
* HTTP GET /mz/api/strg/abspieler/play/liste/[name] |
|
40 |
* HTTP GET /mz/api/strg/abspieler/play/[titel-url] |
|
41 |
* HTTP GET /mz/api/strg/abspieler/pause |
|
42 |
* HTTP GET /mz/api/strg/abspieler/stop |
|
43 |
* HTTP GET /mz/api/strg/abspieler/weiter |
|
44 |
* |
|
45 |
* |
|
46 |
* @author Ulrich Hilger |
|
47 |
* @version 1, 9.4.2021 |
|
48 |
*/ |
|
49 |
public class MediaSteuerung extends AbstractHandler { |
|
50 |
|
|
51 |
private static final Logger logger = Logger.getLogger(MediaSteuerung.class.getName()); |
|
52 |
|
|
53 |
private Map spielt = new HashMap(); |
|
54 |
|
|
55 |
@Override |
|
56 |
protected String get(HttpExchange e) { |
|
57 |
String response = "in Arbeit.."; |
|
58 |
String path = e.getRequestURI().toString(); |
|
59 |
String[] elems = path.split(App.getRs(Server.RB_SLASH)); |
|
60 |
// 4 Player name, 7 listenname |
|
61 |
switch(elems.length) { |
|
62 |
case 8: |
|
63 |
response = play(e, elems[4], elems[7]); |
|
64 |
break; |
|
65 |
} |
|
66 |
return response; |
|
67 |
} |
|
68 |
|
|
69 |
@Override |
|
70 |
protected String put(HttpExchange e) throws IOException { |
|
71 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|
72 |
} |
|
73 |
|
|
74 |
@Override |
|
75 |
protected String post(HttpExchange e) { |
|
76 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|
77 |
} |
|
78 |
|
|
79 |
@Override |
|
80 |
protected boolean delete(HttpExchange e) { |
|
81 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|
82 |
} |
|
83 |
|
|
84 |
private String play(HttpExchange e, String aName, String lName) { |
|
85 |
FileStorage fs = new FileStorage(App.getInitParameter(App.getRs(App.RB_AP_CONF))); |
|
86 |
Entity entity = fs.read(FileStorage.ST_ABSPIELER, aName); |
|
87 |
if(entity instanceof Abspieler) { |
|
88 |
Abspieler abspieler = (Abspieler) entity; |
|
89 |
String aUrl = abspieler.getUrl(); |
|
90 |
entity = fs.read(FileStorage.ST_ABSPIELLISTE, lName); |
|
91 |
if(entity instanceof Abspielliste) { |
|
92 |
Abspielliste liste = (Abspielliste) entity; |
|
93 |
Titel titel = liste.getTitel().get(0); |
|
94 |
spielt.put(aName, (int) 0); |
|
95 |
String titelUrl = titel.getKatalogUrl() + titel.getPfad() + titel.getName(); |
|
96 |
logger.info("abspielen von " + titelUrl + " auf " + aUrl); |
|
97 |
} |
|
98 |
} |
|
99 |
String response = "Abspielen der Liste " + lName + " auf Abspieler " + aName + " gestartet."; |
|
100 |
return response; |
|
101 |
} |
|
102 |
|
|
103 |
private String kommando() { |
|
104 |
return "avd/play?th=60&ti=60&o=local&titel="; |
|
105 |
} |
|
106 |
|
|
107 |
// rpi4-az:9090/avd/play?titel=/Filme/S/sound_city.m4v&th=60&ti=60&o=local |
|
108 |
// aUrl http://rpi4-wz:9090/ |
|
109 |
// titelUrl /media/test/A/The-Alan-Parsons-Project/I-Robot/02-I-Wouldnt-Want-to-Be-Like-You.mp3 |
|
110 |
|
|
111 |
} |