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 |
|
|
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"); |
82594d
|
80 |
if(path.toFile().exists()) { |
U |
81 |
deleteDirectory(path); |
|
82 |
} |
6ff352
|
83 |
//Files.delete(path); |
2dd7a5
|
84 |
} catch (IOException ex) { |
U |
85 |
logger.log(Level.SEVERE, null, ex); |
|
86 |
} |
|
87 |
} |
6ff352
|
88 |
String antwort = App.getPlayer().abspielen( |
U |
89 |
getParam(map, "titel"), params, getParam(map, "r"), "1"); |
2dd7a5
|
90 |
logger.log(Level.FINE, antwort); |
U |
91 |
return antwort; |
|
92 |
} |
|
93 |
|
6ff352
|
94 |
protected void deleteDirectory(Path start) throws IOException { |
U |
95 |
Files.walkFileTree(start, new SimpleFileVisitor<Path>() { |
|
96 |
@Override |
|
97 |
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) |
|
98 |
throws IOException { |
|
99 |
Files.delete(file); |
|
100 |
return FileVisitResult.CONTINUE; |
|
101 |
} |
|
102 |
|
|
103 |
@Override |
|
104 |
public FileVisitResult postVisitDirectory(Path dir, IOException e) |
|
105 |
throws IOException { |
|
106 |
if (e == null) { |
|
107 |
Files.delete(dir); |
|
108 |
return FileVisitResult.CONTINUE; |
|
109 |
} else { |
|
110 |
// directory iteration failed |
|
111 |
throw e; |
|
112 |
} |
|
113 |
} |
|
114 |
}); |
|
115 |
} |
|
116 |
|
8e2038
|
117 |
} |