initial commit

This commit is contained in:
da
2015-11-06 18:15:26 +01:00
commit 64515bdeb7
8 changed files with 181 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
package com.ixab.ConfigHandling;
import java.io.Serializable;
import java.util.ArrayList;
public class Config implements Serializable {
private String LSPath;
private ArrayList<String> streamNames;
public Config() {
this.streamNames = new ArrayList<String>();
}
public void setLSPath(String path) {
this.LSPath = path;
}
public String getLSPath() {
return this.LSPath;
}
public String getStreamName(int streamIndex) {
return this.streamNames.get(streamIndex-1);
}
public void addStream(String streamName) {
this.streamNames.add(streamName);
}
public ArrayList<String> getStreams() {
return this.streamNames;
}
public int getStreamCount() {
return this.streamNames.size();
}
}
@@ -0,0 +1,48 @@
package com.ixab.ConfigHandling;
import java.io.*;
public class ConfigFileHandler {
public static Config load(String path) {
Config c = null;
try
{
FileInputStream fileIn = new FileInputStream(path);
ObjectInputStream in = new ObjectInputStream(fileIn);
c = (Config) in.readObject();
in.close();
fileIn.close();
}catch(IOException i)
{
i.printStackTrace();
return null;
}catch(ClassNotFoundException e)
{
System.out.println("Config class not found");
e.printStackTrace();
return null;
}
return c;
}
public static void save(Config c, String path) {
try
{
FileOutputStream fileOut =
new FileOutputStream("config.dat");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(c);
out.close();
fileOut.close();
System.out.printf("Config data is saved in config.dat");
}catch(IOException i)
{
i.printStackTrace();
}
}
public static Config load() {
return load("config.dat");
}
public static void save(Config c) {
save(c, "config.dat");
}
}
+13
View File
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.ixab.GUI.ConfigMenu">
<grid id="27dc6" row-count="1" column-count="1" layout-manager="GridLayoutManager">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
</form>
+4
View File
@@ -0,0 +1,4 @@
package com.ixab.GUI;
public class ConfigMenu {
}
+13
View File
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.ixab.GUI.StreamChooserMenu">
<grid id="27dc6" row-count="1" column-count="1" layout-manager="GridLayoutManager">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
</form>
+4
View File
@@ -0,0 +1,4 @@
package com.ixab.GUI;
public class StreamChooserMenu {
}
+28
View File
@@ -0,0 +1,28 @@
package com.ixab;
import com.ixab.ConfigHandling.Config;
import com.ixab.ConfigHandling.ConfigFileHandler;
import com.ixab.StreamHandling.StreamOpener;
public class Main {
private static boolean running = true;
public static void exitProgram() {
running = false;
}
public static void main(String[] args) {
while (running) {
// TODO: config dialog
// TODO: stream choosing
}
// begin test
//Config c = new Config();
Config c = ConfigFileHandler.load();
//c.addStream("cohhcarnage");
//c.setLSPath("e:\\downloads\\livestreamer-v1.11.1\\livestreamer.exe");
//ConfigFileHandler.save(c);
StreamOpener so = new StreamOpener(c, 1, "best");
so.start();
// end test
}
}
@@ -0,0 +1,39 @@
package com.ixab.StreamHandling;
import com.ixab.ConfigHandling.Config;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class StreamOpener extends Thread {
private Config c;
private int streamIndex;
private String quality;
public StreamOpener(Config c, int streamIndex, String quality) {
this.c = c;
this.streamIndex = streamIndex;
this.quality = quality;
}
public void run() {
try {
Runtime rt = Runtime.getRuntime();
//Process pr = rt.exec("cmd /c dir");
Process pr = rt.exec(c.getLSPath()+" twitch.tv/"+c.getStreamName(streamIndex)+" "+quality);
BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line=null;
while((line=input.readLine()) != null) {
System.out.println(line);
}
int exitVal = pr.waitFor();
System.out.println("Exited with error code " + exitVal);
} catch(Exception e) {
System.out.println(e.toString());
e.printStackTrace();
}
}
}