Skip to content

Commit

Permalink
CB.com support
Browse files Browse the repository at this point in the history
  • Loading branch information
hayksaakian committed Feb 26, 2015
1 parent 165ca35 commit db22975
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 27 deletions.
Binary file modified .gradle/2.2.1/taskArtifacts/cache.properties.lock
Binary file not shown.
Binary file modified .gradle/2.2.1/taskArtifacts/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/2.2.1/taskArtifacts/fileSnapshots.bin
Binary file not shown.
Binary file modified .gradle/2.2.1/taskArtifacts/taskArtifacts.bin
Binary file not shown.
4 changes: 2 additions & 2 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version='1.0' encoding='utf-8'?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="550"
android:versionName="5.50"
android:versionCode="560"
android:versionName="5.60"
package="gg.destiny.app">

<uses-sdk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public final class BuildConfig {
public static final String APPLICATION_ID = "gg.destiny.app";
public static final String BUILD_TYPE = "debug";
public static final String FLAVOR = "";
public static final int VERSION_CODE = 540;
public static final int VERSION_CODE = 550;
public static final String VERSION_NAME = "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public final class BuildConfig {
public static final String APPLICATION_ID = "gg.destiny.app";
public static final String BUILD_TYPE = "release";
public static final String FLAVOR = "";
public static final int VERSION_CODE = 540;
public static final int VERSION_CODE = 560;
public static final String VERSION_NAME = "";
}
Binary file modified overrustle-app-release.apk
Binary file not shown.
127 changes: 104 additions & 23 deletions src/gg/destiny/app/Business.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,23 @@ protected String checkStream(String url_or_channel_name) {
// 2) check hitbox unless twitch was good
jsno = getHitboxStatus(url_or_channel_name);
// because hitbox is bad and does not actually 404 from bad channel names
if(jsno.length() > 0) {
String liveStatus = jsno.getString("media_is_live");
isLive = "1".equals(liveStatus);
if (isLive) {
return jsno.getString("media_status");
}
isLive = jsno.length() > 0 && "1".equals(jsno.getString("media_is_live"));
if(isLive) {
return jsno.getString("media_status");
}
// 3) check azubu
jsno = getAzubuStatus(url_or_channel_name);
isLive = false;
if (jsno.length() > 0){
isLive = true;
isLive = jsno.length() > 0;
if (isLive){
return jsno.getString("title");
}
// 4) check cb
jsno = getCBStatus(url_or_channel_name);
isLive = (jsno.length() > 0) && !(jsno.get("total_viewers") instanceof Integer) && (Integer.parseInt(jsno.getString("total_viewers")) > 0);
if(isLive){
return channelname + " NSFW for " + jsno.getString("total_viewers") + " viewers";
}

return channelname + " is offline. Type another channel\'s name below to watch something else.";
}

Expand Down Expand Up @@ -212,6 +215,7 @@ protected HashMap doInBackground(String... channels) {
//String retval = "";
channel = channels[0];
//String url = "";
// TODO: instead of checking every platform, use a dict and only check the relevant platorm
if (channel.equals("gameongg")) {
newQualities = parseQualitiesFromURL(GAMEONGG_QUALITIES_URL);
if (newQualities.size() > 0) {
Expand Down Expand Up @@ -261,6 +265,19 @@ protected HashMap doInBackground(String... channels) {

// check azubu if hitbox doesn't have anything
newQualities = getAzubuQualities(channel);

if(newQualities.size() > 0){
return newQualities;
}

// check cb if azubu doesn't have anything
newQualities = getCBQualities(channel);

if(newQualities.size() > 0){
Log.d("testing", "found some for CB");
return newQualities;
}

}

//String readURL = HttpGet(url);
Expand Down Expand Up @@ -290,7 +307,7 @@ protected void onPostExecute(HashMap foundQualities) {

}

public static String HttpGet(String url){
public static Response RawHttpGet(String url){
Log.d("GET ing with OkHTTP", url);

final OkHttpClient client = new OkHttpClient();
Expand All @@ -300,16 +317,28 @@ public static String HttpGet(String url){
.build();

Response response = client.newCall(request).execute();
if(response.isSuccessful()) {
return response.body().string();
}else{
Log.e(Business.class.toString(), "Failed to download file");
}

return response;
}catch(IOException e){
e.printStackTrace();
}
return null;
}

public static String HttpGet(String url){
Response r = RawHttpGet(url);
if(r == null){
return "";
}
if(r.isSuccessful()) {
try {
return r.body().string();
} catch (IOException e) {
e.printStackTrace();
}
}
Log.e(Business.class.toString(), "Failed to download file");
return "";

}

// TODO: Deprecate
Expand Down Expand Up @@ -364,6 +393,53 @@ public static HashMap getTwitchQualities(String channel, String auth) {
}
return mQualities;
}


public static HashMap getCBQualities(String channel) {
try {
JSONObject jsno = getCBStatus(channel);
if ((jsno.length() > 0) && !(jsno.get("total_viewers") instanceof Integer) && (Integer.parseInt(jsno.getString("total_viewers")) > 0)) {
return getCBQualities(channel, jsno);
}
} catch (JSONException e) {
e.printStackTrace();
}
return new HashMap<String, String>();
}

public static HashMap getCBQualities(String channel, JSONObject status) {
HashMap mQualities = new HashMap<String, String>();

String rawhtml = HttpGet("https://www.chaturbate.com/"+channel);

Pattern pattern = Pattern.compile("http.*playlist.m3u8", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(rawhtml);
if(matcher.find()){
Log.d("found matches", "some matches");
}else{
Log.d("found matches", "no/0 matches");
return mQualities;
}

String qualitiesURL = matcher.group(0);

// their qualities are not prefixed by a proper url
mQualities = parseQualitiesFromURL(qualitiesURL, "chunklist");

List<String> list = new ArrayList<String>();
list.addAll(mQualities.keySet());

String urlprefix = qualitiesURL.replace("playlist.m3u8", "");

for (int i = 0; i < list.size(); i++) {
String mq = list.get(i);
String mqpath = (String)mQualities.get(mq);
mQualities.put(mq, urlprefix + mqpath);
}

return mQualities;
}

public static HashMap getAzubuQualities(String channel) {
try {
JSONObject status = getAzubuStatus(channel);
Expand Down Expand Up @@ -425,6 +501,15 @@ public static HashMap getAzubuQualities(String channel, JSONObject status) {
return mQualities;
}

public static JSONObject getCBStatus(String channel) throws JSONException{
String hburl = String.format("https://chaturbate.com/contest/log_presence/%s", channel);
String hbretval = HttpGet(hburl);
if(hbretval.length() == 0){
return new JSONObject();
}
return new JSONObject(hbretval);
}

public static JSONObject getAzubuStatus(String channel) throws JSONException{
String hburl = String.format("http://www.azubu.tv/api/video/active-stream/%s", channel);
String hbretval = HttpGet(hburl);
Expand Down Expand Up @@ -452,12 +537,8 @@ public static JSONObject getHitboxStatus(String channel) throws JSONException{
public static JSONObject getTwitchStatus(String channel) throws JSONException {
JSONObject channelStatus = new JSONObject();
//maybe put this in another task...
String strStatus = "";
try {
strStatus = HttpGet("https://api.twitch.tv/kraken/streams/" + channel);
} catch (Exception e) {
e.printStackTrace();
}
String strStatus = HttpGet("https://api.twitch.tv/kraken/streams/" + channel);

if(strStatus.length() == 0){
return channelStatus;
}
Expand Down Expand Up @@ -563,7 +644,7 @@ public static HashMap<String, String> parseQualitiesFromURL(String url, String u
e.printStackTrace();
}
if(mQualities.size() == 0){
Log.d("Qualities", "Could not parse any qualities from the following respons:");
Log.d("Qualities", "Could not parse any qualities from the following response:");
Log.d("Qualities", qualityOptions);
}
return mQualities;
Expand Down

0 comments on commit db22975

Please sign in to comment.