def mh_buildMenu(self, url): self.d_print("mh_buildMenu:") self.mh_menuListe = [] self.mh_menuListe.append((_('Please wait...'),None)) self.ml.setList(map(self.mh_menuListentry, self.mh_menuListe)) self.mh_lastPageUrl = url twAgentGetPage(url, agent=None, cookieJar=self.mh_cookieJar, headers=std_headers).addCallback(self.mh_parseCategorys).addErrback(self.mh_dataError)
def resolve(self, service, uri): Log.i(uri) uri = uri.replace('mp_euronews://', '').lower().strip() if uri == 'en': uri = 'www' uri = "https://%s.euronews.com/api/watchlive.json" % uri def onUrlReady(uri): try: if not service.ptrValid(): Log.w("Service became invalid!") return if uri: service.setResolvedUri(uri, eServiceReference.idGST) else: service.failedToResolveUri() except: service.failedToResolveUri() if uri: twAgentGetPage(uri).addCallback(self.parseLive, service) else: service.failedToResolveUri() return True
def parseLive(self, data, service): data = data.replace('\/', '/') urls = re.findall('m3u8_url":"(.*?)"', data, re.S) if urls: uri = urls[-1] try: if not service.ptrValid(): Log.w("Service became invalid!") return if uri: twAgentGetPage(uri).addCallback(self.parseData, service) else: service.failedToResolveUri() except: service.failedToResolveUri()
def mh_buildMenu(self, url, addlocation=False, agent=None, headers=std_headers): self.mh_menuListe = [] self.mh_menuListe.append((_('Please wait...'), None)) self.ml.setList(map(self.mh_menuListentry, self.mh_menuListe)) self.mh_lastPageUrl = url self.d_print("mh_buildMenu:", url) if not url: self.mh_parseCategorys(None) else: try: import requests s = requests.session() headers = {'User-Agent': agent} page = s.get(url, cookies=self.mh_cookieJar, headers=headers) return self.mh_parseCategorys(page.content) except: return twAgentGetPage(url, agent=agent, cookieJar=self.mh_cookieJar, headers=headers, addlocation=addlocation, timeout=(10, 30)).addCallback( self.mh_parseCategorys).addErrback( self.mh_dataError)
def _get_page(self, url): url = url.encode("utf-8") if 'HLS_RESET_COOKIES' in os.environ.keys(): self._cookies.clear() timeout = 10 return twAgentGetPage(url, agent=self.agent, cookieJar=self._cookies, headers=self.hls_headers, timeout=timeout, pool=self._poolHelper._pool, proxy_url=self.purl, p_user=self.puser, p_pass=self.ppass)
def getNTStream(self, country): if country == "nl": self.base_url = "utopiatv.nl" else: self.base_url = "utopya.com.tr" auth_url = 'https://token.%s/api/2/GetLongLivedAuthToken/?callback=&authToken=&_=' % self.base_url return twAgentGetPage(auth_url, timeout=10).addCallback(self.getNTAuth).addErrback(self.getNTAuth, True)
def downloadPage(self, url, path): d = twAgentGetPage(url) f = open(path, 'wb') d.addCallback(lambda x: f.write(x)) d.addBoth(lambda _: f.close()) d.addCallback(lambda _: path) return d
def getNTAuth(self, jdata, err=False): try: auth_token = re.search('authToken":"(.*?)"', jdata).group(1) stream_url = 'https://token.%s/api/2/GetToken/?callback=&authToken=%s&streamKey=stream_live_1&platform=web&_=' % (self.base_url, auth_token) except: raise Exception('Cannot get utopia authToken!') else: return twAgentGetPage(stream_url, timeout=10).addCallback(self.getNTM3U8URL)
def _getWebPage(self, result, url, no_token=True): if no_token: if self.connected: self._sessionTimeoutTimer.start(1000 * self.SESSION_TIMEOUT, True) url = url.replace("%TOKEN%", self.session_token) return twAgentGetPage( url, agent=self.USER_AGENT, cookieJar=self.cookies, headers=Headers(self.agent_headers), timeout=15 )
def getNTStream(self, country): if country == "nl": self.base_url = "utopiatv.nl" else: self.base_url = "utopya.com.tr" auth_url = 'https://token.%s/api/2/GetLongLivedAuthToken/?callback=&authToken=&_=' % self.base_url return twAgentGetPage(auth_url, timeout=10).addCallback( self.getNTAuth).addErrback(self.getNTAuth, True)
def mh_buildMenu(self, url, addlocation=False, agent=None, headers=std_headers): self.mh_menuListe = [] self.mh_menuListe.append((_('Please wait...'),None)) self.ml.setList(map(self.mh_menuListentry, self.mh_menuListe)) self.mh_lastPageUrl = url self.d_print("mh_buildMenu:",url) if not url: self.mh_parseCategorys(None) else: return twAgentGetPage(url, agent=agent, cookieJar=self.mh_cookieJar, headers=headers, addlocation=addlocation, timeout=(10,30)).addCallback(self.mh_parseCategorys).addErrback(self.mh_dataError)
def getNTAuth(self, jdata, err=False): try: auth_token = re.search('authToken":"(.*?)"', jdata).group(1) stream_url = 'https://token.%s/api/2/GetToken/?callback=&authToken=%s&streamKey=stream_live_1&platform=web&_=' % ( self.base_url, auth_token) except: raise Exception('Cannot get utopia authToken!') else: return twAgentGetPage(stream_url, timeout=10).addCallback(self.getNTM3U8URL)
def resolve(self, service, uri): Log.i(uri) uri = uri.replace('mp_livestreamcom://', '').lower().strip() def onUrlReady(uri): try: if not service.ptrValid(): Log.w("Service became invalid!") return if uri: service.setResolvedUri(uri, eServiceReference.idGST) else: service.failedToResolveUri() except: service.failedToResolveUri() if uri: twAgentGetPage(uri).addCallback(self.parseLive, service) else: service.failedToResolveUri() return True
def getATVStream(self, station): if station == "atv": self.url = 'http://www.atv.com.tr/webtv/secure?url=http://trkvz-live.ercdn.net/atvhd/atvhd.m3u8' elif station == "aspor": self.url = 'http://www.aspor.com.tr/webtv/secure?url=http://trkvz-live.ercdn.net/asporhd/asporhd.m3u8' elif station == "ahaber": self.url = 'http://www.ahaber.com.tr/webtv/secure?url=http://trkvz-live.ercdn.net/ahaberhd/ahaberhd.m3u8' elif station == "atvavrupa": self.url = 'http://www.atv.com.tr/webtv/secure?url=http://trkvz-live.ercdn.net/atvavrupa/atvavrupa.m3u8' elif station == "minikacocuk": self.url = 'http://www.minikacocuk.com.tr/webtv/secure?url=http://trkvz-live.ercdn.net/minikagococuk/minikagococuk.m3u8' elif station == "minikago": self.url = 'http://www.minikago.com.tr/webtv/secure?url=http://trkvz-live.ercdn.net/minikago/minikago.m3u8' return twAgentGetPage(self.url, timeout=10, agent=agent).addCallback(self.getATVAuthUrl).addErrback(self.getATVAuthUrl, True)
def getATVStream(self, station): if station == "atv": self.url = 'http://www.atv.com.tr/webtv/secure?url=http://trkvz-live.ercdn.net/atvhd/atvhd.m3u8' elif station == "aspor": self.url = 'http://www.aspor.com.tr/webtv/secure?url=http://trkvz-live.ercdn.net/asporhd/asporhd.m3u8' elif station == "ahaber": self.url = 'http://www.ahaber.com.tr/webtv/secure?url=http://trkvz-live.ercdn.net/ahaberhd/ahaberhd.m3u8' elif station == "atvavrupa": self.url = 'http://www.atv.com.tr/webtv/secure?url=http://trkvz-live.ercdn.net/atvavrupa/atvavrupa.m3u8' elif station == "minikacocuk": self.url = 'http://www.minikacocuk.com.tr/webtv/secure?url=http://trkvz-live.ercdn.net/minikagococuk/minikagococuk.m3u8' elif station == "minikago": self.url = 'http://www.minikago.com.tr/webtv/secure?url=http://trkvz-live.ercdn.net/minikago/minikago.m3u8' return twAgentGetPage(self.url, timeout=10, agent=agent).addCallback( self.getATVAuthUrl).addErrback(self.getATVAuthUrl, True)
def requestM3U8(self, url): d = twAgentGetPage(str(url), agent=self.USER_AGENT) d.addCallback(self._getM3U8List) d.addCallback(self._getBestVideoUrl, url).addErrback(self.dataError) return d
def r_getPage(url, *args, **kwargs): def retry(err): return getPage(url.replace('https:', 'http:'), *args, **kwargs) return twAgentGetPage(url, *args, **kwargs).addErrback(retry)
def checkforupdate(self): update_agent = getUserAgent() update_url = getUpdateUrl() twAgentGetPage(update_url, agent=update_agent, timeout=60).addCallback( self.gotUpdateInfo).addErrback(self.gotError)
def checkforupdate(self): update_agent = getUserAgent() update_url = getUpdateUrl() twAgentGetPage(update_url, agent=update_agent, timeout=60).addCallback(self.gotUpdateInfo).addErrback(self.gotError)