Example #1
0
 def do_validate(self, background=False, is_closed=None):
     if self.config.update_running:
         return
     self.config.update_running = True
     chans = list(tools.safeiter(self.iterchannels()))
     channels = []
     pgname = "Updating Channels"
     if background:
         pg = gui.bgprogress(pgname)
     else:
         pg = gui.progress("Checking")
         pg.update(0, pgname)
     index = 0
     for chan in chans:
         if not self.checkinternet():
             gui.warn("No Connection", "Skipping Channel Update")
             self.config.lastupdate = int(time.time())
             self.config.validate = False
             self.config.update_running = False
             pg.close()
             return
         if is_closed or hasattr(pg, "iscanceled") and pg.iscanceled():
             self.config.update_running = False
             break
         c = self.loadchannel(chan)
         if not c:
             continue
         index += 1
         error = None
         found = False
         if c.checkerrors is not None:
             error = c.checkerrors()
         if error is None:
             for url in tools.safeiter(c.get()):
                 error = self.healthcheck(url)
                 if error is None:
                     # at least one url is enough
                     found = True
                     break
         if not error and not found:
             error = "No playlist"
         if error is None:
             channels.append([
                 c.icon, c.title, c.index, c.categories,
                 url if isinstance(url, const.URL) else None
             ])
             error = "UP"
         pg.update(int(100 * index / len(chans)),
                   "%s\n%s: %s" % (c.title, error, c.index))
         if index == 200000:
             break
     self.config.channels = channels
     epg.write(self, pg)
     self.config.lastupdate = int(time.time())
     self.config.update_running = False
     if self.config.validate:
         self.config.validate = False
     self.config.update_pvr = True
     pg.close()
Example #2
0
 def get(self):
     if self.youtube_chanid:
         for yayin in safeiter(youtube.itermedias(self.youtube_chanid, self.youtube_stream, self.youtube_sindex)):
             yield yayin
     if self.canlitv_id or self.canlitv_ids:
         for yayin in safeiter(canlitvcenter.itermedias(self.canlitv_id, self.canlitv_ids)):
             yield yayin
     if self.kolay_id or self.kolay_ids:
         for yayin in safeiter(kolaytv.itermedias(self.kolay_id, self.kolay_ids)):
             yield yayin
     if self.dady_id or self.dady_name:
         for yayin in safeiter(dadylive.itermedias(self.dady_id, self.dady_name)):
             yield yayin
     if self.selcuk_name:
         for yayin in safeiter(selcuk.itermedias(self.selcuk_name, self.selcuk_adaptive)):
             yield yayin
     if self.selcuk_mobile:
         for yayin in safeiter(selcuk.mobile_itermedias(self.selcuk_mobile, self.selcuk_mobile_adaptive)):
             yield yayin
     if self.ses_id or self.ses_ids:
         for yayin in safeiter(ses.itermedias(self.ses_id, self.ses_ids, self.ses_adaptive)):
             yield yayin
     if self.sports24_id:
         for yayin in safeiter(sports24.itermedias(self.sports24_id)):
             yield yayin
    def geturls(self, id):
        fansubxpath = ".//div[@class='panel-body']/div[1]/button"
        mirrorxpath = ".//div[@class='panel-body']/div[4]/button"

        with Browser() as browser:
            page = browser.navigate(id, domain, self.ispagevalid)
        xpage = htmlement.fromstring(page)

        fansubs = {}

        for fansub, fansublink in tools.safeiter(
                self.iterajaxlink(xpage, fansubxpath)):
            fansubs[fansub] = fansublink

        if not fansubs:
            for _, mirrorlink in tools.safeiter(
                    self.iterajaxlink(xpage, mirrorxpath)):
                mirror = self.getlink(mirrorlink)
                if mirror:
                    yield mirror
        else:
            fansubselect = gui.select("Select Fansub", list(fansubs.keys()))
            i = -1
            for _fansub, fansublink in fansubs.items():
                i += 1
                if fansubselect == -1 or fansubselect == i:
                    with Browser(None, 0) as browser:
                        page = browser.navigate(
                            fansublink,
                            id,
                            headers={"x-requested-with": "XMLHttpRequest"})
                    xfansubpage = htmlement.fromstring(page)
                    mirror = self.getlink(None, xfansubpage)
                    if mirror:
                        yield mirror
                    for _, mirrorlink in tools.safeiter(
                            self.iterajaxlink(xfansubpage, mirrorxpath)):
                        mirror = self.getlink(mirrorlink)
                        if mirror:
                            yield mirror
Example #4
0
 def selecturl(self, url, **kwargs):
     key = json.dumps(url)
     info = self.hay(_resolvehay).find(key + "_info").data
     art = self.hay(_resolvehay).find(key + "_art").data
     try:
         links = self.getscrapers(mtd="geturls", args=[url],
                                  **kwargs).next()
     except Exception:
         print traceback.format_exc()
         return
     for link in tools.safeiter(links):
         if not isinstance(link, (str, unicode)):
             continue
         item = self.item(link, info, art, method="geturls")
         item.resolve(link, True, **kwargs)
Example #5
0
 def _iterobjs():
     for mod, cls in extension.getobjects(
             common.dpath, parents=[liblivechannels.scraper]):
         if cls.subchannel:
             continue
         if not cls.index:
             cls.index = "%s:%s:" % (mod.__name__, cls.__name__)
         yield cls
     for mod, cls in extension.getobjects(
             common.dpath, parents=[liblivechannels.scrapers]):
         cls_ob = cls(self.download)
         for cls_sub in tools.safeiter(cls_ob.iteratechannels()):
             if not cls_sub.index:
                 cls_sub.index = "%s:%s:%s" % (
                     mod.__name__, cls.__name__, cls_sub.__name__)
             yield cls_sub
Example #6
0
 def test_links(self):
     valids = []
     invalids = []
     error = None
     if self.channel.checkerrors is not None:
         error = self.channel.checkerrors()
     if error is None:
         for link in tools.safeiter(self.channel.get()):
             error = base.healthcheck(link)
             if error is not None:
                 invalids.append((error, link))
             else:
                 valids.append(link)
     self.assertFalse(
         self.minlinks > len(valids),
         "%s, %s, Minimum requried link is %s but available is %s."
         "Invalids:%s"
         "Valids:%s" % (self.channel.title, self.channel.index,
                        self.minlinks, len(valids), invalids, valids))
Example #7
0
 def onloop(self):
     try:
         icon, title, index, cats, _isdaptive = self.channels[self.index]
     except IndexError:
         self.writeline("</tv>")
         with codecs.open(common.epath, "w", encoding="utf-8") as f:
             f.write(self.wfile)
         self.base.config.update_pvr = True
         self.close()
         return
     self.index += 1
     if "Broken" in cats:
         return
     if self.progress:
         self.progress.update(int(100 * self.index / len(self.channels)),
                              "Updating EPG: %s" % title)
     self.writeline('<channel id="%s">' % index)
     self.writeline('\t<display-name>%s</display-name>' %
                    self.xmlescape(title))
     self.writeline('\t<icon src="%s"/>' % icon)
     self.writeline("</channel>")
     channel = self.base.loadchannel(index)
     if not channel:
         return
     for programme in tools.safeiter(channel.iterprogrammes()):
         if programme is None:
             continue
         self.writeline(
             '<programme start="%s" stop="%s" channel="%s">' %
             (programme.start, programme.end, self.xmlescape(index)))
         self.writeline('\t<title>%s</title>' %
                        self.xmlescape(programme.title))
         if programme.desc:
             self.writeline('\t<desc>%s</desc>' %
                            self.xmlescape(programme.desc))
         for pcat in programme.categories:
             self.writeline('\t<category>%s</category>' %
                            self.xmlescape(pcat))
         if programme.subtitle:
             self.writeline('\t<sub-title>%s</sub-title>' %
                            self.xmlescape(programme.subtitle))
         if programme.airdate:
             self.writeline('\t<date>%s</date>' % programme.airdate)
         if programme.episode:
             self.writeline(
                 '\t<episode-num system="onscreen">%s</episode-num>' %
                 self.xmlescape(programme.episode))
         if len(programme.directors) or len(programme.writers) or len(
                 programme.actors):
             self.writeline('\t<credits>')
             for key, iterable in [("director", programme.directors),
                                   ("writer", programme.writers),
                                   ("actor", programme.actors)]:
                 for item in iterable:
                     self.writeline('\t\t<%s>%s</%s>' %
                                    (key, self.xmlescape(item), key))
             self.writeline('\t</credits>')
         if programme.icon:
             self.writeline('\t<icon src="%s"/>' %
                            self.xmlescape(programme.icon))
         self.writeline('</programme>')
Example #8
0
 def do_GET(self):
     kwargs = hls.decodeurl(self.path)
     qurl = kwargs.get("url")
     qheaders = kwargs.get("headers", {})
     qplaylist = kwargs.get("playlist")
     qepg = kwargs.get("epg")
     if qurl:
         rng = self.headers.get("Range")
         if rng:
             qheaders["Range"] = rng
         resp = self.base.proxy_get(qurl, qheaders)
         if isinstance(resp, Exception) or resp is None:
             self.send_response(500, str(resp))
             self.end_headers()
         else:
             m3file = self.render_m3(resp, qurl, qheaders)
             if isinstance(m3file, Exception):
                 self.send_response(500, str(m3file))
                 return
             self.send_response(resp.status_code)
             self.end_headers()
             if m3file:
                 self.wfile.write(m3file.dumps().encode())
             else:
                 decryptor = hls.DecryptPayload(**kwargs.get("encryption", {}))
                 for chunk in resp.iter_content(decryptor.chunksize, False):
                     data = decryptor.decrypt(chunk)
                     self.wfile.write(data)
                 self.wfile.write(decryptor.flush())
     elif qplaylist:
         chan = self.base.loadchannel(qplaylist)
         if not chan:
             return
         self.send_response(200)
         self.end_headers()
         pgen = hls.PlaylistGenerator(self.base)
         forceproxy = kwargs.get("forceproxy", 0)
         for url in tools.safeiter(chan.get()):
             if isinstance(url, net.mpdurl) and url.inputstream:
                 pass
                 # skip mpds for now
             else:
                 if isinstance(url, net.hlsurl):
                     headers = url.headers
                     u = url.url
                 else:
                     u, headers = net.fromkodiurl(url)
                 if not headers:
                     headers = {}
                 resp = self.base.proxy_get(u, headers)
                 if resp is not None and not isinstance(resp, Exception):
                     content = resp.content.decode()
                     if content[:7] == "#EXTM3U":
                         m3file = m3u8.loads(content, uri=u)
                         m3file.full_uri = u
                         pgen.add(m3file, headers, forceproxy or chan.usehlsproxy)
                         if pgen.playlists.qsize():
                             break
         self.wfile.write(pgen.m3file.dumps().encode())
     elif qepg:  # epg response
         self.send_response(200)
         self.end_headers()
         epg.write(self.base).start()
         self.writeline(common.epath)
     else:  # main channel list
         self.send_response(200)
         # self.send_header("Content-Type", "application/vnd.apple.mpegurl;charset=utf-8")
         self.end_headers()
         self.writeline('#EXTM3U')
         playlists = self.base.config.playlists
         for icon, title, index, cats, url in self.base.config.channels:
             pnames = []
             for playlistname, indexes in self.base.config.iterplaylists(playlists):
                 if index in indexes:
                     pnames.append(playlistname)
             playlisturl = None
             if url:
                 if url.inputstream:
                     self.writeline("#KODIPROP:inputstreamaddon=inputstream.adaptive")
                     self.writeline("#KODIPROP:inputstreamclass=inputstream.adaptive")
                     self.writeline("#KODIPROP:inputstream.adaptive.manifest_type=%s" % url.manifest)
                     if isinstance(url, net.mpdurl):
                         if url.lurl:
                             self.writeline('#KODIPROP:inputstream.adaptive.license_type=%s' % url.license)
                             url.lurl, url.lheaders = net.fromkodiurl(net.tokodiurl(url.lurl, headers=url.lheaders, pushua=const.USERAGENT, pushverify="false"))
                             self.writeline('#KODIPROP:inputstream.adaptive.license_key=%s' % url.kodilurl)
                         playlisturl = net.tokodiurl(url.url, headers=url.headers, pushverify="false", pushua=const.USERAGENT)
                     self.writeline("#KODIPROP:inputstream.adaptive.stream_headers=%s" % const.USERAGENT)
             self.writeline('#EXTINF:0 tvg-logo="%s" tvg-id="%s" group-title="%s",%s' % (icon,
                                                                                         index,
                                                                                         ";".join(cats + pnames),
                                                                                         title))
             self.writeline(playlisturl or hls.encodeurl(playlist=index))
Example #9
0
 def __init__(self, useragent=None, httptimeout=None, *iargs, **ikwargs):
     self.__inittime = time.time()
     self.sysaddon = sys.argv[0]
     self.syshandle = int(sys.argv[1])
     serial = sys.argv[2][1:]
     try:
         data = json.loads(urllib.unquote_plus(serial))
     except Exception:
         data = {}
     self._items = []
     self._playlist = []
     self._hays = {}
     self._container = data.get("container", self.__class__.__name__)
     self._module = data.get("module", self.__class__.__module__)
     self._method = data.get("method", _default_method)
     self._media = data.get("media", None)
     args = data.get("args", [])
     kwargs = data.get("kwargs", {})
     self._disp_container = self._container
     self._disp_module = self._module
     self._disp_method = self._method
     self._isplaying = 0  # 0 stopped, 1: trying, 2: started
     self.ondispatch()
     if self._disp_module == self.__class__.__module__:
         if self._disp_container == self.__class__.__name__:
             self._container = self
         else:
             self._module = sys.modules[self._disp_module]
             self._container = getattr(self._module, self._disp_container)()
             return
     else:
         self._module = importlib.import_module(self._disp_module)
         self._container = getattr(self._module, self._disp_container)()
         return
     self.__itime = (time.time() - _startt) * 1000
     xbmc.log("****** TinyXBMC is Dispatching ******")
     xbmc.log("MODULE    : %s" % self._disp_module)
     xbmc.log("CONTAINER : %s" % self._disp_container)
     xbmc.log("METHOD    : %s" % self._disp_method)
     xbmc.log("ARGUMENTS : %s" % repr(args))
     xbmc.log("KW ARGS   : %s" % repr(kwargs))
     xbmc.log("MEDIA     : %s" % repr(self._media))
     xbmc.log("*************************************")
     self._container.useragent = const.USERAGENT
     self._container.httptimeout = const.HTTPTIMEOUT
     self._container.autoupdate = False
     self._container.init(*iargs, **ikwargs)
     self._method = getattr(self._container, self._disp_method)
     if self._container._media == "resolver":
         p = player()
         redirects = []
         for u, finfo, fart in tools.dynamicret(
                 tools.safeiter(self._method(*args, **kwargs))):
             if p.dlg.iscanceled():
                 break
             p.fallbackinfo = finfo
             p.fallbackart = fart
             self._container._isplaying = 1
             if "plugin://" in u:
                 redirects.append(u)
                 continue
             item = xbmcgui.ListItem(path=u)
             state = p.stream(u, item)
             if state:
                 self._container._isplaying = 2
                 self._close()
                 return
             else:
                 self._container._isplaying = 0
                 p.dlg.update(100, "Skipping broken url: %s" % u)
         if not self._container._isplaying == 2 and len(redirects):
             redirects = list(set(redirects))
             if len(redirects) == 1:
                 u = redirects[0]
             else:
                 u = gui.select("Select Addon", *redirects)
             if p.canresolve:
                 p.stream("", xbmcgui.ListItem())
             tools.builtin(u)
             state = p.waitplayback(u)
             self._close()
             self._container._isplaying = 2
             return
     elif self._container._media == "player":
         p = xbmc.PlayList(1)
         try:
             ret = self._method(*args, **kwargs)
         except Exception:
             print traceback.format_exc()
             self._close()
             sys.exit()
         iterable = tools.safeiter(ret)
         for u in iterable:
             item = xbmcgui.ListItem(path=u)
             p.add(u, item)
         xbmc.Player().play(p)
     else:
         try:
             cnttyp = self._method(*args, **kwargs)
         except Exception:
             print traceback.format_exc()
             self._close()
             sys.exit()
         itemlen = len(self._container._items)
         if cnttyp in const.CT_ALL:
             xbmcplugin.setContent(self.syshandle, cnttyp)
         if itemlen:
             for url, item, isfolder in self._container._items:
                 if cnttyp in const.CT_ALL:
                     setview = self.item("Set view default for %s" %
                                         cnttyp.upper())
                     setview.method = "_setview"
                     item.context(setview, False, cnttyp)
                     item.docontext()
                 xbmcplugin.addDirectoryItem(self.syshandle, url, item.item,
                                             isfolder, itemlen)
             xbmcplugin.endOfDirectory(self.syshandle, cacheToDisc=False)
             if self._container.autoupdate:
                 d = self.item("Auto Update", method="_update")
                 d.run(self._container.autoupdate)
         if cnttyp in const.CT_ALL:
             views = self.hay(const.OPTIONHAY).find("views").data
             if cnttyp in views:
                 spath = xbmc.getSkinDir().decode("utf-8")
                 view = views[cnttyp].get(spath, None)
                 if view:
                     for i in range(0, 10 * 20):
                         if xbmc.getCondVisibility('Container.Content(%s)' %
                                                   cnttyp):
                             xbmc.executebuiltin(
                                 "Container.SetSortMethod(27)")
                             xbmc.executebuiltin(
                                 'Container.SetViewMode(%d)' % view)
                             break
                         xbmc.sleep(100)
     self._close()
Example #10
0
 def geturls(self, url, headers=None):
     for provider in self.providers:
         if provider.regex and re.search(provider.regex, url):
             for url in tools.safeiter(provider().resolve(url, headers)):
                 yield url
             break
Example #11
0
    def geturls(self, url, direct, **kwargs):
        key = json.dumps(url)
        info = self.hay(_resolvehay).find(key + "_info").data
        art = self.hay(_resolvehay).find(key + "_art").data
        playerins = {}

        def getplayer(priority):
            target, hasinit, pcls = playerins[priority]
            if hasinit:
                return target, hasinit
            else:
                print "VODS is initializing %s" % target
                try:
                    ins = pcls(self)
                    playerins[target] = (target, ins, pcls)
                    makenameart(ins)
                    gui.notify("Initialized", ins.title, False)
                    return target, ins
                except Exception:
                    print traceback.format_exc()
                    return target, None

        def prepareplayers(priority, entrypoint):
            for player in extension.getplugins(entrypoint):
                priority += 1
                target = ":".join([str(x) for x in player._tinyxbmc.values()])
                playerins[priority] = (target, False, player)
            return priority

        if not direct:
            try:
                links = self.getscrapers(mtd="geturls", args=[url],
                                         **kwargs).next()
            except Exception:
                print traceback.format_exc()
        else:
            try:
                self.getscrapers(**kwargs).next()
            except Exception:
                print traceback.format_exc()
            links = iter([url])
        priority = 0
        if self.chan.useaddonplayers:
            priority = prepareplayers(priority, _extaddonplayer)
        if self.chan.usedirect:
            priority += 1
            playerins[priority] = ("direct", linkplayerextension(self), None)
        if self.chan.uselinkplayers:
            priority = prepareplayers(priority, _extlinkplayer)
        for k in sorted(playerins, reverse=True):
            print "VODS found player(%s): %s" % (k, playerins[k][0])
        for kodilink in tools.safeiter(links):
            link, headers = net.fromkodiurl(kodilink)
            if not isinstance(link, (str, unicode)):
                print "VODS received broken link, skipping...: %s" % repr(link)
                continue
            gui.notify("Scraping", link, False)
            print "VODS is scraping link: %s" % link.encode("ascii", "replace")
            for priority in sorted(playerins, reverse=True):
                target, pcls = getplayer(priority)
                print "VODS is trying player: %s" % target
                if not pcls:
                    print "VODS received broken player, skipping...: %s" % repr(
                        target)
                    continue
                found = False
                isaddon = False
                for url in tools.safeiter(pcls.geturls(link, headers)):
                    if not url:
                        print "VODS received broken url, skipping...: %s" % repr(
                            url)
                        break
                    found = True
                    if url.startswith("plugin://"):
                        try:
                            url = pcls.builtin % url
                        except Exception:
                            print traceback.format_exc()
                            continue
                        isaddon = True
                    yield url, info, art
                if found and not isaddon:
                    while True:
                        if not self._isplaying == 1:
                            break
                    if self._isplaying == 2:
                        print "VODS started playback : %s" % repr(url)
                        break