commit | author | age
|
2dd7a5
|
1 |
package de.uhilger.avdirektor.handler; |
U |
2 |
|
|
3 |
import com.sun.net.httpserver.HttpExchange; |
|
4 |
import de.uhilger.avdirektor.App; |
|
5 |
import de.uhilger.avdirektor.OMXLogLeser; |
|
6 |
import java.io.File; |
|
7 |
import java.io.FileNotFoundException; |
|
8 |
import java.io.IOException; |
6ff352
|
9 |
import java.nio.file.FileSystem; |
U |
10 |
import java.nio.file.FileSystems; |
|
11 |
import java.nio.file.Files; |
|
12 |
import java.nio.file.Path; |
|
13 |
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; |
2dd7a5
|
14 |
import java.text.ParseException; |
U |
15 |
import java.text.SimpleDateFormat; |
|
16 |
import java.util.Date; |
|
17 |
import java.util.logging.Level; |
|
18 |
import java.util.logging.Logger; |
|
19 |
|
|
20 |
/** |
6ff352
|
21 |
* z.B. |
2dd7a5
|
22 |
* http://rpi4-az:9090/avd/playon?th=1&ti=240&o=local&log=true&titel=http://amd-srv:9090/srv/Filme/C/casino_royale.m4v |
6ff352
|
23 |
* |
2dd7a5
|
24 |
* @author ulrich |
U |
25 |
*/ |
|
26 |
public class PlayOnHandler extends PlayHandler { |
6ff352
|
27 |
|
U |
28 |
private static final Logger logger = Logger.getLogger(PlayOnHandler.class.getName()); |
2dd7a5
|
29 |
|
6ff352
|
30 |
public static final String LOG_DIR = "omx-logs"; |
U |
31 |
public static final String LOG_EXT = "log"; |
|
32 |
public static final String DASH = "-"; |
|
33 |
public static final String DOT = "."; |
|
34 |
|
|
35 |
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss"); |
2dd7a5
|
36 |
|
U |
37 |
public PlayOnHandler(String cmd) { |
|
38 |
super(cmd); |
|
39 |
} |
6ff352
|
40 |
|
2dd7a5
|
41 |
/* |
U |
42 |
1. buildParams |
|
43 |
2. process |
6ff352
|
44 |
*/ |
2dd7a5
|
45 |
@Override |
U |
46 |
protected StringBuilder buildParams(HttpExchange t) { |
6ff352
|
47 |
File logDir = logSichern(); |
2dd7a5
|
48 |
StringBuilder params = super.buildParams(t); |
U |
49 |
params.append(" --pos "); |
|
50 |
try { |
6ff352
|
51 |
params.append(dauerBestimmen(logDir)); |
U |
52 |
} catch (IOException | ParseException ex) { |
|
53 |
logger.log(Level.SEVERE, null, ex); |
2dd7a5
|
54 |
} |
U |
55 |
return params; |
6ff352
|
56 |
} |
U |
57 |
|
|
58 |
private File logSichern() { |
|
59 |
String wd = System.getProperty(App.OMX_WD); |
|
60 |
File zielOrdner = new File(wd, LOG_DIR); |
|
61 |
try { |
|
62 |
// omxplayer.log umbenennen |
|
63 |
FileSystem fs = FileSystems.getDefault(); |
|
64 |
Path logDatei = fs.getPath(wd, OMXPlayer.NAME + DOT + LOG_EXT); |
|
65 |
Date now = new Date(); |
|
66 |
String neuerName = OMXPlayer.NAME + DASH + sdf.format(now) + DOT + LOG_EXT; |
|
67 |
Files.move(logDatei, logDatei.resolveSibling(neuerName)); |
2dd7a5
|
68 |
|
6ff352
|
69 |
// Unterverzeichnis ggf. erzeugen |
U |
70 |
zielOrdner.mkdirs(); |
|
71 |
|
|
72 |
// omxplayer-datum.log verschieben |
|
73 |
Path quellDatei = fs.getPath(wd, neuerName); |
|
74 |
Path zielPfad = fs.getPath(wd, LOG_DIR); |
|
75 |
Files.move(quellDatei, zielPfad.resolve(quellDatei.getFileName()), REPLACE_EXISTING); |
|
76 |
} catch (IOException ex) { |
|
77 |
logger.log(Level.SEVERE, null, ex); |
|
78 |
} |
|
79 |
return zielOrdner; |
|
80 |
} |
|
81 |
|
|
82 |
private String dauerBestimmen(File logDir) throws IOException, FileNotFoundException, ParseException { |
2dd7a5
|
83 |
OMXLogLeser leser = new OMXLogLeser(); |
U |
84 |
return leser.logDirLesen(logDir); |
|
85 |
} |
6ff352
|
86 |
|
2dd7a5
|
87 |
} |