import groovy.util.XmlParser import groovy.json.JsonSlurper import org.serviio.library.metadata.* import org.serviio.library.online.* import org.serviio.util.* /******************************************************************** * tamiltv.tv plugin for Serviio * * @author Arun * * URL to use as video webresource: http://www.tamiltv.tv * * Version: * V1: - Dec 04, 2012 * V2: - Apr 28, 2013 * ********************************************************************/ class TurboTVTamil extends WebResourceUrlExtractor { final VALID_RESOURCE_URL = '^(?:http://)?(?:www\\.)?tamiltv.tv/*' final BASE_URL = '' final BASE_IMAGE_URL = "" final TITLE = 'TAMILTV.TV' final CHANNEL_LIST_EXTRACTOR = 'menu-item-[0-9]+">(.*?)' String getExtractorName() { return 'tamiltv.tv' } boolean extractorMatches(URL resourceURL) { return resourceURL ==~ VALID_RESOURCE_URL } void write_to_log( String text ) { log(TITLE + ' - ' + text) } Boolean URLExists(URL fileURL){ if(((HttpURLConnection) fileURL.openConnection()).getResponseCode() == 404){ return false } return true } Boolean channelOffline( String htmlText, String offlineChecker ) { def offline_check = htmlText =~ offlineChecker if (offline_check.count > 0) { return true } return false } Boolean streamNotSupported( String htmlText, String streamNotSupportedChecker ) { def notsupported_check = htmlText =~ streamNotSupportedChecker if (notsupported_check.count > 0) { return true } return false } String modify_playpath_based_on_page_url(String playpath, String pageURL) { def actual_playpath = playpath return actual_playpath } String modify_playpath_based_on_swf_url(String playpath, String swfURL) { def actual_playpath = playpath return actual_playpath } String fix_playpath(String playpath) { def actual_playpath = playpath actual_playpath = actual_playpath.replaceAll(".flv", "") actual_playpath = java.net.URLDecoder.decode(actual_playpath) return actual_playpath } String redirect_to_actual_stream(String stream) { def actual_stream = stream return actual_stream } String modify_stream_based_on_page_and_playpath(String stream, String pageURL, String playpath) { def actual_stream = stream return actual_stream } String modify_stream_based_on_swf_url(String stream, String swfURL) { def actual_stream = stream return actual_stream } 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 return_val } String process_for_PLAYPATH( String htmlText, String rgxMatcher, String[] streamURLs, String baseURL, String swfURL ) { def return_val = '-NOTFOUND-' def matcher = htmlText =~ rgxMatcher if (matcher.count > 0) { def pageURL = baseURL + matcher[0][1] def playpath = fix_playpath(matcher[0][1]) def stream = streamURLs[ (int)(System.currentTimeMillis() % streamURLs.size()) ] stream = modify_stream_based_on_page_and_playpath(stream, pageURL, playpath) playpath = modify_playpath_based_on_page_url(playpath, pageURL) playpath = modify_playpath_based_on_swf_url(playpath, swfURL) return_val = '-STREAM-' + stream.replaceAll("rtmp://65.49.77.251/redirect","rtmp://50.7.130.43:1939/base2").replaceAll("rtmp://65.49.77.252/redirect","rtmp://50.7.130.42:1940/base2") return_val = return_val + ' playpath=' + playpath return_val = return_val + ' pageUrl=' + pageURL return_val = return_val + ' swfUrl=' + swfURL return_val = return_val + ' live=1' } return return_val } String process_for_SWF_STREAMER_PLAYPATH( String htmlText, String rgxMatcher, String pageUrl ) { def return_val = '-NOTFOUND-' def matcher = htmlText =~ rgxMatcher if (matcher.count > 0) { def swfUrl = matcher[0][1] + '.swf' def playpath = fix_playpath(matcher[0][3]) def stream = matcher[0][2].replaceAll("rtmp://65.49.77.251/redirect","rtmp://50.7.130.43:1939/base2").replaceAll("rtmp://65.49.77.252/redirect","rtmp://50.7.130.42:1940/base2") stream = modify_stream_based_on_page_and_playpath(stream, pageUrl, playpath) stream = modify_stream_based_on_swf_url(stream, swfUrl) stream = redirect_to_actual_stream(stream) playpath = modify_playpath_based_on_page_url(playpath, pageUrl) playpath = modify_playpath_based_on_swf_url(playpath, swfUrl) return_val = '-STREAM-' + stream return_val = return_val + ' playpath=' + playpath return_val = return_val + ' pageUrl=' + pageUrl return_val = return_val + ' swfUrl=' + swfUrl return_val = return_val + ' live=1' } return return_val } String process_for_SWF_PLAYPATH_STREAMER( String htmlText, String rgxMatcher, String pageUrl ) { def return_val = '-NOTFOUND-' def matcher = htmlText =~ rgxMatcher if (matcher.count > 0) { def swfUrl = matcher[0][1] + '.swf' def playpath = fix_playpath(matcher[0][2]) def stream = matcher[0][3] stream = modify_stream_based_on_page_and_playpath(stream, pageUrl, playpath) stream = modify_stream_based_on_swf_url(stream, swfUrl) stream = redirect_to_actual_stream(stream) playpath = modify_playpath_based_on_page_url(playpath, pageUrl) playpath = modify_playpath_based_on_swf_url(playpath, swfUrl) return_val = '-STREAM-' + stream return_val = return_val + ' playpath=' + playpath return_val = return_val + ' pageUrl=' + pageUrl return_val = return_val + ' swfUrl=' + swfUrl return_val = return_val + ' live=1' } return return_val } String processChannel( String channel_url ) { 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) return error } def channel_src_text = openURL( new URL(channel_url), "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.83 Safari/537.1" ) channel_src_text = channel_src_text.replaceAll('%3A',':') channel_src_text = channel_src_text.replaceAll('%2F','/') channel_src_text = channel_src_text.replaceAll('&','&') channel_src_text = channel_src_text.replaceAll('"','"') channel_src_text = channel_src_text.replaceAll('<','<') channel_src_text = channel_src_text.replaceAll('>','>') channel_src_text = channel_src_text.replaceAll('%2D','-') 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) { if (channelOffline(channel_stream_url_text, '

This channel is offline\\.

') || channelOffline(channel_stream_url_text, '

') ) { error = '-OFFLINE-' log_text = log_text + error print error write_to_log(log_text) return error } if (streamNotSupported(channel_stream_url_text, '') ) { error = '-NOTSUPPORTED-' log_text = log_text + error print error write_to_log(log_text) return error } def returned_url = '-NOTFOUND-' if (returned_url == '-NOTFOUND-' ) { returned_url = process_for_SWF_STREAMER_PLAYPATH( channel_stream_url_text, '') /** println channel_stream_url_text println '' println '' println '' println '' println '' /**/ } else if (returned_url.contains("-STREAM-")) { rtmp_url = returned_url url_found = 1 } } write_to_log(log_text) return rtmp_url } WebResourceContainer extractItems(URL resourceURL, int maxItemsToRetrieve) { List items = [] if (URLExists(resourceURL) == false) { write_to_log("Invalid Resource URL") return null } def resource_text = openURL(resourceURL, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.1" ) resource_text = resource_text.replaceAll("\n","") resource_text = resource_text.replaceAll("\r","") def channel_list_matcher = resource_text =~ CHANNEL_LIST_EXTRACTOR def channel_count = channel_list_matcher.count //println 'this is the channel count --> ' + channel_count for (channel_number in 0..