commit | author | age
|
60719c
|
1 |
/* |
U |
2 |
AV-Direktor - Control OMXPlayer on Raspberry Pi via HTTP |
|
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/>. |
6ff352
|
17 |
*/ |
229976
|
18 |
package de.uhilger.calypso.handler; |
8e2038
|
19 |
|
U |
20 |
import com.sun.net.httpserver.HttpExchange; |
229976
|
21 |
import de.uhilger.calypso.App; |
2dd7a5
|
22 |
import java.io.IOException; |
6ff352
|
23 |
import java.nio.file.FileSystem; |
U |
24 |
import java.nio.file.FileSystems; |
|
25 |
import java.nio.file.FileVisitResult; |
|
26 |
import java.nio.file.Files; |
|
27 |
import java.nio.file.Path; |
|
28 |
import java.nio.file.SimpleFileVisitor; |
|
29 |
import java.nio.file.attribute.BasicFileAttributes; |
8e2038
|
30 |
import java.util.logging.Level; |
U |
31 |
import java.util.logging.Logger; |
|
32 |
|
|
33 |
/** |
e499f8
|
34 |
* Play |
6ff352
|
35 |
* |
e499f8
|
36 |
* rpi4-az:9090/avd/play?titel=/Filme/S/sound_city.m4v&th=60&ti=60&o=local |
U |
37 |
* |
6ff352
|
38 |
* OMXPlayer.abspielenMitParameternUndRueckmeldung( String urlStr, String |
U |
39 |
* parameter, String meldeUrlStr, String token) |
e499f8
|
40 |
* |
6ff352
|
41 |
* Parameter des Aufrufs play als query (th threshold, ti timeout) |
e499f8
|
42 |
* |
6ff352
|
43 |
* ?titel=/Filme/S/sound_city.m4v &ti=60 &th=60 &o=local|hdmi|both |
U |
44 |
* &r=http://uhilger.de/mc/api/usw |
|
45 |
* |
|
46 |
* r muss ganz wegbleiben, wenn keine Rueckmeldung gewuescht ist |
|
47 |
* |
8e2038
|
48 |
* @author ulrich |
U |
49 |
*/ |
63b711
|
50 |
public class PlayHandler extends CmdHandler { |
6ff352
|
51 |
|
8e2038
|
52 |
private static final Logger logger = Logger.getLogger(PlayHandler.class.getName()); |
63b711
|
53 |
|
U |
54 |
public PlayHandler(String cmd) { |
|
55 |
super(cmd); |
|
56 |
} |
|
57 |
|
b16b54
|
58 |
|
U |
59 |
@Override |
|
60 |
protected StringBuilder buildParams(HttpExchange t) { |
|
61 |
StringBuilder params = super.buildParams(t); |
|
62 |
params.append(App.getPlayer().buildParams(t, map)); |
|
63 |
return params; |
|
64 |
} |
|
65 |
|
|
66 |
|
|
67 |
/* |
63b711
|
68 |
protected StringBuilder buildParams(HttpExchange t) { |
U |
69 |
StringBuilder params = super.buildParams(t); |
438c31
|
70 |
params.append("-o "); |
a7f0a1
|
71 |
params.append(getParam(map, "o")); |
U |
72 |
params.append(" --threshold "); |
|
73 |
params.append(getParam(map, "th")); |
|
74 |
params.append(" --timeout "); |
|
75 |
params.append(getParam(map, "ti")); |
15ed25
|
76 |
String log = getParam(map, "log"); |
6ff352
|
77 |
if (log != null && log.equalsIgnoreCase("true")) { |
15ed25
|
78 |
params.append(" --genlog"); |
U |
79 |
} |
63b711
|
80 |
return params; |
8e2038
|
81 |
} |
b16b54
|
82 |
*/ |
U |
83 |
|
2dd7a5
|
84 |
@Override |
U |
85 |
protected String process(HttpExchange t, String params) { |
7a79ba
|
86 |
if (cmd.equalsIgnoreCase(BasePlayer.F_PLAY)) { |
2dd7a5
|
87 |
try { |
6ff352
|
88 |
//FileUtils.deleteDirectory(new File(System.getProperty("omx.wd"), "omx-logs")); |
U |
89 |
FileSystem fs = FileSystems.getDefault(); |
|
90 |
Path path = fs.getPath(System.getProperty("omx.wd"), "omx-logs"); |
82594d
|
91 |
if(path.toFile().exists()) { |
U |
92 |
deleteDirectory(path); |
|
93 |
} |
6ff352
|
94 |
//Files.delete(path); |
2dd7a5
|
95 |
} catch (IOException ex) { |
U |
96 |
logger.log(Level.SEVERE, null, ex); |
|
97 |
} |
|
98 |
} |
b16b54
|
99 |
Player player = App.getPlayer(); |
U |
100 |
String antwort = player.abspielen( |
|
101 |
player.getParam(map, "titel"), params, player.getParam(map, "r"), "1"); |
2dd7a5
|
102 |
logger.log(Level.FINE, antwort); |
U |
103 |
return antwort; |
|
104 |
} |
|
105 |
|
6ff352
|
106 |
protected void deleteDirectory(Path start) throws IOException { |
U |
107 |
Files.walkFileTree(start, new SimpleFileVisitor<Path>() { |
|
108 |
@Override |
|
109 |
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) |
|
110 |
throws IOException { |
|
111 |
Files.delete(file); |
|
112 |
return FileVisitResult.CONTINUE; |
|
113 |
} |
|
114 |
|
|
115 |
@Override |
|
116 |
public FileVisitResult postVisitDirectory(Path dir, IOException e) |
|
117 |
throws IOException { |
|
118 |
if (e == null) { |
|
119 |
Files.delete(dir); |
|
120 |
return FileVisitResult.CONTINUE; |
|
121 |
} else { |
|
122 |
// directory iteration failed |
|
123 |
throw e; |
|
124 |
} |
|
125 |
} |
|
126 |
}); |
|
127 |
} |
|
128 |
|
8e2038
|
129 |
} |