MasterPuppeteer

Updates to the new API.

...@@ -25,24 +25,25 @@ import org.json.JSONArray ...@@ -25,24 +25,25 @@ import org.json.JSONArray
25 import org.json.JSONObject 25 import org.json.JSONObject
26 import org.jsoup.Jsoup 26 import org.jsoup.Jsoup
27 import org.jsoup.nodes.Document 27 import org.jsoup.nodes.Document
28 +import tv.puppetmaster.data.BasePuppetIterator
28 import tv.puppetmaster.data.i.* 29 import tv.puppetmaster.data.i.*
29 import tv.puppetmaster.data.i.Puppet.PuppetIterator 30 import tv.puppetmaster.data.i.Puppet.PuppetIterator
30 import tv.puppetmaster.data.i.SourcesPuppet.SourceDescription 31 import tv.puppetmaster.data.i.SourcesPuppet.SourceDescription
31 32
32 import java.util.regex.Matcher 33 import java.util.regex.Matcher
33 34
34 -public class SproutOnlinePuppet implements InstallablePuppet { 35 +class SproutOnlinePuppet implements InstallablePuppet {
35 36
36 static final int VERSION_CODE = 5 37 static final int VERSION_CODE = 5
37 38
38 - def ParentPuppet mParent 39 + ParentPuppet mParent
39 - def String mUrl 40 + String mUrl
40 - def String mName 41 + String mName
41 - def String mDescription 42 + String mDescription
42 - def boolean mIsTopLevel 43 + boolean mIsTopLevel
43 - def String mImageUrl 44 + String mImageUrl
44 45
45 - public SproutOnlinePuppet() { 46 + SproutOnlinePuppet() {
46 this( 47 this(
47 null, 48 null,
48 "http://www.sproutonline.com/watch", 49 "http://www.sproutonline.com/watch",
...@@ -53,7 +54,7 @@ public class SproutOnlinePuppet implements InstallablePuppet { ...@@ -53,7 +54,7 @@ public class SproutOnlinePuppet implements InstallablePuppet {
53 ) 54 )
54 } 55 }
55 56
56 - public SproutOnlinePuppet(ParentPuppet parent, String url, String name, String description, boolean isTopLevel, String imageUrl) { 57 + SproutOnlinePuppet(ParentPuppet parent, String url, String name, String description, boolean isTopLevel, String imageUrl) {
57 mParent = parent 58 mParent = parent
58 mUrl = url 59 mUrl = url
59 mName = name 60 mName = name
...@@ -64,7 +65,7 @@ public class SproutOnlinePuppet implements InstallablePuppet { ...@@ -64,7 +65,7 @@ public class SproutOnlinePuppet implements InstallablePuppet {
64 65
65 @Override 66 @Override
66 PuppetIterator getChildren() { 67 PuppetIterator getChildren() {
67 - PuppetIterator children = new SproutOnlinePuppetIterator() 68 + PuppetIterator children = new BasePuppetIterator()
68 69
69 Document document = Jsoup.connect(mUrl).ignoreContentType(true).get() 70 Document document = Jsoup.connect(mUrl).ignoreContentType(true).get()
70 71
...@@ -183,7 +184,7 @@ public class SproutOnlinePuppet implements InstallablePuppet { ...@@ -183,7 +184,7 @@ public class SproutOnlinePuppet implements InstallablePuppet {
183 } 184 }
184 185
185 @Override 186 @Override
186 - public String toString() { 187 + String toString() {
187 return mParent == null ? getName() : mParent.toString() + " < " + getName() 188 return mParent == null ? getName() : mParent.toString() + " < " + getName()
188 } 189 }
189 190
...@@ -192,43 +193,17 @@ public class SproutOnlinePuppet implements InstallablePuppet { ...@@ -192,43 +193,17 @@ public class SproutOnlinePuppet implements InstallablePuppet {
192 return VERSION_CODE 193 return VERSION_CODE
193 } 194 }
194 195
195 - def class SproutOnlinePuppetIterator extends PuppetIterator { 196 + static class SproutOnlineSourcesPuppet implements SourcesPuppet {
196 197
197 - def ArrayList<Puppet> mPuppets = new ArrayList<>() 198 + ParentPuppet mParent
198 - def int currentIndex = 0 199 + String mUrl
200 + String mName
201 + String mShortDescription
202 + String mImageUrl
199 203
200 - @Override 204 + List<SourcesPuppet.SubtitleDescription> mSubtitles = new ArrayList<SourcesPuppet.SubtitleDescription>()
201 - boolean hasNext() {
202 - return currentIndex < mPuppets.size()
203 - }
204 -
205 - @Override
206 - void add(Puppet puppet) {
207 - mPuppets.add(puppet)
208 - }
209 205
210 - @Override 206 + SproutOnlineSourcesPuppet(parent, url, name, shortDescription, imageUrl) {
211 - Puppet next() {
212 - return mPuppets.get(currentIndex++)
213 - }
214 -
215 - @Override
216 - void remove() {
217 -
218 - }
219 - }
220 -
221 - def static class SproutOnlineSourcesPuppet implements SourcesPuppet {
222 -
223 - def ParentPuppet mParent
224 - def String mUrl
225 - def String mName
226 - def String mShortDescription
227 - def String mImageUrl
228 -
229 - def List<SourcesPuppet.SubtitleDescription> mSubtitles = new ArrayList<SourcesPuppet.SubtitleDescription>()
230 -
231 - public SproutOnlineSourcesPuppet(parent, url, name, shortDescription, imageUrl) {
232 mParent = parent 207 mParent = parent
233 mUrl = url 208 mUrl = url
234 mName = name 209 mName = name
...@@ -288,12 +263,12 @@ public class SproutOnlinePuppet implements InstallablePuppet { ...@@ -288,12 +263,12 @@ public class SproutOnlinePuppet implements InstallablePuppet {
288 263
289 @Override 264 @Override
290 boolean isUnavailableIn(String region) { 265 boolean isUnavailableIn(String region) {
291 - return false 266 + return region != 'us'
292 } 267 }
293 268
294 @Override 269 @Override
295 String getPreferredRegion() { 270 String getPreferredRegion() {
296 - return null 271 + return 'us'
297 } 272 }
298 273
299 @Override 274 @Override
...@@ -312,14 +287,14 @@ public class SproutOnlinePuppet implements InstallablePuppet { ...@@ -312,14 +287,14 @@ public class SproutOnlinePuppet implements InstallablePuppet {
312 } 287 }
313 288
314 @Override 289 @Override
315 - public String toString() { 290 + String toString() {
316 return mParent == null ? getName() : mParent.toString() + " < " + getName() 291 return mParent == null ? getName() : mParent.toString() + " < " + getName()
317 } 292 }
318 293
319 - def class SproutOnlineSourceIterator implements SourcesPuppet.SourceIterator { 294 + class SproutOnlineSourceIterator implements SourcesPuppet.SourceIterator {
320 295
321 - def List<SourceDescription> mSources = null 296 + List<SourceDescription> mSources = null
322 - def int currentIndex = 0 297 + int currentIndex = 0
323 298
324 @Override 299 @Override
325 boolean hasNext() { 300 boolean hasNext() {
...@@ -327,24 +302,20 @@ public class SproutOnlinePuppet implements InstallablePuppet { ...@@ -327,24 +302,20 @@ public class SproutOnlinePuppet implements InstallablePuppet {
327 302
328 mSources = new ArrayList<SourceDescription>() 303 mSources = new ArrayList<SourceDescription>()
329 304
330 - String html = new URL(SproutOnlineSourcesPuppet.this.mUrl).getText().replaceAll("\n", "") 305 + String html = new URL(mUrl).getText().replaceAll("\n", "")
331 - Matcher matcher = html =~ /"video": "(.+?)"/ 306 + Matcher matcher = html =~ /"(https:\/\/player.theplatform.com\/p\/.+?)"/
332 307
333 String url = null 308 String url = null
334 if (matcher.find()) { 309 if (matcher.find()) {
335 url = matcher.group(1) 310 url = matcher.group(1)
336 - } else { 311 +
337 - matcher = html =~ /http:\/\/player.theplatform.com\/(.+?)"/ 312 + html = new URL(url).getText().replaceAll("\n", "")
313 +
314 + matcher = html =~ /tp:releaseUrl="(.+?)"/
338 if (matcher.find()) { 315 if (matcher.find()) {
339 url = matcher.group(1) 316 url = matcher.group(1)
340 - html = new URL("http://player.theplatform.com/" + url).getText().replaceAll("\n", "") 317 + if (url.contains("?")) {
341 - 318 + url = url.split("\\?")[0]
342 - matcher = html =~ /tp:releaseUrl="(.+?)"/
343 - if (matcher.find()) {
344 - url = matcher.group(1)
345 - if (url.contains("?")) {
346 - url = url.split("\\?")[0]
347 - }
348 } 319 }
349 } 320 }
350 } 321 }
...@@ -387,7 +358,6 @@ public class SproutOnlinePuppet implements InstallablePuppet { ...@@ -387,7 +358,6 @@ public class SproutOnlinePuppet implements InstallablePuppet {
387 358
388 @Override 359 @Override
389 void remove() { 360 void remove() {
390 -
391 } 361 }
392 } 362 }
393 } 363 }
......