import org.serviio.library.metadata.* import org.serviio.library.online.* import org.serviio.util.* class DesiStreams extends WebResourceUrlExtractor { final VALID_FEED_URL = 'http://www.eboundservices.com/istream/istream_demo.php' final TITLE = 'eboundservices' // final CHANNEL_LIST_EXTRACTOR = '

(.*?)
' final CHANNEL_LIST_EXTRACTOR = ' String getExtractorName() { return 'DesiStreams' } // end getExtractorName boolean extractorMatches(URL feedUrl) { return feedURL ==~ VALID_FEED_URL } // end extractorMatches Boolean URLExists(URL fileURL){ if(((HttpURLConnection) fileURL.openConnection()).getResponseCode() == 404){ return false } return true } // end URLExists String process_for_URL(String htmlText, String rgxMatcher, String baseURL) { def return_val = '-NOTFOUND-' def matcher = htmlText =~ rgxMatcher if (matcher.count > 0) { return_val = '-URL-' + baseURL + matcher[0][1] } //return_val = '-URL-' + 'http://www.eboundservices.com:8888/iframe/iframe.php?app=tv&stream=newsone&screen=true' return return_val } // end process_for_URL String processChannel(String channel_url) { println "processChannel... Starting" def log_text = '' def error = '' if (!URLExists(new URL(channel_url))) { error = '-DEADLINK-' log_text = log_text + error print error // write_to_log(log_text) println 'URL Does Not Exist' return error } //end if println 'URL Exists...' def channel_src_text = new URL(channel_url).getText() new File('2.txt').text = channel_src_text def channel_stream_url_text = channel_src_text def url_found = 0 def loop = 0 def base_url = '' def current_url = channel_url //channel_src def rtmp_url = '' while (url_found == 0) { def returned_url = '-NOTFOUND-' if (returned_url == '-NOTFOUND-') { //returned_url = 'http://www.eboundservices.com:8888/iframe/iframe.php?app=tv&stream=newsone&screen=true' returned_url = process_for_URL( channel_stream_url_text, 'htt.*?eboundservices\\.com:8888/iframe/(.*?)"', 'http://www.eboundservices.com:8888/iframe/' ) } // end if println 'Returned Url ... ' + returned_url if (returned_url == '-NOTFOUND-') { error = '-NOTFOUND-' // write_to_log(log_text) return error } // end if else if (returned_url.contains("-URL-")) { returned_url = returned_url.replaceFirst("-URL-","") current_url = returned_url if (!URLExists(new URL(current_url))) { error = '-DEADLINK-' log_text = log_text + error print error // write_to_log(log_text) println '-DEADLINK-' return error } channel_stream_url_text = new URL(current_url).getText() new File('3.txt').text = channel_stream_url_text } // end else if } // end while println "processChannel... Finished" } // end processChannel WebResourceContainer extractItems(URL resourceURL, int maxItemsToRetrieve) { println "WebResourceContainer... Starting" List items = [] if (URLExists(resourceURL) == false) { write_to_log("Invalid Resource URL") println "URL Does not Exist" return null } println "URL Exists..." def resource_text = resourceURL.getText() new File('1.txt').text = resource_text def channel_list_matcher = resource_text =~ CHANNEL_LIST_EXTRACTOR def channel_count = channel_list_matcher.count for (channel_number in 0..<1) { // change back to channel_count from 1 def channel_url = channel_list_matcher[channel_number][1] def channel_image = channel_list_matcher[channel_number][2] def channel_title_matcher = (channel_url =~ 'stream=(.*)') def channel_title = '' channel_title_matcher.each { channel_title = channel_title_matcher[0][1] } println channel_url + channel_image + channel_title processChannel(channel_url) } // end for println "WebResourceContainer... Finished" } // end WebResourceContainer ContentURLContainer extractUrl(WebResourceItem item, PreferredQuality requestedQuality) { println "ContentURLContainer... Starting" println "ContentURLContainer... Finished" items << new WebResourceItem(title: channel_title, additionalInfo: [channelURL: channel_url, thumbnailUrl: channel_image]) return new WebResourceContainer(title: TITLE, items: items) } // end ContentURLContainer static void main(args) { println "Main... Starting" DesiStreams extractor = new DesiStreams() WebResourceContainer container = extractor.extractItems( new URL("http://www.eboundservices.com/istream/istream_demo.php"), 50) /**/ container.getItems().each { ContentURLContainer result = extractor.extractUrl(it, PreferredQuality.MEDIUM) println result println '' } /**/ println "Main... Finished" } } // end class