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 |
*/ |
8e2038
|
18 |
package de.uhilger.avdirektor.handler; |
U |
19 |
|
|
20 |
import com.sun.net.httpserver.HttpExchange; |
cfe367
|
21 |
import de.uhilger.avdirektor.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 |
|
|
58 |
protected StringBuilder buildParams(HttpExchange t) { |
|
59 |
StringBuilder params = super.buildParams(t); |
438c31
|
60 |
params.append("-o "); |
a7f0a1
|
61 |
params.append(getParam(map, "o")); |
U |
62 |
params.append(" --threshold "); |
|
63 |
params.append(getParam(map, "th")); |
|
64 |
params.append(" --timeout "); |
|
65 |
params.append(getParam(map, "ti")); |
15ed25
|
66 |
String log = getParam(map, "log"); |
6ff352
|
67 |
if (log != null && log.equalsIgnoreCase("true")) { |
15ed25
|
68 |
params.append(" --genlog"); |
U |
69 |
} |
63b711
|
70 |
return params; |
8e2038
|
71 |
} |
6ff352
|
72 |
|
2dd7a5
|
73 |
@Override |
U |
74 |
protected String process(HttpExchange t, String params) { |
6ff352
|
75 |
if (cmd.equalsIgnoreCase(OMXPlayer.F_PLAY)) { |
2dd7a5
|
76 |
try { |
6ff352
|
77 |
//FileUtils.deleteDirectory(new File(System.getProperty("omx.wd"), "omx-logs")); |
U |
78 |
FileSystem fs = FileSystems.getDefault(); |
|
79 |
Path path = fs.getPath(System.getProperty("omx.wd"), "omx-logs"); |
|
80 |
deleteDirectory(path); |
|
81 |
//Files.delete(path); |
2dd7a5
|
82 |
} catch (IOException ex) { |
U |
83 |
logger.log(Level.SEVERE, null, ex); |
|
84 |
} |
|
85 |
} |
6ff352
|
86 |
String antwort = App.getPlayer().abspielen( |
U |
87 |
getParam(map, "titel"), params, getParam(map, "r"), "1"); |
2dd7a5
|
88 |
logger.log(Level.FINE, antwort); |
U |
89 |
return antwort; |
|
90 |
} |
|
91 |
|
6ff352
|
92 |
protected void deleteDirectory(Path start) throws IOException { |
U |
93 |
Files.walkFileTree(start, new SimpleFileVisitor<Path>() { |
|
94 |
@Override |
|
95 |
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) |
|
96 |
throws IOException { |
|
97 |
Files.delete(file); |
|
98 |
return FileVisitResult.CONTINUE; |
|
99 |
} |
|
100 |
|
|
101 |
@Override |
|
102 |
public FileVisitResult postVisitDirectory(Path dir, IOException e) |
|
103 |
throws IOException { |
|
104 |
if (e == null) { |
|
105 |
Files.delete(dir); |
|
106 |
return FileVisitResult.CONTINUE; |
|
107 |
} else { |
|
108 |
// directory iteration failed |
|
109 |
throw e; |
|
110 |
} |
|
111 |
} |
|
112 |
}); |
|
113 |
} |
|
114 |
|
8e2038
|
115 |
} |