class VideoStarApi: MAINURL_PC = 'https://videostar.pl/' MAINURL_IOS = 'https://m.videostar.pl/' HTTP_HEADER_PC = { 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:12.0) Gecko/20100101 Firefox/12.0', 'Referer': MAINURL_PC } HTTP_HEADER_IOS = { 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B179 Safari/7534.48.3', 'Referer': MAINURL_IOS } HTTP_HEADER2 = { 'User-Agent':'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16', 'Referer': MAINURL_IOS} API_URLS = { 'login_url' : 'login', 'get_ad_show' : 'api/ad/show', 'get_ad_urls' : 'api/ad/urls', 'get_channels_list' : 'api/channels/list/web', 'get_channel_url' : 'api/channels/get/%s?format_id=%s', 'close_channel' : 'api/channels/close', } VIDEO_STAR_T = '' VIDEO_GUEST_M = False def __init__(self): self.cm = common()#proxyURL= '', useProxy = True) self.up = urlparser() self.sessionEx = MainSessionWrapper() def doInit(self): if config.plugins.iptvplayer.videostar_use_proxy_gateway.value: self.proxy_gateway_url = "http://www.bramka-proxy.pl/browse.php?u={0}&b=192&f=norefer" #config.plugins.iptvplayer.videostar_proxy_gateway_url.value self.proxy_gateway_ssl = "http://www.bramka-proxy.pl/includes/process.php?action=sslagree" self.my_ip = self.getProxyGatewayIP() else: self.my_ip = '' self.proxy_gateway_url = '' self._reInit() self.channelsList = [] def getProxyGatewayIP(self): url = 'http://showip.net/' sts, data = self.cm.getPage(url, {'header':{'User-Agent':'Mozilla/5.0', 'Referer':self.proxy_gateway_url}, 'proxy_gateway':self.proxy_gateway_url}) my_ip = '' if sts: try: my_ip = self.cm.ph.getSearchGroups(data, 'name="check_ip"[^>]+?value="([^"]+?)"')[0] printDBG('getProxyGatewayIP my_ip[%s]' % my_ip) except: printExc() if '' == my_ip: self.sessionEx.open(MessageBox, _('Problem z uzyskaniem IP bramki proxy!'), type = MessageBox.TYPE_INFO, timeout = 10 ) return my_ip def _getUrl(self, key): if '2' == self.streamprotocol: MAINURL = VideoStarApi.MAINURL_IOS else: MAINURL = VideoStarApi.MAINURL_PC if key in VideoStarApi.API_URLS: return MAINURL + VideoStarApi.API_URLS[key] if not key.startswith('http'): return MAINURL + key return key def _reInit(self): self.streamprotocol = config.plugins.iptvplayer.videostar_streamprotocol.value if '2' == self.streamprotocol: self.MAINURL = VideoStarApi.MAINURL_IOS self.cm.HEADER = dict(VideoStarApi.HTTP_HEADER_IOS) else: self.MAINURL = VideoStarApi.MAINURL_PC self.cm.HEADER = dict(VideoStarApi.HTTP_HEADER_PC) if '' != self.my_ip: self.cm.HEADER['X-Forwarded-For'] = self.my_ip self.PREMIUM = config.plugins.iptvplayer.videostar_premium.value self.LOGIN = config.plugins.iptvplayer.videostar_login.value self.PASSWORD = config.plugins.iptvplayer.videostar_password.value def getDefaultQuality(self): return config.plugins.iptvplayer.videostar_defquality.value def getChannelsList(self, refresh=False): printDBG("VideoStarApi.getChannelsList") self.doInit() if not refresh and 0 < len(self.channelsList): return self.channelsList self.channelsList = [] if '' != self.LOGIN.strip() and '' != self.PASSWORD.strip(): if not self.doLogin(self.LOGIN, self.PASSWORD): self.sessionEx.open(MessageBox, _('Problem z zalogowanie użytkownika "%s. Sprawdź dane do logowania w konfiguracji hosta."') % self.LOGIN, type = MessageBox.TYPE_INFO, timeout = 10 ) return self.channelsList else: self.sessionEx.open(MessageBox, _('Strona wymaga zalogowania. Proszę uzupełnić dane w konfiguracji hosta.'), type = MessageBox.TYPE_INFO, timeout = 10 ) return self.channelsList self._fillChannelsList() return self.channelsList def _fillChannelsList(self): printDBG("VideoStarApi._fillChannelsList") # get channels list sts, data = self.cm.getPage( self._getUrl('get_channels_list') ) if sts: try: data = json.loads(data) if "ok" == data['status']: self.channelsList = data['channels'] except: printExc() #self.getVideoLink(12) #self.getVideoLink(12) def getVideoLink(self, channelID): printDBG("VideoStarApi.getVideoLink") urlsTab = [] #get referer page referer = '' guestMode = False for item in self.channelsList: if channelID == item['id']: referer = self.MAINURL + '#' + item['slug'] # "slug" attrib can be also taken from stream_channel data if "unsubscribed" == item['access_status']: guestMode = True break for tryNum in range(2): # there is need to close previuse played channel self._closePrevChannel() # retrie if there was unknown problem with getting link self._reInit() if not guestMode: self.doLogin(self.LOGIN, self.PASSWORD) sts, data = self.cm.getPage( referer ) if not sts: printExc('Error when downloading referer') else: self.cm.HEADER = dict(VideoStarApi.HTTP_HEADER2) if '' != self.my_ip: self.cm.HEADER['X-Forwarded-For'] = self.my_ip url = self._getUrl('get_channel_url') % (channelID, self.streamprotocol) HTTP_HEADER = dict(self.cm.HEADER) HTTP_HEADER.update( {'X-Reguested-With':'XMLHttpReguest'} ) if guestMode: url = url.replace('https://videostar.pl/api', 'https://api.videostar.pl/guest') sts, data = self.cm.getPage( url, {'header': HTTP_HEADER} ) try: #printDBG("--------------------------------------------------") #printDBG(data) #printDBG("--------------------------------------------------") data = json.loads(data) if "ok" == data['status']: VideoStarApi.VIDEO_STAR_T = data['stream_channel']['url_params'][-1].decode('utf-8') url_param1 = data['stream_channel']['url_params'][1].decode('utf-8') VideoStarApi.VIDEO_GUEST_M = guestMode if '1' == self.streamprotocol: url = data['stream_channel']['url_base'].decode('utf-8') sts, data = self.cm.getPage( url, {'header': HTTP_HEADER}) r = re.search('<baseURL>([^<]+?)</baseURL>', data).group(1) streams = re.findall('url="([^"]+?)" bitrate="([0-9]+?)"', data) for item in streams: # swfVfy=https://videostar.pl/javascripts/libs/flowplayer/flowplayer.netvi-x.swf protocol=1 url = r + '/' + item[0] + ' live=1 swfUrl=https://videostar.pl/javascripts/libs/flowplayer/flowplayer.commercial-3.2.11.swf' + ' pageUrl=' + referer + (' conn=S:%s conn=S:%s token=%s' % (url_param1, VideoStarApi.VIDEO_STAR_T, VideoStarApi.VIDEO_STAR_T)) + ' flashVer=WIN 12,0,0,44 ' urlsTab.append({'url': strwithmeta(url, {'iptv_proto':'rtmp'}), 'name': item[1], 'bitrate':item[1]+'000', 'type':'rtmpt'}) else: # hls url = data['stream_channel']['url_base'].decode('utf-8') meta = {'iptv_proto':'m3u8'} if '' != self.proxy_gateway_url: channelID = data['stream_channel']['channel_id'] #if url.startswith('https://'): url = 'http://' + url[8:] server = self.cm.ph.getSearchGroups(url, r'://([^/]+?)/')[0] meta['iptv_m3u8_custom_base_link'] = 'http://%s:1935/%s/smil:%s.ism/list.m3u8' % (server, channelID, 'basic') meta['iptv_proxy_gateway'] = self.proxy_gateway_url meta['Referer'] = self.proxy_gateway_url meta['User-Agent'] = 'Mozilla/5.0' meta['X-Forwarded-For'] = self.my_ip meta['Cookie'] = self.getCookieItem('s', self.proxy_gateway_ssl, {'header':{'User-Agent':'Mozilla/5.0'}}) urlsTab.append({'url': self.up.decorateUrl(url, meta), 'name': 'videostar hls', 'type':'hls'}) except: printExc() if 0 < len(urlsTab): break printDBG(urlsTab) return urlsTab def _closePrevChannel(self): printDBG("VideoStarApi._closePrevChannel start VIDEO_STAR_T[%s]" % VideoStarApi.VIDEO_STAR_T) if '' != VideoStarApi.VIDEO_STAR_T: url = self._getUrl('close_channel') HTTP_HEADER = dict(self.cm.HEADER) HTTP_HEADER.update( {'X-Reguested-With':'XMLHttpReguest', 'Content-Type':'application/x-www-form-urlencoded', 'charset':'UTF-8'} ) post_data = {'t': VideoStarApi.VIDEO_STAR_T} if VideoStarApi.VIDEO_GUEST_M: url = url.replace('https://videostar.pl/api', 'https://api.videostar.pl/guest') sts, data = self.cm.getPage( url, {'header': HTTP_HEADER}, post_data) try: data = json.loads(data) if "ok" == data['status']: VideoStarApi.VIDEO_STAR_T = '' except: printExc() printDBG("_closePrevChannel end VIDEO_STAR_T[%s]" % VideoStarApi.VIDEO_STAR_T) def doLogin(self, login, password): HTTP_HEADER= dict(self.cm.HEADER) HTTP_HEADER.update( {'Content-Type':'application/x-www-form-urlencoded'} ) cookiePath = GetCookieDir('videostar.cookie') params = {'header':HTTP_HEADER, 'cookiefile': cookiePath, 'use_cookie': True, 'save_cookie':True} post_data = {'login': login, 'password': password, 'permanent': '1'} sts, data = self.cm.getPage( self._getUrl('login_url'), params, post_data) if sts: # the LWP has problem to read prepared Cookie, so we will manually read them and add to header try: with open(cookiePath, 'r') as infile: data = infile.read() PHPSESSID = re.search('(PHPSESSID=[^;]+?;)', data).group(1) netviapisessid = re.findall('(netviapisessid[^;]+?;)', data)[-1] #HttpOnly self.cm.HEADER['Cookie'] = PHPSESSID + netviapisessid sts, data = self.cm.getPage(self.MAINURL) if sts and 'Wyloguj' in data: return True except: printExc() return False def getCookieItem(self, key, url, params={}, post_data=None): cookiePath = GetCookieDir('tmp.cookie') params.update({'cookiefile': cookiePath, 'use_cookie': True, 'save_cookie':True}) sts, data = self.cm.getPage(url, params, post_data) itemValue = '' if sts: # the LWP has problem to read prepared Cookie, so we will manually read them and add to header try: with open(cookiePath, 'r') as infile: data = infile.read() itemValue = re.search(' (%s=[^;]+?;)' % key, data).group(1) except: printExc() return itemValue
class PierwszaTVApi: def __init__(self): self.MAIN_URL = 'http://pierwsza.tv/' self.HTTP_HEADER = { 'User-Agent':'Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/37.0.2062.120 Chrome/37.0.2062.120 Safari/537.36', 'Referer': self.MAIN_URL } self.COOKIE_FILE = GetCookieDir('pierwszatv.cookie') self.COOKIE_FILE2 = GetCookieDir('pierwszatv2.cookie') self.COOKIE_FILE3 = GetCookieDir('pierwszatv3.cookie') self.sessionEx = MainSessionWrapper() self.cm = common() self.up = urlparser() self.http_params = {'header': dict(self.HTTP_HEADER), 'save_cookie': True, 'load_cookie': True, 'cookiefile': self.COOKIE_FILE} self.http_params2 = {'header': dict(self.HTTP_HEADER), 'save_cookie': True, 'load_cookie': True, 'cookiefile': self.COOKIE_FILE2} self.http_params3 = {'header': dict(self.HTTP_HEADER), 'save_cookie': True, 'load_cookie': True, 'cookiefile': self.COOKIE_FILE3} self.cacheList = {} self.mainConnectData = {} def getWindowDict(self, varData): printDBG("PierwszaTVApi.fillMainConnectData") window = {'isPromoMode':'', 'utype':'', 'u0td':'', 'u1td':'', 'uTypeRoute':''} for key in window: val = self.cm.ph.getSearchGroups(varData, '''window\.%s[^'^"]*?=([^;]+?);''' % key, 1, True)[0].strip() if val.startswith("'") and val.endswith("'"): val = val[1:-1] if val.startswith('"') and val.endswith('"'): val = val[1:-1] window[key] = val return window def fillMainConnectData(self): printDBG("PierwszaTVApi.fillMainConnectData") self.mainConnectData = {} sts, data = self.cm.getPage(self.MAIN_URL, self.http_params) if not sts: return False self.mainConnectData = self.getWindowDict(data) tmp = self.cm.ph.getDataBeetwenMarkers(data, 'connectToLive(', ')', False)[1] tmp = self.cm.ph.getSearchGroups(tmp, '''['"]([^'^"]+?)['"][^'^"]+?['"]([^'^"]+?)['"]''', 2, True) self.mainConnectData['connect_to_live_url'] = tmp[0] self.mainConnectData['connect_to_live_token'] = tmp[1] tmp = self.cm.ph.getDataBeetwenMarkers(data, 'setItem(', ')', False)[1] tmp = self.cm.ph.getSearchGroups(tmp, '''['"]([^'^"]+?)['"][^'^"]+?['"]([^'^"]+?)['"]''', 2, True) self.mainConnectData[tmp[0]] = tmp[1] jsUrl = self.getFullUrl(self.cm.ph.getSearchGroups(data, '''<script[^>]+?src=['"]([^'^"]*?/build/[^'^"]+?\.js)['"]''')[0]) sts, data = self.cm.getPage(jsUrl, self.http_params) if not sts: self.mainConnectData['api_path'] = '' else: self.mainConnectData['api_path'] = self.cm.ph.getSearchGroups(data, '''['"]?apiPath['"]?\s*:\s*["'](http[^'^"]+?)["']''')[0] printDBG(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> fillMainConnectData start") printDBG(self.mainConnectData) printDBG("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< fillMainConnectData end") def cryptoJS_AES_decrypt(self, encrypted, password, salt): def derive_key_and_iv(password, salt, key_length, iv_length): d = d_i = '' while len(d) < key_length + iv_length: d_i = md5(d_i + password + salt).digest() d += d_i return d[:key_length], d[key_length:key_length+iv_length] bs = 16 key, iv = derive_key_and_iv(password, salt, 32, 16) cipher = AES_CBC(key=key, keySize=32) return cipher.decrypt(encrypted, iv) def getTimestamp(self, t, s=64): a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_" e = "" t = int(t) while t > 0: e = a[t % s] + e t = int(t / s) return e def getFullUrl(self, url): if url.strip() == '': return '' elif self.cm.isValidUrl(url): return url elif url.startswith('//'): return 'http:' + url elif url.startswith('/'): return self.MAIN_URL + url[1:] return self.MAIN_URL + url def cleanHtmlStr(self, str): return CBaseHostClass.cleanHtmlStr(str) def getChannelsList(self, cItem): printDBG("TelewizjadaNetApi.getChannelsList") login = config.plugins.iptvplayer.pierwszatv_login.value password = config.plugins.iptvplayer.pierwszatv_password.value if login != '' and password != '': if self.doLogin(login, password): self.loggedIn = True self.http_params.update({'save_cookie': True, 'load_cookie': True, 'cookiefile': self.COOKIE_FILE}) else: self.sessionEx.open(MessageBox, _('Problem z zalogowanie użytkownika "%s. Sprawdź dane do logowania w konfiguracji hosta."') % login, type = MessageBox.TYPE_INFO, timeout = 10 ) self.fillMainConnectData() liveChannelsTab = [] sts, data = self.cm.getPage(self.getFullUrl('player/watch?show=active'), self.http_params) if not sts: return [] url = self.mainConnectData.get('api_path', '') + "/sources?watchToken=" + self.mainConnectData.get('wt', '') sts, data = self.cm.getPage(url, self.http_params2) if not sts: return [] scheduledChannelsTab = [] try: data = byteify(json.loads(data))['sources'] for idx in range(200): try: if isinstance(data, list): item = data[idx] else: item = data[str(idx)] except Exception: continue #printDBG(item) #printDBG("===============================================") url = strwithmeta(self.getFullUrl('player/watch/{0}'.format(item['id'])), {'id':item['id']}) icon = '' icon = item.get('thumbUrl', '') if icon == None: icon = '' title = self.cleanHtmlStr( item['name'] ) desc = [] try: if 'scheduleStartIn' in item: d = item['scheduleStartIn'] desc.append('Start za: %s:%s:%s' % (str(d['hours']).zfill(2), str(d['minutes']).zfill(2), str(d['seconds']).zfill(2)) ) except Exception: printExc() for d in ['author', 'updated_at']: #, 'scheduleStartAt', 'scheduleEndAt' if item.get(d, None) != None: desc.append(str(item[d])) params = dict(cItem) params.update({'title':title, 'url':url, 'icon':self.getFullUrl(icon), 'desc':'[/br]'.join(desc)}) if item.get('transmiting', False) and not item.get('isScheduled', False): liveChannelsTab.append(params) elif item.get('isScheduled', False): scheduledChannelsTab.append(params) except Exception: SetIPTVPlayerLastHostError('Błąd w parsowaniu danych z serwera.') printExc() liveChannelsTab.extend(scheduledChannelsTab) return liveChannelsTab def getVideoLink(self, cItem): printDBG("TelewizjadaNetApi.getVideoLink") url = cItem['url'] sourceId = str(url.meta['id']) mainCon = {'url':self.mainConnectData.get('connect_to_live_url', ''), 'token':self.mainConnectData.get('connect_to_live_token', '')} sts, data = self.cm.getPage(cItem['url'], self.http_params) if not sts: return [] params = dict(self.http_params) params['header'] = dict(params['header']) params['header']['Referer'] = cItem['url'] params['header']['Origin'] = self.MAIN_URL[:-1] liveCon = {} url = self.mainConnectData.get('api_path', '') + '/live?wt=' + self.mainConnectData.get('wt', '') sts, data = self.cm.getPage(url, self.http_params2) if not sts: return [] try: liveCon = byteify(json.loads(data)) except Exception: printExc() return [] url = self.mainConnectData.get('api_path', '') + "/play?id=%swatchToken=%s" % (sourceId, self.mainConnectData.get('wt', '')) sts, data = self.cm.getPage(url, self.http_params2) if not sts: return [] try: def to_byte_array(inArray): import struct outArray = [] for item in inArray: outArray.append(struct.pack('>l', item)) return ''.join(outArray) data = byteify(json.loads(data)) ciphertext = to_byte_array(data['window']['encServers']['ciphertext']['words']) iv = to_byte_array(data['window']['encServers']['iv']['words']) key = to_byte_array(data['window']['encServers']['key']['words']) salt = to_byte_array(data['window']['encServers']['salt']['words']) tmp = self.cryptoJS_AES_decrypt(ciphertext, 'number-one', salt) printDBG(tmp) tmp = byteify(json.loads(tmp)) except Exception: printExc() return [] urlsTab = [] try: if isinstance(tmp, list): tmp = tmp[0] if isinstance(tmp, dict): baseUrl1 = liveCon['url'] streamToken1 = liveCon['token'] baseUrl2 = tmp['server'] streamToken2 = tmp['token'] serverId = str(tmp['id']) printDBG("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++") printDBG(tmp) printDBG("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++") #def _getSocketIoUrl1(baseUrl, params): # t1 = self.getTimestamp(time()*1000) t1 = self.getTimestamp(time()*1000) url = baseUrl1 + '/socket.io/?EIO=3&transport=polling&t=' + t1 sts, data = self.cm.getPage(url, self.http_params2) if sts: baseParams1 = data[data.find('{'):] baseParams1 = byteify(json.loads(baseParams1)) printDBG("=========================================================") printDBG([data]) else: baseParams1 = {'sid':''} printDBG(baseParams1) printDBG("=========================================================") t2 = self.getTimestamp(time()*1000) url = baseUrl2.replace(":8000",":8004") + '/socket.io/?EIO=3&transport=polling&t=' + t2 sts, data = self.cm.getPage(url, self.http_params3) baseParams2 = data[data.find('{'):] baseParams2 = byteify(json.loads(baseParams2)) printDBG("=========================================================") printDBG([data]) printDBG(baseParams2) printDBG("=========================================================") #===================== t1 = self.getTimestamp(time()*1000) url = baseUrl1 + '/socket.io/?EIO=3&transport=polling&t={0}&sid={1}'.format(t1, baseParams1['sid']) sts, data = self.cm.getPage(url, self.http_params2) if sts: printDBG("=========================================================") printDBG(data.split('\x00\x02\xff')) printDBG("=========================================================") t2 = self.getTimestamp(time()*1000) url = baseUrl2.replace(":8000",":8004") + '/socket.io/?EIO=3&transport=polling&t={0}&sid={1}'.format(t2, baseParams2['sid']) sts, data = self.cm.getPage(url, self.http_params3) printDBG("=========================================================") printDBG(data.split('\x00\x02\xff')) printDBG("=========================================================") #===================== #raw_post_data t1 = self.getTimestamp(time()*1000) url = baseUrl1 + '/socket.io/?EIO=3&transport=polling&t={0}&sid={1}'.format(t1, baseParams1['sid']) self.http_params2['raw_post_data'] = True sts, data = self.cm.getPage(url, self.http_params2, '92:42["authorize",{"token":"%s"}]' % streamToken1) printDBG("=========================================================") printDBG([data]) printDBG("=========================================================") if 0: t1 = self.getTimestamp(time()*1000) url = baseUrl1 + '/socket.io/?EIO=3&transport=polling&t={0}&sid={1}'.format(t1, baseParams1['sid']) sts, data = self.cm.getPage(url, self.http_params2) printDBG("=========================================================") printDBG([data]) printDBG("=========================================================") #+++++ t2 = self.getTimestamp(time()*1000) url = baseUrl2.replace(":8000",":8004") + '/socket.io/?EIO=3&transport=polling&t={0}&sid={1}'.format(t2, baseParams2['sid']) self.http_params3['raw_post_data'] = True sts, data = self.cm.getPage(url, self.http_params3, '82:42["authorize","%s"]' % streamToken2) printDBG("=========================================================") printDBG([data]) printDBG("=========================================================") t2 = self.getTimestamp(time()*1000) url = baseUrl2.replace(":8000",":8004") + '/socket.io/?EIO=3&transport=polling&t={0}&sid={1}'.format(t2, baseParams2['sid']) sts, data = self.cm.getPage(url, self.http_params3) data = byteify( json.loads(data[data.find('42')+2:]) ) stoken = data[1]['stoken'] printDBG("=========================================================") printDBG([data]) printDBG("=========================================================") n = sha256(serverId + '_' + sourceId + '_' + stoken + '_rabbit_foot').hexdigest() url = self.mainConnectData['api_path'] + '/request-stream' + "?token=" + streamToken2 + "&server=" + serverId + "&source=" + sourceId + "&cs=" + n sts, data = self.cm.getPage(url, self.http_params) data = byteify( json.loads(data) ) streamId = str(data['id']) if 0: t2 = self.getTimestamp(time()*1000) url = baseUrl2.replace(":8000",":8004") + '/socket.io/?EIO=3&transport=polling&t={0}&sid={1}'.format(t2, baseParams2['sid']) self.http_params3['raw_post_data'] = True sts, data = self.cm.getPage(url, self.http_params3, '84:42["subscribe","%s"]' % streamId) wsUrl2 = baseUrl2.replace(":8000",":8004").replace('http://', 'ws://') + '/socket.io/?EIO=3&transport=websocket&sid={0}'.format(baseParams2['sid']) wsUrl1 = baseUrl1.replace('http://', 'ws://') + '/socket.io/?EIO=3&transport=websocket&sid={0}'.format(baseParams1['sid']) libsPath = GetPluginDir('libs/') pyCmd = GetPyScriptCmd('pierwszatv') + ' "%s" "%s" "%s" "%s" "%s" "%s" "%s" "%s" ' % (self.http_params['header']['User-Agent'], baseUrl2, wsUrl2, wsUrl1, stoken, streamId, libsPath, baseParams2['sid']) vidUrl = strwithmeta("ext://url/" + cItem['url'], {'iptv_proto':'em3u8', 'iptv_refresh_cmd':pyCmd, 'Referer':cItem['url'], 'User-Agent':self.http_params['header']['User-Agent']}) printDBG("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++") printDBG(pyCmd) printDBG("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++") #return [] return [{'name':'pierwsza_hls', 'url':vidUrl}] except Exception: printExc() return [] return urlsTab def doLogin(self, login, password): logged = False loginUrl = self.MAIN_URL + 'account/log-in' params = dict(self.http_params) params['load_cookie'] = False sts, data = self.cm.getPage(loginUrl, params) if not sts: return False _token = self.cm.ph.getSearchGroups(data, '''_token"[\s]*?value="([^"]+?)"''', 1, True)[0] HTTP_HEADER= dict(self.HTTP_HEADER) HTTP_HEADER.update( {'Referer':loginUrl} ) post_data = {'email' : login, 'password' : password, '_token' : _token, 'remember_me' : 'on' } params = {'header' : HTTP_HEADER, 'cookiefile' : self.COOKIE_FILE, 'save_cookie' : True, 'load_cookie' : True} sts, data = self.cm.getPage( loginUrl, params, post_data) if sts: if os_path.isfile(self.COOKIE_FILE): if 'dashboard/logout' in data: printDBG('PierwszaTVApi.doLogin login as [%s]' % login) logged = True else: printDBG('PierwszaTVApi.doLogin login failed - wrong user or password?') else: printDBG('PierwszaTVApi.doLogin there is no cookie file after login') return logged
class PurecastNetApi: MAIN_URL = 'http://api.pure-cast.net/' MOVIE_URL = MAIN_URL + 'filmy' LIVE_URL = MAIN_URL + 'kanaly' VER_URL = MAIN_URL + 'wersja' AUTH = '?email={0}&pass={1}' HTTP_HEADER = { 'User-Agent': 'XBMC', 'ContentType': 'application/x-www-form-urlencoded' } def __init__(self): self.cm = common() self.up = urlparser() self.sessionEx = MainSessionWrapper() self.defParams = {'header':self.HTTP_HEADER} self.warned = False def id_generator(self, size=18, chars=string.ascii_uppercase + string.digits): return ''.join(random.choice(chars) for _ in range(size)) def cleanHtmlStr(self, str): return CBaseHostClass.cleanHtmlStr(str) def getChannelsList(self, cItem): printDBG("PurecastNetApi.getChannelsList") login = config.plugins.iptvplayer.purecastnet_login.value passwd = config.plugins.iptvplayer.purecastnet_password.value if ('' == login or '' == passwd) and not self.warned: self.sessionEx.open(MessageBox, _("There are no active premium account.\nUsing a limited version that may not work properly with congested links."), type = MessageBox.TYPE_INFO, timeout = 10 ) self.warned = True channelsTab = [] privCategory = cItem.get('priv_category', None) if None == privCategory: for item in [('Telewizja Online', 'tv'), ('Filmy Online', 'filmy')]: params = dict(cItem) params.update({'title':item[0], 'priv_category':item[1]}) channelsTab.append(params) return channelsTab elif 'tv' == privCategory: url = self.LIVE_URL prefix = 'station' elif 'filmy' == privCategory: url = self.MOVIE_URL prefix = 'movie' url += self.AUTH.format(login, passwd) sts, data = self.cm.getPage(url, self.defParams) if not sts: return [] try: data = byteify(json.loads(data)) for item in data: params = dict(cItem) params.update({'type':'video', 'title':item[prefix+'Name'], 'icon':item[prefix+'Logo'], 'vid_url':item[prefix+'URL'].replace('swfVfy=true', ' ')}) channelsTab.append(params) except: printExc() return channelsTab def getPage(self, url, params={}, post_data=None): proxy = 'http://www.proxy-german.de/index.php?q={0}&hl=240'.format(urllib.quote_plus(url)) params['header']['Referer'] = proxy url = proxy return self.cm.getPage(url, params, post_data) def getVideoLink(self, cItem): printDBG("PurecastNetApi.getVideoLink") urlsTab = [{'name':'kodi', 'url':cItem['vid_url']}] if 0: channelID = self.cm.ph.getSearchGroups(cItem['vid_url'], '[^\?]+?/([^/^\?]+?)\?')[0] url = 'http://pure-cast.net/kanalyPlayer?id=%s' % channelID HTTP_HEADER = dict(self.HTTP_HEADER) HTTP_HEADER['User-Agent'] = self.id_generator() HTTP_HEADER['X-Forwarded-For'] = ".".join(map(str, (random.randint(0, 255) for _ in range(4)))) sts, data = self.getPage(url, {'header':HTTP_HEADER}) if not sts: return urlsTab rtmpUrl = self.cm.ph.getSearchGroups(data, '''["'](rtmp[^'^"]+?)['"]''')[0] url = rtmpUrl + ' swfUrl=http://pure-cast.net/jwplayer/jwplayer.flash.swf live=live' if url.startswith('rtmp://'): urlsTab.append({'name':'webpage', 'url':url}) return urlsTab
class SatLiveApi: MAINURL = 'http://web-live.tv/' LIST_URL = MAINURL + 'transmissions/transmission/index' SWF_URL = MAINURL + 'themes/default/swf/jwplayer.flash.swf' LOGIN_URL = MAINURL + 'site/site/login' HTTP_HEADER = { 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:12.0) Gecko/20100101 Firefox/12.0', 'Referer': MAINURL } def __init__(self): self.COOKIE_FILE = GetCookieDir('satlivetv.cookie') self.cm = common() self.sessionEx = MainSessionWrapper() self.loggedIn = True self.http_params = {} #self._reInit() #self.channelsList = [] def getChannelsList(self): printDBG("SatLiveApi.getChannelsList") # login premium = config.plugins.iptvplayer.satlivetv_premium.value login = config.plugins.iptvplayer.satlivetv_login.value password = config.plugins.iptvplayer.satlivetv_password.value if premium: if self.doLogin(login, password): self.loggedIn = True self.http_params.update({'save_cookie': True, 'load_cookie': True, 'cookiefile': self.COOKIE_FILE}) else: self.sessionEx.open(MessageBox, _('Problem z zalogowanie użytkownika "%s. Sprawdź dane do logowania w konfiguracji hosta."') % login, type = MessageBox.TYPE_INFO, timeout = 10 ) # get channels channelsList = [] sts, data = self.cm.getPage(SatLiveApi.LIST_URL, self.http_params) if not sts: return [] data = self.cm.ph.getDataBeetwenMarkers(data, '<div class="tab-pane active" id="live">', '<div class="tab-pane" id="all">', False)[1] data = data.split('</li>') for item in data: tmp = self.cm.ph.getSearchGroups(item, '<h4><a href="([^"]+?)">([^<]+?)</a></h4>', 2) if '' != tmp[0]: params = {} params['url'] = SatLiveApi.MAINURL + tmp[0] params['title'] = tmp[1] icon = self.cm.ph.getSearchGroups(item, '<img class="" src="([^"]+?)"')[0] if '' != icon: params['icon'] = SatLiveApi.MAINURL + icon params['desc'] = self.cm.ph.removeDoubles(clean_html(item.replace('>', '> ')).replace('\t', ' '), ' ') channelsList.append(params) return channelsList def getVideoLink(self, url): printDBG("SatLiveApi.getVideoLink") id = self.cm.ph.getSearchGroups(url+"/", 'id/([0-9]+?)/')[0] sts, data = self.cm.getPage(SatLiveApi.MAINURL + 'ge/' + id, self.http_params) if not sts: return '' base = self.cm.ph.getSearchGroups(data, 'base="([^"]+?)"')[0] src = self.cm.ph.getSearchGroups(data, 'src="([^"]+?)"')[0] if base.startswith('rtmp'): return base + '/' + src + ' swfUrl=%s live=1' % SatLiveApi.SWF_URL return '' def doLogin(self, login, password): logged = False HTTP_HEADER= dict(SatLiveApi.HTTP_HEADER) HTTP_HEADER.update( {'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8', 'X-Requested-With' : 'XMLHttpRequest'} ) post_data = {'LoginForm[email]' : login, 'LoginForm[password]' : password, 'ajax' : 'fast-login-form', 'undefined' : '' } params = {'header' : HTTP_HEADER, 'cookiefile' : self.COOKIE_FILE, 'save_cookie' : True} sts, data = self.cm.getPage( SatLiveApi.LOGIN_URL, params, post_data) if sts: if os_path.isfile(self.COOKIE_FILE): printDBG(data) if '[]' == data: printDBG('SatLiveApi.doLogin login as [%s]' % login) logged = True else: printDBG('SatLiveApi.doLogin login failed - wrong user or password?') else: printDBG('SatLiveApi.doLogin there is no cookie file after login') return logged
class UstvnowApi: MAIN_URL = 'http://m.ustvnow.com/' LIVE_URL = MAIN_URL + 'iphone/1/live/playingnow?pgonly=true' HTTP_HEADER = { 'User-Agent': 'Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10', 'Referer': MAIN_URL } def __init__(self): self.cm = common() self.up = urlparser() self.sessionEx = MainSessionWrapper() self.cookiePath = GetCookieDir('ustvnow.cookie') self.token = '' self.passkey = '' HTTP_HEADER = dict(self.HTTP_HEADER) HTTP_HEADER.update( {'Content-Type': 'application/x-www-form-urlencoded'}) self.defParams = { 'header': HTTP_HEADER, 'cookiefile': self.cookiePath, 'use_cookie': True, 'load_cookie': True, 'save_cookie': True } def getFullUrl(self, url): if url.startswith('//'): return 'http:' + url if url.startswith('/'): url = url[1:] if 0 < len(url) and not url.startswith('http'): url = self.MAIN_URL + url if not self.MAIN_URL.startswith('https://'): url = url.replace('https://', 'http://') return url def cleanHtmlStr(self, str): return CBaseHostClass.cleanHtmlStr(str) def _getChannelsNames(self): printDBG("UstvnowApi._getChannelsNames") url = 'http://m.ustvnow.com/gtv/1/live/listchannels?%s' % urllib.urlencode( {'token': self.token}) sts, data = self.cm.getPage(url) if not sts: return [] channelList = [] try: data = json_loads(data) for item in data['results']['streamnames']: params = {} params['sname'] = item['sname'] params['img'] = item['img'] params['scode'] = item['scode'] params['t'] = item['t'] params['callsign'] = item['callsign'] params['prgsvcid'] = item['prgsvcid'] params['data_provider'] = item['data_provider'] params['lang'] = item['lang'] params['af'] = item['af'] channelList.append(params) printDBG(channelList) except Exception: printExc() return channelList def getChannelsList(self, cItem): printDBG("UstvnowApi.getChannelsList") login = config.plugins.iptvplayer.ustvnow_login.value passwd = config.plugins.iptvplayer.ustvnow_password.value if '' != login.strip() and '' != passwd.strip(): self.token = self.doLogin(login, passwd) self.passkey = self.getPasskey() if self.token == '' or self.passkey == '': self.sessionEx.open( MessageBox, _('An error occurred when try to sign in the user "%s.\nPlease check your login credentials and try again later..."' ) % login, type=MessageBox.TYPE_INFO, timeout=10) return [] else: self.sessionEx.open( MessageBox, _('You need to enter email and password in configuration.'), type=MessageBox.TYPE_INFO, timeout=10) return [] sts, data = self.cm.getPage(self.LIVE_URL, self.defParams) if not sts: return [] channelsNames = self._getChannelsNames() channelsTab = [] data = self.cm.ph.getDataBeetwenMarkers( data, '<div data-role="content" data-theme="c">', '</ul>', False)[1] data = data.split('</li>') prgsvcidMap = {} for item in data: url = self.cm.ph.getSearchGroups(item, 'href="([^"]+?)"')[0] ui = url.split('ui-page=')[-1] icon = self.cm.ph.getSearchGroups(item, 'src="([^"]+?)"')[0] desc = self.cleanHtmlStr(item) params = dict(cItem) params.pop('url') params.update({ 'priv_url': self.getFullUrl(url), 'ui_page': ui, 'icon': icon, 'desc': desc }) for nameItem in channelsNames: if nameItem['img'] in icon: if config.plugins.iptvplayer.ustvnow_only_available.value and 0 == nameItem[ 't']: break params[ 'title'] = nameItem['sname'] + ' [%s]' % nameItem['t'] params['prgsvcid'] = nameItem['prgsvcid'] params['scode'] = nameItem['scode'] prgsvcidMap[params['prgsvcid']] = len(channelsTab) channelsTab.append(params) break # calculate time difference from utcnow and the local system time reported by OS OFFSET = datetime.now() - datetime.utcnow() if config.plugins.iptvplayer.ustvnow_epg.value: sts, data = self.cm.getPage( self.MAIN_URL + 'gtv/1/live/channelguide', self.defParams) if sts: try: data = json_loads(data) for item in data['results']: if item['prgsvcid'] in prgsvcidMap: idx = prgsvcidMap[item['prgsvcid']] utc_date = datetime.strptime( item.get('event_date', '') + ' ' + item.get('event_time', ''), '%Y-%m-%d %H:%M:%S') utc_date = utc_date + OFFSET if utc_date.time().second == 59: utc_date = utc_date + timedelta(0, 1) channelsTab[idx][ 'desc'] += '[/br][/br] [%s][/br]%s[/br]%s[/br]%s[/br]%s' % ( utc_date.strftime('%Y-%m-%d %H:%M:%S'), item.get('title', ''), item.get('synopsis', ''), item.get('description', ''), item.get('episode_title', '')) except Exception: printExc() return channelsTab def doLogin(self, login, password): printDBG("UstvnowApi.doLogin") rm(self.cookiePath) token = '' sts, data = self.cm.getPage(self.getFullUrl('iphone/1/live/settings'), self.defParams) if not sts: return token printDBG("===") printDBG(data) printDBG("===") url = self.getFullUrl( self.cm.ph.getSearchGroups(data, '''action=['"]([^'^"]+?)['"]''')[0]) if not self.cm.isValidUrl(url): return token post_data = { 'username': login, 'password': password, 'device': 'iphone' } sts, data = self.cm.getPage(url, self.defParams, post_data) if sts: token = self.cm.getCookieItem(self.cookiePath, 'token') return token def getPasskey(self): url = 'http://m.ustvnow.com/gtv/1/live/viewdvrlist?%s' % urllib.urlencode( {'token': self.token}) sts, data = self.cm.getPage(url) if not sts: return '' try: data = json_loads(data) return data['globalparams']['passkey'] except Exception: return '' def getVideoLink(self, cItem): printDBG("UstvnowApi.getVideoLink %s" % cItem) urlsTab = [] cookieParams = { 'cookiefile': self.cookiePath, 'use_cookie': True, 'load_cookie': True, 'save_cookie': True } sts, data = self.cm.getPage( 'http://m-api.ustvnow.com/stream/1/live/view?scode=%s&token=%s&key=%s' % (cItem.get('scode', ''), self.token, self.passkey), self.defParams) if sts: try: data = json_loads(data) tmp = getDirectM3U8Playlist(strwithmeta( data['stream'], {'User-Agent': self.HTTP_HEADER['User-Agent']}), cookieParams=cookieParams, checkContent=True) cookieValue = self.cm.getCookieHeader(self.cookiePath) for item in tmp: vidUrl = item['url'] item['url'] = urlparser.decorateUrl( vidUrl, { 'User-Agent': self.HTTP_HEADER['User-Agent'], 'Cookie': cookieValue }) urlsTab.append(item) if len(urlsTab): return urlsTab except Exception: printExc() sts, data = self.cm.getPage(self.LIVE_URL, self.defParams) if not sts: return [] url = self.cm.ph.getSearchGroups( data, 'for="popup-%s"[^>]*?href="([^"]+?)"[^>]*?>' % cItem['ui_page'])[0] url = self.getFullUrl(url) sts, data = self.cm.getPage(url, self.defParams) if not sts: return [] url = self.cm.ph.getSearchGroups(data, 'src="([^"]+?)"')[0] tmp = getDirectM3U8Playlist(strwithmeta( url, {'User-Agent': self.HTTP_HEADER['User-Agent']}), cookieParams=cookieParams, checkContent=True) cookieValue = self.cm.getCookieHeader(self.cookiePath) for item in tmp: vidUrl = item['url'] item['url'] = urlparser.decorateUrl( vidUrl, { 'User-Agent': self.HTTP_HEADER['User-Agent'], 'Cookie': cookieValue }) urlsTab.append(item) return urlsTab
class ZalukajCOM(CBaseHostClass): USER_AGENT = 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.18) Gecko/20110621 Mandriva Linux/1.9.2.18-0.1mdv2010.2 (2010.2) Firefox/3.6.18' HEADER = { 'User-Agent': USER_AGENT, 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' } AJAX_HEADER = dict(HEADER) AJAX_HEADER.update({ 'X-Requested-With': 'XMLHttpRequest', 'Connection': 'keep-alive', 'Pragma': 'no-cache', 'Cache-Control': 'no-cache' }) DOMAIN = 'zalukaj.com' MAIN_URL = 'https://' + DOMAIN + '/' FILMS_URL = MAIN_URL + '/gatunek,%d/%s,%s,strona-%d' SEARCH_URL = MAIN_URL + '/szukaj' LOGIN_URL = MAIN_URL + '/account.php' DEFAULT_ICON_URL = 'http://www.userlogos.org/files/logos/8596_famecky/zalukaj.png' MAIN_CAT_TAB = [{ 'category': 'films_sub_menu', 'title': "Filmy", 'url': '' }, { 'category': 'series_sub_menu', 'title': "Seriale", 'url': MAIN_URL }, { 'category': 'search', 'title': "Szukaj filmu", 'search_item': True }, { 'category': 'search_history', 'title': _('Search history') }] FILMS_SUB_MENU = [{ 'category': 'films_category', 'title': 'Kategorie', 'url': MAIN_URL }, { 'category': 'films_list', 'title': 'Ostatnio oglądane', 'url': MAIN_URL + '/cache/lastseen.html' }, { 'category': 'films_list', 'title': 'Ostatnio dodane', 'url': MAIN_URL + '/cache/lastadded.html' }, { 'category': 'films_popular', 'title': 'Najpopularniejsze', 'url': '' }] FILMS_POPULAR = [{ 'category': 'films_list', 'title': 'Wczoraj', 'url': MAIN_URL + '/cache/wyswietlenia-wczoraj.html' }, { 'category': 'films_list', 'title': 'Ostatnie 7 dni', 'url': MAIN_URL + '/cache/wyswietlenia-tydzien.html' }, { 'category': 'films_list', 'title': 'W tym miesiącu', 'url': MAIN_URL + '/cache/wyswietlenia-miesiac.html' }] SERIES_SUB_MENU = [{ 'category': 'series_list', 'title': 'Lista', 'url': MAIN_URL }, { 'category': 'series_updated', 'title': 'Ostatnio zaktualizowane', 'url': MAIN_URL + '/seriale' }] LANGS_TAB = [{ 'title': 'Wszystkie', 'lang': 'wszystkie' }, { 'title': 'Z lektorem', 'lang': 'tlumaczone' }, { 'title': 'Napisy pl', 'lang': 'napisy-pl' }, { 'title': 'Nietłumaczone', 'lang': 'nie-tlumaczone' }] def __init__(self): printDBG("ZalukajCOM.__init__") CBaseHostClass.__init__(self, { 'history': 'ZalukajCOM', 'cookie': 'zalukajtv.cookie' }) self.loggedIn = None self.login = '' self.password = '' self.msg = '' def _getPage(self, url, http_params_base={}, params=None, loggedIn=None): if None == loggedIn: loggedIn = self.loggedIn HEADER = ZalukajCOM.HEADER if loggedIn: http_params = { 'header': HEADER, 'use_cookie': True, 'save_cookie': True, 'load_cookie': True, 'cookiefile': self.COOKIE_FILE } else: http_params = {'header': HEADER} http_params.update(http_params_base) return self.getPage(url, http_params, params) def getPage(self, url, addParams={}, post_data=None): HTTP_HEADER = dict(self.HEADER) addParams = dict(addParams) addParams.update({'header': HTTP_HEADER}) proxy = config.plugins.iptvplayer.zalukajtv_proxy.value if proxy != 'None': if proxy == 'proxy_1': proxy = config.plugins.iptvplayer.alternative_proxy1.value else: proxy = config.plugins.iptvplayer.alternative_proxy2.value addParams = dict(addParams) addParams.update({'http_proxy': proxy}) sts, data = self.cm.getPage(url, addParams, post_data) try: if 'Duze obciazenie!' in data: message = self.cleanHtmlStr( re.compile('<script.+?</script>', re.DOTALL).sub("", data)) GetIPTVNotify().push(message, 'info', 5) SetIPTVPlayerLastHostError(message) except Exception: pass return sts, data def getFullIconUrl(self, url): url = self.getFullUrl(url) proxy = config.plugins.iptvplayer.zalukajtv_proxy.value if proxy != 'None': if proxy == 'proxy_1': proxy = config.plugins.iptvplayer.alternative_proxy1.value else: proxy = config.plugins.iptvplayer.alternative_proxy2.value url = strwithmeta(url, {'iptv_http_proxy': proxy}) return url def _listLeftTable(self, cItem, category, m1, m2, sp): printDBG("ZalukajCOM.listLeftGrid") sts, data = self._getPage(cItem['url']) if not sts: return printDBG(data) data = self.cm.ph.getDataBeetwenMarkers(data, m1, m2, False)[1] data = data.split(sp) if len(data): del data[-1] for item in data: params = dict(cItem) url = self.getFullUrl( self.cm.ph.getSearchGroups(item, 'href="([^"]+?)"', 1)[0]) if self.DOMAIN not in url: continue params.update({ 'category': category, 'title': self.cleanHtmlStr(item), 'url': url }) self.addDir(params) def listFilmsCategories(self, cItem, category): printDBG("ZalukajCOM.listFilmsCategories") self._listLeftTable( cItem, category, '<table id="one" cellpadding="0" cellspacing="3">', '</table>', '</td>') def listSeries(self, cItem, category): printDBG("ZalukajCOM.listFilmsCategories") self._listLeftTable( cItem, category, '<table id="main_menu" cellpadding="0" cellspacing="3">', '</table>', '</td>') def listFilms(self, cItem): printDBG("ZalukajCOM.listFilms") url = cItem['url'] page = cItem.get('page', 1) nextPage = False extract = False try: cat = int(url.split('/')[-1]) sort = config.plugins.iptvplayer.zalukajtv_filmssort.value url = ZalukajCOM.FILMS_URL % (cat, sort, cItem['lang'], page) extract = True except Exception: pass sts, data = self._getPage(url, {}, cItem.get('post_data', None)) #self.cm.ph.writeToFile("/home/sulge/zalukaj.html", data) if not sts: return printDBG("ZalukajCOM data " + data) sp = '<div class="tivief4">' if not sp in data: sp = '<div class="details">' if extract: if self.cm.ph.getSearchGroups(data, 'strona\-(%d)[^0-9]' % (page + 1))[0] != '': nextPage = True m2 = '<div class="categories_page">' if m2 not in data: m2 = '<div class="doln">' data = self.cm.ph.getDataBeetwenMarkers(data, sp, m2, True)[1] data = data.split(sp) if len(data): del data[0] for item in data: year = self.cleanHtmlStr( self.cm.ph.getDataBeetwenMarkers(item, '<p>', '</p>', False)[1]) desc = self.cleanHtmlStr( self.cm.ph.getDataBeetwenMarkers(item, '</h3>', '</div>', False)[1]) more = self.cleanHtmlStr( self.cm.ph.getDataBeetwenMarkers(item, '<p class="few_more">', '</p>', False)[1]) desc = '%s | %s | %s |' % (year, more, desc) icon = self.getFullUrl( self.cm.ph.getDataBeetwenMarkers(item, 'background-image:url(', ')', False)[1]) if '' == icon: icon = self.getFullUrl( self.cm.ph.getSearchGroups(item, 'src="([^"]+?)"', 1)[0]) url = self.getFullUrl( self.cm.ph.getSearchGroups(item, '<a href="([^"]+?)"', 1)[0]) title = self.cleanHtmlStr( self.cm.ph.getSearchGroups(item, 'title="([^"]+?)"', 1)[0]) title2 = self.cleanHtmlStr( self.cm.ph.getDataBeetwenMarkers(item, '<h3>', '</h3>', False)[1]) if len(title) < len(title2): title = title2 if '' != url: self.addVideo({ 'title': title, 'url': url, 'desc': desc, 'icon': icon }) if nextPage: params = dict(cItem) params.update({'title': _('Next page'), 'page': page + 1}) self.addDir(params) def listUpdatedSeries(self, cItem, category): printDBG("ZalukajCOM.listUpdatedSeries") sts, data = self._getPage(cItem['url']) if not sts: return sp = '<div class="latest tooltip">' m2 = '<div class="doln">' data = self.cm.ph.getDataBeetwenMarkers(data, sp, m2, True)[1] data = data.split(sp) if len(data): del data[0] for item in data: icon = self.getFullUrl( self.cm.ph.getSearchGroups(item, 'src="([^"]+?)"', 1)[0]) url = self.getFullUrl( self.cm.ph.getSearchGroups(item, '<a href="([^"]+?)"', 1)[0]) title = self.cleanHtmlStr( self.cm.ph.getDataBeetwenMarkers(item, '<div class="latest_title">', '</div>', False)[1]) desc = self.cleanHtmlStr( self.cm.ph.getDataBeetwenMarkers(item, '<div class="latest_info">', '</div>', False)[1]) if '' == url: continue params = dict(cItem) params.update({ 'category': category, 'title': title, 'url': url, 'desc': desc, 'icon': icon }) self.addDir(params) def _listSeriesBase(self, cItem, category, m1, m2, sp): printDBG("ZalukajCOM._listSeriesBase") sts, data = self._getPage(cItem['url']) if not sts: return icon = self.getFullIconUrl( self.cm.ph.getSearchGroups( data, '''<img[^>]+?src=['"]([^'^"]*?/promote_serial/[^'^"]+?)['"]''') [0]) data = self.cm.ph.getDataBeetwenNodes(data, m1, m2, False)[1] data = data.split(sp) if len(data): del data[-1] for item in data: url = self.getFullUrl( self.cm.ph.getSearchGroups(item, 'href="([^"]+?)"', 1)[0]) title = self.cleanHtmlStr(item) if '' == url: continue params = dict(cItem) params.update({ 'category': category, 'title': title, 'url': url, 'icon': icon }) if 'video' == category: self.addVideo(params) else: self.addDir(params) def listSeriesSeasons(self, cItem, category): printDBG("ZalukajCOM.listSeriesSeasons") self._listSeriesBase(cItem, category, ('<div', '>', '"sezony"'), ('<div', '>', 'class="doln2"'), '</div>') if 1 == len(self.currList): newItem = self.currList[0] self.currList = [] self.listSeriesEpisodes(newItem) def listSeriesEpisodes(self, cItem): printDBG("ZalukajCOM.listSeriesEpisodes") self._listSeriesBase(cItem, 'video', ('<div', '>', '"odcinkicat"'), ('<div', '>', 'class="doln2"'), '</div>') def listSearchResult(self, cItem, searchPattern, searchType): printDBG( "ZalukajCOM.listSearchResult cItem[%s], searchPattern[%s] searchType[%s]" % (cItem, searchPattern, searchType)) #searchPattern = urllib.quote_plus(searchPattern) post_data = {'searchinput': searchPattern} szukaj = 'https://zalukaj.com/v2/ajax/load.search?html=1&q=%s' % searchPattern params = { 'name': 'category', 'category': 'films_list', 'url': szukaj, 'post_data': None } self.listFilms(params) def getLinksForVideo(self, cItem): printDBG("ZalukajCOM.getLinksForVideo url[%s]" % cItem['url']) self.tryTologin() if self.loggedIn: tries = [True, False] else: tries = [False] urlTab = [] for loggedIn in tries: url = cItem['url'] sts, data = self._getPage(url, loggedIn=loggedIn) if not sts: continue url = self.getFullUrl( self.cm.ph.getSearchGroups(data, '"([^"]+?player.php[^"]+?)"', 1)[0]) if '' == url: printDBG('No player.php in data') data = self.cm.ph.getDataBeetwenMarkers( data, 'Oglądaj Film Online', '<div class="doln">', False)[1] url = self.getFullUrl( self.cm.ph.getSearchGroups(data, 'href="([^"]+?)"[^>]*?target', 1)[0]) urlTab.extend(self.up.getVideoLinkExt(url)) continue sts, data = self._getPage(url, loggedIn=loggedIn) if not sts: continue url = self.getFullUrl( self.cm.ph.getSearchGroups(data, '<a href="([^"]+?)"', 1)[0]) if '' == url: printDBG('No href in data[%s]' % '') continue sts, data = self._getPage(url, loggedIn=loggedIn) if not sts: continue # First check for premium link premium = False premiumLinks = self.cm.ph.getSearchGroups( data, '"bitrates"\t?\:\t?(\[[^]]+?\])', 1)[0] if premiumLinks != '': printDBG("New premium premiumLinks: [%s]" % premiumLinks) try: premiumLinks = byteify(json.loads(premiumLinks)) for pItem in premiumLinks: urlTab.append({ 'name': 'zalukaj.tv premium ' + pItem.get('label', ''), 'url': pItem['url'] }) premium = True except Exception: printExc() if not premium: url = self.cm.ph.getSearchGroups(data, "url:'([^']+?)'", 1)[0] printDBG("Old premium url: [%s]" % url) if url.startswith('http'): urlTab.append({'name': 'zalukaj.tv premium ', 'url': url}) premium = True if not premium: printDBG('No premium link data[%s]' % data) tmp = self.cm.ph.getAllItemsBeetwenMarkers( data, '<source', '>', False, False) for item in tmp: if 'video/mp4' in item or '.mp4' in item: label = self.cm.ph.getSearchGroups( item, '''label=['"]([^"^']+?)['"]''')[0] res = self.cm.ph.getSearchGroups( item, '''res=['"]([^"^']+?)['"]''')[0] if label == '': label = res url = self.cm.ph.getSearchGroups( item, '''src=['"]([^"^']+?)['"]''')[0] if url.startswith('//'): url = 'http:' + url if not self.cm.isValidUrl(url): continue urlTab.append({ 'name': 'zalukaj.tv premium ' + label, 'url': strwithmeta(url, {'Referer': cItem['url']}) }) premium = True if not premium: url = self.getFullUrl( self.cm.ph.getSearchGroups(data, 'iframe src="([^"]+?)" width=', 1)[0]) if self.cm.isValidUrl(url): urlTab.extend(self.up.getVideoLinkExt(url)) # premium link should be checked at first, so if we have free link here break if len(urlTab): break return urlTab def captcha(self): self.USER_AGENT = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0' self.HTTP_HEADER = { 'User-Agent': self.USER_AGENT, 'DNT': '1', 'Accept': 'application/json, text/javascript, */*; q=0.01', 'Accept-Encoding': 'gzip, deflate', 'Referer': 'https://zalukaj.com/', 'Origin': 'https://zalukaj.com/' } self.defaultParams = { 'header': self.HTTP_HEADER, 'with_metadata': True, 'use_cookie': True, 'load_cookie': True, 'save_cookie': True, 'cookiefile': self.COOKIE_FILE } httpParams = dict(self.defaultParams) imgUrl = 'https://zalukaj.com/captcha-image' from copy import deepcopy from Plugins.Extensions.IPTVPlayer.components.iptvmultipleinputbox import IPTVMultipleInputBox from Plugins.Extensions.IPTVPlayer.components.asynccall import MainSessionWrapper self.sessionEx = MainSessionWrapper() captchaTitle = '' captchaLabel = _('Captcha') captchaTitle = captchaLabel sendLabel = _('Send') header = dict(self.HTTP_HEADER) header['Accept'] = 'image/png,image/*;q=0.8,*/*;q=0.5' params = dict(self.defaultParams) params.update({ 'maintype': 'image', 'subtypes': ['jpeg', 'png'], 'check_first_bytes': ['\xFF\xD8', '\xFF\xD9', '\x89\x50\x4E\x47'], 'header': header }) filePath = GetTmpDir('.iptvplayer_captcha.jpg') rm(filePath) ret = self.cm.saveWebFile(filePath, imgUrl.replace('&', '&'), params) if not ret.get('sts'): SetIPTVPlayerLastHostError(_('Fail to get "%s".') % imgUrl) return [] params = deepcopy(IPTVMultipleInputBox.DEF_PARAMS) params['accep_label'] = sendLabel params['title'] = captchaLabel params['status_text'] = captchaTitle params['status_text_hight'] = 200 params['with_accept_button'] = True params['list'] = [] item = deepcopy(IPTVMultipleInputBox.DEF_INPUT_PARAMS) item['label_size'] = (660, 110) item['input_size'] = (680, 25) item['icon_path'] = filePath item['title'] = _('Answer') item['input']['text'] = '' params['list'].append(item) params['vk_params'] = {'invert_letters_case': True} ret = 0 retArg = self.sessionEx.waitForFinishOpen(IPTVMultipleInputBox, params) printDBG(retArg) if retArg and len(retArg) and retArg[0]: return retArg[0][0].lower() else: return [] def tryTologin(self): printDBG('tryTologin start') config.plugins.iptvplayer.zalukajtv_login config.plugins.iptvplayer.zalukajtv_password if None == self.loggedIn or self.login != config.plugins.iptvplayer.zalukajtv_login.value or\ self.password != config.plugins.iptvplayer.zalukajtv_password.value: self.login = config.plugins.iptvplayer.zalukajtv_login.value self.password = config.plugins.iptvplayer.zalukajtv_password.value rm(self.COOKIE_FILE) self.loggedIn = False self.msg = '' if '' == self.login.strip() or '' == self.password.strip(): return False rm(self.COOKIE_FILE) captcha = self.captcha() sts, msg = False, 'Problem z zalogowaniem użytkownika \n"%s".' % self.login post_data = None sts, data = self._getPage(ZalukajCOM.LOGIN_URL, params=post_data, loggedIn=True) if sts: printDBG(data) hash = self.cm.ph.getSearchGroups( data, '''name="hash" value=['"]([^'^"]+?)['"]''')[0].strip() expires = self.cm.ph.getSearchGroups( data, '''"expires" value=['"]([^'^"]+?)['"]''')[0].strip() post_data = { 'expires': expires, 'hash': hash, 'username': self.login, 'password': self.password, 'captcha': captcha } #%(expires,hash,self.login,self.password) self.USER_AGENT = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0' self.HTTP_HEADER = { 'User-Agent': self.USER_AGENT, 'DNT': '1', 'Accept': 'application/json, text/javascript, */*; q=0.01', 'Accept-Encoding': 'gzip, deflate', 'Referer': 'https://zalukaj.com/', 'Origin': 'https://zalukaj.com/' } self.defaultParams = { 'header': self.HTTP_HEADER, 'with_metadata': True, 'use_cookie': True, 'load_cookie': True, 'save_cookie': True, 'cookiefile': self.COOKIE_FILE } httpParams = dict(self.defaultParams) httpParams['header'] = dict(httpParams['header']) httpParams['header']['Referer'] = 'https://zalukaj.com/' sts, data = self.cm.getPage('https://zalukaj.com/ajax/login', httpParams, post_data) printDBG(data) #printDBG( 'Host getInitList: chyba zalogowano do premium...' ) #if 'error' in data: captcha() sts, data = self._getPage( url=self.getFullUrl('/libs/ajax/login.php?login=1'), loggedIn=True) if sts: sts, data2 = self._getPage( self.getFullUrl('/libs/ajax/login.php?login=1'), loggedIn=True) if sts: printDBG(data) sts, tmp = self.cm.ph.getDataBeetwenMarkers( data, '<p>Typ Konta:', '</p>', False) if sts: tmp = tmp.replace('(kliknij by oglądać bez limitów)', '') msg = 'Zostałeś poprawnie zalogowany.' + '\nTyp Konta: ' + self.cleanHtmlStr( tmp) tmp = self.cm.ph.getDataBeetwenMarkers( data, '<p>Zebrane Punkty:', '</p>', False)[1].replace('» Wymień na VIP «', '') if '' != tmp: msg += '\nZebrane Punkty: ' + self.cleanHtmlStr( tmp) self.loggedIn = True if not self.loggedIn: self.sessionEx.open(MessageBox, msg, type=MessageBox.TYPE_INFO, timeout=10) else: self.msg = msg.replace('\n', '[/br]') return self.loggedIn def handleService(self, index, refresh=0, searchPattern='', searchType=''): printDBG('ZalukajCOM.handleService start') self.tryTologin() CBaseHostClass.handleService(self, index, refresh, searchPattern, searchType) name = self.currItem.get("name", None) category = self.currItem.get("category", '') printDBG( "ZalukajCOM.handleService: ---------> name[%s], category[%s] " % (name, category)) searchPattern = self.currItem.get("search_pattern", searchPattern) self.currList = [] if None == name: self.listsTab(ZalukajCOM.MAIN_CAT_TAB, { 'name': 'category', 'desc': self.msg }) #FILMS elif 'films_sub_menu' == category: self.listsTab(ZalukajCOM.FILMS_SUB_MENU, self.currItem) elif 'films_popular' == category: self.listsTab(ZalukajCOM.FILMS_POPULAR, self.currItem) elif 'films_category' == category: self.listFilmsCategories(self.currItem, 'add_lang') #LANGS elif 'add_lang' == category: newItem = dict(self.currItem) newItem.update({'category': 'films_list'}) self.listsTab(ZalukajCOM.LANGS_TAB, newItem) #LIST FILMS elif 'films_list' == category: self.listFilms(self.currItem) #SERIES elif 'series_sub_menu' == category: self.listsTab(ZalukajCOM.SERIES_SUB_MENU, self.currItem) elif 'series_list' == category: self.listSeries(self.currItem, 'series_seasons') elif 'series_updated' == category: self.listUpdatedSeries(self.currItem, 'series_episodes') elif 'series_seasons' == category: self.listSeriesSeasons(self.currItem, 'series_episodes') elif 'series_episodes' == category: self.listSeriesEpisodes(self.currItem) #WYSZUKAJ elif category in ["search", "search_next_page"]: cItem = dict(self.currItem) cItem.update({'search_item': False, 'name': 'category'}) self.listSearchResult(cItem, searchPattern, searchType) #HISTORIA WYSZUKIWANIA elif category == "search_history": self.listsHistory({ 'name': 'history', 'category': 'search' }, 'desc', _("Type: ")) else: printExc() CBaseHostClass.endHandleService(self, index, refresh)
class GoldVodTVApi: MAIN_URL = 'http://goldvod.tv/' HTTP_HEADER = { 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:12.0) Gecko/20100101 Firefox/12.0', 'Referer': MAIN_URL } def __init__(self): self.COOKIE_FILE = GetCookieDir('goldvodtv.cookie') self.sessionEx = MainSessionWrapper() self.cm = common() self.up = urlparser() self.http_params = {} self.http_params.update({ 'save_cookie': True, 'load_cookie': True, 'cookiefile': self.COOKIE_FILE }) self.cacheList = {} self.loggedIn = False def getFullUrl(self, url): if url.startswith('http'): return url elif url.startswith('/'): return self.MAIN_URL + url[1:] else: return self.MAIN_URL + url return url def cleanHtmlStr(self, str): return CBaseHostClass.cleanHtmlStr(str) def getChannelsList(self, cItem): printDBG("TelewizjadaNetApi.getChannelsList") login = config.plugins.iptvplayer.goldvodtv_login.value password = config.plugins.iptvplayer.goldvodtv_password.value if login != '' and password != '': if self.doLogin(login, password): self.loggedIn = True self.http_params.update({ 'save_cookie': True, 'load_cookie': True, 'cookiefile': self.COOKIE_FILE }) else: self.sessionEx.open( MessageBox, _('Problem z zalogowanie użytkownika "%s. Sprawdź dane do logowania w konfiguracji hosta."' ) % login, type=MessageBox.TYPE_INFO, timeout=10) self.loggedIn = False channelsTab = [] sts, data = self.cm.getPage(self.MAIN_URL + 'channels.html?show=on', self.http_params) if not sts: return [] sts, data = self.cm.ph.getDataBeetwenMarkers(data, '<div class="row">', "<div id='footer'>") data = self.cm.ph.getAllItemsBeetwenMarkers(data, '<a ', '</a>') for item in data: printDBG("item [%r]" % item) url = self.cm.ph.getSearchGroups(item, '''href=['"]([^"^']+?)['"]''')[0] icon = self.cm.ph.getSearchGroups(item, '''src=['"]([^"^']+?)['"]''')[0] id = self.cm.ph.getSearchGroups(url, '''[^0-9]([0-9]+?)[^0-9]''')[0] if '' != url: params = dict(cItem) params['url'] = self.getFullUrl(url) params['icon'] = self.getFullUrl(icon) params['title'] = self.cm.ph.getSearchGroups( item, '''title=['"]([^"^']+?)['"]''')[0] if '' == params['title']: params['title'] = self.cm.ph.getSearchGroups( item, '''alt=['"]([^"^']+?)['"]''')[0] if '' == params['title']: params['title'] = url.replace('.html', '').replace(',', ' ').title() params['desc'] = params['url'] channelsTab.append(params) return channelsTab def getVideoLink(self, cItem): printDBG("GoldVodTVApi.getVideoLink") if self.loggedIn: url = strwithmeta(cItem['url'], {'params': {'load_cookie': True}}) else: url = cItem['url'] return self.up.getVideoLinkExt(url) def doLogin(self, login, password): logged = False loginUrl = self.MAIN_URL + 'login.html' params = dict(self.http_params) params['load_cookie'] = False sts, data = self.cm.getPage(loginUrl, params) if not sts: return False HTTP_HEADER = dict(GoldVodTVApi.HTTP_HEADER) HTTP_HEADER.update({'Referer': loginUrl}) post_data = { 'login': login, 'pass': password, 'remember': 1, 'logged': '' } params = { 'header': HTTP_HEADER, 'cookiefile': self.COOKIE_FILE, 'save_cookie': True, 'load_cookie': True } sts, data = self.cm.getPage(loginUrl, params, post_data) if sts: if os_path.isfile(self.COOKIE_FILE): if 'logout.html' in data: printDBG('GoldVodTVApi.doLogin login as [%s]' % login) logged = True else: printDBG( 'GoldVodTVApi.doLogin login failed - wrong user or password?' ) else: printDBG( 'GoldVodTVApi.doLogin there is no cookie file after login') return logged
class PurecastNetApi: MAIN_URL = 'http://pure-cast.net/' MOVIE_URL = MAIN_URL + 'kodi-filmy' LIVE_URL = MAIN_URL + 'kodi-kanaly' AUTH = '?email={0}&pass={1}' HTTP_HEADER = { 'User-Agent': 'XBMC', 'ContentType': 'application/x-www-form-urlencoded' } def __init__(self): self.cm = common() self.up = urlparser() self.sessionEx = MainSessionWrapper() self.defParams = {'header': self.HTTP_HEADER} self.warned = False def id_generator(self, size=18, chars=string.ascii_uppercase + string.digits): return ''.join(random.choice(chars) for _ in range(size)) def cleanHtmlStr(self, str): return CBaseHostClass.cleanHtmlStr(str) def getChannelsList(self, cItem): printDBG("PurecastNetApi.getChannelsList") login = config.plugins.iptvplayer.purecastnet_login.value passwd = config.plugins.iptvplayer.purecastnet_password.value if ('' == login or '' == passwd) and not self.warned: self.sessionEx.open( MessageBox, _("There are no active premium account.\nUsing a limited version that may not work properly with congested links." ), type=MessageBox.TYPE_INFO, timeout=10) self.warned = True channelsTab = [] privCategory = cItem.get('priv_category', None) if None == privCategory: for item in [('Telewizja Online', 'tv'), ('Filmy Online', 'filmy')]: params = dict(cItem) params.update({'title': item[0], 'priv_category': item[1]}) channelsTab.append(params) return channelsTab elif 'tv' == privCategory: url = self.LIVE_URL prefix = 'station' elif 'filmy' == privCategory: url = self.MOVIE_URL prefix = 'movie' url += self.AUTH.format(login, passwd) sts, data = self.cm.getPage(url, self.defParams) if not sts: return [] try: data = byteify(json.loads(data)) for item in data: params = dict(cItem) params.update({ 'type': 'video', 'title': item[prefix + 'Name'], 'icon': item[prefix + 'Logo'], 'vid_url': item[prefix + 'URL'].replace('swfVfy=true', ' ') }) channelsTab.append(params) except: printExc() return channelsTab def getPage(self, url, params={}, post_data=None): proxy = 'http://www.proxy-german.de/index.php?q={0}&hl=240'.format( urllib.quote_plus(url)) params['header']['Referer'] = proxy url = proxy return self.cm.getPage(url, params, post_data) def getVideoLink(self, cItem): printDBG("PurecastNetApi.getVideoLink") urlsTab = [{'name': 'kodi', 'url': cItem['vid_url']}] if 0: channelID = self.cm.ph.getSearchGroups(cItem['vid_url'], '[^\?]+?/([^/^\?]+?)\?')[0] url = 'http://pure-cast.net/kanalyPlayer?id=%s' % channelID HTTP_HEADER = dict(self.HTTP_HEADER) HTTP_HEADER['User-Agent'] = self.id_generator() HTTP_HEADER['X-Forwarded-For'] = ".".join( map(str, (random.randint(0, 255) for _ in range(4)))) sts, data = self.getPage(url, {'header': HTTP_HEADER}) if not sts: return urlsTab rtmpUrl = self.cm.ph.getSearchGroups( data, '''["'](rtmp[^'^"]+?)['"]''')[0] url = rtmpUrl + ' swfUrl=http://pure-cast.net/jwplayer/jwplayer.flash.swf live=live' if url.startswith('rtmp://'): urlsTab.append({'name': 'webpage', 'url': url}) return urlsTab
class Host: currList = [] MAIN_URL = '' PREMIUM = False konto = '' HOST = 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.18) Gecko/20110621 Mandriva Linux/1.9.2.18-0.1mdv2010.2 (2010.2) Firefox/3.6.18' def __init__(self): printDBG( 'Host __init__ begin' ) self.exSession = MainSessionWrapper() self.COOKIEFILE = GetCookieDir('zalukajtv.cookie') self.cm = common() self.up = urlparser() self.history = CSearchHistoryHelper('wspolne') self.currList = [] printDBG( 'Host __init__ end' ) def setCurrList(self, list): printDBG( 'Host setCurrList begin' ) self.currList = list printDBG( 'Host setCurrList end' ) return def fullUrl(self, phUrl): if not phUrl.startswith('http'): if '/' == phUrl[0]: phUrl = '/' + phUrl phUrl = self.MAIN_URL + phUrl return phUrl def getInitList(self): printDBG( 'Host getInitList begin' ) #################################### # logowanie #################################### if config.plugins.iptvplayer.zalukajtvPREMIUM.value: url = 'http://zalukaj.tv/account.php' try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': True, 'host': self.HOST, 'use_cookie': True, 'save_cookie': True, 'load_cookie': False, 'cookiefile': self.COOKIEFILE, 'use_post': True, 'return_data': True },{'login': config.plugins.iptvplayer.zalukajtv_login.value, 'password': config.plugins.iptvplayer.zalukajtv_password.value}) except: printDBG( 'Host getInitList query error' ) printDBG( 'Host getInitList query error url:'+url ) printDBG( 'Host getInitList query error: Uzywam Player z limitami') data = None if data: self.PREMIUM = True printDBG( 'Host getInitList: chyba zalogowano do premium...' ) url = 'http://zalukaj.tv/libs/ajax/login.php?login=1' try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': True, 'host': self.HOST, 'use_cookie': True, 'save_cookie': False, 'load_cookie': True, 'cookiefile': self.COOKIEFILE, 'use_post': False, 'return_data': True }) printDBG( 'Host listsItems data: '+data ) parse = re.search('Typ Konta:.*?>(.*?)<.*?>(.*?)<', data, re.S) if parse: self.konto = '- Typ Konta: '+parse.group(1)+parse.group(2) else: self.konto = '' except: printDBG( 'Host getInitList: blad pobrania danych o koncie premium' ) if '' == self.konto: self.exSession.open(MessageBox, 'Problem z zalogowaniem użytkownika \n"%s" jako VIP.' % config.plugins.iptvplayer.zalukajtv_login.value, type = MessageBox.TYPE_INFO, timeout = 10) #if 'Wyloguj' in data: # self.PREMIUM = True # printDBG('Host getInitList:' + config.plugins.iptvplayer.zalukajtv_login.value + ', Zostales poprawnie zalogowany') #else: # printDBG('Host getInitList: Blad logowania, uzywam Player z limitami') #################################### self.currList = self.listsItems(-1, '', 'main-menu') printDBG( 'Host getInitList end' ) return self.currList def getListForItem(self, Index = 0, refresh = 0, selItem = None): printDBG( 'Host getListForItem begin' ) valTab = [] if len(self.currList[Index].urlItems) == 0: return valTab valTab = self.listsItems(Index, self.currList[Index].urlItems[0], self.currList[Index].urlSeparateRequest) self.currList = valTab printDBG( 'Host getListForItem end' ) return self.currList def getSearchResults(self, pattern, searchType = None): printDBG( "Host getSearchResults begin" ) printDBG( "Host getSearchResults pattern: " +pattern) valTab = [] valTab = self.listsItems(-1, pattern, 'search') #valTab = [] #test self.currList = valTab printDBG( "Host getSearchResults end" ) return self.currList def listsItems(self, Index, url, name = ''): printDBG( 'Host listsItems begin' ) printDBG( 'Host listsItems url: '+url ) valTab = [] if name == 'main-menu': printDBG( 'Host listsItems begin name='+name ) self.MAIN_URL = 'http://zalukaj.tv' valTab.append(CDisplayListItem('Filmy '+self.konto, 'http://zalukaj.tv', CDisplayListItem.TYPE_CATEGORY, ['http://zalukaj.tv/'], 'filmy', '', None)) valTab.append(CDisplayListItem('Seriale', 'http://zalukaj.tv/seriale', CDisplayListItem.TYPE_CATEGORY, ['http://zalukaj.tv/seriale'], 'seriale', '', None)) valTab.append(CDisplayListItem('Szukaj', 'Szukaj filmów', CDisplayListItem.TYPE_SEARCH, ['http://szukaj.zalukaj.tv/szukaj'], 'seriale', '', None)) valTab.append(CDisplayListItem('Historia wyszukiwania', 'Historia wyszukiwania', CDisplayListItem.TYPE_CATEGORY, ['http://zalukaj.tv/seriale'], 'history', '', None)) printDBG( 'Host listsItems end' ) return valTab # ########## # if 'history' == name: printDBG( 'Host listsItems begin name='+name ) for histItem in self.history.getHistoryList(): valTab.append(CDisplayListItem(histItem['pattern'], 'Szukaj ', CDisplayListItem.TYPE_CATEGORY, [histItem['pattern'],histItem['type']], 'search', '', None)) printDBG( 'Host listsItems end' ) return valTab # ########## # if 'search' == name: printDBG( 'Host listsItems begin name='+name ) pattern = url if Index==-1: self.history.addHistoryItem( pattern, 'video') url = 'http://k.zalukaj.tv/szukaj' try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': True, 'return_data': True },{'searchinput': pattern}) except: printDBG( 'Host listsItems query error' ) printDBG( 'Host listsItems query error url:'+url ) return valTab #printDBG( 'Host listsItems data: '+data ) phMovies = re.findall('class="tivief4".*?src="(.*?)".*?<a href="(.*?)".*?title="(.*?)".*?div style.*?">(.*?)<.*?class="few_more">(.*?)<', data, re.S) if phMovies: for (phImage, phUrl, phTitle, phDescr, phMore) in phMovies: printDBG( 'Host listsItems phImage: ' +phImage ) printDBG( 'Host listsItems phUrl: ' +phUrl ) printDBG( 'Host listsItems phTitle: ' +phTitle ) printDBG( 'Host listsItems phDescr: ' +phDescr ) printDBG( 'Host listsItems phMore: ' +phMore ) valTab.append(CDisplayListItem(phTitle, phMore+' | '+decodeHtml(phDescr), CDisplayListItem.TYPE_VIDEO, [CUrlItem('', phUrl, 1)], 0, phImage, None)) printDBG( 'Host listsItems end' ) return valTab # ########## # if 'seriale' == name: printDBG( 'Host listsItems begin name='+name ) self.MAIN_URL = 'http://zalukaj.tv' try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True }) except: printDBG( 'Host listsItems query error' ) printDBG( 'Host listsItems query error url:'+url ) return valTab #printDBG( 'Host listsItems data: '+data ) parse = re.search('<div id="two"(.*?)</table>', data, re.S) if not parse: return '' phMovies = re.findall('<td class="wef32f"><a href="(.*?)" title="(.*?)"', parse.group(1), re.S) if phMovies: for (phUrl, phTitle) in phMovies: printDBG( 'Host listsItems phUrl: ' +phUrl ) printDBG( 'Host listsItems phTitle: '+phTitle ) valTab.append(CDisplayListItem(phTitle, phTitle, CDisplayListItem.TYPE_CATEGORY, [self.fullUrl(phUrl)], 'seriale-sezony', '', None)) valTab.insert(0,CDisplayListItem('--Ostatnio zaktualizowane seriale--', 'Ostatnio zaktualizowane seriale', CDisplayListItem.TYPE_CATEGORY, ['http://zalukaj.tv/seriale'], 'seriale-last', '', None)) printDBG( 'Host listsItems end' ) return valTab if 'seriale-last' == name: printDBG( 'Host listsItems begin name='+name ) self.MAIN_URL = 'http://zalukaj.tv' try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True }) except: printDBG( 'Host listsItems query error' ) printDBG( 'Host listsItems query error url:'+url ) return valTab #printDBG( 'Host listsItems data: '+data ) phMovies = re.findall('<div class="latest tooltip".*?href="(.*?)" title="(.*?)".*?src="(.*?)"', data, re.S) if phMovies: for (phUrl, phTitle, phImage) in phMovies: printDBG( 'Host listsItems phUrl: ' +phUrl ) printDBG( 'Host listsItems phTitle: '+phTitle ) printDBG( 'Host listsItems phImage: '+phImage ) valTab.append(CDisplayListItem(phTitle, phTitle, CDisplayListItem.TYPE_CATEGORY, [self.fullUrl(phUrl)], 'seriale-sezon', phImage, None)) printDBG( 'Host listsItems end' ) return valTab if 'seriale-sezony' == name: printDBG( 'Host listsItems begin name='+name ) self.MAIN_URL = 'http://zalukaj.tv' try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True }) except: printDBG( 'Host listsItems query error' ) printDBG( 'Host listsItems query error url:'+url ) return valTab #printDBG( 'Host listsItems data: '+data ) phImage = '' parse = re.search('<div id="sezony".*?img src="(.*?)"', data, re.S) if parse: phImage = parse.group(1) printDBG( 'Host listsItems phImage: ' +phImage ) phMovies = re.findall('<a class="sezon" href="(.*?)".*?>(.*?)<', data, re.S) if phMovies: for (phUrl, phTitle) in phMovies: printDBG( 'Host listsItems phUrl: ' +phUrl ) printDBG( 'Host listsItems phTitle: '+phTitle ) valTab.append(CDisplayListItem(phTitle, phTitle, CDisplayListItem.TYPE_CATEGORY, [self.fullUrl(phUrl)], 'seriale-sezon', phImage, None)) printDBG( 'Host listsItems end' ) return valTab if 'seriale-sezon' == name: printDBG( 'Host listsItems begin name='+name ) self.MAIN_URL = 'http://zalukaj.tv' try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True }) except: printDBG( 'Host listsItems query error' ) printDBG( 'Host listsItems query error url:'+url ) return valTab #printDBG( 'Host listsItems data: '+data ) phImage = '' parse = re.search('<img src="(.*?)"', data, re.S) if parse: phImage = parse.group(1) printDBG( 'Host listsItems phImage: ' +phImage ) phMovies = re.findall('id="sezony".*?>(.*?)<.*?href="(.*?)" title="(.*?)"', data, re.S) if phMovies: for (phEpisode, phUrl, phTitle) in phMovies: printDBG( 'Host listsItems phEpizod: ' +phEpisode ) printDBG( 'Host listsItems phUrl: ' +phUrl ) printDBG( 'Host listsItems phTitle: '+phTitle ) valTab.append(CDisplayListItem(phEpisode+' - '+phTitle, phTitle, CDisplayListItem.TYPE_VIDEO, [CUrlItem('', self.fullUrl(phUrl), 1)], 0, phImage, None)) printDBG( 'Host listsItems end' ) return valTab if 'filmy' == name: printDBG( 'Host listsItems begin name='+name ) self.MAIN_URL = 'http://zalukaj.tv' try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True }) except: printDBG( 'Host listsItems query error' ) printDBG( 'Host listsItems query error url:'+url ) return valTab #printDBG( 'Host listsItems data: '+data ) sts,parse = CParsingHelper.getDataBeetwenMarkers(data, '<table id="one"', '</table>', False) phMovies = re.findall('<td class="wef32f"><a href="([^"]+?)">([^<]+?)</a>', parse, re.S) if phMovies: for (phUrl, phTitle) in phMovies: printDBG( 'Host listsItems phUrl: ' + phUrl ) printDBG( 'Host listsItems phTitle: ' + phTitle ) valTab.append(CDisplayListItem(phTitle, phTitle, CDisplayListItem.TYPE_CATEGORY, [ self.fullUrl(phUrl) ], 'filmy-clip', '', None)) #valTab.insert(0,CDisplayListItem('--Najpopularniejsze--', 'Najpopularniejsze wyswietlenia-miesiac', CDisplayListItem.TYPE_CATEGORY, ['http://zalukaj.tv/#wyswietlenia-miesiac'], 'filmy-last', '', None)) #valTab.insert(0,CDisplayListItem('--Ostatnio oglądane--', 'Ostatnio oglądane', CDisplayListItem.TYPE_CATEGORY, ['http://zalukaj.tv/#lastseen'], 'filmy-last', '', None)) valTab.insert(0,CDisplayListItem('--Ostatnio dodane--', 'Ostatnio dodane', CDisplayListItem.TYPE_CATEGORY, ['http://zalukaj.tv'], 'filmy-last', '', None)) printDBG( 'Host listsItems end' ) return valTab if 'filmy-clip' == name: printDBG( 'Host listsItems begin name='+name ) self.MAIN_URL = 'http://zalukaj.tv' try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True }) except: printDBG( 'Host listsItems query error' ) printDBG( 'Host listsItems query error url:'+url ) return valTab #printDBG( 'Host listsItems data: '+data ) phMovies = re.findall('background-image:url(.*?);"><p><span>(.*?)</span>.*?<h3><a href="(.*?)".*?">(.*?)<.*?">(.*?)<.*?class="few_more">(.*?)<', data, re.S) if phMovies: for (phImage, phRok, phUrl, phTitle, phDescr, phMore) in phMovies: printDBG( 'Host listsItems phImage: ' +phImage ) printDBG( 'Host listsItems phRok: ' +phRok ) printDBG( 'Host listsItems phUrl: ' +phUrl ) printDBG( 'Host listsItems phTitle: ' +phTitle ) printDBG( 'Host listsItems phDescr: ' +phDescr ) printDBG( 'Host listsItems phMore: ' +phMore ) valTab.append(CDisplayListItem(phTitle, phRok+' | '+phMore+' | '+decodeHtml(phDescr), CDisplayListItem.TYPE_VIDEO, [CUrlItem('', phUrl, 1)], 0, phImage[1:-1], None)) match = re.findall('class="pc_current">.*?href="(.*?)">(.*?)<', data, re.S) if match: phUrl = match[-1][0] phTitle = match[-1][1] valTab.append(CDisplayListItem('Strona '+phTitle, 'Strona: '+phUrl, CDisplayListItem.TYPE_CATEGORY, [self.fullUrl(phUrl)], name, '', None)) printDBG( 'Host listsItems end' ) return valTab if 'filmy-last' == name: printDBG( 'Host listsItems begin name='+name ) self.MAIN_URL = 'http://zalukaj.tv' try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True }) except: printDBG( 'Host listsItems query error' ) printDBG( 'Host listsItems query error url:'+url ) return valTab #printDBG( 'Host listsItems data: '+data ) phMovies = re.findall('class="tivief4".*?src="(.*?)".*?<h3><a href="(.*?)".*?">(.*?)<.*?">(.*?)<.*?class="few_more">(.*?)<', data, re.S) if phMovies: for (phImage, phUrl, phTitle, phDescr, phMore) in phMovies: printDBG( 'Host listsItems phImage: ' +phImage ) printDBG( 'Host listsItems phUrl: ' +phUrl ) printDBG( 'Host listsItems phTitle: ' +phTitle ) printDBG( 'Host listsItems phDescr: ' +phDescr ) printDBG( 'Host listsItems phMore: ' +phMore ) valTab.append(CDisplayListItem(phTitle, phMore+' | '+decodeHtml(phDescr), CDisplayListItem.TYPE_VIDEO, [CUrlItem('', self.fullUrl(phUrl), 1)], 0, phImage, None)) printDBG( 'Host listsItems end' ) return valTab return valTab def getResolvedURL(self, url): printDBG( 'Host getResolvedURL begin' ) printDBG( 'Host getResolvedURL url: '+url ) videoUrl = '' valTab = [] if self.PREMIUM: sts, data = self.cm.getPage(url, {'use_host': True, 'host': self.HOST, 'use_cookie': True, 'save_cookie': False, 'load_cookie': True, 'cookiefile': self.COOKIEFILE}) if sts: parse = re.search('/player.php.*?"', data, re.S) if parse: printDBG( 'parse1p: '+parse.group(0) ) url2 = self.fullUrl(parse.group(0)) sts, data = self.cm.getPage(url2, {'use_host': True, 'host': self.HOST, 'use_cookie': True, 'save_cookie': False, 'load_cookie': True, 'cookiefile': self.COOKIEFILE, 'use_post': False, 'return_data': True }) if sts: parse = re.search('<a href="(.*?)"', data, re.S) if parse: printDBG( 'parse2p: '+parse.group(1) ) url2 = parse.group(1) sts,data = self.cm.getPage(url2, { 'use_host': True, 'host': self.HOST, 'use_cookie': True, 'save_cookie': False, 'load_cookie': True, 'cookiefile': self.COOKIEFILE, 'use_post': False, 'return_data': True }) if sts: printDBG( 'parse3pdata ') match = re.compile("url:'(.+?)'").findall(data) if len(match) > 0: printDBG( 'parse3p: PREMIUM: '+match[0] ) linkvideo = match[0] return linkvideo else: printDBG( 'Host getResolvedURL query error premium' ) printDBG( 'Host getResolvedURL query error premium url: '+url2 ) else: printDBG( 'Host getResolvedURL query error premium' ) printDBG( 'Host getResolvedURL query error premium url: '+url2 ) else: printDBG( 'Host getResolvedURL query error premium' ) printDBG( 'Host getResolvedURL query error premium url: '+url ) if url[0:30] == 'http://zalukaj.tv/zalukaj-film' or url[0:31] == 'http://zalukaj.tv/serial-online': sts, data = self.cm.getPage(url) if not sts: printDBG( 'Host getResolvedURL query error' ) printDBG( 'Host getResolvedURL query error url: '+url ) return '' parse = re.search('/player.php.*?"', data, re.S) if not parse: return '' printDBG( 'parse1: '+parse.group(0) ) url2 = self.fullUrl(parse.group(0)) sts, data = self.cm.getPage(url2) if not sts: printDBG( 'Host getResolvedURL query error' ) printDBG( 'Host getResolvedURL query error url: '+ url2 ) return '' parse = re.search('<a href="([^"]+?)"', data, re.S) if not parse: return '' printDBG( 'parse2: '+parse.group(1) ) url2 = parse.group(1) sts, data = self.cm.getPage(url2) if not sts: return '' parse = re.search('iframe src="([^"]+?)" width=', data) if not parse: return '' ret = self.up.getVideoLink( parse.group(1) ) if ret: return ret return ''
class Host: currList = [] MAIN_URL = '' PREMIUM = False konto = '' HOST = 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.18) Gecko/20110621 Mandriva Linux/1.9.2.18-0.1mdv2010.2 (2010.2) Firefox/3.6.18' def __init__(self): printDBG('Host __init__ begin') self.exSession = MainSessionWrapper() self.COOKIEFILE = GetCookieDir('zalukajtv.cookie') self.cm = common() self.up = urlparser() self.history = CSearchHistoryHelper('wspolne') self.currList = [] printDBG('Host __init__ end') def setCurrList(self, list): printDBG('Host setCurrList begin') self.currList = list printDBG('Host setCurrList end') return def fullUrl(self, phUrl): if not phUrl.startswith('http'): if '/' == phUrl[0]: phUrl = '/' + phUrl phUrl = self.MAIN_URL + phUrl return phUrl def getInitList(self): printDBG('Host getInitList begin') #################################### # logowanie #################################### if config.plugins.iptvplayer.zalukajtvPREMIUM.value: url = 'http://zalukaj.tv/account.php' try: data = self.cm.getURLRequestData( { 'url': url, 'use_host': True, 'host': self.HOST, 'use_cookie': True, 'save_cookie': True, 'load_cookie': False, 'cookiefile': self.COOKIEFILE, 'use_post': True, 'return_data': True }, { 'login': config.plugins.iptvplayer.zalukajtv_login.value, 'password': config.plugins.iptvplayer.zalukajtv_password.value }) except: printDBG('Host getInitList query error') printDBG('Host getInitList query error url:' + url) printDBG( 'Host getInitList query error: Uzywam Player z limitami') data = None if data: self.PREMIUM = True printDBG('Host getInitList: chyba zalogowano do premium...') url = 'http://zalukaj.tv/libs/ajax/login.php?login=1' try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': True, 'host': self.HOST, 'use_cookie': True, 'save_cookie': False, 'load_cookie': True, 'cookiefile': self.COOKIEFILE, 'use_post': False, 'return_data': True }) printDBG('Host listsItems data: ' + data) parse = re.search('Typ Konta:.*?>(.*?)<.*?>(.*?)<', data, re.S) if parse: self.konto = '- Typ Konta: ' + parse.group( 1) + parse.group(2) else: self.konto = '' except: printDBG( 'Host getInitList: blad pobrania danych o koncie premium' ) if '' == self.konto: self.exSession.open( MessageBox, 'Problem z zalogowaniem użytkownika \n"%s" jako VIP.' % config.plugins.iptvplayer.zalukajtv_login.value, type=MessageBox.TYPE_INFO, timeout=10) #if 'Wyloguj' in data: # self.PREMIUM = True # printDBG('Host getInitList:' + config.plugins.iptvplayer.zalukajtv_login.value + ', Zostales poprawnie zalogowany') #else: # printDBG('Host getInitList: Blad logowania, uzywam Player z limitami') #################################### self.currList = self.listsItems(-1, '', 'main-menu') printDBG('Host getInitList end') return self.currList def getListForItem(self, Index=0, refresh=0, selItem=None): printDBG('Host getListForItem begin') valTab = [] if len(self.currList[Index].urlItems) == 0: return valTab valTab = self.listsItems(Index, self.currList[Index].urlItems[0], self.currList[Index].urlSeparateRequest) self.currList = valTab printDBG('Host getListForItem end') return self.currList def getSearchResults(self, pattern, searchType=None): printDBG("Host getSearchResults begin") printDBG("Host getSearchResults pattern: " + pattern) valTab = [] valTab = self.listsItems(-1, pattern, 'search') #valTab = [] #test self.currList = valTab printDBG("Host getSearchResults end") return self.currList def listsItems(self, Index, url, name=''): printDBG('Host listsItems begin') printDBG('Host listsItems url: ' + url) valTab = [] if name == 'main-menu': printDBG('Host listsItems begin name=' + name) self.MAIN_URL = 'http://zalukaj.tv' valTab.append( CDisplayListItem('Filmy ' + self.konto, 'http://zalukaj.tv', CDisplayListItem.TYPE_CATEGORY, ['http://zalukaj.tv/'], 'filmy', '', None)) valTab.append( CDisplayListItem('Seriale', 'http://zalukaj.tv/seriale', CDisplayListItem.TYPE_CATEGORY, ['http://zalukaj.tv/seriale'], 'seriale', '', None)) valTab.append( CDisplayListItem('Szukaj', 'Szukaj filmów', CDisplayListItem.TYPE_SEARCH, ['http://szukaj.zalukaj.tv/szukaj'], 'seriale', '', None)) valTab.append( CDisplayListItem('Historia wyszukiwania', 'Historia wyszukiwania', CDisplayListItem.TYPE_CATEGORY, ['http://zalukaj.tv/seriale'], 'history', '', None)) printDBG('Host listsItems end') return valTab # ########## # if 'history' == name: printDBG('Host listsItems begin name=' + name) for histItem in self.history.getHistoryList(): valTab.append( CDisplayListItem(histItem['pattern'], 'Szukaj ', CDisplayListItem.TYPE_CATEGORY, [histItem['pattern'], histItem['type']], 'search', '', None)) printDBG('Host listsItems end') return valTab # ########## # if 'search' == name: printDBG('Host listsItems begin name=' + name) pattern = url if Index == -1: self.history.addHistoryItem(pattern, 'video') url = 'http://k.zalukaj.tv/szukaj' try: data = self.cm.getURLRequestData( { 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': True, 'return_data': True }, {'searchinput': pattern}) except: printDBG('Host listsItems query error') printDBG('Host listsItems query error url:' + url) return valTab #printDBG( 'Host listsItems data: '+data ) phMovies = re.findall( 'class="tivief4".*?src="(.*?)".*?<a href="(.*?)".*?title="(.*?)".*?div style.*?">(.*?)<.*?class="few_more">(.*?)<', data, re.S) if phMovies: for (phImage, phUrl, phTitle, phDescr, phMore) in phMovies: printDBG('Host listsItems phImage: ' + phImage) printDBG('Host listsItems phUrl: ' + phUrl) printDBG('Host listsItems phTitle: ' + phTitle) printDBG('Host listsItems phDescr: ' + phDescr) printDBG('Host listsItems phMore: ' + phMore) valTab.append( CDisplayListItem(phTitle, phMore + ' | ' + decodeHtml(phDescr), CDisplayListItem.TYPE_VIDEO, [CUrlItem('', phUrl, 1)], 0, phImage, None)) printDBG('Host listsItems end') return valTab # ########## # if 'seriale' == name: printDBG('Host listsItems begin name=' + name) self.MAIN_URL = 'http://zalukaj.tv' try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True }) except: printDBG('Host listsItems query error') printDBG('Host listsItems query error url:' + url) return valTab #printDBG( 'Host listsItems data: '+data ) parse = re.search('<div id="two"(.*?)</table>', data, re.S) if not parse: return '' phMovies = re.findall( '<td class="wef32f"><a href="(.*?)" title="(.*?)"', parse.group(1), re.S) if phMovies: for (phUrl, phTitle) in phMovies: printDBG('Host listsItems phUrl: ' + phUrl) printDBG('Host listsItems phTitle: ' + phTitle) valTab.append( CDisplayListItem(phTitle, phTitle, CDisplayListItem.TYPE_CATEGORY, [self.fullUrl(phUrl)], 'seriale-sezony', '', None)) valTab.insert( 0, CDisplayListItem('--Ostatnio zaktualizowane seriale--', 'Ostatnio zaktualizowane seriale', CDisplayListItem.TYPE_CATEGORY, ['http://zalukaj.tv/seriale'], 'seriale-last', '', None)) printDBG('Host listsItems end') return valTab if 'seriale-last' == name: printDBG('Host listsItems begin name=' + name) self.MAIN_URL = 'http://zalukaj.tv' try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True }) except: printDBG('Host listsItems query error') printDBG('Host listsItems query error url:' + url) return valTab #printDBG( 'Host listsItems data: '+data ) phMovies = re.findall( '<div class="latest tooltip".*?href="(.*?)" title="(.*?)".*?src="(.*?)"', data, re.S) if phMovies: for (phUrl, phTitle, phImage) in phMovies: printDBG('Host listsItems phUrl: ' + phUrl) printDBG('Host listsItems phTitle: ' + phTitle) printDBG('Host listsItems phImage: ' + phImage) valTab.append( CDisplayListItem(phTitle, phTitle, CDisplayListItem.TYPE_CATEGORY, [self.fullUrl(phUrl)], 'seriale-sezon', phImage, None)) printDBG('Host listsItems end') return valTab if 'seriale-sezony' == name: printDBG('Host listsItems begin name=' + name) self.MAIN_URL = 'http://zalukaj.tv' try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True }) except: printDBG('Host listsItems query error') printDBG('Host listsItems query error url:' + url) return valTab #printDBG( 'Host listsItems data: '+data ) phImage = '' parse = re.search('<div id="sezony".*?img src="(.*?)"', data, re.S) if parse: phImage = parse.group(1) printDBG('Host listsItems phImage: ' + phImage) phMovies = re.findall('<a class="sezon" href="(.*?)".*?>(.*?)<', data, re.S) if phMovies: for (phUrl, phTitle) in phMovies: printDBG('Host listsItems phUrl: ' + phUrl) printDBG('Host listsItems phTitle: ' + phTitle) valTab.append( CDisplayListItem(phTitle, phTitle, CDisplayListItem.TYPE_CATEGORY, [self.fullUrl(phUrl)], 'seriale-sezon', phImage, None)) printDBG('Host listsItems end') return valTab if 'seriale-sezon' == name: printDBG('Host listsItems begin name=' + name) self.MAIN_URL = 'http://zalukaj.tv' try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True }) except: printDBG('Host listsItems query error') printDBG('Host listsItems query error url:' + url) return valTab #printDBG( 'Host listsItems data: '+data ) phImage = '' parse = re.search('<img src="(.*?)"', data, re.S) if parse: phImage = parse.group(1) printDBG('Host listsItems phImage: ' + phImage) phMovies = re.findall( 'id="sezony".*?>(.*?)<.*?href="(.*?)" title="(.*?)"', data, re.S) if phMovies: for (phEpisode, phUrl, phTitle) in phMovies: printDBG('Host listsItems phEpizod: ' + phEpisode) printDBG('Host listsItems phUrl: ' + phUrl) printDBG('Host listsItems phTitle: ' + phTitle) valTab.append( CDisplayListItem( phEpisode + ' - ' + phTitle, phTitle, CDisplayListItem.TYPE_VIDEO, [CUrlItem('', self.fullUrl(phUrl), 1)], 0, phImage, None)) printDBG('Host listsItems end') return valTab if 'filmy' == name: printDBG('Host listsItems begin name=' + name) self.MAIN_URL = 'http://zalukaj.tv' try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True }) except: printDBG('Host listsItems query error') printDBG('Host listsItems query error url:' + url) return valTab #printDBG( 'Host listsItems data: '+data ) sts, parse = CParsingHelper.getDataBeetwenMarkers( data, '<table id="one"', '</table>', False) phMovies = re.findall( '<td class="wef32f"><a href="([^"]+?)">([^<]+?)</a>', parse, re.S) if phMovies: for (phUrl, phTitle) in phMovies: printDBG('Host listsItems phUrl: ' + phUrl) printDBG('Host listsItems phTitle: ' + phTitle) valTab.append( CDisplayListItem(phTitle, phTitle, CDisplayListItem.TYPE_CATEGORY, [self.fullUrl(phUrl)], 'filmy-clip', '', None)) #valTab.insert(0,CDisplayListItem('--Najpopularniejsze--', 'Najpopularniejsze wyswietlenia-miesiac', CDisplayListItem.TYPE_CATEGORY, ['http://zalukaj.tv/#wyswietlenia-miesiac'], 'filmy-last', '', None)) #valTab.insert(0,CDisplayListItem('--Ostatnio oglądane--', 'Ostatnio oglądane', CDisplayListItem.TYPE_CATEGORY, ['http://zalukaj.tv/#lastseen'], 'filmy-last', '', None)) valTab.insert( 0, CDisplayListItem('--Ostatnio dodane--', 'Ostatnio dodane', CDisplayListItem.TYPE_CATEGORY, ['http://zalukaj.tv'], 'filmy-last', '', None)) printDBG('Host listsItems end') return valTab if 'filmy-clip' == name: printDBG('Host listsItems begin name=' + name) self.MAIN_URL = 'http://zalukaj.tv' try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True }) except: printDBG('Host listsItems query error') printDBG('Host listsItems query error url:' + url) return valTab #printDBG( 'Host listsItems data: '+data ) phMovies = re.findall( 'background-image:url(.*?);"><p><span>(.*?)</span>.*?<h3><a href="(.*?)".*?">(.*?)<.*?">(.*?)<.*?class="few_more">(.*?)<', data, re.S) if phMovies: for (phImage, phRok, phUrl, phTitle, phDescr, phMore) in phMovies: printDBG('Host listsItems phImage: ' + phImage) printDBG('Host listsItems phRok: ' + phRok) printDBG('Host listsItems phUrl: ' + phUrl) printDBG('Host listsItems phTitle: ' + phTitle) printDBG('Host listsItems phDescr: ' + phDescr) printDBG('Host listsItems phMore: ' + phMore) valTab.append( CDisplayListItem( phTitle, phRok + ' | ' + phMore + ' | ' + decodeHtml(phDescr), CDisplayListItem.TYPE_VIDEO, [CUrlItem('', phUrl, 1)], 0, phImage[1:-1], None)) match = re.findall('class="pc_current">.*?href="(.*?)">(.*?)<', data, re.S) if match: phUrl = match[-1][0] phTitle = match[-1][1] valTab.append( CDisplayListItem('Strona ' + phTitle, 'Strona: ' + phUrl, CDisplayListItem.TYPE_CATEGORY, [self.fullUrl(phUrl)], name, '', None)) printDBG('Host listsItems end') return valTab if 'filmy-last' == name: printDBG('Host listsItems begin name=' + name) self.MAIN_URL = 'http://zalukaj.tv' try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True }) except: printDBG('Host listsItems query error') printDBG('Host listsItems query error url:' + url) return valTab #printDBG( 'Host listsItems data: '+data ) phMovies = re.findall( 'class="tivief4".*?src="(.*?)".*?<h3><a href="(.*?)".*?">(.*?)<.*?">(.*?)<.*?class="few_more">(.*?)<', data, re.S) if phMovies: for (phImage, phUrl, phTitle, phDescr, phMore) in phMovies: printDBG('Host listsItems phImage: ' + phImage) printDBG('Host listsItems phUrl: ' + phUrl) printDBG('Host listsItems phTitle: ' + phTitle) printDBG('Host listsItems phDescr: ' + phDescr) printDBG('Host listsItems phMore: ' + phMore) valTab.append( CDisplayListItem( phTitle, phMore + ' | ' + decodeHtml(phDescr), CDisplayListItem.TYPE_VIDEO, [CUrlItem('', self.fullUrl(phUrl), 1)], 0, phImage, None)) printDBG('Host listsItems end') return valTab return valTab def getResolvedURL(self, url): printDBG('Host getResolvedURL begin') printDBG('Host getResolvedURL url: ' + url) videoUrl = '' valTab = [] if self.PREMIUM: sts, data = self.cm.getPage( url, { 'use_host': True, 'host': self.HOST, 'use_cookie': True, 'save_cookie': False, 'load_cookie': True, 'cookiefile': self.COOKIEFILE }) if sts: parse = re.search('/player.php.*?"', data, re.S) if parse: printDBG('parse1p: ' + parse.group(0)) url2 = self.fullUrl(parse.group(0)) sts, data = self.cm.getPage( url2, { 'use_host': True, 'host': self.HOST, 'use_cookie': True, 'save_cookie': False, 'load_cookie': True, 'cookiefile': self.COOKIEFILE, 'use_post': False, 'return_data': True }) if sts: parse = re.search('<a href="(.*?)"', data, re.S) if parse: printDBG('parse2p: ' + parse.group(1)) url2 = parse.group(1) sts, data = self.cm.getPage( url2, { 'use_host': True, 'host': self.HOST, 'use_cookie': True, 'save_cookie': False, 'load_cookie': True, 'cookiefile': self.COOKIEFILE, 'use_post': False, 'return_data': True }) if sts: printDBG('parse3pdata ') match = re.compile("url:'(.+?)'").findall(data) if len(match) > 0: printDBG('parse3p: PREMIUM: ' + match[0]) linkvideo = match[0] return linkvideo else: printDBG('Host getResolvedURL query error premium') printDBG( 'Host getResolvedURL query error premium url: ' + url2) else: printDBG('Host getResolvedURL query error premium') printDBG('Host getResolvedURL query error premium url: ' + url2) else: printDBG('Host getResolvedURL query error premium') printDBG('Host getResolvedURL query error premium url: ' + url) if url[0:30] == 'http://zalukaj.tv/zalukaj-film' or url[ 0:31] == 'http://zalukaj.tv/serial-online': sts, data = self.cm.getPage(url) if not sts: printDBG('Host getResolvedURL query error') printDBG('Host getResolvedURL query error url: ' + url) return '' parse = re.search('/player.php.*?"', data, re.S) if not parse: return '' printDBG('parse1: ' + parse.group(0)) url2 = self.fullUrl(parse.group(0)) sts, data = self.cm.getPage(url2) if not sts: printDBG('Host getResolvedURL query error') printDBG('Host getResolvedURL query error url: ' + url2) return '' parse = re.search('<a href="([^"]+?)"', data, re.S) if not parse: return '' printDBG('parse2: ' + parse.group(1)) url2 = parse.group(1) sts, data = self.cm.getPage(url2) if not sts: return '' parse = re.search('iframe src="([^"]+?)" width=', data) if not parse: return '' ret = self.up.getVideoLink(parse.group(1)) if ret: return ret return ''
class UstvnowApi: MAIN_URL = 'http://m.ustvnow.com/' LOG_URL = MAIN_URL + 'iphone/1/live/login' LIVE_URL = MAIN_URL + 'iphone/1/live/playingnow' HTTP_HEADER = { 'User-Agent': 'Mozilla/5.0', 'Referer': MAIN_URL } def __init__(self): self.cm = common() self.up = urlparser() self.sessionEx = MainSessionWrapper() self.cookiePath = GetCookieDir('ustvnow.cookie') self.token = '' HTTP_HEADER= dict(self.HTTP_HEADER) HTTP_HEADER.update( {'Content-Type':'application/x-www-form-urlencoded'} ) self.defParams = {'header':HTTP_HEADER, 'cookiefile': self.cookiePath, 'use_cookie': True, 'load_cookie':True, 'save_cookie':True} def _getFullUrl(self, url): if url.startswith('//'): return 'http:' + url if url.startswith('/'): url = url[1:] if 0 < len(url) and not url.startswith('http'): url = self.MAIN_URL + url if not self.MAIN_URL.startswith('https://'): url = url.replace('https://', 'http://') return url def cleanHtmlStr(self, str): return CBaseHostClass.cleanHtmlStr(str) def _getChannelsNames(self): printDBG("UstvnowApi._getChannelsNames") url = 'http://m.ustvnow.com/gtv/1/live/listchannels?%s' % urllib.urlencode({'token': self.token}) sts, data = self.cm.getPage(url) if not sts: return [] channelList = [] try: data = byteify(json.loads(data)) for item in data['results']['streamnames']: params = {} params['sname'] = item['sname'] params['img'] = item['img'] params['scode'] = item['scode'] params['t'] = item['t'] params['callsign'] = item['callsign'] params['prgsvcid'] = item['prgsvcid'] params['data_provider'] = item['data_provider'] params['lang'] = item['lang'] params['af'] = item['af'] channelList.append(params) except: printExc() return channelList def getChannelsList(self, cItem): printDBG("UstvnowApi.getChannelsList") login = config.plugins.iptvplayer.ustvnow_login.value passwd = config.plugins.iptvplayer.ustvnow_password.value if '' != login.strip() and '' != passwd.strip(): self.token = self.doLogin(login, passwd) if self.token == '': self.sessionEx.open(MessageBox, _('An error occurred when try to sign in the user "%s.\nPlease check your login credentials and try again later..."') % login, type = MessageBox.TYPE_INFO, timeout = 10 ) return [] else: self.sessionEx.open(MessageBox, _('You need to enter email and password in configuration.'), type = MessageBox.TYPE_INFO, timeout = 10 ) return [] sts, data = self.cm.getPage(self.LIVE_URL, self.defParams) if not sts: return [] channelsNames = self._getChannelsNames() channelsTab = [] data = self.cm.ph.getDataBeetwenMarkers(data, '<div data-role="content" data-theme="c">', '</ul>', False)[1] data = data.split('</li>') prgsvcidMap = {} for item in data: url = self.cm.ph.getSearchGroups(item, 'href="([^"]+?)"')[0] ui = url.split('ui-page=')[-1] icon = self.cm.ph.getSearchGroups(item, 'src="([^"]+?)"')[0] desc = self.cleanHtmlStr(item) params = dict(cItem) params.pop('url') params.update({'priv_url':self._getFullUrl(url), 'ui_page':ui, 'icon':icon, 'desc':desc}) for nameItem in channelsNames: if nameItem['img'] in icon: if config.plugins.iptvplayer.ustvnow_only_available.value and 0 == nameItem['t']: break params['title'] = nameItem['sname'] + ' [%s]' % nameItem['t'] params['prgsvcid'] = nameItem['prgsvcid'] prgsvcidMap[params['prgsvcid']] = len(channelsTab) channelsTab.append(params) break if config.plugins.iptvplayer.ustvnow_epg.value: sts, data = self.cm.getPage(self.MAIN_URL + 'gtv/1/live/channelguide', self.defParams) if sts: try: data = byteify(json.loads(data)) for item in data['results']: if item['prgsvcid'] in prgsvcidMap: idx = prgsvcidMap[item['prgsvcid']] channelsTab[idx]['desc'] += '[/br][/br] [%s %s][/br]%s[/br]%s[/br]%s[/br]%s' % (item.get('event_date', ''), item.get('event_time', ''), item.get('title', ''), item.get('synopsis', ''), item.get('description', ''), item.get('episode_title', '')) except: printExc() return channelsTab def doLogin(self, login, password): printDBG("UstvnowApi.doLogin") token = '' post_data = {'username':login, 'password':password, 'device':'iphone'} sts, data = self.cm.getPage(self.LOG_URL, self.defParams, post_data) if sts: token = self.cm.getCookieItem(self.cookiePath, 'token') return token def getVideoLink(self, cItem): printDBG("UstvnowApi.getVideoLink") sts, data = self.cm.getPage(cItem['priv_url'], self.defParams) if not sts: return [] url = self.cm.ph.getSearchGroups(data, 'for="popup-%s"[^>]*?href="([^"]+?)"[^>]*?>' % cItem['ui_page'])[0] url = self._getFullUrl(url) sts, data = self.cm.getPage(url, self.defParams) if not sts: return [] url = self.cm.ph.getSearchGroups(data, 'src="([^"]+?)"')[0] urlsTab = [] tmp = getDirectM3U8Playlist(strwithmeta(url, {'User-Agent':self.HTTP_HEADER['User-Agent']}), cookieParams = {'cookiefile': self.cookiePath, 'use_cookie': True, 'load_cookie':True, 'save_cookie':True}) hdntl = self.cm.getCookieItem(self.cookiePath, 'hdntl') for item in tmp: item['url'] = urlparser.decorateUrl(item['url'], {'User-Agent':self.HTTP_HEADER['User-Agent'], 'Cookie':"hdntl=%s" % urllib.unquote(hdntl)}) urlsTab.append(item) return urlsTab
class Host: currList = [] MAIN_URL = '' PREMIUM = False konto = '' COOKIEFILE = '' HOST = 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.18) Gecko/20110621 Mandriva Linux/1.9.2.18-0.1mdv2010.2 (2010.2) Firefox/3.6.18' def __init__(self): printDBG( 'Host __init__ begin' ) self.exSession = MainSessionWrapper() self.COOKIEFILE = GetCookieDir('scseriale.cookie') self.cm = common() self.currList = [] self.up = urlparser() self.history = CSearchHistoryHelper('wspolne') printDBG( 'Host __init__ end' ) def setCurrList(self, list): printDBG( 'Host setCurrList begin' ) self.currList = list printDBG( 'Host setCurrList end' ) return def getInitList(self): printDBG( 'Host getInitList begin' ) #################################### # logowanie #################################### self.PREMIUM = self.listsItems(-1, 'zaloguj', 'zaloguj') #################################### self.currList = self.listsItems(-1, 'main-menu', 'main-menu') printDBG( 'Host getInitList end' ) return self.currList def getListForItem(self, Index = 0, refresh = 0, selItem = None): printDBG( 'Host getListForItem begin' ) valTab = [] if len(self.currList[Index].urlItems) == 0: return valTab valTab = self.listsItems(Index, self.currList[Index].urlItems[0], self.currList[Index].urlSeparateRequest) self.currList = valTab printDBG( 'Host getListForItem end' ) return self.currList def getSearchResults(self, pattern, searchType = None): printDBG( "Host getSearchResults begin" ) printDBG( "Host getSearchResults pattern: " +pattern) valTab = [] valTab = self.listsItems(-1, pattern, 'search') self.currList = valTab printDBG( "Host getSearchResults end" ) return self.currList def listsItems(self, Index, url, name = ''): printDBG( 'Host listsItems begin' ) printDBG( 'Host listsItems url: '+url ) valTab = [] # ########## # if name == 'main-menu': printDBG( 'Host listsItems begin name='+name ) self.MAIN_URL = 'http://scs.pl' valTab.append(CDisplayListItem("Seriale wg. kategorii"+self.konto,'http://scs.pl/seriale.html', CDisplayListItem.TYPE_CATEGORY, ['http://scs.pl/seriale.html'], 'seriale-kategorie', '', None)) valTab.append(CDisplayListItem("Seriale alfabetycznie", 'http://scs.pl/seriale.html', CDisplayListItem.TYPE_CATEGORY, ['http://scs.pl/seriale.html'], 'seriale-abc', '', None)) valTab.append(CDisplayListItem("Ostatnio aktualizowane seriale", 'http://scs.pl/ostatnio_aktualizowane_seriale.html', CDisplayListItem.TYPE_CATEGORY, ['http://scs.pl/ostatnio_aktualizowane_seriale.html'], 'seriale-last', '', None)) valTab.append(CDisplayListItem('Szukaj', 'Szukaj', CDisplayListItem.TYPE_SEARCH, ['http://scs.pl/serial,szukaj.html'], 'search', '', None)) valTab.append(CDisplayListItem('Historia wyszukiwania', 'Historia wyszukiwania', CDisplayListItem.TYPE_CATEGORY, [''], 'history', '', None)) printDBG( 'Host listsItems end' ) return valTab # ########## # if 'zaloguj' == name: printDBG( 'Host listsItems begin name='+name ) if config.plugins.iptvplayer.scserialePREMIUM.value: url = 'http://scs.pl/logowanie.html' try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': True, 'host': self.HOST, 'use_cookie': True, 'save_cookie': True, 'load_cookie': False, 'cookiefile': self.COOKIEFILE, 'use_post': True, 'return_data': True },{'email': config.plugins.iptvplayer.scseriale_login.value, 'password': config.plugins.iptvplayer.scseriale_password.value}) except: printDBG( 'Host listsItems query error' ) printDBG( 'Host listsItems query error url:'+url ) printDBG( 'Host listsItems query error: Uzywam Player z limitami') data = None if data: self.PREMIUM = True printDBG( 'Host listsItems: chyba zalogowano do premium...' ) url = 'http://scs.pl/premium.html' try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': True, 'host': self.HOST, 'use_cookie': True, 'save_cookie': False, 'load_cookie': True, 'cookiefile': self.COOKIEFILE, 'use_post': False, 'return_data': True }) printDBG( 'Host listsItems data: '+data ) parse = re.search('Konto premium ważne do(.*?)".*?;(.*?)<', data, re.S) if parse: self.konto = ' - Twoje konto: '+parse.group(2)+parse.group(1) else: self.konto = '' except: printDBG( 'Host listsItems: blad pobrania danych o koncie premium' ) if '' == self.konto: self.exSession.open(MessageBox, 'Problem z zalogowaniem użytkownika \n"%s" jako VIP.' % config.plugins.iptvplayer.scseriale_login.value, type = MessageBox.TYPE_INFO, timeout = 10) printDBG( 'Host listsItems end' ) return self.PREMIUM # ########## # if 'history' == name: printDBG( 'Host listsItems begin name='+name ) for histItem in self.history.getHistoryList(): valTab.append(CDisplayListItem(histItem['pattern'], 'Szukaj ', CDisplayListItem.TYPE_CATEGORY, [histItem['pattern'],histItem['type']], 'search', '', None)) printDBG( 'Host listsItems end' ) return valTab # ########## # if 'search' == name: printDBG( 'Host listsItems begin name='+name ) pattern = url if Index==-1: self.history.addHistoryItem( pattern, 'seriale') url = 'http://scs.pl/serial,szukaj.html' postdata = { 'search': pattern } try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': True, 'return_data': True },postdata) except: printDBG( 'Host listsItems query error' ) printDBG( 'Host listsItems query error url:'+url ) return valTab #printDBG( 'Host listsItems data: '+data ) match = re.findall('<div class="img_box"><a href="(.*?)">.*?<img src="(.*?)" alt="(.*?)"', data, re.S) if len(match) > 0: for i in range(len(match)): phImage = match[i][1] phUrl = self.MAIN_URL+'/'+ match[i][0] phTitle = match[i][2] printDBG( 'Host listsItems phImage: ' +phImage ) printDBG( 'Host listsItems phUrl: ' +phUrl ) printDBG( 'Host listsItems phTitle: ' +phTitle ) valTab.append(CDisplayListItem(phTitle, phTitle, CDisplayListItem.TYPE_CATEGORY, [phUrl], 'seriale-sezony', phImage, None)) printDBG( 'Host listsItems end' ) return valTab # ########## # if 'seriale-last' == name: printDBG( 'Host listsItems begin name='+name ) try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True }) except: printDBG( 'Host listsItems query error' ) printDBG( 'Host listsItems query error url:'+url ) return valTab #printDBG( 'Host listsItems data: '+data ) match = re.compile('online">(.+?)</a></div></div><span class="newest_ep" id=".+?">Ostatnio dodany:<br/><a href="odcinek,(.+?),(.+?),(.+?),(.+?).html">').findall(data) if len(match) > 0: for i in range(len(match)): phImage='http://static.scs.pl/static/serials/' + match[i][1].replace('.html', '.jpg')+'.jpg' phTitleS = match[i][1] phTitle = match[i][0] + ' - ' + match[i][4] + ' - ' + match[i][2].capitalize().replace('-', ' ') phUrlS = self.MAIN_URL + '/serial,' + match[i][0] phUrl = self.MAIN_URL + '/odcinek,' + match[i][1] + ',' + match[i][2] + ',' + match[i][3] + ',' + match[i][4] + '.html' printDBG( 'Host listsItems phImage: ' +phImage ) printDBG( 'Host listsItems phUrl: ' +phUrl ) printDBG( 'Host listsItems phTitle: '+phTitle ) valTab.append(CDisplayListItem(phTitleS, phTitleS, CDisplayListItem.TYPE_CATEGORY, [phUrlS], 'seriale-sezony', phImage, None)) valTab.append(CDisplayListItem(phTitle, phTitle, CDisplayListItem.TYPE_VIDEO, [CUrlItem('', phUrl, 1)], 0, phImage, None)) printDBG( 'Host listsItems end' ) return valTab if 'seriale-kategorie' == name: printDBG( 'Host listsItems begin name='+name ) try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True }) except: printDBG( 'Host listsItems query error' ) printDBG( 'Host listsItems query error url:'+url ) return valTab #printDBG( 'Host listsItems data: '+data ) phMovies = re.findall('<span class="title1">(.*?)</span>(.*?)<.*?href="(.*?)"', data, re.S) if phMovies: for (phTitle, phCount, phUrl) in phMovies: printDBG( 'Host listsItems phTitle: '+phTitle ) printDBG( 'Host listsItems phCount: '+phCount ) printDBG( 'Host listsItems phUrl: ' +phUrl ) valTab.append(CDisplayListItem(phTitle+phCount, phTitle, CDisplayListItem.TYPE_CATEGORY, [self.MAIN_URL+'/'+phUrl], 'seriale-kategoria', '', None)) printDBG( 'Host listsItems end' ) return valTab if 'seriale-kategoria' == name: printDBG( 'Host listsItems begin name='+name ) try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True }) except: printDBG( 'Host listsItems query error' ) printDBG( 'Host listsItems query error url:'+url ) return valTab #printDBG( 'Host listsItems data: '+data ) match = re.compile('class="serial_green" href="serial,(.+?)">(.+?)</a><br/>').findall(data) if len(match) > 0: for i in range(len(match)): phImage='http://static.scs.pl/static/serials/' + match[i][0].replace('.html', '.jpg') phTitle = match[i][1] phUrl = self.MAIN_URL + '/serial,' + match[i][0] printDBG( 'Host listsItems phImage: ' +phImage ) printDBG( 'Host listsItems phUrl: ' +phUrl ) printDBG( 'Host listsItems phTitle: '+phTitle ) valTab.append(CDisplayListItem(phTitle, phTitle, CDisplayListItem.TYPE_CATEGORY, [phUrl], 'seriale-sezony', phImage, None)) printDBG( 'Host listsItems end' ) return valTab if 'seriale-abc' == name: printDBG( 'Host listsItems begin name='+name ) abcTab = self.cm.makeABCList() for i in range(len(abcTab)): phTitle = abcTab[i] valTab.append(CDisplayListItem(phTitle, phTitle, CDisplayListItem.TYPE_CATEGORY, [url,phTitle], 'seriale-alfabet', '', None)) printDBG( 'Host listsItems end' ) return valTab if 'seriale-alfabet' == name: printDBG( 'Host listsItems begin name='+name ) try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True }) except: printDBG( 'Host listsItems query error' ) printDBG( 'Host listsItems query error url:'+url ) return valTab #printDBG( 'Host listsItems data: '+data ) letter = self.currList[Index].urlItems[1] match = re.compile(' <a class="serial_green" href="serial,(.+?)">(.+?)</a><br/>').findall(data) if len(match) > 0: for i in range(len(match)): addItem = False if letter == '0 - 9' and (ord(match[i][1][0]) < 65 or ord(match[i][1][0]) > 91): addItem = True if (letter == match[i][1][0].upper()): addItem = True if (addItem): phImage='http://static.scs.pl/static/serials/' + match[i][0].replace('.html', '.jpg') phTitle = match[i][1] phUrl = self.MAIN_URL + '/serial,' + match[i][0] printDBG( 'Host listsItems phImage: ' +phImage ) printDBG( 'Host listsItems phUrl: ' +phUrl ) printDBG( 'Host listsItems phTitle: '+phTitle ) valTab.append(CDisplayListItem(phTitle, phTitle, CDisplayListItem.TYPE_CATEGORY, [phUrl], 'seriale-sezony', phImage, None)) printDBG( 'Host listsItems end' ) return valTab if 'seriale-sezony' == name: printDBG( 'Host listsItems begin name='+name ) try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True }) except: printDBG( 'Host listsItems query error' ) printDBG( 'Host listsItems query error url:'+url ) return valTab #printDBG( 'Host listsItems data: '+data ) phMovies = re.compile('<meta itemprop="seasonNumber" content="(.+?)">').findall(data) if phMovies: phImage=url.replace(self.MAIN_URL + '/serial,', 'http://static.scs.pl/static/serials/').replace('.html', '.jpg') printDBG( 'Host listsItems phImage: '+phImage ) for (phTitle) in phMovies: printDBG( 'Host listsItems phTitle: '+phTitle ) valTab.append(CDisplayListItem('Sezon '+phTitle, 'Sezon '+phTitle, CDisplayListItem.TYPE_CATEGORY, [url,phTitle], 'seriale-odcinki', phImage, None)) printDBG( 'Host listsItems end' ) return valTab if 'seriale-odcinki' == name: printDBG( 'Host listsItems begin name='+name ) try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True }) except: printDBG( 'Host listsItems query error' ) printDBG( 'Host listsItems query error url:'+url ) return valTab #printDBG( 'Host listsItems data: '+data ) sezon = self.currList[Index].urlItems[1] r = re.compile('<meta itemprop="seasonNumber" content="' + sezon + '">(.+?)</ul></div>', re.DOTALL).findall(data) if not r: return [] phMovies = re.compile('itemprop="episodeNumber">(.+?)<.+?class="aLink " href="(odcinek,.+?,.+?,.+?,.+?.html)"><span itemprop="name">(.+?)</span></a>').findall(r[0]) if phMovies: phImage=url.replace(self.MAIN_URL + '/serial,', 'http://static.scs.pl/static/serials/').replace('.html', '.jpg') serial=url.replace(self.MAIN_URL + '/serial,','').replace('.html', '') printDBG( 'Host listsItems phImage: '+phImage ) for (phEpizod, phUrl, phName) in phMovies: printDBG( 'Host listsItems phEpizod: '+phEpizod ) printDBG( 'Host listsItems phUrl: '+phUrl ) phTitle = '%s S%sE%s - %s' % (serial, sezon, phEpizod, phName) printDBG( 'Host listsItems phTitle: '+phTitle ) valTab.append(CDisplayListItem(phTitle, phTitle, CDisplayListItem.TYPE_CATEGORY, [self.MAIN_URL+'/'+phUrl,phTitle], 'seriale-odcinki-wersje', phImage, None)) printDBG( 'Host listsItems end' ) return valTab if 'seriale-odcinki-wersje' == name: printDBG( 'Host listsItems begin name='+name ) try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True }) except: printDBG( 'Host listsItems query error' ) printDBG( 'Host listsItems query error url:'+url ) return valTab #printDBG( 'Host listsItems data: '+data ) parse = re.search('Wersje:(.*?)Kopie:', data, re.S) if not parse: return [] phMovies = re.findall('<a href="(.+?)">(.+?)<', parse.group(1), re.S) if phMovies: phImage=url.replace(self.MAIN_URL + '/serial,', 'http://static.scs.pl/static/serials/').replace('.html', '.jpg') printDBG( 'Host listsItems phImage: '+phImage ) for (phUrl, phWersja) in phMovies: printDBG( 'Host listsItems phUrl: '+phUrl ) printDBG( 'Host listsItems phWersja: '+phWersja ) valTab.append(CDisplayListItem(phWersja, phWersja, CDisplayListItem.TYPE_CATEGORY, [self.MAIN_URL+'/'+phUrl], 'seriale-odcinki-kopie', phImage, None)) printDBG( 'Host listsItems end' ) return valTab if 'seriale-odcinki-kopie' == name: printDBG( 'Host listsItems begin name='+name ) try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True }) except: printDBG( 'Host listsItems query error' ) printDBG( 'Host listsItems query error url:'+url ) return valTab #printDBG( 'Host listsItems data: '+data ) parse = re.search('class="mirrors"(.*?)class="switch"', data, re.S) if not parse: return [] phMovies = re.findall('= "(.+?)"; ccc.+?;.+?"(.+?)";.+?"(.+?)";.+?"(.+?)";', parse.group(1), re.S) if phMovies: for (phUrl, phTime, phUser, phComment) in phMovies: printDBG( 'Host listsItems phUrl: '+phUrl ) printDBG( 'Host listsItems phTime: '+phTime ) printDBG( 'Host listsItems phUser: '******' '+phUser, phTime+' '+phUser+' '+phComment, CDisplayListItem.TYPE_VIDEO, [CUrlItem('', phUrl, 1)], 0, '', None)) printDBG( 'Host listsItems end' ) return valTab return valTab def getResolvedURL(self, url): printDBG( 'Host getResolvedURL begin' ) printDBG( 'Host getResolvedURL url: '+url ) postdata = {'f' : url } if self.PREMIUM: query_data = { 'url': 'http://scs.pl/getVideo.html', 'use_host': True, 'host': self.HOST, 'use_cookie': True, 'save_cookie': False, 'load_cookie': True, 'cookiefile': self.COOKIEFILE, 'use_post': True, 'return_data': True } else: query_data = { 'url': 'http://scs.pl/getVideo.html', 'use_host': False, 'use_cookie': False, 'use_post': True, 'return_data': True } try: data = self.cm.getURLRequestData(query_data, postdata) except: printDBG( 'Host getResolvedURL query error premium' ) printDBG( 'Host getResolvedURL query error premium url: '+url ) return '' #printDBG( 'Host getResolvedURL premium data: ' +data) match = re.compile("url: '(.+?)',").findall(data) if len(match) > 0: linkVideo = match[0] printDBG( 'Host getResolvedURL linkVideo: ' + linkVideo) printDBG( 'Host getResolvedURL end premium' ) return linkVideo printDBG( 'Host getResolvedURL end' ) return ''
class EdemTvApi: def __init__(self): self.MAIN_URL = 'https://edem.tv/' self.HTTP_HEADER = { 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:12.0) Gecko/20100101 Firefox/12.0', 'Referer': self.MAIN_URL } self.COOKIE_FILE = GetCookieDir('edemtv.cookie') self.cm = common() self.up = urlparser() self.http_params = {} self.http_params.update({'save_cookie': True, 'load_cookie': True, 'cookiefile': self.COOKIE_FILE}) self.cacheChannels = {} self.sessionEx = MainSessionWrapper() def getFullUrl(self, url): if url.startswith('http'): return url elif url.startswith('/'): return self.MAIN_URL + url[1:] return self.MAIN_URL + url def cleanHtmlStr(self, str): return CBaseHostClass.cleanHtmlStr(str) def doLogin(self, login, password): logged = False HTTP_HEADER= dict(self.HTTP_HEADER) HTTP_HEADER.update( {'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8', 'X-Requested-With' : 'XMLHttpRequest'} ) post_data = {'email' : login, 'password' : password} params = {'header' : HTTP_HEADER, 'cookiefile' : self.COOKIE_FILE, 'save_cookie' : True} loginUrl = self.getFullUrl('account/login') sts, data = self.cm.getPage( loginUrl, params, post_data) if sts and '/account/logout' in data: logged = True return logged def getChannelsList(self, cItem): printDBG("EdemTvApi.getChannelsList") channelsTab = [] getList = cItem.get('get_list', True) if getList: login = config.plugins.iptvplayer.edemtv_login.value passwd = config.plugins.iptvplayer.edemtv_password .value if '' != login.strip() and '' != passwd.strip(): if not self.doLogin(login, passwd): self.sessionEx.open(MessageBox, _('Login failed.'), type = MessageBox.TYPE_INFO, timeout = 10 ) return [] else: self.sessionEx.open(MessageBox, _('This host requires registration. \nPlease fill your login and password in the host configuration. Available under blue button.'), type = MessageBox.TYPE_ERROR, timeout = 10 ) return [] self.cacheChannels = {} categoryUrl = self.getFullUrl('category') sts, data = self.cm.getPage(categoryUrl, self.http_params) if not sts: return [] marker = "animated_hidden uk-width-1-1" channelsData = self.cm.ph.getDataBeetwenMarkers(data, marker, 'uk-visible-small', False)[1] channelsData = channelsData.split(marker) for catItem in channelsData: catId = self.cm.ph.getSearchGroups(catItem, ''' id=['"]([^'^"]+?)['"]''')[0] if catId == '': continue channelsPerCat = self.cm.ph.getAllItemsBeetwenMarkers(catItem, '<a ', '</a>') for item in channelsPerCat: url = self.cm.ph.getSearchGroups(item, ''' href=['"]([^'^"]+?)['"]''')[0] icon = self.cm.ph.getSearchGroups(item, ''' src=['"]([^'^"]+?)['"]''')[0] alt = self.cm.ph.getSearchGroups(item, ''' alt=['"]([^'^"]+?)['"]''')[0] params = {'type':'video', 'url':self.getFullUrl(url), 'title':self.cleanHtmlStr(alt), 'icon':self.getFullUrl(icon), 'desc':self.cleanHtmlStr(item)} if catId not in self.cacheChannels: self.cacheChannels[catId] = [params] else: self.cacheChannels[catId].append(params) catsData = self.cm.ph.getDataBeetwenMarkers(data, 'uk-visible-small', '</ul>')[1] catsData = self.cm.ph.getAllItemsBeetwenMarkers(catsData, '<li ', '</li>') for item in catsData: catId = self.cm.ph.getSearchGroups(item, '''data-target=['"]([^'^"]+?)['"]''')[0] catTitle = self.cleanHtmlStr(item) + ' (%s)' % catId.title() if 0 == len(self.cacheChannels.get(catId, [])): continue if 'adult' == catId: adult = True else: adult = False params = dict(cItem) params.update({'title':catTitle, 'cat_id':catId, 'get_list':False, 'pin_locked':adult}) channelsTab.append(params) else: catId = cItem.get('cat_id', '') channels = self.cacheChannels.get(catId, []) for item in channels: params = dict(cItem) params.update(item) channelsTab.append(params) return channelsTab def getVideoLink(self, cItem): printDBG("EdemTvApi.getVideoLink") sts, data = self.cm.getPage(cItem['url'], self.http_params) if not sts: return [] data = self.cm.ph.getDataBeetwenMarkers(data, 'playlist:', ']', False)[1] hlsUrl = self.cm.ph.getSearchGroups(data, '''['"](http[^'^"]+?)['"]''')[0] rmpUrl = self.cm.ph.getSearchGroups(data, '''['"](rtmp[^'^"]+?)['"]''')[0] urlsTab = [] if hlsUrl.startswith('http://') and 'm3u8' in hlsUrl: urlsTab = getDirectM3U8Playlist(hlsUrl) if rmpUrl.startswith('rtmp'): urlsTab.append({'name':'rtmp', 'url':rmpUrl + ' live=1'}) return urlsTab
class VideoStarApi: MAINURL_PC = 'https://videostar.pl/' MAINURL_IOS = 'https://m.videostar.pl/' HTTP_HEADER_PC = { 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:12.0) Gecko/20100101 Firefox/12.0', 'Referer': MAINURL_PC } HTTP_HEADER_IOS = { 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B179 Safari/7534.48.3', 'Referer': MAINURL_IOS } HTTP_HEADER2 = { 'User-Agent': 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16', 'Referer': MAINURL_IOS } API_URLS = { 'login_url': 'login', 'get_ad_show': 'api/ad/show', 'get_ad_urls': 'api/ad/urls', 'get_channels_list': 'api/channels/list/web', 'get_channel_url': 'api/channels/get/%s?format_id=%s', 'close_channel': 'api/channels/close', } VIDEO_STAR_T = '' VIDEO_GUEST_M = False def __init__(self): self.cm = common() self.sessionEx = MainSessionWrapper() self._reInit() self.channelsList = [] def _getUrl(self, key): if '2' == self.streamprotocol: MAINURL = VideoStarApi.MAINURL_IOS else: MAINURL = VideoStarApi.MAINURL_PC if key in VideoStarApi.API_URLS: return MAINURL + VideoStarApi.API_URLS[key] if not key.startswith('http'): return MAINURL + key return key def _reInit(self): self.streamprotocol = config.plugins.iptvplayer.videostar_streamprotocol.value if '2' == self.streamprotocol: self.MAINURL = VideoStarApi.MAINURL_IOS self.cm.HEADER = dict(VideoStarApi.HTTP_HEADER_IOS) else: self.MAINURL = VideoStarApi.MAINURL_PC self.cm.HEADER = dict(VideoStarApi.HTTP_HEADER_PC) self.PREMIUM = config.plugins.iptvplayer.videostar_premium.value self.LOGIN = config.plugins.iptvplayer.videostar_login.value self.PASSWORD = config.plugins.iptvplayer.videostar_password.value def getDefaultQuality(self): return config.plugins.iptvplayer.videostar_defquality.value def getChannelsList(self, refresh=False): printDBG("VideoStarApi.getChannelsList") self._reInit() if not refresh and 0 < len(self.channelsList): return self.channelsList self.channelsList = [] if '' != self.LOGIN.strip() and '' != self.PASSWORD.strip(): if not self.doLogin(self.LOGIN, self.PASSWORD): self.sessionEx.open( MessageBox, _('Problem z zalogowanie użytkownika "%s. Sprawdź dane do logowania w konfiguracji hosta."' ) % self.LOGIN, type=MessageBox.TYPE_INFO, timeout=10) return self.channelsList else: self.sessionEx.open( MessageBox, _('Strona wymaga zalogowania. Proszę uzupełnić dane w konfiguracji hosta.' ), type=MessageBox.TYPE_INFO, timeout=10) return self.channelsList self._fillChannelsList() return self.channelsList def _fillChannelsList(self): printDBG("VideoStarApi._fillChannelsList") # get channels list sts, data = self.cm.getPage(self._getUrl('get_channels_list')) if sts: try: data = json.loads(data) if "ok" == data['status']: self.channelsList = data['channels'] except: printExc() #self.getVideoLink(12) #self.getVideoLink(12) def getVideoLink(self, channelID): printDBG("VideoStarApi.getVideoLink") urlsTab = [] #get referer page referer = '' guestMode = False for item in self.channelsList: if channelID == item['id']: referer = self.MAINURL + '#' + item[ 'slug'] # "slug" attrib can be also taken from stream_channel data if "unsubscribed" == item['access_status']: guestMode = True break for tryNum in range(2): # there is need to close previuse played channel self._closePrevChannel() # retrie if there was unknown problem with getting link self._reInit() if not guestMode: self.doLogin(self.LOGIN, self.PASSWORD) #this block of code is probably not needed try: sts, data = self.cm.getPage(self._getUrl('get_ad_show')) if json.loads(data)['show']: sts, data = self.cm.getPage( self._getUrl('get_ad_urls')) adUrls = json.loads(data)['urls'] for item in adUrls: printDBG('VideoStarApi.getVideoLink get ad[%s]' % item) sts, data = self.cm.getPage(item) except: printExc() sts, data = self.cm.getPage(referer) if not sts: printExc('Error when downloading referer') else: self.cm.HEADER = VideoStarApi.HTTP_HEADER2 url = self._getUrl('get_channel_url') % (channelID, self.streamprotocol) HTTP_HEADER = dict(self.cm.HEADER) HTTP_HEADER.update({'X-Reguested-With': 'XMLHttpReguest'}) if guestMode: url = url.replace('https://videostar.pl/api', 'https://api.videostar.pl/guest') sts, data = self.cm.getPage(url, {'header': HTTP_HEADER}) try: data = json.loads(data) if "ok" == data['status']: VideoStarApi.VIDEO_STAR_T = data['stream_channel'][ 'url_params'][-1].decode('utf-8') url_param1 = data['stream_channel']['url_params'][ 1].decode('utf-8') VideoStarApi.VIDEO_GUEST_M = guestMode if '1' == self.streamprotocol: url = data['stream_channel']['url_base'].decode( 'utf-8') sts, data = self.cm.getPage(url, {'header': HTTP_HEADER}) r = re.search('<baseURL>([^<]+?)</baseURL>', data).group(1) streams = re.findall( 'url="([^"]+?)" bitrate="([0-9]+?)"', data) for item in streams: # swfVfy=https://videostar.pl/javascripts/libs/flowplayer/flowplayer.netvi-x.swf protocol=1 url = r + '/' + item[ 0] + ' live=1 swfUrl=https://videostar.pl/javascripts/libs/flowplayer/flowplayer.commercial-3.2.11.swf' + ' pageUrl=' + referer + ( ' conn=S:%s conn=S:%s token=%s' % (url_param1, VideoStarApi.VIDEO_STAR_T, VideoStarApi.VIDEO_STAR_T) ) + ' flashVer=WIN 12,0,0,44 ' urlsTab.append({ 'url': strwithmeta(url, {'iptv_proto': 'rtmp'}), 'name': item[1], 'bitrate': item[1] + '000', 'type': 'rtmpt' }) else: # hls url = data['stream_channel']['url_base'].decode( 'utf-8') urlsTab.append({ 'url': strwithmeta(url, {'iptv_proto': 'm3u8'}), 'name': 'videostar hls', 'type': 'hls' }) except: printExc() if 0 < len(urlsTab): break printDBG(urlsTab) return urlsTab def _closePrevChannel(self): printDBG("VideoStarApi._closePrevChannel start VIDEO_STAR_T[%s]" % VideoStarApi.VIDEO_STAR_T) if '' != VideoStarApi.VIDEO_STAR_T: url = self._getUrl('close_channel') HTTP_HEADER = dict(self.cm.HEADER) HTTP_HEADER.update({ 'X-Reguested-With': 'XMLHttpReguest', 'Content-Type': 'application/x-www-form-urlencoded', 'charset': 'UTF-8' }) post_data = {'t': VideoStarApi.VIDEO_STAR_T} if VideoStarApi.VIDEO_GUEST_M: url = url.replace('https://videostar.pl/api', 'https://api.videostar.pl/guest') sts, data = self.cm.getPage(url, {'header': HTTP_HEADER}, post_data) try: data = json.loads(data) if "ok" == data['status']: VideoStarApi.VIDEO_STAR_T = '' except: printExc() printDBG("_closePrevChannel end VIDEO_STAR_T[%s]" % VideoStarApi.VIDEO_STAR_T) def doLogin(self, login, password): HTTP_HEADER = dict(self.cm.HEADER) HTTP_HEADER.update( {'Content-Type': 'application/x-www-form-urlencoded'}) cookiePath = GetCookieDir('videostar.cookie') params = { 'header': HTTP_HEADER, 'cookiefile': cookiePath, 'use_cookie': True, 'save_cookie': True } post_data = {'login': login, 'password': password, 'permanent': '1'} sts, data = self.cm.getPage(self._getUrl('login_url'), params, post_data) if sts: # the LWP has problem to read prepared Cookie, so we will manually read them and add to header try: with open(cookiePath, 'r') as infile: data = infile.read() PHPSESSID = re.search('(PHPSESSID=[^;]+?;)', data).group(1) netviapisessid = re.findall('(netviapisessid[^;]+?;)', data)[-1] #HttpOnly self.cm.HEADER['Cookie'] = PHPSESSID + netviapisessid sts, data = self.cm.getPage(self.MAINURL) if sts and 'Wyloguj' in data: return True except: printExc() return False
class PierwszaTVApi: MAIN_URL = 'http://pierwsza.tv/' HTTP_HEADER = { 'User-Agent':'Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/37.0.2062.120 Chrome/37.0.2062.120 Safari/537.36', 'Referer': MAIN_URL } def __init__(self): self.COOKIE_FILE = GetCookieDir('pierwszatv.cookie') self.COOKIE_FILE2 = GetCookieDir('pierwszatv2.cookie') self.COOKIE_FILE3 = GetCookieDir('pierwszatv3.cookie') self.sessionEx = MainSessionWrapper() self.cm = common() self.up = urlparser() self.http_params = {'header': dict(self.HTTP_HEADER), 'save_cookie': True, 'load_cookie': True, 'cookiefile': self.COOKIE_FILE} self.http_params2 = {'header': dict(self.HTTP_HEADER), 'save_cookie': True, 'load_cookie': True, 'cookiefile': self.COOKIE_FILE2} self.http_params3 = {'header': dict(self.HTTP_HEADER), 'save_cookie': True, 'load_cookie': True, 'cookiefile': self.COOKIE_FILE3} self.cacheList = {} def cryptoJS_AES_decrypt(self, encrypted, password, salt): def derive_key_and_iv(password, salt, key_length, iv_length): d = d_i = '' while len(d) < key_length + iv_length: d_i = md5(d_i + password + salt).digest() d += d_i return d[:key_length], d[key_length:key_length+iv_length] bs = 16 key, iv = derive_key_and_iv(password, salt, 32, 16) cipher = AES_CBC(key=key, keySize=32) return cipher.decrypt(encrypted, iv) def getTimestamp(self, t, s=64): a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_" e = "" t = int(t) while t > 0: e = a[t % s] + e t = int(t / s) return e def getFullUrl(self, url): if url.startswith('http'): return url elif url.startswith('/'): return self.MAIN_URL + url[1:] return url def cleanHtmlStr(self, str): return CBaseHostClass.cleanHtmlStr(str) def getChannelsList(self, cItem): printDBG("TelewizjadaNetApi.getChannelsList") login = config.plugins.iptvplayer.pierwszatv_login.value password = config.plugins.iptvplayer.pierwszatv_password.value if login != '' and password != '': if self.doLogin(login, password): self.loggedIn = True self.http_params.update({'save_cookie': True, 'load_cookie': True, 'cookiefile': self.COOKIE_FILE}) else: self.sessionEx.open(MessageBox, _('Problem z zalogowanie użytkownika "%s. Sprawdź dane do logowania w konfiguracji hosta."') % login, type = MessageBox.TYPE_INFO, timeout = 10 ) channelsTab = [] sts, data = self.cm.getPage(self.MAIN_URL + 'player/watch?show=active') if not sts: return [] data = self.cm.ph.getAllItemsBeetwenMarkers(data, '<a class="source', '</a>') for item in data: url = self.getFullUrl( self.cm.ph.getSearchGroups(item, '''href="([^"]+?)"''', 1, True)[0] ) icon = self.getFullUrl( self.cm.ph.getSearchGroups(item, '''src="([^"]+?)"''', 1, True)[0] ) #icon = '' title = self.cleanHtmlStr( self.cm.ph.getDataBeetwenMarkers(item, '<div class="name">', '</div>', False)[1] ) desc = self.cleanHtmlStr( item.split('<div class="author">')[-1] ) if not url.startswith('http'): continue params = dict(cItem) params.update({'title':title, 'url':url, 'icon':icon, 'desc':desc}) channelsTab.append(params) return channelsTab def getVideoLink(self, cItem): printDBG("TelewizjadaNetApi.getVideoLink") params = {'header' : self.HTTP_HEADER, 'cookiefile' : self.COOKIE_FILE, 'save_cookie' : True} sts, data = self.cm.getPage(cItem['url'], params) if not sts: return [] tmp = self.cm.ph.getDataBeetwenMarkers(data, 'connectToLive(', ')', False)[1] tmp = self.cm.ph.getSearchGroups(tmp, '''['"]([^'^"]+?)['"][^'^"]+?['"]([^'^"]+?)['"]''', 2, True) mainCon = {'url':tmp[0], 'token':tmp[1]} varData = data #self.cm.ph.getDataBeetwenMarkers(data, 'window.', 'var items')[1] window = {'streamUrl':'', 'endpoints':'', 'sourceId':'', 'sourceType':'', 'sourcePlayer':'', 'streamId':'', 'streamToken':'', 'serverId':''} for key in window: val = self.cm.ph.getSearchGroups(varData, '''window\.%s[^'^"]*?=([^;]+?);''' % key, 1, True)[0].strip() if val.startswith("'") and val.endswith("'"): val = val[1:-1] if val.startswith('"') and val.endswith('"'): val = val[1:-1] window[key] = val window['urls'] = {} for keyUrl in ['playRecord', 'player', 'sync', 'multiLogin', 'reportError', 'reportOk', 'bumpToken']: window['urls'][keyUrl] = self.cm.ph.getSearchGroups(varData, '''window\.urls\['[^']+?\@%s'\][\s]*?=[\s]*?['"]([^'^"]+?)['"]''' % keyUrl, 1, True)[0].strip() for keyUrl in ['requestStream']: window['urls'][keyUrl] = self.cm.ph.getSearchGroups(varData, '''window\.routes\['[^']+?\@%s'\][\s]*?=[\s]*?['"]([^'^"]+?)['"]''' % keyUrl, 1, True)[0].strip() urlsTab = [] try: printDBG(window) if '' != window['streamUrl']: tmp = window['streamUrl'].replace('\\"', '"') else: tmp = window['endpoints'].replace('\\"', '"') streamUrl = byteify(json.loads(tmp)) ciphertext = base64.b64decode(streamUrl['ct']) iv = a2b_hex(streamUrl['iv']) salt = a2b_hex(streamUrl['s']) tmp = self.cryptoJS_AES_decrypt(ciphertext, 'number-one', salt) tmp = byteify(json.loads(tmp)) tmp = byteify(json.loads(tmp)) if isinstance(tmp, list): tmp = tmp[0] if isinstance(tmp, dict): baseUrl1 = mainCon['url'] streamToken1 = mainCon['token'] baseUrl2 = tmp['server'] streamToken2 = tmp['token'] serverId = tmp['id'] printDBG("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++") printDBG(tmp) printDBG("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++") t1 = self.getTimestamp(time()*1000) url = baseUrl1 + '/socket.io/?EIO=3&transport=polling&t=' + t1 sts, data = self.cm.getPage(url, self.http_params2) baseParams1 = data[data.find('{'):] baseParams1 = byteify(json.loads(baseParams1)) printDBG("=========================================================") printDBG([data]) printDBG(baseParams1) printDBG("=========================================================") t2 = self.getTimestamp(time()*1000) url = baseUrl2.replace(":8000",":8004") + '/socket.io/?EIO=3&transport=polling&t=' + t2 sts, data = self.cm.getPage(url, self.http_params3) baseParams2 = data[data.find('{'):] baseParams2 = byteify(json.loads(baseParams2)) printDBG("=========================================================") printDBG([data]) printDBG(baseParams2) printDBG("=========================================================") #===================== t1 = self.getTimestamp(time()*1000) url = baseUrl1 + '/socket.io/?EIO=3&transport=polling&t={0}&sid={1}'.format(t1, baseParams1['sid']) sts, data = self.cm.getPage(url, self.http_params2) printDBG("=========================================================") printDBG(data.split('\x00\x02\xff')) printDBG("=========================================================") t2 = self.getTimestamp(time()*1000) url = baseUrl2.replace(":8000",":8004") + '/socket.io/?EIO=3&transport=polling&t={0}&sid={1}'.format(t2, baseParams2['sid']) sts, data = self.cm.getPage(url, self.http_params3) printDBG("=========================================================") printDBG(data.split('\x00\x02\xff')) printDBG("=========================================================") #===================== #raw_post_data t1 = self.getTimestamp(time()*1000) url = baseUrl1 + '/socket.io/?EIO=3&transport=polling&t={0}&sid={1}'.format(t1, baseParams1['sid']) self.http_params2['raw_post_data'] = True sts, data = self.cm.getPage(url, self.http_params2, '92:42["authorize",{"token":"%s"}]' % streamToken1) printDBG("=========================================================") printDBG([data]) printDBG("=========================================================") if 0: t1 = self.getTimestamp(time()*1000) url = baseUrl1 + '/socket.io/?EIO=3&transport=polling&t={0}&sid={1}'.format(t1, baseParams1['sid']) sts, data = self.cm.getPage(url, self.http_params2) printDBG("=========================================================") printDBG([data]) printDBG("=========================================================") #+++++ t2 = self.getTimestamp(time()*1000) url = baseUrl2.replace(":8000",":8004") + '/socket.io/?EIO=3&transport=polling&t={0}&sid={1}'.format(t2, baseParams2['sid']) self.http_params3['raw_post_data'] = True sts, data = self.cm.getPage(url, self.http_params3, '102:42["authorize","%s"]' % streamToken2) printDBG("=========================================================") printDBG([data]) printDBG("=========================================================") t2 = self.getTimestamp(time()*1000) url = baseUrl2.replace(":8000",":8004") + '/socket.io/?EIO=3&transport=polling&t={0}&sid={1}'.format(t2, baseParams2['sid']) sts, data = self.cm.getPage(url, self.http_params3) data = byteify( json.loads(data[data.find('42')+2:]) ) stoken = data[1]['stoken'] printDBG("=========================================================") printDBG([data]) printDBG("=========================================================") n = sha256(serverId + window['sourceId'] + stoken).hexdigest() url = window['urls']["requestStream"] + "?token=" + streamToken2 + "&server=" + serverId + "&source=" + window['sourceId'] + "&cs=" + n sts, data = self.cm.getPage(url, self.http_params) data = byteify( json.loads(data) ) streamId = data['id'] if 0: t2 = self.getTimestamp(time()*1000) url = baseUrl2.replace(":8000",":8004") + '/socket.io/?EIO=3&transport=polling&t={0}&sid={1}'.format(t2, baseParams2['sid']) self.http_params3['raw_post_data'] = True sts, data = self.cm.getPage(url, self.http_params3, '84:42["subscribe","%s"]' % streamId) wsUrl2 = baseUrl2.replace(":8000",":8004").replace('http://', 'ws://') + '/socket.io/?EIO=3&transport=websocket&sid={0}'.format(baseParams2['sid']) wsUrl1 = baseUrl1.replace('http://', 'ws://') + '/socket.io/?EIO=3&transport=websocket&sid={0}'.format(baseParams1['sid']) libsPath = GetPluginDir('libs/') pyCmd = GetPyScriptCmd('pierwszatv') + ' "%s" "%s" "%s" "%s" "%s" "%s" "%s" "%s" ' % (self.http_params['header']['User-Agent'], baseUrl2, wsUrl2, wsUrl1, stoken, streamId, libsPath, baseParams2['sid']) vidUrl = strwithmeta("fake://fake", {'iptv_proto':'em3u8', 'iptv_buffering': 'required', 'iptv_refresh_cmd':pyCmd, 'Referer':cItem['url'], 'User-Agent':self.http_params['header']['User-Agent']}) printDBG("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++") printDBG(pyCmd) printDBG("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++") return [{'name':'pierwsza_hls', 'url':vidUrl}] except: printExc() return [] return urlsTab def doLogin(self, login, password): logged = False loginUrl = self.MAIN_URL + 'account/login' params = dict(self.http_params) params['load_cookie'] = False sts, data = self.cm.getPage(loginUrl, params) if not sts: return False _token = self.cm.ph.getSearchGroups(data, '''_token"[\s]*?value="([^"]+?)"''', 1, True)[0] HTTP_HEADER= dict(PierwszaTVApi.HTTP_HEADER) HTTP_HEADER.update( {'Referer':loginUrl} ) post_data = {'email' : login, 'password' : password, '_token' : _token, 'remember_me' : 'on' } params = {'header' : HTTP_HEADER, 'cookiefile' : self.COOKIE_FILE, 'save_cookie' : True, 'load_cookie' : True} sts, data = self.cm.getPage( loginUrl, params, post_data) if sts: if os_path.isfile(self.COOKIE_FILE): if 'dashboard/logout' in data: printDBG('PierwszaTVApi.doLogin login as [%s]' % login) logged = True else: printDBG('PierwszaTVApi.doLogin login failed - wrong user or password?') else: printDBG('PierwszaTVApi.doLogin there is no cookie file after login') return logged
class Sport365LiveApi: MAIN_URL = 'http://www.sport365.live/' HTTP_HEADER = { 'User-Agent': 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/37.0.2062.120 Chrome/37.0.2062.120 Safari/537.36', 'Referer': MAIN_URL } CACHE_AES_PASSWORD = '' def __init__(self): self.COOKIE_FILE = GetCookieDir('sport365live.cookie') self.sessionEx = MainSessionWrapper() self.cm = common() self.up = urlparser() self.http_params = { 'header': dict(self.HTTP_HEADER), 'use_cookie': True, 'save_cookie': True, 'load_cookie': True, 'cookiefile': self.COOKIE_FILE } self.needRefreshAdvert = True def getFullUrl(self, url): if url.startswith('http'): return url elif url.startswith('//'): return 'http:' + url elif url.startswith('/'): return self.MAIN_URL + url[1:] return self.MAIN_URL + url def cleanHtmlStr(self, str): return CBaseHostClass.cleanHtmlStr(str) def cryptoJS_AES_decrypt(self, encrypted, password, salt): def derive_key_and_iv(password, salt, key_length, iv_length): d = d_i = '' while len(d) < key_length + iv_length: d_i = md5(d_i + password + salt).digest() d += d_i return d[:key_length], d[key_length:key_length + iv_length] bs = 16 key, iv = derive_key_and_iv(password, salt, 32, 16) cipher = AES_CBC(key=key, keySize=32) return cipher.decrypt(encrypted, iv) def getMarketCookie(self, url, referer, num=1): try: id = url.split('.')[-2] except Exception: printExc() id = '403' xz = str(int(time() * 1000)) + id + str(int( random.random() * 1000)) + str( 2 * int(random.random() * 4)) + str(num) xz = base64.b64encode(xz) return 'MarketGidStorage=%s; ' % urllib.quote( '{"0":{"svspr":"%s","svsds":%s,"TejndEEDj":"%s"},"C%s":{"page":1,"time":%s}}' % (referer, num, xz, id, int(time() * 100))) def refreshAdvert(self): if not self.needRefreshAdvert: return self.sessionEx.open( MessageBox, _('Please remember to visit http://www.sport365.live/ and watch a few advertisements.\nThis will fix problem, if your playback is constantly interrupted.' ), type=MessageBox.TYPE_INFO, timeout=10) self.needRefreshAdvert = False COOKIE_FILE = GetCookieDir('sport365live2.cookie') params = dict(self.http_params) params['cookiefile'] = COOKIE_FILE params['header'] = dict(params['header']) params['return_data'] = False baseUrl = self.MAIN_URL try: sts, response = self.cm.getPage(baseUrl, params) baseUrl = response.geturl() data = response.read() response.close() except Exception: printExc() return sessionCookie = self.cm.getCookieHeader(COOKIE_FILE) params['return_data'] = True params['header']['Referer'] = baseUrl awrapperUrls = re.compile( '''['"]([^"^']*?/awrapper/[^'^"]*?)["']''').findall(data) D = datetime.now() timeMarker = '{0}{1}{2}{3}'.format(D.year - 1900, D.month - 1, D.day, D.hour) jscUrl = self.cm.ph.getSearchGroups( data, '''['"]([^'^"]*?jsc\.mgid[^'^"]*?)['"]''')[0] if jscUrl.endswith('t='): jscUrl += timeMarker adUrl = self.cm.ph.getSearchGroups( data, '''['"]([^'^"]*?\.adshell\.[^'^"]*?)['"]''')[0] sts, data = self.cm.getPage(self.getFullUrl(adUrl), params) if sts: adUrl = self.cm.ph.getSearchGroups( data, '''['"]([^'^"]*?\.adshell\.[^'^"]*?)['"]''')[0] sts, data = self.cm.getPage(self.getFullUrl(jscUrl), params) marketCookie = self.getMarketCookie(jscUrl, baseUrl) params['use_cookie'] = False params['header']['Cookie'] = marketCookie sts, data = self.cm.getPage(self.getFullUrl(adUrl), params) for awrapperUrl in awrapperUrls: awrapperUrl = self.getFullUrl(awrapperUrl) params['header']['Referer'] = baseUrl params['header']['Cookie'] = sessionCookie + marketCookie sts, data = self.cm.getPage(awrapperUrl, params) if not sts: continue adUrl = self.cm.ph.getSearchGroups( data, '''['"]([^'^"]*?\.adshell\.[^'^"]*?)['"]''')[0] params['header']['Referer'] = awrapperUrl params['header']['Cookie'] = marketCookie sts, data = self.cm.getPage(self.getFullUrl(adUrl), params) if not sts: continue jscUrl = self.cm.ph.getSearchGroups( data, '''['"]([^'^"]*?jsc\.mgid[^'^"]*?)['"]''')[0] if jscUrl.endswith('t='): jscUrl += timeMarker if jscUrl != '': sts, tmp = self.cm.getPage(self.getFullUrl(jscUrl), params) if sts: params['header']['Cookie'] = self.getMarketCookie( jscUrl, awrapperUrl) adUrls = re.compile( '''['"]([^'^"]*?bannerid[^'^"]*?)['"]''').findall(data) for adUrl in adUrls: adUrl = adUrl.replace('&', '&') sts, tmp = self.cm.getPage(self.getFullUrl(adUrl), params) return def getMainCategries(self, cItem): printDBG("Sport365LiveApi.getMainCategries") channelsTab = [] dt = datetime.now() - datetime.utcnow() OFFSET = (dt.microseconds + (dt.seconds + dt.days * 24 * 3600) * 10**6) / 10**6 OFFSET /= 60 if OFFSET % 10 == 9: OFFSET += 1 url = self.getFullUrl('en/events/-/1/-/-/%s' % (OFFSET)) sts, data = self.cm.getPage(self.MAIN_URL, self.http_params) sts, data = self.cm.getPage(url, self.http_params) if not sts: return [] date = '' data = self.cm.ph.getDataBeetwenMarkers(data, '<table', '</table>')[1] data = self.cm.ph.getAllItemsBeetwenMarkers(data, '<tr', '</tr>') for item in data: if '/types/' not in item: tmp = self.cm.ph.getSearchGroups( item, '''>([0-9]{2}\.[0-9]{2}\.[0-9]{4})<''')[0] if tmp != '': date = tmp else: if '/types/dot-green-big.png' in item: title = '[live] ' else: title = '' title += self.cleanHtmlStr(item) desc = self.cm.ph.getSearchGroups( item, '''alt=['"]([^'^"]+?)['"]''')[0] desc = date + ' ' + self.cleanHtmlStr(desc) linksData = [] tmp = self.cm.ph.getSearchGroups( item, '''onClick=[^(]*?\(([^)]+?)\)''')[0].split(',') for t in tmp: linksData.append(t.replace('"', '').strip()) printDBG(linksData) params = dict(cItem) params.update({ 'type': 'category', 'priv_cat': 'streams_links', 'links_data': linksData, 'title': title, 'desc': desc }) channelsTab.append(params) return channelsTab def getStreamsLinks(self, cItem): printDBG("Sport365LiveApi.getStreamsLinks") channelsTab = [] linksData = cItem.get('links_data', []) if len(linksData) < 4 or not linksData[0].startswith('event_'): return [] eventId = linksData[0].replace('event_', '') url = self.getFullUrl('en/links/{0}/{1}'.format( eventId, linksData[-1])) sts, data = self.cm.getPage(url, self.http_params) if not sts: return [] desc = self.cleanHtmlStr( self.cm.ph.getDataBeetwenMarkers( data, '<table', '</table>')[1]) + '[/br]' + cItem.get( 'desc', '') data = self.cm.ph.getAllItemsBeetwenMarkers(data, '<tr', '</tr>') for item in data: sourceTitle = self.cleanHtmlStr(item.split('<span')[0]) links = self.cm.ph.getAllItemsBeetwenMarkers( item, '<span ', '</span>') for link in links: linkTitle = self.cleanHtmlStr(link) if '{' in linkTitle: continue linkData = self.cm.ph.getSearchGroups( link, '''onClick=[^(]*?\(([^)]+?)\)''')[0].split(',')[0].replace( '"', '').replace("'", '').strip() #printDBG("=========================================================") #printDBG(linkData) #printDBG("=========================================================") if linkData != '': params = dict(cItem) params.update({ 'type': 'video', 'link_data': linkData, 'event_id': eventId, 'desc': desc, 'title': sourceTitle + ' ' + linkTitle }) channelsTab.append(params) return channelsTab def getChannelsList(self, cItem): printDBG("Sport365LiveApi.getChannelsList") self.refreshAdvert() category = cItem.get('priv_cat', None) if None == category: return self.getMainCategries(cItem) elif 'streams_links' == category: return self.getStreamsLinks(cItem) return [] def getAesPassword(self, cItem, forceRefresh=False): if Sport365LiveApi.CACHE_AES_PASSWORD != '' and not forceRefresh: return Sport365LiveApi.CACHE_AES_PASSWORD sts, data = self.cm.getPage( self.getFullUrl('en/home/' + cItem['event_id']), self.http_params) if not sts: return [] aes = '' data = re.compile( '''src=['"](http[^"^']*?/js/[0-9a-fA-F]{32}\.js[^'^"]*?)["']''' ).findall(data) deObfuscatedData = '' for commonUrl in data: sts, tmpData = self.cm.getPage(commonUrl, self.http_params) if not sts: return [] aes = '' try: while 'eval' in tmpData: tmp = tmpData.split('eval(') if len(tmp): del tmp[0] tmpData = '' for item in tmp: for decFun in [ VIDEOWEED_decryptPlayerParams, VIDEOWEED_decryptPlayerParams2, SAWLIVETV_decryptPlayerParams ]: tmpData = unpackJSPlayerParams( 'eval(' + item, decFun, 0) if '' != tmpData: break deObfuscatedData += tmpData aes = self.cm.ph.getSearchGroups( tmpData, 'aes_key="([^"]+?)"')[0] if '' == aes: aes = self.cm.ph.getSearchGroups( tmpData, 'aes\(\)\{return "([^"]+?)"')[0] if aes != '': break aes = aes.encode('utf-8') except Exception: printExc() aes = '' if aes != '': break if aes == '': funname = self.cm.ph.getSearchGroups( deObfuscatedData, 'CryptoJS\.AES\.decrypt\([^\,]+?\,([^\,]+?)\,')[0].strip() printDBG("ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ") printDBG("FUN NAME: [%s]" % funname) printDBG("ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ") tmp = self.cm.ph.getDataBeetwenMarkers(deObfuscatedData, 'function %s' % funname, '}')[1] try: aes = self.cm.ph.getSearchGroups( tmp, '"([^"]+?)"')[0].encode('utf-8') except Exception: printExc() #aes = self.cm.ph.getSearchGroups(deObfuscatedData, '%s\s*\{\s*return\s*"([^"]+?)"' % funname)[0] if aes != '': Sport365LiveApi.CACHE_AES_PASSWORD = aes return aes def getVideoLink(self, cItem): printDBG("Sport365LiveApi.getVideoLink") if Sport365LiveApi.CACHE_AES_PASSWORD != '': tries = 2 else: tries = 1 urlsTab = [] for checkIdx in range(tries): if checkIdx > 0: aes = self.getAesPassword(cItem, True) else: aes = self.getAesPassword(cItem) if aes == '': return [] #printDBG(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> [%s]" % aes) try: linkData = base64.b64decode(cItem['link_data']) linkData = byteify(json.loads(linkData)) ciphertext = base64.b64decode(linkData['ct']) iv = a2b_hex(linkData['iv']) salt = a2b_hex(linkData['s']) playerUrl = self.cryptoJS_AES_decrypt(ciphertext, aes, salt) printDBG(playerUrl) playerUrl = byteify(json.loads(playerUrl)) if not playerUrl.startswith('http'): continue sts, data = self.cm.getPage(playerUrl, self.http_params) if not sts: return [] data = self.cm.ph.getDataBeetwenMarkers( data, 'document.write(', '(')[1] playerUrl = self.cleanHtmlStr( self.cm.ph.getSearchGroups( data, '''<iframe[^>]+?src=['"](http[^"^']+?)['"]''', 1, True)[0]) urlsTab = self.up.getVideoLinkExt( strwithmeta(playerUrl, {'aes_key': aes})) if len(urlsTab): break except Exception: printExc() return urlsTab
class SatLiveApi: MAINURL = 'http://web-live.tv/' LIST_URL = MAINURL + 'transmissions/transmission/index' SWF_URL = MAINURL + 'themes/default/swf/jwplayer.flash.swf' LOGIN_URL = MAINURL + 'site/site/login' HTTP_HEADER = { 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:12.0) Gecko/20100101 Firefox/12.0', 'Referer': MAINURL } def __init__(self): self.COOKIE_FILE = GetCookieDir('satlivetv.cookie') self.cm = common() self.sessionEx = MainSessionWrapper() self.loggedIn = True self.http_params = {} #self._reInit() #self.channelsList = [] def getChannelsList(self): printDBG("SatLiveApi.getChannelsList") # login premium = config.plugins.iptvplayer.satlivetv_premium.value login = config.plugins.iptvplayer.satlivetv_login.value password = config.plugins.iptvplayer.satlivetv_password.value if premium: if self.doLogin(login, password): self.loggedIn = True self.http_params.update({'save_cookie': True, 'load_cookie': True, 'cookiefile': self.COOKIE_FILE}) else: self.sessionEx.open(MessageBox, _('Problem z zalogowanie użytkownika "%s. Sprawdź dane do logowania w konfiguracji hosta."') % login, type = MessageBox.TYPE_INFO, timeout = 10 ) # get channels channelsList = [] sts, data = self.cm.getPage(SatLiveApi.LIST_URL, self.http_params) if not sts: return [] data = self.cm.ph.getDataBeetwenMarkers(data, '<div class="tab-pane active" id="live">', '<div class="tab-pane" id="all">', False)[1] data = data.split('</li>') for item in data: tmp = self.cm.ph.getSearchGroups(item, '<h4><a href="([^"]+?)">([^<]+?)</a></h4>', 2) if '' != tmp[0]: params = {} params['url'] = SatLiveApi.MAINURL + tmp[0] params['title'] = tmp[1] icon = self.cm.ph.getSearchGroups(item, '<img class="" src="([^"]+?)"')[0] if '' != icon: params['icon'] = SatLiveApi.MAINURL + icon params['desc'] = self.cm.ph.removeDoubles(clean_html(item.replace('>', '> ')).replace('\t', ' '), ' ') channelsList.append(params) if True: num = 1 m = 'eyI1NzkiOiAiVFZQIDEiLCAiNjA0IjogIlBvbHNhdCBTcG9ydCIsICI2MTgiOiAiUG9sc2F0IFNwb3J0IiwgIjU3MiI6ICJUQ00iLCAiNjA2IjogIlBvbHNhdCBTcG9ydCBFeHRyYSIsICI2MDAiOiAiQ2FuYWwrIFNwb3J0IiwgIjYwMiI6ICJQb2xzYXQiLCAiNDY5IjogIkhCTyBbSERdIiwgIjEyMCI6ICJBWE4gV2hpdGUiLCAiOTgiOiAiTmF0R2VvIiwgIjEyMiI6ICJOYXRHZW8gV2lsZCIsICI5MyI6ICJIQk8iLCAiOTQiOiAiSEJPIDIiLCAiOTciOiAiQ2luZW1heCAyIiwgIjU5MSI6ICJDYW5hbCsgW0hEXSIsICI1OTAiOiAiTWluaU1pbmkiLCAiNTkzIjogIkNhbmFsKyBGaWxtIiwgIjU5MiI6ICJDYW5hbCsiLCAiNjAxIjogIlBvbHNhdCBbSERdIiwgIjU5NCI6ICJBbGVLaW5vKyIsICI1OTciOiAiQ2FuYWwrIFNlcmlhbGUiLCAiNTk2IjogIlRlbGVUb29uIiwgIjU5OSI6ICJDYW5hbCsgRmFtaWx5IiwgIjU5OCI6ICJDYW5hbCsiLCAiMTE0IjogIkRpc2NvdmVyeSBTY2llbmNlIiwgIjExNyI6ICJEaXNuZXkgSnVuaW9yIiwgIjExMCI6ICJEaXNuZXkgWEQiLCAiMTEyIjogIkZpbG1ib3giLCAiMTE5IjogIkZPWCIsICIxMTgiOiAiVHJhdmVsIENoYW5uZWwiLCAiNTI4IjogIlR1cmJvIFh0cmEiLCAiNTg3IjogIm5TcG9ydCIsICI1ODQiOiAiVFZQIFNlcmlhbGUiLCAiNTg1IjogIlRWUCBTcG9ydCIsICI1ODIiOiAiVFZQIDIgW0hEXSIsICI1ODMiOiAiVFZQIEluZm8iLCAiNTgwIjogIlRWUCAxIFtIRF0iLCAiNTgxIjogIlRWUCAyIiwgIjYxMiI6ICJVbmtub3duIiwgIjYxMyI6ICJVbmtub3duIiwgIjYxMCI6ICJVbmtub3duIiwgIjYxMSI6ICJUVk4gMjQiLCAiNTg4IjogIm5TcG9ydCBbSERdIiwgIjU4OSI6ICJDYW5hbCsgU3BvcnQgW0hEXSIsICIxMDgiOiAiRGlzY292ZXJ5IGxpZmUiLCAiMTA5IjogIkFYTiIsICIxMDIiOiAiRXVyb3Nwb3J0IDIiLCAiMTAxIjogIkV1cm9zcG9ydCIsICIxMDYiOiAiSEJPIENvbWVkeSIsICIxMDciOiAiS2lubyBQb2xza2EiLCAiMTA0IjogIlRMQyIsICI0NzAiOiAiRGlzY292ZXJ5IFtIRF0iLCAiNDcxIjogIk5hdEdlbyBbSERdIiwgIjQ3NiI6ICJCQkMgZWFydGgiLCAiNDc0IjogIkRpc2NvdmVyeSIsICI0NzgiOiAiVmlhc2F0IE5hdHVyZSIsICI0NzkiOiAiVmlhc2F0IEhpc3RvcnkiLCAiNjE2IjogIlBvbHNhdCBIRCIsICI2MTciOiAiUG9sc2F0IiwgIjYxOSI6ICJQb2xzYXQgU3BvcnQgRXh0cmEifQ==' try: m = byteify(json.loads(base64.b64decode(m))) except: m = {} for a in base64.b64decode('OTMsOTQsOTcsOTgsMTAxLDEwMiwxMDQsMTA2LDEwOSwxMTAsMTEyLDExNCwxMTcsMTE4LDExOSwxMjAsMTIyLDQ2OSw0NzAsNDcxLDQ3NCw0NzYsNDc4LDQ3OSw1MjgsNTcxLDU3Miw1NzksNTgwLDU4MSw1ODIsNTgzLDU4NCw1ODUsNTg3LDU4OCw1ODksNTkwLDU5MSw1OTIsNTkzLDU5NCw1OTUsNTk2LDU5Nyw1OTgsNTk5LDYwMCw2MTAsNjExLDYxMiw2MTMsNjE2LDYxNyw2MTgsNjE5').split(','): channelsList.append({'title':'Test %s' % m.get(a, ''), 'url':SatLiveApi.MAINURL+'/id/%s/' % a, 'icon':'http://web-live.tv/uploads/transmissions/Transmission/live/%s.jpg?%s' % (a, time.time()), 'desc':''}) num += 1 return channelsList def getVideoLink(self, url): printDBG("SatLiveApi.getVideoLink") id = self.cm.ph.getSearchGroups(url+"/", 'id/([0-9]+?)/')[0] sts, data = self.cm.getPage(SatLiveApi.MAINURL + 'ge/' + id, self.http_params) if not sts: return '' base = self.cm.ph.getSearchGroups(data, 'base="([^"]+?)"')[0] src = self.cm.ph.getSearchGroups(data, 'src="([^"]+?)"')[0] if base.startswith('rtmp'): return base + '/' + src + ' swfUrl=%s live=1' % SatLiveApi.SWF_URL return '' def doLogin(self, login, password): logged = False HTTP_HEADER= dict(SatLiveApi.HTTP_HEADER) HTTP_HEADER.update( {'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8', 'X-Requested-With' : 'XMLHttpRequest'} ) post_data = {'LoginForm[email]' : login, 'LoginForm[password]' : password, 'ajax' : 'fast-login-form', 'undefined' : '' } params = {'header' : HTTP_HEADER, 'cookiefile' : self.COOKIE_FILE, 'save_cookie' : True} sts, data = self.cm.getPage( SatLiveApi.LOGIN_URL, params, post_data) if sts: if os_path.isfile(self.COOKIE_FILE): printDBG(data) if '[]' == data: printDBG('SatLiveApi.doLogin login as [%s]' % login) logged = True else: printDBG('SatLiveApi.doLogin login failed - wrong user or password?') else: printDBG('SatLiveApi.doLogin there is no cookie file after login') return logged
class UstvnowApi: MAIN_URL = 'http://m.ustvnow.com/' LOG_URL = MAIN_URL + 'iphone/1/live/login' LIVE_URL = MAIN_URL + 'iphone/1/live/playingnow' HTTP_HEADER = {'User-Agent': 'Mozilla/5.0', 'Referer': MAIN_URL} def __init__(self): self.cm = common() self.up = urlparser() self.sessionEx = MainSessionWrapper() self.cookiePath = GetCookieDir('ustvnow.cookie') self.token = '' HTTP_HEADER = dict(self.HTTP_HEADER) HTTP_HEADER.update( {'Content-Type': 'application/x-www-form-urlencoded'}) self.defParams = { 'header': HTTP_HEADER, 'cookiefile': self.cookiePath, 'use_cookie': True, 'load_cookie': True, 'save_cookie': True } def _getFullUrl(self, url): if url.startswith('//'): return 'http:' + url if url.startswith('/'): url = url[1:] if 0 < len(url) and not url.startswith('http'): url = self.MAIN_URL + url if not self.MAIN_URL.startswith('https://'): url = url.replace('https://', 'http://') return url def cleanHtmlStr(self, str): return CBaseHostClass.cleanHtmlStr(str) def _getChannelsNames(self): printDBG("UstvnowApi._getChannelsNames") url = 'http://m.ustvnow.com/gtv/1/live/listchannels?%s' % urllib.urlencode( {'token': self.token}) sts, data = self.cm.getPage(url) if not sts: return [] channelList = [] try: data = byteify(json.loads(data)) for item in data['results']['streamnames']: params = {} params['sname'] = item['sname'] params['img'] = item['img'] params['scode'] = item['scode'] params['t'] = item['t'] params['callsign'] = item['callsign'] params['prgsvcid'] = item['prgsvcid'] params['data_provider'] = item['data_provider'] params['lang'] = item['lang'] params['af'] = item['af'] channelList.append(params) except: printExc() return channelList def getChannelsList(self, cItem): printDBG("UstvnowApi.getChannelsList") login = config.plugins.iptvplayer.ustvnow_login.value passwd = config.plugins.iptvplayer.ustvnow_password.value if '' != login.strip() and '' != passwd.strip(): self.token = self.doLogin(login, passwd) if self.token == '': self.sessionEx.open( MessageBox, _('An error occurred when try to sign in the user "%s.\nPlease check your login credentials and try again later..."' ) % login, type=MessageBox.TYPE_INFO, timeout=10) return [] else: self.sessionEx.open( MessageBox, _('You need to enter email and password in configuration.'), type=MessageBox.TYPE_INFO, timeout=10) return [] sts, data = self.cm.getPage(self.LIVE_URL, self.defParams) if not sts: return [] channelsNames = self._getChannelsNames() channelsTab = [] data = self.cm.ph.getDataBeetwenMarkers( data, '<div data-role="content" data-theme="c">', '</ul>', False)[1] data = data.split('</li>') prgsvcidMap = {} for item in data: url = self.cm.ph.getSearchGroups(item, 'href="([^"]+?)"')[0] ui = url.split('ui-page=')[-1] icon = self.cm.ph.getSearchGroups(item, 'src="([^"]+?)"')[0] desc = self.cleanHtmlStr(item) params = dict(cItem) params.pop('url') params.update({ 'priv_url': self._getFullUrl(url), 'ui_page': ui, 'icon': icon, 'desc': desc }) for nameItem in channelsNames: if nameItem['img'] in icon: if config.plugins.iptvplayer.ustvnow_only_available.value and 0 == nameItem[ 't']: break params[ 'title'] = nameItem['sname'] + ' [%s]' % nameItem['t'] params['prgsvcid'] = nameItem['prgsvcid'] prgsvcidMap[params['prgsvcid']] = len(channelsTab) channelsTab.append(params) break if config.plugins.iptvplayer.ustvnow_epg.value: sts, data = self.cm.getPage( self.MAIN_URL + 'gtv/1/live/channelguide', self.defParams) if sts: try: data = byteify(json.loads(data)) for item in data['results']: if item['prgsvcid'] in prgsvcidMap: idx = prgsvcidMap[item['prgsvcid']] channelsTab[idx][ 'desc'] += '[/br][/br] [%s %s][/br]%s[/br]%s[/br]%s[/br]%s' % ( item.get('event_date', ''), item.get('event_time', ''), item.get('title', ''), item.get('synopsis', ''), item.get('description', ''), item.get('episode_title', '')) except: printExc() return channelsTab def doLogin(self, login, password): printDBG("UstvnowApi.doLogin") token = '' post_data = { 'username': login, 'password': password, 'device': 'iphone' } sts, data = self.cm.getPage(self.LOG_URL, self.defParams, post_data) if sts: token = self.cm.getCookieItem(self.cookiePath, 'token') return token def getVideoLink(self, cItem): printDBG("UstvnowApi.getVideoLink") sts, data = self.cm.getPage(cItem['priv_url'], self.defParams) if not sts: return [] url = self.cm.ph.getSearchGroups( data, 'for="popup-%s"[^>]*?href="([^"]+?)"[^>]*?>' % cItem['ui_page'])[0] url = self._getFullUrl(url) sts, data = self.cm.getPage(url, self.defParams) if not sts: return [] url = self.cm.ph.getSearchGroups(data, 'src="([^"]+?)"')[0] urlsTab = [] tmp = getDirectM3U8Playlist(strwithmeta( url, {'User-Agent': self.HTTP_HEADER['User-Agent']}), cookieParams={ 'cookiefile': self.cookiePath, 'use_cookie': True, 'load_cookie': True, 'save_cookie': True }) hdntl = self.cm.getCookieItem(self.cookiePath, 'hdntl') for item in tmp: item['url'] = urlparser.decorateUrl( item['url'], { 'User-Agent': self.HTTP_HEADER['User-Agent'], 'Cookie': "hdntl=%s" % urllib.unquote(hdntl) }) urlsTab.append(item) return urlsTab
class WagasWorldApi(CBaseHostClass): def __init__(self): CBaseHostClass.__init__(self) self.sessionEx = MainSessionWrapper() self.MAIN_URL = 'http://www.wagasworld.com/' self.HTTP_HEADER = { 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:12.0) Gecko/20100101 Firefox/12.0', 'Referer': self.MAIN_URL } self.COOKIE_FILE = GetCookieDir('wagasworld.cookie') self.http_params = { 'header': dict(self.HTTP_HEADER), 'save_cookie': True, 'load_cookie': True, 'cookiefile': self.COOKIE_FILE } self.DEFAULT_URL_ICON = self.getFullIconUrl( '/sites/default/files/styles/slideshow_full/public/12_0.jpg?itok=LHobtpyX' ) def getMainCategories(self, cItem): printDBG("WagasWorldApi.getMainCategories") list = [] list.append({ 'type': 'waga_cat', 'waga_cat': 'groups', 'title': _('Channel'), 'url': self.MAIN_URL + 'channel' }) list.append({ 'type': 'waga_cat', 'waga_cat': 'groups', 'title': _('LiveTv'), 'url': self.MAIN_URL + 'LiveTv' }) return list def getGroups(self, cItem): printDBG("WagasWorldApi.getGroups") list = [] sts, data = self.cm.getPage(cItem['url'], self.http_params) if not sts: return list data = ph.find(data, ('<div', '>', 'form-item'), '<select', flags=0)[1] data = re.compile( '<a[^>]+?href="([^"]+?)"[^>]*?>([^<]+?)</a>').findall(data) for item in data: list.append({ 'type': 'waga_cat', 'waga_cat': 'items', 'title': ph.clean_html(item[1]), 'icon': self.DEFAULT_URL_ICON, 'url': self.getFullUrl(item[0]) }) return list def getItems(self, cItem): printDBG("WagasWorldApi.getItems") list = [] page = cItem.get('page', 0) url = cItem['url'] if page > 0: if '?' in url: url += '&' else: url += '?' url += 'page={0}'.format(page) sts, data = self.cm.getPage(url, self.http_params) if not sts: return list nextPage = False if '&page={0}"'.format(page + 1) in data: nextPage = True data = ph.find(data, '<div class="view-content">', '</section>')[1] data = data.split('</span>') if len(data): del data[-1] for item in data: title = ph.search(item, '>([^<]+?)</a>')[0] url = self.getFullUrl(ph.getattr(item, 'href')) icon = self.getFullIconUrl(ph.search(item, ph.IMG)[1]) if '' != url and '' != title: list.append({ 'waga_cat': 'explore', 'type': 'waga_cat', 'title': ph.clean_html(title), 'icon': icon, 'url': url }) if nextPage: list.append({ 'type': 'waga_cat', 'waga_cat': 'items', 'title': _('Next page'), 'url': cItem['url'], 'page': page + 1 }) return list def getChannelsList(self, cItem): printDBG("WagasWorldApi.getChannelsList waga_cat[%s]" % cItem.get('waga_cat', '')) list = [] waga_cat = cItem.get('waga_cat', '') if '' == waga_cat: login = config.plugins.iptvplayer.wagasworld_login.value password = config.plugins.iptvplayer.wagasworld_password.value if login != '' and password != '': if self.doLogin(login, password): self.loggedIn = True self.http_params.update({ 'save_cookie': True, 'load_cookie': True, 'cookiefile': self.COOKIE_FILE }) else: self.sessionEx.open( MessageBox, _('"%s" login failed! Please check your login and password.' ) % login, type=MessageBox.TYPE_INFO, timeout=10) list = self.getGroups({'url': self.MAIN_URL + 'channel'}) #list = self.getMainCategories(cItem) elif 'groups' == waga_cat: list = self.getGroups(cItem) elif 'items' == waga_cat: list = self.getItems(cItem) elif 'explore' == waga_cat: list = self.exploreItem(cItem) elif 'more' == waga_cat: list = self.loadMore(cItem) return list def _getEpisode(self, baseUrl, episode=-1): tmp = baseUrl.split('/') url = '/'.join(tmp[:-2]) + '/x.php?%s=%s&' % (tmp[-2], tmp[-1]) if episode > -1: url += 'episode=%s&' % episode url += 'v=%s' % (int(time() * 1000)) HTTP_HEADER = dict(self.HTTP_HEADER) HTTP_HEADER['Referer'] = baseUrl HTTP_HEADER['X-Requested-With'] = 'XMLHttpRequest' sts, data = self.cm.getPage(url, {'header': HTTP_HEADER}) if not sts: return [] ret = None errorMsg = '' try: data = json_loads(data) errorMsg = self.cleanHtmlStr(data.get('err', '')) ret = { 'url': data['url'], 'episode': data['episode'], 'title': data['name'] } except Exception: printExc() if errorMsg != '': self.sessionEx.open(MessageBox, errorMsg, type=MessageBox.TYPE_ERROR, timeout=10) return ret def exploreItem(self, cItem): printDBG("WagasWorldApi.exploreItem url[%s]" % cItem['url']) sts, data = self.cm.getPage(cItem['url'], self.http_params) if not sts: return [] desc = ph.clean_html( ph.find(data, ('<div', '>', 'alert-danger'), '</div>', flags=0)[1]) data = self.cm.ph.getDataBeetwenMarkers(data, '<div class="videoWrapper">', ' </section>', False)[1] if 'pr3v4t.tk' not in data: params = dict(cItem) params['type'] = 'video' params['desc'] = desc return [params] retTab = [] url = self.cm.ph.getSearchGroups( data, '''<iframe[^>]+?src=["'](https?://[^"^']*?pr3v4t\.tk[^"^']+)["']''', 1, True)[0] data = self._getEpisode(url) if data: params = dict(cItem) params.update({ 'type': 'video', 'title': cItem['title'] + ' ' + data['title'], 'waga_url': url, 'waga_episode': int(data['episode']) }) retTab.append(params) params = dict(cItem) params.update({ 'type': 'more', 'waga_cat': 'more', 'title': _('More'), 'waga_title': cItem['title'], 'waga_url': url, 'waga_episode': int(data['episode']) + 1 }) retTab.append(params) return retTab def loadMore(self, cItem): printDBG("WagasWorldApi.loadMore cItem[%s]" % cItem) episode = cItem.get('waga_episode', 1) baseUrl = cItem.get('waga_url', '') title = cItem.get('waga_title', '') retTab = [] data = self._getEpisode(baseUrl, episode) if data: params = dict(cItem) params.update({ 'type': 'video', 'title': title + ' ' + data['title'], 'waga_url': baseUrl, 'waga_episode': int(data['episode']) }) retTab.append(params) params = dict(cItem) params.update({'waga_episode': int(data['episode']) + 1}) retTab.append(params) return retTab def getVideoLink(self, cItem): printDBG("WagasWorldApi.getVideoLink cItem[%s]" % cItem) baseUrl = cItem['url'] url = cItem.get('waga_url', '') if url != '': data = self._getEpisode(url, cItem.get('waga_episode', 1)) if data: return [{'name': data['title'], 'url': data['url']}] else: sts, data = self.cm.getPage(baseUrl, self.http_params) if not sts: return [] data = self.cm.ph.getDataBeetwenMarkers( data, '<div class="videoWrapper">', '</section>', False)[1] return self.up.getAutoDetectedStreamLink(baseUrl, data) return [] def doLogin(self, login, password): logged = False loginUrl = self.MAIN_URL + '?q=user' params = dict(self.http_params) params['load_cookie'] = False sts, data = self.cm.getPage(loginUrl, params) if not sts: return False data = self.cm.ph.getDataBeetwenMarkers(data, '<form', '</form>', False, False)[1] action = self.cm.ph.getSearchGroups(data, '''action=['"]([^'^"]+?)['"]''')[0] if action.startswith('/'): action = self.MAIN_URL + action[1:] printDBG(data) post_data = dict( re.findall( r'<(?:input|button)[^>]*name="([^"]*)"[^>]*value="([^"]*)"[^>]*>', data)) post_data.update({'name': login, 'pass': password}) HTTP_HEADER = dict(self.HTTP_HEADER) HTTP_HEADER.update({'Referer': loginUrl}) params = { 'header': HTTP_HEADER, 'cookiefile': self.COOKIE_FILE, 'save_cookie': True, 'load_cookie': True } sts, data = self.cm.getPage(loginUrl, params, post_data) if sts: if os_path.isfile(self.COOKIE_FILE): if 'user/logout' in data: printDBG('WagasWorldApi.doLogin login as [%s]' % login) logged = True else: printDBG( 'WagasWorldApi.doLogin login failed - wrong user or password?' ) else: printDBG( 'WagasWorldApi.doLogin there is no cookie file after login' ) return logged
class GoldVodTVApi: MAIN_URL = 'http://goldvod.tv/' HTTP_HEADER = { 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:12.0) Gecko/20100101 Firefox/12.0', 'Referer': MAIN_URL } def __init__(self): self.COOKIE_FILE = GetCookieDir('goldvodtv.cookie') self.sessionEx = MainSessionWrapper() self.cm = common() self.up = urlparser() self.http_params = {} self.http_params.update({ 'save_cookie': True, 'load_cookie': True, 'cookiefile': self.COOKIE_FILE }) self.cacheList = {} self.loggedIn = False def getFullUrl(self, url): if url.startswith('http'): return url elif url.startswith('/'): return self.MAIN_URL + url[1:] else: return self.MAIN_URL + url return url def cleanHtmlStr(self, str): return CBaseHostClass.cleanHtmlStr(str) def getChannelsList(self, cItem): printDBG("TelewizjadaNetApi.getChannelsList") login = config.plugins.iptvplayer.goldvodtv_login.value password = config.plugins.iptvplayer.goldvodtv_password.value if login != '' and password != '': if self.doLogin(login, password): self.loggedIn = True self.http_params.update({ 'save_cookie': True, 'load_cookie': True, 'cookiefile': self.COOKIE_FILE }) else: self.sessionEx.open( MessageBox, _('Problem z zalogowanie użytkownika "%s. Sprawdź dane do logowania w konfiguracji hosta."' ) % login, type=MessageBox.TYPE_INFO, timeout=10) self.loggedIn = False channelsTab = [] nameMap = { '3': 'Eleven', '2': 'TVP 1 HD', '4': 'Polsat HD', '5': 'Polsat 2 HD', '6': 'Canal+ Sport HD', '7': 'Eleven Sports', '8': 'Canal+ Sport 2 HD', '9': 'Canal+ HD', '10': 'HGTV', '11': 'Eurosport 2 HD', '12': 'nSport HD', '13': 'Eurosport HD', '14': 'Nickelodeon', '15': 'Comedy Central', '16': 'National Geographic Channel HD', '17': 'MTV', '18': 'Polsat Sport News', '19': 'TTV', '20': 'TVN 7 HD', '21': 'MiniMini+', '22': 'Discovery Channel HD', '23': 'BBC Earth', '24': 'Nat Geo Wild HD', '25': 'AXN HD', '26': 'TVP Seriale', '27': 'TVP Info', '28': 'Fokus TV', '29': 'TV Puls', '30': 'TVP 2 HD', '31': 'TVN HD', '32': 'HBO HD', '33': 'TLC HD', '34': 'TVP HD', '35': 'TVP Sport HD', '36': 'Canal+ Film HD', '37': 'Canal+ Family HD', '38': 'Canal+ Seriale', '39': 'Eska Rock', '40': 'Polo TV', '41': 'Eska go', '42': 'Eska TV', '43': '6', '44': 'Stopklatka TV', '45': 'Animal Planet HD', '46': 'TVN Style HD', '47': 'TVN Turbo HD', '48': 'TVN 24', '49': 'KinoPolska PL', '50': 'HBO 2 HD', '51': 'HBO Comedy HD', '52': 'Travel Channel', '53': 'Polsat Sport HD', '54': 'Fox HD', '55': 'TVP Historia', '56': 'TVN 24 Biznes i Świat', '57': 'AXN White', '58': 'AXN Black', '59': 'Polsat News', '60': 'Cinemax 2 HD', '61': 'Discovery ID HD', '62': 'History HD', '63': 'Explorer', '64': 'Filmbox', '65': 'TVP Kultura', '66': 'Comedy Central Family', '67': 'NickJR.', '68': 'Music VOX TV', '69': 'Eska Best Music TV', '70': 'Planete+', '71': 'Tuba TV', '72': 'Music VOX TV', '73': 'TVK', '74': 'Czwórka Polskie Radio', '75': 'Disney XD', '76': 'Filmbox Family', '77': 'TVP Pololnia', '78': 'Da Vinci Learning', '79': 'Polsat Film', '80': 'Disney Channel', '81': 'Kuchnia+', '82': 'History', '83': '4 Fun.TV', '84': 'SportKlub', '85': 'Domo+', '86': 'AXN Spin HD', '87': 'Discovery Historia', '88': '4 Fun.TV', '89': 'Disney Junior', '94': 'Kino Polska Muzyka', '102': 'Boomerang', '97': 'Polo Party TV', '96': 'Fightklub', '100': 'Canal+ HD', '101': 'Canal+ Sport HD', '117': 'nSport', '116': 'Extreme Sport', '117': 'Discovery Turbo', '118': 'MGM', '109': 'AXN Black', '106': 'nSport', '134': 'TVP ABC', '135': 'Puls 2', '113': 'Polsat Sport Extra', '121': 'NATGEO people HD', '119': 'FilmBox HD', '139': 'TV4', '146': 'ATM rozrywka', '147': 'Polsat Cafe HD', '123': 'FilmBox Premium', '141': 'JimJam Polsat', '167': 'Animal Planet HD', '156': 'Discovery life', '165': 'Discovery life', '169': 'Nat Geo Wild HD', '170': 'Superstacja', '179': '4Fun TV', '126': 'Polsat Play', '140': 'Polsat Sport News', '206': 'VOX Music TV', '193': 'Filmbox', '192': 'Filmbox Premium', '191': '8TV', '190': 'Disco Polo Music', '202': 'Polsat Sport Extra', '203': 'Polsat Sport HD', '194': 'Filmbox Family', '181': 'Polsat 2', '204': 'Polsat HD', '120': 'Discovery Science', '205': 'Canal+', '172': 'Eleven Extra HD', '171': 'Cartoon Network', '211': '13 Ulica HD', '212': 'Lifetime HD', '213': 'Universal Channel HD', '214': 'BBC HD', '215': 'FOX Comedy HD', '217': 'Nowa TV', '218': 'Nuta TV', '219': 'TVN Fabula HD', '220': 'Cartoon Network' } sts, data = self.cm.getPage(self.MAIN_URL + 'kanaly.html?show=on', self.http_params) if not sts: return [] m1 = "<div class='box-channel'" if m1 not in data: m1 = "<a class='box-channel'" sts, data = self.cm.ph.getDataBeetwenMarkers(data, m1, "<div id='footer'>") data = self.cm.ph.getAllItemsBeetwenMarkers(data, '<a ', '</a>') for item in data: printDBG("item [%r]" % item) url = self.cm.ph.getSearchGroups(item, '''href=['"]([^"^']+?)['"]''')[0] icon = self.cm.ph.getSearchGroups(item, '''src=['"]([^"^']+?)['"]''')[0] id = self.cm.ph.getSearchGroups(url, '''[^0-9]([0-9]+?)[^0-9]''')[0] if '' != url: params = dict(cItem) params['url'] = self.getFullUrl(url) params['icon'] = self.getFullUrl(icon) params['title'] = self.cm.ph.getSearchGroups( item, '''title=['"]([^"^']+?)['"]''')[0] if '' == params['title']: params['title'] = self.cm.ph.getSearchGroups( item, '''alt=['"]([^"^']+?)['"]''')[0] if '' == params['title']: params['title'] = url.replace('.html', '').replace(',', ' ').title() params['title'] = nameMap.get(id, params['title']) params['desc'] = params['url'] channelsTab.append(params) return channelsTab def getVideoLink(self, cItem): printDBG("GoldVodTVApi.getVideoLink") if self.loggedIn: url = strwithmeta(cItem['url'], {'params': {'load_cookie': True}}) else: url = cItem['url'] return self.up.getVideoLinkExt(url) def doLogin(self, login, password): logged = False loginUrl = self.MAIN_URL + 'login.html' params = dict(self.http_params) params['load_cookie'] = False sts, data = self.cm.getPage(loginUrl, params) if not sts: return False HTTP_HEADER = dict(GoldVodTVApi.HTTP_HEADER) HTTP_HEADER.update({'Referer': loginUrl}) post_data = { 'login': login, 'pass': password, 'remember': 1, 'logged': '' } params = { 'header': HTTP_HEADER, 'cookiefile': self.COOKIE_FILE, 'save_cookie': True, 'load_cookie': True } sts, data = self.cm.getPage(loginUrl, params, post_data) if sts: if os_path.isfile(self.COOKIE_FILE): if 'logout.html' in data: printDBG('GoldVodTVApi.doLogin login as [%s]' % login) logged = True else: printDBG( 'GoldVodTVApi.doLogin login failed - wrong user or password?' ) else: printDBG( 'GoldVodTVApi.doLogin there is no cookie file after login') return logged
class Host: currList = [] MAIN_URL = '' PREMIUM = False konto = '' COOKIEFILE = '' HOST = 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.18) Gecko/20110621 Mandriva Linux/1.9.2.18-0.1mdv2010.2 (2010.2) Firefox/3.6.18' def __init__(self): printDBG('Host __init__ begin') self.exSession = MainSessionWrapper() self.COOKIEFILE = GetCookieDir('scseriale.cookie') self.cm = common() self.currList = [] self.up = urlparser() self.history = CSearchHistoryHelper('wspolne') printDBG('Host __init__ end') def setCurrList(self, list): printDBG('Host setCurrList begin') self.currList = list printDBG('Host setCurrList end') return def getInitList(self): printDBG('Host getInitList begin') #################################### # logowanie #################################### self.PREMIUM = self.listsItems(-1, 'zaloguj', 'zaloguj') #################################### self.currList = self.listsItems(-1, 'main-menu', 'main-menu') printDBG('Host getInitList end') return self.currList def getListForItem(self, Index=0, refresh=0, selItem=None): printDBG('Host getListForItem begin') valTab = [] if len(self.currList[Index].urlItems) == 0: return valTab valTab = self.listsItems(Index, self.currList[Index].urlItems[0], self.currList[Index].urlSeparateRequest) self.currList = valTab printDBG('Host getListForItem end') return self.currList def getSearchResults(self, pattern, searchType=None): printDBG("Host getSearchResults begin") printDBG("Host getSearchResults pattern: " + pattern) valTab = [] valTab = self.listsItems(-1, pattern, 'search') self.currList = valTab printDBG("Host getSearchResults end") return self.currList def listsItems(self, Index, url, name=''): printDBG('Host listsItems begin') printDBG('Host listsItems url: ' + url) valTab = [] # ########## # if name == 'main-menu': printDBG('Host listsItems begin name=' + name) self.MAIN_URL = 'http://scs.pl' valTab.append( CDisplayListItem("Seriale wg. kategorii" + self.konto, 'http://scs.pl/seriale.html', CDisplayListItem.TYPE_CATEGORY, ['http://scs.pl/seriale.html'], 'seriale-kategorie', '', None)) valTab.append( CDisplayListItem("Seriale alfabetycznie", 'http://scs.pl/seriale.html', CDisplayListItem.TYPE_CATEGORY, ['http://scs.pl/seriale.html'], 'seriale-abc', '', None)) valTab.append( CDisplayListItem( "Ostatnio aktualizowane seriale", 'http://scs.pl/ostatnio_aktualizowane_seriale.html', CDisplayListItem.TYPE_CATEGORY, ['http://scs.pl/ostatnio_aktualizowane_seriale.html'], 'seriale-last', '', None)) valTab.append( CDisplayListItem('Szukaj', 'Szukaj', CDisplayListItem.TYPE_SEARCH, ['http://scs.pl/serial,szukaj.html'], 'search', '', None)) valTab.append( CDisplayListItem('Historia wyszukiwania', 'Historia wyszukiwania', CDisplayListItem.TYPE_CATEGORY, [''], 'history', '', None)) printDBG('Host listsItems end') return valTab # ########## # if 'zaloguj' == name: printDBG('Host listsItems begin name=' + name) if config.plugins.iptvplayer.scserialePREMIUM.value: url = 'http://scs.pl/logowanie.html' try: data = self.cm.getURLRequestData( { 'url': url, 'use_host': True, 'host': self.HOST, 'use_cookie': True, 'save_cookie': True, 'load_cookie': False, 'cookiefile': self.COOKIEFILE, 'use_post': True, 'return_data': True }, { 'email': config.plugins.iptvplayer.scseriale_login.value, 'password': config.plugins.iptvplayer.scseriale_password.value }) except: printDBG('Host listsItems query error') printDBG('Host listsItems query error url:' + url) printDBG( 'Host listsItems query error: Uzywam Player z limitami' ) data = None if data: self.PREMIUM = True printDBG('Host listsItems: chyba zalogowano do premium...') url = 'http://scs.pl/premium.html' try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': True, 'host': self.HOST, 'use_cookie': True, 'save_cookie': False, 'load_cookie': True, 'cookiefile': self.COOKIEFILE, 'use_post': False, 'return_data': True }) printDBG('Host listsItems data: ' + data) parse = re.search( 'Konto premium ważne do(.*?)".*?;(.*?)<', data, re.S) if parse: self.konto = ' - Twoje konto: ' + parse.group( 2) + parse.group(1) else: self.konto = '' except: printDBG( 'Host listsItems: blad pobrania danych o koncie premium' ) if '' == self.konto: self.exSession.open( MessageBox, 'Problem z zalogowaniem użytkownika \n"%s" jako VIP.' % config.plugins.iptvplayer.scseriale_login.value, type=MessageBox.TYPE_INFO, timeout=10) printDBG('Host listsItems end') return self.PREMIUM # ########## # if 'history' == name: printDBG('Host listsItems begin name=' + name) for histItem in self.history.getHistoryList(): valTab.append( CDisplayListItem(histItem['pattern'], 'Szukaj ', CDisplayListItem.TYPE_CATEGORY, [histItem['pattern'], histItem['type']], 'search', '', None)) printDBG('Host listsItems end') return valTab # ########## # if 'search' == name: printDBG('Host listsItems begin name=' + name) pattern = url if Index == -1: self.history.addHistoryItem(pattern, 'seriale') url = 'http://scs.pl/serial,szukaj.html' postdata = {'search': pattern} try: data = self.cm.getURLRequestData( { 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': True, 'return_data': True }, postdata) except: printDBG('Host listsItems query error') printDBG('Host listsItems query error url:' + url) return valTab #printDBG( 'Host listsItems data: '+data ) match = re.findall( '<div class="img_box"><a href="(.*?)">.*?<img src="(.*?)" alt="(.*?)"', data, re.S) if len(match) > 0: for i in range(len(match)): phImage = match[i][1] phUrl = self.MAIN_URL + '/' + match[i][0] phTitle = match[i][2] printDBG('Host listsItems phImage: ' + phImage) printDBG('Host listsItems phUrl: ' + phUrl) printDBG('Host listsItems phTitle: ' + phTitle) valTab.append( CDisplayListItem(phTitle, phTitle, CDisplayListItem.TYPE_CATEGORY, [phUrl], 'seriale-sezony', phImage, None)) printDBG('Host listsItems end') return valTab # ########## # if 'seriale-last' == name: printDBG('Host listsItems begin name=' + name) try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True }) except: printDBG('Host listsItems query error') printDBG('Host listsItems query error url:' + url) return valTab #printDBG( 'Host listsItems data: '+data ) match = re.compile( 'online">(.+?)</a></div></div><span class="newest_ep" id=".+?">Ostatnio dodany:<br/><a href="odcinek,(.+?),(.+?),(.+?),(.+?).html">' ).findall(data) if len(match) > 0: for i in range(len(match)): phImage = 'http://static.scs.pl/static/serials/' + match[ i][1].replace('.html', '.jpg') + '.jpg' phTitleS = match[i][1] phTitle = match[i][0] + ' - ' + match[i][ 4] + ' - ' + match[i][2].capitalize().replace( '-', ' ') phUrlS = self.MAIN_URL + '/serial,' + match[i][0] phUrl = self.MAIN_URL + '/odcinek,' + match[i][ 1] + ',' + match[i][2] + ',' + match[i][ 3] + ',' + match[i][4] + '.html' printDBG('Host listsItems phImage: ' + phImage) printDBG('Host listsItems phUrl: ' + phUrl) printDBG('Host listsItems phTitle: ' + phTitle) valTab.append( CDisplayListItem(phTitleS, phTitleS, CDisplayListItem.TYPE_CATEGORY, [phUrlS], 'seriale-sezony', phImage, None)) valTab.append( CDisplayListItem(phTitle, phTitle, CDisplayListItem.TYPE_VIDEO, [CUrlItem('', phUrl, 1)], 0, phImage, None)) printDBG('Host listsItems end') return valTab if 'seriale-kategorie' == name: printDBG('Host listsItems begin name=' + name) try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True }) except: printDBG('Host listsItems query error') printDBG('Host listsItems query error url:' + url) return valTab #printDBG( 'Host listsItems data: '+data ) phMovies = re.findall( '<span class="title1">(.*?)</span>(.*?)<.*?href="(.*?)"', data, re.S) if phMovies: for (phTitle, phCount, phUrl) in phMovies: printDBG('Host listsItems phTitle: ' + phTitle) printDBG('Host listsItems phCount: ' + phCount) printDBG('Host listsItems phUrl: ' + phUrl) valTab.append( CDisplayListItem(phTitle + phCount, phTitle, CDisplayListItem.TYPE_CATEGORY, [self.MAIN_URL + '/' + phUrl], 'seriale-kategoria', '', None)) printDBG('Host listsItems end') return valTab if 'seriale-kategoria' == name: printDBG('Host listsItems begin name=' + name) try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True }) except: printDBG('Host listsItems query error') printDBG('Host listsItems query error url:' + url) return valTab #printDBG( 'Host listsItems data: '+data ) match = re.compile( 'class="serial_green" href="serial,(.+?)">(.+?)</a><br/>' ).findall(data) if len(match) > 0: for i in range(len(match)): phImage = 'http://static.scs.pl/static/serials/' + match[ i][0].replace('.html', '.jpg') phTitle = match[i][1] phUrl = self.MAIN_URL + '/serial,' + match[i][0] printDBG('Host listsItems phImage: ' + phImage) printDBG('Host listsItems phUrl: ' + phUrl) printDBG('Host listsItems phTitle: ' + phTitle) valTab.append( CDisplayListItem(phTitle, phTitle, CDisplayListItem.TYPE_CATEGORY, [phUrl], 'seriale-sezony', phImage, None)) printDBG('Host listsItems end') return valTab if 'seriale-abc' == name: printDBG('Host listsItems begin name=' + name) abcTab = self.cm.makeABCList() for i in range(len(abcTab)): phTitle = abcTab[i] valTab.append( CDisplayListItem(phTitle, phTitle, CDisplayListItem.TYPE_CATEGORY, [url, phTitle], 'seriale-alfabet', '', None)) printDBG('Host listsItems end') return valTab if 'seriale-alfabet' == name: printDBG('Host listsItems begin name=' + name) try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True }) except: printDBG('Host listsItems query error') printDBG('Host listsItems query error url:' + url) return valTab #printDBG( 'Host listsItems data: '+data ) letter = self.currList[Index].urlItems[1] match = re.compile( ' <a class="serial_green" href="serial,(.+?)">(.+?)</a><br/>' ).findall(data) if len(match) > 0: for i in range(len(match)): addItem = False if letter == '0 - 9' and (ord(match[i][1][0]) < 65 or ord(match[i][1][0]) > 91): addItem = True if (letter == match[i][1][0].upper()): addItem = True if (addItem): phImage = 'http://static.scs.pl/static/serials/' + match[ i][0].replace('.html', '.jpg') phTitle = match[i][1] phUrl = self.MAIN_URL + '/serial,' + match[i][0] printDBG('Host listsItems phImage: ' + phImage) printDBG('Host listsItems phUrl: ' + phUrl) printDBG('Host listsItems phTitle: ' + phTitle) valTab.append( CDisplayListItem(phTitle, phTitle, CDisplayListItem.TYPE_CATEGORY, [phUrl], 'seriale-sezony', phImage, None)) printDBG('Host listsItems end') return valTab if 'seriale-sezony' == name: printDBG('Host listsItems begin name=' + name) try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True }) except: printDBG('Host listsItems query error') printDBG('Host listsItems query error url:' + url) return valTab #printDBG( 'Host listsItems data: '+data ) phMovies = re.compile( '<meta itemprop="seasonNumber" content="(.+?)">').findall(data) if phMovies: phImage = url.replace( self.MAIN_URL + '/serial,', 'http://static.scs.pl/static/serials/').replace( '.html', '.jpg') printDBG('Host listsItems phImage: ' + phImage) for (phTitle) in phMovies: printDBG('Host listsItems phTitle: ' + phTitle) valTab.append( CDisplayListItem('Sezon ' + phTitle, 'Sezon ' + phTitle, CDisplayListItem.TYPE_CATEGORY, [url, phTitle], 'seriale-odcinki', phImage, None)) printDBG('Host listsItems end') return valTab if 'seriale-odcinki' == name: printDBG('Host listsItems begin name=' + name) try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True }) except: printDBG('Host listsItems query error') printDBG('Host listsItems query error url:' + url) return valTab #printDBG( 'Host listsItems data: '+data ) sezon = self.currList[Index].urlItems[1] r = re.compile( '<meta itemprop="seasonNumber" content="' + sezon + '">(.+?)</ul></div>', re.DOTALL).findall(data) if not r: return [] phMovies = re.compile( 'itemprop="episodeNumber">(.+?)<.+?class="aLink " href="(odcinek,.+?,.+?,.+?,.+?.html)"><span itemprop="name">(.+?)</span></a>' ).findall(r[0]) if phMovies: phImage = url.replace( self.MAIN_URL + '/serial,', 'http://static.scs.pl/static/serials/').replace( '.html', '.jpg') serial = url.replace(self.MAIN_URL + '/serial,', '').replace('.html', '') printDBG('Host listsItems phImage: ' + phImage) for (phEpizod, phUrl, phName) in phMovies: printDBG('Host listsItems phEpizod: ' + phEpizod) printDBG('Host listsItems phUrl: ' + phUrl) phTitle = '%s S%sE%s - %s' % (serial, sezon, phEpizod, phName) printDBG('Host listsItems phTitle: ' + phTitle) valTab.append( CDisplayListItem( phTitle, phTitle, CDisplayListItem.TYPE_CATEGORY, [self.MAIN_URL + '/' + phUrl, phTitle], 'seriale-odcinki-wersje', phImage, None)) printDBG('Host listsItems end') return valTab if 'seriale-odcinki-wersje' == name: printDBG('Host listsItems begin name=' + name) try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True }) except: printDBG('Host listsItems query error') printDBG('Host listsItems query error url:' + url) return valTab #printDBG( 'Host listsItems data: '+data ) parse = re.search('Wersje:(.*?)Kopie:', data, re.S) if not parse: return [] phMovies = re.findall('<a href="(.+?)">(.+?)<', parse.group(1), re.S) if phMovies: phImage = url.replace( self.MAIN_URL + '/serial,', 'http://static.scs.pl/static/serials/').replace( '.html', '.jpg') printDBG('Host listsItems phImage: ' + phImage) for (phUrl, phWersja) in phMovies: printDBG('Host listsItems phUrl: ' + phUrl) printDBG('Host listsItems phWersja: ' + phWersja) valTab.append( CDisplayListItem(phWersja, phWersja, CDisplayListItem.TYPE_CATEGORY, [self.MAIN_URL + '/' + phUrl], 'seriale-odcinki-kopie', phImage, None)) printDBG('Host listsItems end') return valTab if 'seriale-odcinki-kopie' == name: printDBG('Host listsItems begin name=' + name) try: data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True }) except: printDBG('Host listsItems query error') printDBG('Host listsItems query error url:' + url) return valTab #printDBG( 'Host listsItems data: '+data ) parse = re.search('class="mirrors"(.*?)class="switch"', data, re.S) if not parse: return [] phMovies = re.findall( '= "(.+?)"; ccc.+?;.+?"(.+?)";.+?"(.+?)";.+?"(.+?)";', parse.group(1), re.S) if phMovies: for (phUrl, phTime, phUser, phComment) in phMovies: printDBG('Host listsItems phUrl: ' + phUrl) printDBG('Host listsItems phTime: ' + phTime) printDBG('Host listsItems phUser: '******' ' + phUser, phTime + ' ' + phUser + ' ' + phComment, CDisplayListItem.TYPE_VIDEO, [CUrlItem('', phUrl, 1)], 0, '', None)) printDBG('Host listsItems end') return valTab return valTab def getResolvedURL(self, url): printDBG('Host getResolvedURL begin') printDBG('Host getResolvedURL url: ' + url) postdata = {'f': url} if self.PREMIUM: query_data = { 'url': 'http://scs.pl/getVideo.html', 'use_host': True, 'host': self.HOST, 'use_cookie': True, 'save_cookie': False, 'load_cookie': True, 'cookiefile': self.COOKIEFILE, 'use_post': True, 'return_data': True } else: query_data = { 'url': 'http://scs.pl/getVideo.html', 'use_host': False, 'use_cookie': False, 'use_post': True, 'return_data': True } try: data = self.cm.getURLRequestData(query_data, postdata) except: printDBG('Host getResolvedURL query error premium') printDBG('Host getResolvedURL query error premium url: ' + url) return '' #printDBG( 'Host getResolvedURL premium data: ' +data) match = re.compile("url: '(.+?)',").findall(data) if len(match) > 0: linkVideo = match[0] printDBG('Host getResolvedURL linkVideo: ' + linkVideo) printDBG('Host getResolvedURL end premium') return linkVideo printDBG('Host getResolvedURL end') return ''
class GoldVodTVApi: MAIN_URL = 'http://goldvod.tv/' HTTP_HEADER = { 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:12.0) Gecko/20100101 Firefox/12.0', 'Referer': MAIN_URL } def __init__(self): self.COOKIE_FILE = GetCookieDir('goldvodtv.cookie') self.sessionEx = MainSessionWrapper() self.cm = common() self.up = urlparser() self.http_params = {} self.http_params.update({'save_cookie': True, 'load_cookie': True, 'cookiefile': self.COOKIE_FILE}) self.cacheList = {} self.loggedIn = False def getFullUrl(self, url): if url.startswith('http'): return url elif url.startswith('/'): return self.MAIN_URL + url[1:] else: return self.MAIN_URL + url return url def cleanHtmlStr(self, str): return CBaseHostClass.cleanHtmlStr(str) def getChannelsList(self, cItem): printDBG("TelewizjadaNetApi.getChannelsList") login = config.plugins.iptvplayer.goldvodtv_login.value password = config.plugins.iptvplayer.goldvodtv_password.value if login != '' and password != '': if self.doLogin(login, password): self.loggedIn = True self.http_params.update({'save_cookie': True, 'load_cookie': True, 'cookiefile': self.COOKIE_FILE}) else: self.sessionEx.open(MessageBox, _('Problem z zalogowanie użytkownika "%s. Sprawdź dane do logowania w konfiguracji hosta."') % login, type = MessageBox.TYPE_INFO, timeout = 10 ) self.loggedIn = False channelsTab = [] nameMap = {'3':'Eleven','2':'TVgP 1 HD','4':'Polsat HD','5':'Polsat 2 HD','6':'Canal+ Sport HD','7':'Eleven Sports', '8':'Canal+ Sport 2 HD','9':'Canal+ HD','10':'TVN Meteo Active','11':'Eurosport 2 HD','12':'nSport HD', '13':'Erosport HD','14':'Nickelodeon','15':'Comedy Central','16':'National Geographic Channel HD','17':'MTV', '18':'Polsat Sport News','19':'TTV','20':'TVN 7 HD','21':'MiniMini+','22':'Discavery Channel HD','23':'BBC Earth', '24':'Nat Geo Wild HD','25':'AXN HD','26':'TVP Seriale','27':'TVP Info','28':'Fokus TV','29':'TV Puls', '30':'TVP 2 HD','31':'TVN HD','32':'HBO HD','33':'TLC HD','34':'TVP HD','35':'TVP Sport HD','36':'Canal+ Film HD', '37':'Canal+ Family HD','38':'Canal+ Seriale','39':'Eska Rock','40':'Polo TV','41':'Eska go','42':'Eska TV', '43':'6','44':'Stopklatka TV','45':'Animal Planet HD','46':'TVN Style HD','47':'TVN Trurbo HD','48':'TVN 24', '49':'KinoPolska PL','50':'HBO 2 HD','51':'HBO Comedy HD','52':'Travel Channel','53':'Polsat Sport HD', '54':'Fox HD','55':'TVP Historia','56':'TVN 24 Biznes i Świat','57':'AXN White','58':'AXN Black','59':'Polsat News', '60':'Cinemax 2 HD','61':'Discovery ID HD','62':'History HD','63':'Explorer','64':'Filmbox','65':'TVP Kultura', '66':'Comedy Central Family','67':'NickJR.','68':'Music VOX TV','69':'Eska Best Music TV','70':'Planete+', '71':'Tuba TV','72':'Music VOX TV','73':'TVK','74':'Czwórka Polskie Radio','75':'Disney XD','76':'Filmbox Family', '77':'TVP Pololnia','78':'Da Vinci Learning','79':'Polsat Film','80':'Disney Channel','81':'Kuchnia+','82':'History', '83':'4 Fun.TV','84':'SportKlub','85':'Domo+','86':'AXN Spin HD','87':'Discovery Historia','88':'4 Fun.TV','89':'Disney Junior', '94':'Kino Polska Muzyka', '102':'Boomerang', '97':'Polo Party TV', '96':'Fight Klube', '100':'Canal+ HD', '101':'Canal+ Sport HD'} sts, data = self.cm.getPage(self.MAIN_URL + 'kanaly.html') if not sts: return [] sts, data = self.cm.ph.getDataBeetwenMarkers(data, "<div id='content'>", "<div id='footer'>", False) data = self.cm.ph.getAllItemsBeetwenMarkers(data, '<a ', '</a>') for item in data: printDBG("item [%r]" % item) url = self.cm.ph.getSearchGroups(item, '''href=['"]([^"^']+?)['"]''')[0] icon = self.cm.ph.getSearchGroups(item, '''src=['"]([^"^']+?)['"]''')[0] id = self.cm.ph.getSearchGroups(url, '''[^0-9]([0-9]+?)[^0-9]''')[0] if '' != url: params = dict(cItem) params['url'] = self.getFullUrl(url) params['icon'] = self.getFullUrl(icon) params['title'] = self.cm.ph.getSearchGroups(item, '''title=['"]([^"^']+?)['"]''')[0] if '' == params['title']: params['title'] = self.cm.ph.getSearchGroups(item, '''alt=['"]([^"^']+?)['"]''')[0] if '' == params['title']: params['title'] = url.replace('.html', '').replace(',', ' ').title() params['title'] = nameMap.get(id, params['title']) params['desc'] = params['url'] channelsTab.append(params) return channelsTab def getVideoLink(self, cItem): printDBG("GoldVodTVApi.getVideoLink") if self.loggedIn: url = strwithmeta(cItem['url'], {'params':{'load_cookie': True}}) else: url = cItem['url'] return self.up.getVideoLinkExt(url) def doLogin(self, login, password): logged = False loginUrl = self.MAIN_URL params = dict(self.http_params) params['load_cookie'] = False sts, data = self.cm.getPage(loginUrl, params) if not sts: return False HTTP_HEADER= dict(GoldVodTVApi.HTTP_HEADER) HTTP_HEADER.update( {'Referer':loginUrl} ) post_data = {'login': login, 'pass': password, 'remember': 1, 'logged': ''} params = {'header': HTTP_HEADER, 'cookiefile': self.COOKIE_FILE, 'save_cookie': True, 'load_cookie': True} sts, data = self.cm.getPage( loginUrl, params, post_data) if sts: if os_path.isfile(self.COOKIE_FILE): if 'logout.html' in data: printDBG('GoldVodTVApi.doLogin login as [%s]' % login) logged = True else: printDBG('GoldVodTVApi.doLogin login failed - wrong user or password?') else: printDBG('GoldVodTVApi.doLogin there is no cookie file after login') return logged
class Sport365LiveApi: MAIN_URL = 'http://www.sport365.live/' HTTP_HEADER = { 'User-Agent': 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/37.0.2062.120 Chrome/37.0.2062.120 Safari/537.36', 'Accept-Encoding': 'gzip, deflate', 'Referer': MAIN_URL } CACHE_AES_PASSWORD = '' def __init__(self): self.COOKIE_FILE = GetCookieDir('sport365live.cookie') self.sessionEx = MainSessionWrapper() self.cm = common() self.up = urlparser() self.http_params = { 'header': dict(self.HTTP_HEADER), 'use_cookie': True, 'save_cookie': True, 'load_cookie': True, 'cookiefile': self.COOKIE_FILE } self.needRefreshAdvert = True def getPage(self, url, params={}, post_data=None): sts, data = self.cm.getPage(url, params, post_data) if sts: #printDBG("---") #printDBG("url: %s" % url) #printDBG(data) #printDBG("---") return sts, data def getFullUrl(self, url): if url.startswith('http'): return url elif url.startswith('//'): return 'http:' + url elif url.startswith('/'): return self.MAIN_URL + url[1:] return self.MAIN_URL + url def cleanHtmlStr(self, str): return CBaseHostClass.cleanHtmlStr(str) def cryptoJS_AES_decrypt(self, encrypted, password, salt): printDBG("cryptoJS_AES_decrypt") def derive_key_and_iv(password, salt, key_length, iv_length): d = d_i = '' while len(d) < key_length + iv_length: d_i = md5(d_i + password + salt).digest() d += d_i return d[:key_length], d[key_length:key_length + iv_length] bs = 16 key, iv = derive_key_and_iv(password, salt, 32, 16) cipher = AES_CBC(key=key, keySize=32) return cipher.decrypt(encrypted, iv) def decryptUrl(self, linkData, aes): playerUrl = '' if linkData: try: linkData = json_loads(base64.b64decode(linkData)) ciphertext = base64.b64decode(linkData['ct']) iv = a2b_hex(linkData['iv']) salt = a2b_hex(linkData['s']) playerUrl = json_loads( self.cryptoJS_AES_decrypt(ciphertext, aes, salt)) printDBG("player Url --> %s " % str(playerUrl)) except Exception: printExc() return playerUrl def getMarketCookie(self, url, referer, num=1): try: id = url.split('.')[-2] except Exception: printExc() id = '403' printDBG(">> id[%s]\n" % id) xz = str(int(time() * 1000)) + id + str(int( random.random() * 1000)) + str( 2 * int(random.random() * 4)) + str(num) xz = base64.b64encode(xz) return 'MarketGidStorage=%s; ' % urllib.quote( '{"0":{"svspr":"%s","svsds":%s,"TejndEEDj":"%s"},"C%s":{"page":1,"time":%s}}' % (referer, num, xz, id, int(time() * 100))) def refreshAdvert(self): if not self.needRefreshAdvert: return self.sessionEx.open( MessageBox, _('Please remember to visit http://www.sport365.live/ and watch a few advertisements.\nThis will fix problem, if your playback is constantly interrupted.' ), type=MessageBox.TYPE_INFO, timeout=10) self.needRefreshAdvert = False COOKIE_FILE = GetCookieDir('sport365live2.cookie') params = dict(self.http_params) params['cookiefile'] = COOKIE_FILE params['header'] = dict(params['header']) sts, data = self.getPage(self.MAIN_URL, params) if not sts: return baseUrl = self.cm.meta['url'] sessionCookie = self.cm.getCookieHeader(COOKIE_FILE) params['header']['Referer'] = baseUrl awrapperUrls = re.compile( '''['"]([^"^']*?/awrapper/[^'^"]*?)["']''').findall(data) D = datetime.now() timeMarker = '{0}{1}{2}{3}'.format(D.year - 1900, D.month - 1, D.day, D.hour) jscUrl = self.cm.ph.getSearchGroups( data, '''['"]([^'^"]*?jsc\.mgid[^'^"]*?)['"]''')[0] printDBG(">> [%s]" % jscUrl) if jscUrl.endswith('t='): jscUrl += timeMarker adUrl = self.cm.ph.getSearchGroups( data, '''['"]([^'^"]*?\.adshell\.[^'^"]*?)['"]''')[0] sts, data = self.getPage(self.getFullUrl(adUrl), params) if sts: adUrl = self.cm.ph.getSearchGroups( data, '''['"]([^'^"]*?\.adshell\.[^'^"]*?)['"]''')[0] sts, data = self.getPage(self.getFullUrl(jscUrl), params) marketCookie = self.getMarketCookie(jscUrl, baseUrl) params['use_cookie'] = False params['header']['Cookie'] = marketCookie sts, data = self.getPage(self.getFullUrl(adUrl), params) return for awrapperUrl in awrapperUrls: awrapperUrl = self.getFullUrl(awrapperUrl) params['header']['Referer'] = baseUrl params['header']['Cookie'] = sessionCookie + marketCookie sts, data = self.getPage(awrapperUrl, params) if not sts: continue adUrl = self.cm.ph.getSearchGroups( data, '''['"]([^'^"]*?\.adshell\.[^'^"]*?)['"]''')[0] params['header']['Referer'] = awrapperUrl params['header']['Cookie'] = marketCookie sts, data = self.getPage(self.getFullUrl(adUrl), params) if not sts: continue jscUrl = self.cm.ph.getSearchGroups( data, '''['"]([^'^"]*?jsc\.mgid[^'^"]*?)['"]''')[0] if jscUrl.endswith('t='): jscUrl += timeMarker if jscUrl != '': sts, tmp = self.getPage(self.getFullUrl(jscUrl), params) if sts: params['header']['Cookie'] = self.getMarketCookie( jscUrl, awrapperUrl) adUrls = re.compile( '''['"]([^'^"]*?bannerid[^'^"]*?)['"]''').findall(data) for adUrl in adUrls: adUrl = adUrl.replace('&', '&') sts, tmp = self.getPage(self.getFullUrl(adUrl), params) return def getMainCategories(self, cItem): printDBG("Sport365LiveApi.getMainCategories") channelsTab = [] dt = datetime.now() - datetime.utcnow() OFFSET = (dt.microseconds + (dt.seconds + dt.days * 24 * 3600) * 10**6) / 10**6 OFFSET /= 60 if OFFSET % 10 == 9: OFFSET += 1 url = self.getFullUrl('en/events/-/1/-/-/%s' % (OFFSET)) sts, data = self.getPage(self.MAIN_URL, self.http_params) sts, data = self.getPage(url, self.http_params) if not sts: return [] date = '' data = self.cm.ph.getDataBeetwenMarkers(data, '<table', '</table>')[1] data = self.cm.ph.getAllItemsBeetwenMarkers(data, '<tr', '</tr>') for item in data: if '/types/' not in item: tmp = self.cm.ph.getSearchGroups( item, '''>([0-9]{2}\.[0-9]{2}\.[0-9]{4})<''')[0] if tmp != '': date = tmp else: if '/types/dot-green-big.png' in item: title = '[live] ' else: title = '' title += self.cleanHtmlStr(item) desc = self.cm.ph.getSearchGroups( item, '''alt=['"]([^'^"]+?)['"]''')[0] desc = date + ' ' + self.cleanHtmlStr(desc) linksData = [] tmp = self.cm.ph.getSearchGroups( item, '''onClick=[^(]*?\(([^)]+?)\)''')[0].split(',') for t in tmp: linksData.append(t.replace('"', '').strip()) params = dict(cItem) params.update({ 'type': 'category', 'priv_cat': 'streams_links', 'links_data': linksData, 'title': title, 'desc': desc }) printDBG(str(params)) channelsTab.append(params) return channelsTab def getStreamsLinks(self, cItem): printDBG("Sport365LiveApi.getStreamsLinks") channelsTab = [] linksData = cItem.get('links_data', []) if len(linksData) < 4 or not linksData[0].startswith('event_'): return [] eventId = linksData[0].replace('event_', '') url = self.getFullUrl('en/links/{0}/{1}'.format( eventId, linksData[-1])) sts, data = self.getPage(url, self.http_params) if not sts: return [] desc = self.cleanHtmlStr( self.cm.ph.getDataBeetwenMarkers( data, '<table', '</table>')[1]) + '[/br]' + cItem.get( 'desc', '') data = self.cm.ph.getAllItemsBeetwenMarkers(data, '<tr', '</tr>') for item in data: sourceTitle = self.cleanHtmlStr(item.split('<span')[0]) links = self.cm.ph.getAllItemsBeetwenMarkers( item, '<span ', '</span>') for link in links: linkTitle = self.cleanHtmlStr(link) if '{' in linkTitle: continue linkData = self.cm.ph.getSearchGroups( link, '''onClick=[^(]*?\(([^)]+?)\)''')[0].split(',')[0].replace( '"', '').replace("'", '').strip() if linkData != '': params = dict(cItem) params.update({ 'type': 'video', 'link_data': linkData, 'event_id': eventId, 'desc': desc, 'title': sourceTitle + ' ' + linkTitle }) printDBG(str(params)) channelsTab.append(params) return channelsTab def getChannelsList(self, cItem): printDBG("Sport365LiveApi.getChannelsList") self.refreshAdvert() category = cItem.get('priv_cat', None) if None == category: return self.getMainCategories(cItem) elif 'streams_links' == category: return self.getStreamsLinks(cItem) return [] def _getAesPassword(self, cItem, forceRefresh=False): if Sport365LiveApi.CACHE_AES_PASSWORD != '' and not forceRefresh: return Sport365LiveApi.CACHE_AES_PASSWORD sts, data = self.getPage( self.getFullUrl('en/home/' + cItem['event_id']), self.http_params) if not sts: return [] jsData = '' tmp = self.cm.ph.getAllItemsBeetwenMarkers(data, '<script', '</script>') for item in tmp: if 'Contact' in item: item = self.cm.ph.getDataBeetwenReMarkers( item, re.compile('<script[^>]+?>'), re.compile('</script>'), False)[1] if 'Contact' in item: jsData = 'try{ %s; } catch(e){ ; }\n' % (item) break jsData2 = '' aes = '' data = re.compile( '''src=['"](http[^"^']*?/js/[0-9a-fA-F]{32}\.js[^'^"]*?)["']''' ).findall(data)[::-1] for commonUrl in data: sts, tmpData = self.getPage(commonUrl, self.http_params) if not sts: continue if tmpData.startswith(';eval('): try: jscode = base64.b64decode( '''dmFyIGRvY3VtZW50ID0ge307DQp2YXIgd2luZG93ID0gdGhpczsNCmRvY3VtZW50LndyaXRlID0gZnVuY3Rpb24oKXt9Ow0Kd2luZG93LmF0b2IgPSBmdW5jdGlvbigpe3JldHVybiAiIjt9Ow0KDQpmdW5jdGlvbiBkZWNyeXB0KCl7DQogICAgdmFyIHRleHQgPSBKU09OLnN0cmluZ2lmeSh7YWVzOmFyZ3VtZW50c1sxXX0pOw0KICAgIHByaW50KHRleHQpOw0KICAgIHJldHVybiAiIjsNCn0NCg0KdmFyIENyeXB0b0pTID0ge307DQpDcnlwdG9KUy5BRVMgPSB7fTsNCkNyeXB0b0pTLkFFUy5kZWNyeXB0ID0gZGVjcnlwdDsNCkNyeXB0b0pTLmVuYyA9IHt9Ow0KQ3J5cHRvSlMuZW5jLlV0ZjggPSAidXRmLTgiOw0K''' ) jscode = '%s %s %s' % (jscode, tmpData, jsData) ret = js_execute(jscode) if ret['sts'] and 0 == ret['code']: decoded = ret['data'].strip() aes = json_loads(decoded)['aes'] except Exception: printExc() if aes != '': break if aes != '': Sport365LiveApi.CACHE_AES_PASSWORD = aes return aes def getAesPassword(self, cItem, forceRefresh=False): if Sport365LiveApi.CACHE_AES_PASSWORD != '' and not forceRefresh: return Sport365LiveApi.CACHE_AES_PASSWORD sts, data = self.getPage( self.getFullUrl('en/home/' + cItem['event_id']), self.http_params) if not sts: return [] aes = '' data = re.compile( '''src=['"](http[^"^']*?/js/[0-9a-fA-F]{32}\.js[^'^"]*?)["']''' ).findall(data)[::-1] num = 0 deObfuscatedData = '' aes_password = [] for commonUrl in data: num += 1 printDBG("common url n. %s : %s " % (str(num), commonUrl)) sts, tmpData = self.getPage(commonUrl, self.http_params) if not sts: continue aes = '' try: while ('eval' in tmpData) and (not aes): tmp = tmpData.split('eval(') if len(tmp): del tmp[0] tmpData = '' for item in tmp: for decFun in [ VIDEOWEED_decryptPlayerParams, VIDEOWEED_decryptPlayerParams2, SAWLIVETV_decryptPlayerParams ]: if not (item.startswith('function(w,i,s,e){for') and decFun == VIDEOWEED_decryptPlayerParams): tmpData = unpackJSPlayerParams( 'eval(' + item, decFun, 0) if '' != tmpData: printDBG( '**********************************') printDBG(tmpData) printDBG( '**********************************') break aes = self.cm.ph.getSearchGroups( tmpData, 'aes_key="([^"]+?)"')[0] if '' == aes: aes = self.cm.ph.getSearchGroups( tmpData, 'aes\(\)\{return "([^"]+?)"')[0] if aes == '': funname = self.cm.ph.getSearchGroups( tmpData, 'CryptoJS\.AES\.decrypt\([^\,]+?\,([^\,]+?)\,' )[0].strip() if funname != '': printDBG("ZZZZZZZZZZZZZ") printDBG("FUN NAME: [%s]" % funname) printDBG("ZZZZZZZZZZZZZ") tmp = self.cm.ph.getDataBeetwenMarkers( tmpData, 'function %s' % funname, '}')[1] try: aes = self.cm.ph.getSearchGroups( tmp, '"([^"]+?)"')[0].encode('utf-8') except Exception: printExc() aes = aes.encode('utf-8') except Exception: printExc() aes = '' if aes: printDBG("Added password %s" % aes) aes_password.append(aes) if aes_password: Sport365LiveApi.CACHE_AES_PASSWORD = aes_password return aes_password def getVideoLink(self, cItem): printDBG("Sport365LiveApi.getVideoLink") if Sport365LiveApi.CACHE_AES_PASSWORD != '': tries = 2 else: tries = 1 urlsTab = [] for checkIdx in range(tries): if checkIdx > 0: aes_password = self.getAesPassword(cItem, True) else: aes_password = self.getAesPassword(cItem) if not aes_password: return [] printDBG("aes -----> %s" % str(aes_password)) for aes in aes_password: try: printDBG("link_data -----> " + str(cItem['link_data'])) playerUrl = self.decryptUrl(cItem['link_data'], aes) if not playerUrl.startswith('http'): continue sts, data = self.getPage(playerUrl, self.http_params) if not sts: return [] links = re.compile( '(http://www.[^\.]+.pw/(?!&#)[^"]+)', re.IGNORECASE + re.DOTALL + re.MULTILINE + re.UNICODE).findall(data) link = [x for x in links if '&#' in x] if link: link = re.sub(r'&#(\d+);', lambda x: chr(int(x.group(1))), link[0]) printDBG("Found *.pw link ------> %s " % link) h = self.http_params h['header']['Referer'] = playerUrl sts, data = self.getPage(link, h) if sts: #printDBG("*****************") #printDBG(data) #printDBG("*****************") # search form data in page action = re.compile( '[\'"]action[\'"][,\s]*[\'"](http.*?)[\'"]' ).findall(data) r = re.compile( '.*?name="r"\s*value=["\']([^"\']+)["\']' ).findall(data) d = re.compile( '.*?name="d"\s*value=["\']([^"\']+)["\']' ).findall(data) f = re.compile( '.*?name="f"\s*value=["\']([^"\']+)["\']' ).findall(data) srcs = re.compile('src=[\'"](.*?)[\'"]').findall( data) if f and r and d and action: postData = {'r': r[0], 'd': d[0], 'f': f[0]} h['header']['Referer'] = link sts, data = self.getPage( action[0], h, postData) if sts: #printDBG("*****************") #printDBG(data) #printDBG("*****************") try: #######ads banners######### # simulate ads viewing bheaders = h bheaders['header']['Referer'] = action[ 0] banner = re.findall( r'<script\s*src=[\'"](.+?)[\'"]', data)[-1] sts, bsrc = self.getPage( banner, bheaders) banner = re.findall( r"url:'([^']+)", bsrc)[0] sts, bsrc = self.getPage( banner, bheaders) bheaders['header']['Referer'] = banner banner = re.findall( r'window.location.replace\("([^"]+)"\);\s*}\)<\/script><div', bsrc)[0] banner = urllib.quote( banner, ':/()!@#$%^&;><?') sts, bsrc = self.getPage( banner, bheaders) ########################### except BaseException: pass link2 = re.compile( '\([\'"][^"\']+[\'"], [\'"][^"\']+[\'"], [\'"]([^"\']+)[\'"], 1\)' ).findall(data) if link2: printDBG(link2[0]) playerUrl = self.decryptUrl( link2[0], aes).replace("/i", "/master.m3u8") printDBG( "Final player Url -----------> %s " % str(playerUrl)) playerUrl = strwithmeta( playerUrl, { 'User-Agent': h['header']['User-Agent'], 'Referer': action[0] }) COOKIE_FILE_M3U8 = GetCookieDir( 'sport365live.cookie') params = { 'cookiefile': COOKIE_FILE_M3U8, 'use_cookie': True, 'load_cookie': False, 'save_cookie': True } urlsTab.extend( getDirectM3U8Playlist( playerUrl, checkExt=False, variantCheck=True, cookieParams=params, checkContent=True, sortWithMaxBitrate=99999999)) else: # old system playerUrl = self.cm.ph.getSearchGroups( data, '''location\.replace\(\s*?['"]([^'^"]+?)['"]''', 1, True)[0] if playerUrl: printDBG("player Url 2 ------> %s " % playerUrl) else: data = self.cm.ph.getDataBeetwenMarkers( data, 'document.write(', '(')[1] playerUrl = self.cleanHtmlStr( self.cm.ph.getSearchGroups( data, '''<iframe[^>]+?src=['"](http[^"^']+?)['"]''', 1, True)[0]) urlsTab = self.up.getVideoLinkExt( strwithmeta(playerUrl, {'aes_key': aes})) if len(urlsTab): break except Exception: printExc() return urlsTab
class VideoStarApi: MAINURL_PC = 'https://videostar.pl/' MAINURL_IOS = 'https://m.videostar.pl/' HTTP_HEADER_PC = { 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:12.0) Gecko/20100101 Firefox/12.0', 'Referer': MAINURL_PC } HTTP_HEADER_IOS = { 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B179 Safari/7534.48.3', 'Referer': MAINURL_IOS } HTTP_HEADER2 = { 'User-Agent': 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16', 'Referer': MAINURL_IOS } API_URLS = { 'subscriptions_url': 'subscriptions', 'login_url': 'login', 'get_ad_show': 'api/ad/show', 'get_ad_urls': 'api/ad/urls', 'get_channels_list': 'api/channels/list/web', 'get_channel_url': 'api/channels/get/%s?format_id=%s', 'close_channel': 'api/channels/close', } VIDEO_STAR_T = '' VIDEO_GUEST_M = False def __init__(self): self.cm = common() #proxyURL= '', useProxy = True) self.up = urlparser() self.sessionEx = MainSessionWrapper() def printPageData(self, url, data): printDBG("printPageData") printDBG(": [%s]" % url) printDBG(data) printDBG("--------------------------------------------------") def doInit(self): if config.plugins.iptvplayer.videostar_use_proxy_gateway.value and '2' == config.plugins.iptvplayer.videostar_streamprotocol.value: self.proxy_gateway_url = "http://www.bramka-proxy.pl/browse.php?u={0}&b=60" #192&f=norefer" #config.plugins.iptvplayer.videostar_proxy_gateway_url.value self.proxy_gateway_url_ssl = "http://www.bramka-proxy.pl/includes/process.php?action=sslagree" self.my_ip = '' #self.my_ip = self.getProxyGatewayIP() else: self.my_ip = '' self.proxy_gateway_url = '' self.proxy_gateway_url_ssl = '' self._reInit() self.channelsList = [] def getProxyGatewayIP(self): url = 'http://showip.net/' sts, data = self.cm.getPage( url, { 'header': { 'User-Agent': 'Mozilla/5.0', 'Referer': self.proxy_gateway_url }, 'proxy_gateway': self.proxy_gateway_url }) my_ip = '' if sts: try: my_ip = self.cm.ph.getSearchGroups( data, 'name="checkip"[^>]+?value="([^"]+?)"')[0] printDBG('getProxyGatewayIP my_ip[%s]' % my_ip) except Exception: printExc() if '' == my_ip: self.sessionEx.open(MessageBox, _('Problem z uzyskaniem IP bramki proxy!'), type=MessageBox.TYPE_INFO, timeout=10) return my_ip def _getUrl(self, key): if '2' == self.streamprotocol: MAINURL = VideoStarApi.MAINURL_IOS else: MAINURL = VideoStarApi.MAINURL_PC if key in VideoStarApi.API_URLS: return MAINURL + VideoStarApi.API_URLS[key] if not key.startswith('http'): return MAINURL + key return key def _reInit(self): self.streamprotocol = config.plugins.iptvplayer.videostar_streamprotocol.value if '2' == self.streamprotocol: self.MAINURL = VideoStarApi.MAINURL_IOS self.cm.HEADER = dict(VideoStarApi.HTTP_HEADER_IOS) else: self.MAINURL = VideoStarApi.MAINURL_PC self.cm.HEADER = dict(VideoStarApi.HTTP_HEADER_PC) if '' != self.my_ip: self.cm.HEADER['X-Forwarded-For'] = self.my_ip self.LOGIN = config.plugins.iptvplayer.videostar_login.value self.PASSWORD = config.plugins.iptvplayer.videostar_password.value def getDefaultQuality(self): return config.plugins.iptvplayer.videostar_defquality.value def getChannelsList(self, refresh=False): printDBG("VideoStarApi.getChannelsList") self.doInit() if not refresh and 0 < len(self.channelsList): return self.channelsList self.channelsList = [] if '' != self.LOGIN.strip() and '' != self.PASSWORD.strip(): if not self.doLogin(self.LOGIN, self.PASSWORD): self.sessionEx.open( MessageBox, _('Problem z zalogowanie użytkownika "%s. Sprawdź dane do logowania w konfiguracji hosta."' ) % self.LOGIN, type=MessageBox.TYPE_INFO, timeout=10) return self.channelsList else: self.sessionEx.open( MessageBox, _('Strona wymaga darmowego konta na http://videostar.pl/.\nProszę uzupełnić dane w konfiguracji hosta.' ), type=MessageBox.TYPE_INFO, timeout=10) return self.channelsList self._fillChannelsList() return self.channelsList def _fillChannelsList(self): printDBG("VideoStarApi._fillChannelsList") HTTP_HEADER = dict(self.cm.HEADER) HTTP_HEADER.update({'X-Reguested-With': 'XMLHttpReguest'}) if self.proxy_gateway_url != '': HTTP_HEADER['Referer'] = self.proxy_gateway_url.format( urllib.quote(HTTP_HEADER['Referer'])) params = { 'header': HTTP_HEADER, 'proxy_gateway': self.proxy_gateway_url } else: params = {'header': HTTP_HEADER} # get channels list url = self._getUrl('get_channels_list') sts, data = self.cm.getPage(url, params) if sts: self.printPageData(url, data) try: data = byteify(json.loads(data)) if "ok" == data['status']: self.channelsList = data['channels'] except Exception: printExc() def getVideoLink(self, channelID): printDBG("VideoStarApi.getVideoLink") urlsTab = [] #get referer page referer = '' guestMode = False for item in self.channelsList: if channelID == item['id']: referer = self.MAINURL + '#' + item[ 'slug'] # "slug" attrib can be also taken from stream_channel data linkType = 'basic' if "unsubscribed" == item['access_status']: guestMode = True elif 'subscribed' == item['access_status']: linkType = 'premium' break for tryNum in range(2): # there is need to close previuse played channel #self._closePrevChannel() if tryNum > 0: # retrie if there was unknown problem with getting link self._reInit() if not guestMode: self.doLogin(self.LOGIN, self.PASSWORD) else: self.cm.HEADER = dict(VideoStarApi.HTTP_HEADER2) if '' != self.my_ip: self.cm.HEADER['X-Forwarded-For'] = self.my_ip url = self._getUrl('get_channel_url') % (channelID, self.streamprotocol) HTTP_HEADER = dict(self.cm.HEADER) HTTP_HEADER.update({'X-Reguested-With': 'XMLHttpReguest'}) if self.proxy_gateway_url != '': HTTP_HEADER['Referer'] = self.proxy_gateway_url.format( urllib.quote(HTTP_HEADER['Referer'])) params = { 'header': HTTP_HEADER, 'proxy_gateway': self.proxy_gateway_url } else: params = {'header': HTTP_HEADER} if guestMode: url = url.replace('https://videostar.pl/api', 'https://api.videostar.pl/guest') sts, data = self.cm.getPage(url, params) try: self.printPageData(url, data) data = byteify(json.loads(data)) if "ok" == data['status']: VideoStarApi.VIDEO_STAR_T = data['stream_channel'][ 'url_params'][-1].decode('utf-8') url_param1 = data['stream_channel']['url_params'][ 1].decode('utf-8') VideoStarApi.VIDEO_GUEST_M = guestMode if '1' == self.streamprotocol: url = data['stream_channel']['url_base'].decode( 'utf-8') sts, data = self.cm.getPage(url, params) self.printPageData(url, data) r = re.search('<baseURL>([^<]+?)</baseURL>', data).group(1) streams = re.findall( 'url="([^"]+?)" bitrate="([0-9]+?)"', data) for item in streams: # swfVfy=https://videostar.pl/javascripts/libs/flowplayer/flowplayer.netvi-x.swf protocol=1 url = r + '/' + item[ 0] + ' live=1 swfUrl=https://videostar.pl/javascripts/libs/flowplayer/flowplayer.commercial-3.2.11.swf' + ' pageUrl=' + referer + ( ' conn=S:%s conn=S:%s token=%s' % (url_param1, VideoStarApi.VIDEO_STAR_T, VideoStarApi.VIDEO_STAR_T) ) + ' flashVer=WIN 12,0,0,44 ' urlsTab.append({ 'url': strwithmeta(url, {'iptv_proto': 'rtmp'}), 'name': item[1], 'bitrate': item[1] + '000', 'type': 'rtmpt' }) else: # hls url = data['stream_channel']['url_base'].decode( 'utf-8') meta = {'iptv_proto': 'm3u8'} if '' != self.proxy_gateway_url: channelID = data['stream_channel']['channel_id'] #if url.startswith('https://'): url = 'http://' + url[8:] server = self.cm.ph.getSearchGroups( url, r'://([^/]+?)/')[0] #if linkType == 'basic': # meta['iptv_m3u8_custom_base_link'] = 'https://%s:443/%s/%s%s.stream/list.m3u8' % (server, channelID, channelID, 2) #else: meta['iptv_m3u8_custom_base_link'] = 'https://%s:443/%s/smil:%s.ism/list.m3u8' % ( server, channelID, linkType ) #'http://%s:1935/%s/smil:%s.ism/list.m3u8' % (server, channelID, linkType) meta['iptv_proxy_gateway'] = self.proxy_gateway_url meta['Referer'] = self.proxy_gateway_url meta['User-Agent'] = 'Mozilla/5.0' if '' != self.my_ip: meta['X-Forwarded-For'] = self.my_ip meta['Cookie'] = self.cm.HEADER.get('Cookie', '') urlsTab.append({ 'url': self.up.decorateUrl(url, meta), 'name': 'videostar hls', 'type': 'hls' }) except Exception: printExc() if 0 < len(urlsTab): break printDBG(urlsTab) return urlsTab def doLogin(self, login, password): HTTP_HEADER = dict(self.cm.HEADER) HTTP_HEADER.update( {'Content-Type': 'application/x-www-form-urlencoded'}) cookiePath = GetCookieDir('videostar.cookie') params = { 'header': HTTP_HEADER, 'cookiefile': cookiePath, 'use_cookie': True, 'save_cookie': True } rm(cookiePath) if self.proxy_gateway_url_ssl != '': HTTP_HEADER['Referer'] = self.proxy_gateway_url sts, data = self.cm.getPage(self.proxy_gateway_url_ssl, params) self.printPageData(self.proxy_gateway_url_ssl, data) if not sts: return False params['load_cookie'] = True params['proxy_gateway'] = self.proxy_gateway_url post_data = {'login': login, 'password': password, 'permanent': '1'} url = self._getUrl('login_url') sts, data = self.cm.getPage(url, params, post_data) if not sts: return False self.printPageData(url, data) self.cm.HEADER['Cookie'] = self.cm.getCookieHeader(cookiePath) if self.proxy_gateway_url != '': HTTP_HEADER = dict(self.cm.HEADER) HTTP_HEADER['Referer'] = self.proxy_gateway_url.format( urllib.quote(HTTP_HEADER['Referer'])) params = { 'proxy_gateway': self.proxy_gateway_url, 'header': HTTP_HEADER } else: params = {} url = self._getUrl('subscriptions_url') sts, data = self.cm.getPage(url, params) if sts: self.printPageData(url, data) if 'Wyloguj' in data: return True return False
class EdemTvApi: def __init__(self): self.MAIN_URL = 'https://edem.tv/' self.HTTP_HEADER = { 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:12.0) Gecko/20100101 Firefox/12.0', 'Referer': self.MAIN_URL } self.COOKIE_FILE = GetCookieDir('edemtv.cookie') self.cm = common() self.up = urlparser() self.http_params = {} self.http_params.update({ 'header': self.HTTP_HEADER, 'save_cookie': True, 'load_cookie': True, 'cookiefile': self.COOKIE_FILE }) self.cacheChannels = {} self.sessionEx = MainSessionWrapper() def getFullUrl(self, url): if url.startswith('http'): return url elif url.startswith('/'): return self.MAIN_URL + url[1:] return self.MAIN_URL + url def cleanHtmlStr(self, str): return CBaseHostClass.cleanHtmlStr(str) def doLogin(self, login, password): logged = False HTTP_HEADER = dict(self.HTTP_HEADER) HTTP_HEADER.update({ 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 'X-Requested-With': 'XMLHttpRequest' }) post_data = {'email': login, 'password': password} params = { 'header': HTTP_HEADER, 'cookiefile': self.COOKIE_FILE, 'save_cookie': True } loginUrl = self.getFullUrl('account/login') sts, data = self.cm.getPage(loginUrl, params, post_data) if sts and '/account/logout' in data: logged = True return logged def getChannelsList(self, cItem): printDBG("EdemTvApi.getChannelsList") channelsTab = [] getList = cItem.get('get_list', True) if getList: login = config.plugins.iptvplayer.edemtv_login.value passwd = config.plugins.iptvplayer.edemtv_password.value if '' != login.strip() and '' != passwd.strip(): if not self.doLogin(login, passwd): self.sessionEx.open(MessageBox, _('Login failed.'), type=MessageBox.TYPE_INFO, timeout=10) return [] else: self.sessionEx.open( MessageBox, _('This host requires registration. \nPlease fill your login and password in the host configuration. Available under blue button.' ), type=MessageBox.TYPE_ERROR, timeout=10) return [] self.cacheChannels = {} categoryUrl = self.getFullUrl('category') sts, data = self.cm.getPage(categoryUrl, self.http_params) if not sts: return [] marker = "animated_hidden uk-width-1-1" channelsData = self.cm.ph.getDataBeetwenMarkers( data, marker, 'uk-visible-small', False)[1] channelsData = channelsData.split(marker) for catItem in channelsData: catId = self.cm.ph.getSearchGroups( catItem, ''' id=['"]([^'^"]+?)['"]''')[0] if catId == '': continue channelsPerCat = self.cm.ph.getAllItemsBeetwenMarkers( catItem, '<a ', '</a>') for item in channelsPerCat: url = self.cm.ph.getSearchGroups( item, ''' href=['"]([^'^"]+?)['"]''')[0] icon = self.cm.ph.getSearchGroups( item, ''' src=['"]([^'^"]+?)['"]''')[0] alt = self.cm.ph.getSearchGroups( item, ''' alt=['"]([^'^"]+?)['"]''')[0] params = { 'type': 'video', 'url': self.getFullUrl(url), 'title': self.cleanHtmlStr(alt), 'icon': self.getFullUrl(icon), 'desc': self.cleanHtmlStr(item) } if catId not in self.cacheChannels: self.cacheChannels[catId] = [params] else: self.cacheChannels[catId].append(params) catsData = self.cm.ph.getDataBeetwenMarkers( data, 'uk-visible-small', '</ul>')[1] catsData = self.cm.ph.getAllItemsBeetwenMarkers( catsData, '<li ', '</li>') for item in catsData: catId = self.cm.ph.getSearchGroups( item, '''data-target=['"]([^'^"]+?)['"]''')[0] catTitle = self.cleanHtmlStr(item) + ' (%s)' % catId.title() if 0 == len(self.cacheChannels.get(catId, [])): continue if 'adult' == catId: adult = True else: adult = False params = dict(cItem) params.update({ 'title': catTitle, 'cat_id': catId, 'get_list': False, 'pin_locked': adult }) channelsTab.append(params) else: catId = cItem.get('cat_id', '') channels = self.cacheChannels.get(catId, []) for item in channels: params = dict(cItem) params.update(item) channelsTab.append(params) return channelsTab def getCookieItem(self, name): value = '' try: value = self.cm.getCookieItem(self.COOKIE_FILE, name) except Exception: printExc() return value def getVideoLink(self, cItem): printDBG("EdemTvApi.getVideoLink") playlistUrl = self.getFullUrl('playlist') tries = 0 while tries < 7: tries += 1 sts, data = self.cm.getPage(playlistUrl, self.http_params) if not sts: return [] subdomain = self.cm.ph.getSearchGroups( data, '''<input[^>]*?name=['"]subdomain['"][^>]*?value=['"]([^'^"]+?)['"]''' )[0] domainTab = self.cm.ph.getSearchGroups( data, '''<option[^>]*?value="([0-9]+?)"[^>]*?selected[^>]*?>([^<]+?)</option>''', 2) if subdomain == '' or '' == domainTab[0] or '' == domainTab[1]: HTTP_HEADER = dict(self.HTTP_HEADER) HTTP_HEADER.update({ 'Referer': playlistUrl, 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 'X-Requested-With': 'XMLHttpRequest' }) login = config.plugins.iptvplayer.edemtv_login.value passwd = config.plugins.iptvplayer.edemtv_password.value subdomain = md5(login + passwd).hexdigest() post_data = {'server_id': tries, 'name': subdomain} params = dict(self.http_params) params['header'] = HTTP_HEADER url = self.getFullUrl('ajax/user_server') sts, data = self.cm.getPage(url, params, post_data) printDBG(data) if 'success' in data: post_data = { 'server': tries, 'subdomain': subdomain, 'type': 1 } sts, data = self.cm.getPage(playlistUrl, params, post_data) printDBG(data) else: break sts, data = self.cm.getPage(cItem['url'], self.http_params) if not sts: return [] #printDBG(data) data = self.cm.ph.getDataBeetwenMarkers(data, 'playlist:', ']', False)[1] hlsUrl = self.cm.ph.getSearchGroups(data, '''['"](http[^'^"]+?)['"]''')[0] rmpUrl = self.cm.ph.getSearchGroups(data, '''['"](rtmp[^'^"]+?)['"]''')[0] urlsTab = [] if hlsUrl.startswith('http://') and 'm3u8' in hlsUrl: hlsUrl = 'http://{0}.{1}/iptv/'.format( subdomain, domainTab[1]) + hlsUrl.split('/iptv/')[-1] hlsUrl = strwithmeta( hlsUrl, { 'Cookie': 'session=%s;' % self.getCookieItem('session'), 'Referer': cItem['url'], 'User-Agent': self.HTTP_HEADER['User-Agent'] }) urlsTab = getDirectM3U8Playlist(hlsUrl) #if rmpUrl.startswith('rtmp'): # urlsTab.append({'name':'rtmp', 'url':rmpUrl + ' live=1'}) return urlsTab
class SatLiveApi: MAINURL = 'http://web-live.tv/' LIST_URL = MAINURL + 'transmissions/transmission/index' SWF_URL = MAINURL + 'themes/default/swf/jwplayer.flash.swf' LOGIN_URL = MAINURL + 'site/site/login' HTTP_HEADER = { 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:12.0) Gecko/20100101 Firefox/12.0', 'Referer': MAINURL } def __init__(self): self.COOKIE_FILE = GetCookieDir('satlivetv.cookie') self.cm = common() self.sessionEx = MainSessionWrapper() self.loggedIn = True self.http_params = {} #self._reInit() #self.channelsList = [] def getChannelsList(self): printDBG("SatLiveApi.getChannelsList") # login premium = config.plugins.iptvplayer.satlivetv_premium.value login = config.plugins.iptvplayer.satlivetv_login.value password = config.plugins.iptvplayer.satlivetv_password.value if premium: if self.doLogin(login, password): self.loggedIn = True self.http_params.update({ 'save_cookie': True, 'load_cookie': True, 'cookiefile': self.COOKIE_FILE }) else: self.sessionEx.open( MessageBox, _('Problem z zalogowanie użytkownika "%s. Sprawdź dane do logowania w konfiguracji hosta."' ) % login, type=MessageBox.TYPE_INFO, timeout=10) # get channels channelsList = [] sts, data = self.cm.getPage(SatLiveApi.LIST_URL, self.http_params) if not sts: return [] data = self.cm.ph.getDataBeetwenMarkers( data, '<div class="tab-pane active" id="live">', '<div class="tab-pane" id="all">', False)[1] data = data.split('</li>') for item in data: tmp = self.cm.ph.getSearchGroups( item, '<h4><a href="([^"]+?)">([^<]+?)</a></h4>', 2) if '' != tmp[0]: params = {} params['url'] = SatLiveApi.MAINURL + tmp[0] params['title'] = tmp[1] icon = self.cm.ph.getSearchGroups( item, '<img class="" src="([^"]+?)"')[0] if '' != icon: params['icon'] = SatLiveApi.MAINURL + icon params['desc'] = self.cm.ph.removeDoubles( clean_html(item.replace('>', '> ')).replace('\t', ' '), ' ') channelsList.append(params) return channelsList def getVideoLink(self, url): printDBG("SatLiveApi.getVideoLink") id = self.cm.ph.getSearchGroups(url + "/", 'id/([0-9]+?)/')[0] sts, data = self.cm.getPage(SatLiveApi.MAINURL + 'ge/' + id, self.http_params) if not sts: return '' base = self.cm.ph.getSearchGroups(data, 'base="([^"]+?)"')[0] src = self.cm.ph.getSearchGroups(data, 'src="([^"]+?)"')[0] if base.startswith('rtmp'): return base + '/' + src + ' swfUrl=%s live=1' % SatLiveApi.SWF_URL return '' def doLogin(self, login, password): logged = False HTTP_HEADER = dict(SatLiveApi.HTTP_HEADER) HTTP_HEADER.update({ 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 'X-Requested-With': 'XMLHttpRequest' }) post_data = { 'LoginForm[email]': login, 'LoginForm[password]': password, 'ajax': 'fast-login-form', 'undefined': '' } params = { 'header': HTTP_HEADER, 'cookiefile': self.COOKIE_FILE, 'save_cookie': True } sts, data = self.cm.getPage(SatLiveApi.LOGIN_URL, params, post_data) if sts: if os_path.isfile(self.COOKIE_FILE): printDBG(data) if '[]' == data: printDBG('SatLiveApi.doLogin login as [%s]' % login) logged = True else: printDBG( 'SatLiveApi.doLogin login failed - wrong user or password?' ) else: printDBG( 'SatLiveApi.doLogin there is no cookie file after login') return logged