MasterPuppeteer

Updates broken fetches.

......@@ -236,12 +236,12 @@ public class CometTVPuppet implements InstallablePuppet {
@Override
boolean isUnavailableIn(String region) {
return false
return region != 'us'
}
@Override
String getPreferredRegion() {
return null
return 'us'
}
@Override
......
......@@ -77,7 +77,18 @@ public class PBSKidsPuppet implements InstallablePuppet {
description += " (Ages " + item.getString("age_range") + ")"
}
String url = "http://pbskids.org/pbsk/video/api/getVideos/?startindex=1&endindex=200&category=&group=&selectedID=&status=available&player=flash&flash=true&program=" + name.replace(" ","%20").replace("&", "%26")
String image = item.getJSONObject("images").getJSONObject("program-kids-square").getString("url")
String image = null
try {
image = item.getJSONObject("images").getJSONObject("program-kids-square").getString("url")
} catch (Exception ex) {
try {
image = item.getJSONObject("images").getJSONObject("originalres_4x3").getString("url")
} catch (Exception exx) {
try {
image = item.getJSONObject("images").getJSONObject("kids-mezzannine-4x3").getString("url")
} catch (ignore) { }
}
}
children.add(new PBSKidsPuppet(this, url, name, description, false, image))
}
} else if (mUrl.contains("/api/getVideos") && !mUrl.contains("&type=")) {
......
......@@ -46,11 +46,11 @@ public class PBSThinkTVPuppet implements InstallablePuppet {
public PBSThinkTVPuppet() {
this(
null,
"http://www.pbs.org/shows-page/0/?genre=&title=&callsign=",
"http://www.pbs.org/shows-page/0/?genre=&title=&callsign=&alphabetically=false",
"PBS Think TV",
"Your favorite PBS shows.",
"https://superrepo.org/static/images/icons/original/xplugin.video.thinktv.png.pagespeed.ic.SmysxYmAM7.jpg",
"https://superrepo.org/static/images/fanart/original/plugin.video.thinktv.jpg"
"https://images-na.ssl-images-amazon.com/images/I/51GpY5aDb8L.png",
"http://bento.cdn.pbs.org/hostedbento-prod/blog/20151102_211520_484137_pbs_bemore_bub_blu.png"
)
}
......@@ -67,7 +67,9 @@ public class PBSThinkTVPuppet implements InstallablePuppet {
PuppetIterator getChildren() {
PuppetIterator children = new PBSThinkTVPuppetIterator()
JSONArray json = new JSONObject(new URL(mUrl).getText()).getJSONObject("results").getJSONArray("content")
JSONArray json = new JSONObject(new URL(mUrl).getText(requestProperties: [
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36',
])).getJSONObject("results").getJSONArray("content")
for (int i = 0; i < json.length(); i++) {
JSONObject item = json.getJSONObject(i)
......@@ -214,9 +216,9 @@ public class PBSThinkTVPuppet implements InstallablePuppet {
public PBSThinkTVCategoryPuppet(ParentPuppet parent, JSONObject item) {
mParent = parent
mId = item.getString("id")
mId = item.getString("url")
mName = item.getString("title")
mDescription = item.getString("description")
mDescription = item.has("description") && !item.isNull("description") ? item.getString("description") : null
mImageUrl = item.isNull("image") ? parent.getImageUrl() : item.getString("image")
}
......@@ -233,18 +235,20 @@ public class PBSThinkTVPuppet implements InstallablePuppet {
PuppetIterator getChildren() {
PuppetIterator children = new PBSThinkTVPuppetIterator()
if (mPage == 0) {
["episodes", "previews", "clips"].each { videoType ->
["episodes", "extras"].each { videoType ->
children.add(new PBSThinkTVCategoryPuppet(this, mId, videoType.capitalize(), mImageUrl, videoType, mPage + 1))
}
} else {
String url = "http://www.pbs.org/show/" + mId + "/$mVideoType/?page=$mPage"
if (!Jsoup.connect(url).followRedirects(false).execute().hasHeader("location")) {
Document document = Jsoup.connect(url).ignoreContentType(true).get()
String url = "http://www.pbs.org" + mId + mVideoType
Document document = Jsoup.connect(url)
.userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")
.ignoreContentType(true)
.get()
int numItems = 0
document.select(".video-summary").each { node ->
String id = node.select("a").first().attr("href").replace("/video/", "").replace("/", "")
String id = node.select(".btn--watchlist").attr("data-id")
String name = node.select(".video-summary__title").first().text()
String duration = node.select(".video-summary__duration").first().text()
String duration = ""
def images = node.select(".video-summary__image").attr("data-srcset").split()
String imageUrl = images[0]
String backgroundImageUrl = images[images.length - 2]
......@@ -255,7 +259,6 @@ public class PBSThinkTVPuppet implements InstallablePuppet {
children.add(new PBSThinkTVCategoryPuppet(this, mId, mVideoType.capitalize() + " page " + (mPage + 1), mImageUrl, mVideoType, mPage + 1))
}
}
}
return children
}
......