43 lines
720 B
Java
43 lines
720 B
Java
package eu.univento.core.api.twitch;
|
|
|
|
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.JsonArray;
|
|
import com.google.gson.JsonObject;
|
|
|
|
|
|
public class Twitch_API {
|
|
public static Gson gson = new Gson();
|
|
|
|
|
|
|
|
|
|
public static Twitch_Stream getStream(String channelname){
|
|
try{
|
|
String json = API.readJsonFromUrl("http://api.justin.tv/api/stream/list.json?channel="+channelname);
|
|
|
|
|
|
Twitch_Stream stream = new Twitch_Stream();
|
|
if(json.equalsIgnoreCase("[]")){
|
|
stream.setOnline(false);
|
|
return stream;
|
|
}
|
|
JsonArray jb = gson.fromJson(json, JsonArray.class);
|
|
JsonObject jo = (JsonObject) jb.get(0);
|
|
stream.setOnline(true);
|
|
stream.load(jo);
|
|
return stream;
|
|
} catch (Exception error){
|
|
error.printStackTrace();
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
}
|
|
} |