MasterPuppeteer

Updates to the new API.

......@@ -25,24 +25,25 @@ import org.json.JSONArray
import org.json.JSONObject
import org.jsoup.Jsoup
import org.jsoup.nodes.Document
import tv.puppetmaster.data.BasePuppetIterator
import tv.puppetmaster.data.i.*
import tv.puppetmaster.data.i.Puppet.PuppetIterator
import tv.puppetmaster.data.i.SourcesPuppet.SourceDescription
import java.util.regex.Matcher
public class SproutOnlinePuppet implements InstallablePuppet {
class SproutOnlinePuppet implements InstallablePuppet {
static final int VERSION_CODE = 5
def ParentPuppet mParent
def String mUrl
def String mName
def String mDescription
def boolean mIsTopLevel
def String mImageUrl
ParentPuppet mParent
String mUrl
String mName
String mDescription
boolean mIsTopLevel
String mImageUrl
public SproutOnlinePuppet() {
SproutOnlinePuppet() {
this(
null,
"http://www.sproutonline.com/watch",
......@@ -53,7 +54,7 @@ public class SproutOnlinePuppet implements InstallablePuppet {
)
}
public SproutOnlinePuppet(ParentPuppet parent, String url, String name, String description, boolean isTopLevel, String imageUrl) {
SproutOnlinePuppet(ParentPuppet parent, String url, String name, String description, boolean isTopLevel, String imageUrl) {
mParent = parent
mUrl = url
mName = name
......@@ -64,7 +65,7 @@ public class SproutOnlinePuppet implements InstallablePuppet {
@Override
PuppetIterator getChildren() {
PuppetIterator children = new SproutOnlinePuppetIterator()
PuppetIterator children = new BasePuppetIterator()
Document document = Jsoup.connect(mUrl).ignoreContentType(true).get()
......@@ -183,7 +184,7 @@ public class SproutOnlinePuppet implements InstallablePuppet {
}
@Override
public String toString() {
String toString() {
return mParent == null ? getName() : mParent.toString() + " < " + getName()
}
......@@ -192,43 +193,17 @@ public class SproutOnlinePuppet implements InstallablePuppet {
return VERSION_CODE
}
def class SproutOnlinePuppetIterator extends PuppetIterator {
static class SproutOnlineSourcesPuppet implements SourcesPuppet {
def ArrayList<Puppet> mPuppets = new ArrayList<>()
def int currentIndex = 0
ParentPuppet mParent
String mUrl
String mName
String mShortDescription
String mImageUrl
@Override
boolean hasNext() {
return currentIndex < mPuppets.size()
}
@Override
void add(Puppet puppet) {
mPuppets.add(puppet)
}
List<SourcesPuppet.SubtitleDescription> mSubtitles = new ArrayList<SourcesPuppet.SubtitleDescription>()
@Override
Puppet next() {
return mPuppets.get(currentIndex++)
}
@Override
void remove() {
}
}
def static class SproutOnlineSourcesPuppet implements SourcesPuppet {
def ParentPuppet mParent
def String mUrl
def String mName
def String mShortDescription
def String mImageUrl
def List<SourcesPuppet.SubtitleDescription> mSubtitles = new ArrayList<SourcesPuppet.SubtitleDescription>()
public SproutOnlineSourcesPuppet(parent, url, name, shortDescription, imageUrl) {
SproutOnlineSourcesPuppet(parent, url, name, shortDescription, imageUrl) {
mParent = parent
mUrl = url
mName = name
......@@ -288,12 +263,12 @@ public class SproutOnlinePuppet implements InstallablePuppet {
@Override
boolean isUnavailableIn(String region) {
return false
return region != 'us'
}
@Override
String getPreferredRegion() {
return null
return 'us'
}
@Override
......@@ -312,14 +287,14 @@ public class SproutOnlinePuppet implements InstallablePuppet {
}
@Override
public String toString() {
String toString() {
return mParent == null ? getName() : mParent.toString() + " < " + getName()
}
def class SproutOnlineSourceIterator implements SourcesPuppet.SourceIterator {
class SproutOnlineSourceIterator implements SourcesPuppet.SourceIterator {
def List<SourceDescription> mSources = null
def int currentIndex = 0
List<SourceDescription> mSources = null
int currentIndex = 0
@Override
boolean hasNext() {
......@@ -327,24 +302,20 @@ public class SproutOnlinePuppet implements InstallablePuppet {
mSources = new ArrayList<SourceDescription>()
String html = new URL(SproutOnlineSourcesPuppet.this.mUrl).getText().replaceAll("\n", "")
Matcher matcher = html =~ /"video": "(.+?)"/
String html = new URL(mUrl).getText().replaceAll("\n", "")
Matcher matcher = html =~ /"(https:\/\/player.theplatform.com\/p\/.+?)"/
String url = null
if (matcher.find()) {
url = matcher.group(1)
} else {
matcher = html =~ /http:\/\/player.theplatform.com\/(.+?)"/
html = new URL(url).getText().replaceAll("\n", "")
matcher = html =~ /tp:releaseUrl="(.+?)"/
if (matcher.find()) {
url = matcher.group(1)
html = new URL("http://player.theplatform.com/" + url).getText().replaceAll("\n", "")
matcher = html =~ /tp:releaseUrl="(.+?)"/
if (matcher.find()) {
url = matcher.group(1)
if (url.contains("?")) {
url = url.split("\\?")[0]
}
if (url.contains("?")) {
url = url.split("\\?")[0]
}
}
}
......@@ -387,7 +358,6 @@ public class SproutOnlinePuppet implements InstallablePuppet {
@Override
void remove() {
}
}
}
......