package de.uhilger.avdirektor.handler; import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; import de.uhilger.avdirektor.App; import de.uhilger.avdirektor.OMXLogLeser; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.logging.Level; import java.util.logging.Logger; import org.apache.commons.io.FileUtils; /** * z.B. * 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 * @author ulrich */ public class PlayOnHandler extends PlayHandler { private static final Logger logger = Logger.getLogger(PlayOnHandler.class.getName()); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd-hh-MM-ss"); public PlayOnHandler(String cmd) { super(cmd); } /* 1. buildParams 2. process */ @Override protected StringBuilder buildParams(HttpExchange t) { String wd = System.getProperty("omx.wd"); File targetDir = new File(wd, "omx-logs"); try { File logFile = new File(wd, "omxplayer.log"); Date date = new Date(logFile.lastModified()); File srcFile = new File(wd, "omxplayer-" + sdf.format(date) + ".log"); logFile.renameTo(srcFile); targetDir.mkdirs(); FileUtils.moveFileToDirectory(srcFile, targetDir, false); } catch (IOException ex) { Logger.getLogger(PlayOnHandler.class.getName()).log(Level.SEVERE, null, ex); } StringBuilder params = super.buildParams(t); params.append(" --pos "); try { // hier das Ergebnis der Log-Auswertung angeben params.append(logsLesen(targetDir)); } catch (IOException ex) { Logger.getLogger(PlayOnHandler.class.getName()).log(Level.SEVERE, null, ex); } catch (ParseException ex) { Logger.getLogger(PlayOnHandler.class.getName()).log(Level.SEVERE, null, ex); } return params; } private String logsLesen(File logDir) throws IOException, FileNotFoundException, ParseException { OMXLogLeser leser = new OMXLogLeser(); return leser.logDirLesen(logDir); } }