MasterPuppeteer

Fix for API change

...@@ -23,6 +23,7 @@ package tv.puppetmaster.usa ...@@ -23,6 +23,7 @@ package tv.puppetmaster.usa
23 23
24 import org.json.JSONArray 24 import org.json.JSONArray
25 import org.json.JSONObject 25 import org.json.JSONObject
26 +import org.jsoup.Jsoup
26 import tv.puppetmaster.data.i.* 27 import tv.puppetmaster.data.i.*
27 import tv.puppetmaster.data.i.Puppet.PuppetIterator 28 import tv.puppetmaster.data.i.Puppet.PuppetIterator
28 import tv.puppetmaster.data.i.SourcesPuppet.SourceDescription 29 import tv.puppetmaster.data.i.SourcesPuppet.SourceDescription
...@@ -224,7 +225,7 @@ public class RedBullTVPuppet implements InstallablePuppet { ...@@ -224,7 +225,7 @@ public class RedBullTVPuppet implements InstallablePuppet {
224 JSONObject json = new JSONObject(page) 225 JSONObject json = new JSONObject(page)
225 226
226 if (mUrl == "https://api.redbull.tv/v1/") { 227 if (mUrl == "https://api.redbull.tv/v1/") {
227 - RedBullTVIterator videos = new RedBullTVIterator(mParent, json.get("videos").toString()) 228 + RedBullTVIterator videos = new RedBullTVIterator(mParent, json.get("videos").toString() + "/clips")
228 while (videos.hasNext()) { 229 while (videos.hasNext()) {
229 Puppet p = videos.next() 230 Puppet p = videos.next()
230 sourcesItems.put(new JSONArray()) 231 sourcesItems.put(new JSONArray())
...@@ -292,7 +293,7 @@ public class RedBullTVPuppet implements InstallablePuppet { ...@@ -292,7 +293,7 @@ public class RedBullTVPuppet implements InstallablePuppet {
292 sourcesItems.put(new JSONArray()) // Dummy, TODO: make this more efficient by excluding sourcesItems/categoryItems with count 293 sourcesItems.put(new JSONArray()) // Dummy, TODO: make this more efficient by excluding sourcesItems/categoryItems with count
293 mPuppets.add(item) 294 mPuppets.add(item)
294 } 295 }
295 - ["episodes", "clips", "films", "event_streams", "events", "usa", "featured_shows"].each { videoType -> 296 + ["episodes", "clips", "films", "event_streams", "events"/*, "usa"*/, "featured_shows"].each { videoType ->
296 mPuppets.add(new RedBullTVPuppet( 297 mPuppets.add(new RedBullTVPuppet(
297 mParent, 298 mParent,
298 videoType.replace("_", " ").capitalize(), 299 videoType.replace("_", " ").capitalize(),
...@@ -353,11 +354,29 @@ public class RedBullTVPuppet implements InstallablePuppet { ...@@ -353,11 +354,29 @@ public class RedBullTVPuppet implements InstallablePuppet {
353 if (item.has("duration")) { 354 if (item.has("duration")) {
354 mDuration = convertDuration(item.get("duration").toString()) 355 mDuration = convertDuration(item.get("duration").toString())
355 } 356 }
356 - mImageUrl = ((JSONObject) ((JSONObject) item.get("images")).get("landscape")).get("uri").toString() 357 + try {
358 + mImageUrl = ((JSONObject) ((JSONObject) item.get("images")).get("landscape")).get("uri").toString()
359 + } catch (ex) {
360 + try {
361 + mImageUrl = ((JSONObject) ((JSONObject) item.get("images")).get("background")).get("uri").toString()
362 + } catch (ignored) {}
363 + }
364 + if (mImageUrl == null) {
365 + mImageUrl = mParent.getImageUrl()
366 + } else if (mImageUrl.count("http") > 1) {
367 + mImageUrl = Jsoup.parse(mImageUrl.substring(mImageUrl.indexOf("http", 1)))
368 + }
357 try { 369 try {
358 mBackgroundImageUrl = ((JSONObject) ((JSONObject) item.get("images")).get("background")).get("uri").toString() 370 mBackgroundImageUrl = ((JSONObject) ((JSONObject) item.get("images")).get("background")).get("uri").toString()
359 - } catch (ignored) { 371 + } catch (ex) {
360 - mBackgroundImageUrl = ((JSONObject) ((JSONObject) item.get("images")).get("landscape")).get("uri").toString() 372 + try {
373 + mBackgroundImageUrl = ((JSONObject) ((JSONObject) item.get("images")).get("landscape")).get("uri").toString()
374 + } catch (ignored) {}
375 + }
376 + if (mBackgroundImageUrl == null) {
377 + mBackgroundImageUrl = mParent.getBackgroundImageUrl()
378 + } else if (mBackgroundImageUrl.count("http") > 1) {
379 + mBackgroundImageUrl = Jsoup.parse(mBackgroundImageUrl.substring(mBackgroundImageUrl.indexOf("http", 1)))
361 } 380 }
362 381
363 if (item.has("closed_captions")) { 382 if (item.has("closed_captions")) {
......