diff --git a/.gradle/2.2.1/taskArtifacts/cache.properties.lock b/.gradle/2.2.1/taskArtifacts/cache.properties.lock index f910b93..16d4105 100644 Binary files a/.gradle/2.2.1/taskArtifacts/cache.properties.lock and b/.gradle/2.2.1/taskArtifacts/cache.properties.lock differ diff --git a/.gradle/2.2.1/taskArtifacts/fileHashes.bin b/.gradle/2.2.1/taskArtifacts/fileHashes.bin index a4549f6..2788252 100644 Binary files a/.gradle/2.2.1/taskArtifacts/fileHashes.bin and b/.gradle/2.2.1/taskArtifacts/fileHashes.bin differ diff --git a/.gradle/2.2.1/taskArtifacts/fileSnapshots.bin b/.gradle/2.2.1/taskArtifacts/fileSnapshots.bin index 1a5157f..c87e757 100644 Binary files a/.gradle/2.2.1/taskArtifacts/fileSnapshots.bin and b/.gradle/2.2.1/taskArtifacts/fileSnapshots.bin differ diff --git a/.gradle/2.2.1/taskArtifacts/taskArtifacts.bin b/.gradle/2.2.1/taskArtifacts/taskArtifacts.bin index a9fd6fd..dae1754 100644 Binary files a/.gradle/2.2.1/taskArtifacts/taskArtifacts.bin and b/.gradle/2.2.1/taskArtifacts/taskArtifacts.bin differ diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 18e93cd..865a12b 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,8 +1,8 @@ 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."; } @@ -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) { @@ -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); @@ -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(); @@ -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 @@ -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(); + } + + public static HashMap getCBQualities(String channel, JSONObject status) { + HashMap mQualities = new HashMap(); + + 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 list = new ArrayList(); + 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); @@ -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); @@ -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; } @@ -563,7 +644,7 @@ public static HashMap 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;