예제 #1
0
def run():
    # Make sure the XBMC jsonrpc server is started.
    xbmc.startServer(xbmc.SERVER_JSONRPCSERVER, True)

    # Make the monitor
    monitor = ElementumMonitor()

    threads = [
        threading.Thread(target=server_thread),  # JSONRPC thread
    ]
    if not ONLY_CLIENT:
        sys.stderr.write("elementum: ONLY " + str(ONLY_CLIENT))
        threads.append(
            threading.Thread(target=elementumd_thread,
                             args=[monitor]))  # Elementumd thread

    for t in threads:
        t.daemon = True
        t.start()

    # XBMC loop
    while not xbmc.abortRequested:
        xbmc.sleep(1000)

    log.info("elementum: exiting elementumd")
예제 #2
0
def run():
    # Make sure the XBMC jsonrpc server is started.
    xbmc.startServer(xbmc.SERVER_JSONRPCSERVER, True)

    # Make the monitor
    monitor = ElementumMonitor()

    threads = [
        threading.Thread(target=server_thread),  # JSONRPC thread
    ]
    if not ONLY_CLIENT and PLATFORM["fork"]:
        threads.append(
            threading.Thread(target=elementumd_thread,
                             args=[monitor]))  # Elementumd thread

    for t in threads:
        t.daemon = True
        t.start()

    # XBMC loop
    while not monitor.abortRequested():
        xbmc.sleep(1000)

    if PLATFORM['kodi'] >= 19:
        monitor.onAbortRequested()

    log.info("elementum: exiting elementumd")
예제 #3
0
def run():
    # Make sure the XBMC jsonrpc server is started.
    xbmc.startServer(xbmc.SERVER_JSONRPCSERVER, True)

    # Make the monitor
    monitor = QuasarMonitor()

    threads = [
        threading.Thread(target=server_thread),  # JSONRPC thread
        threading.Thread(target=quasard_thread,
                         args=[monitor]),  # Quasard thread
    ]
    for t in threads:
        t.daemon = True
        t.start()

    # XBMC loop
    while not monitor.abortRequested():
        xbmc.sleep(1000)

    try:
        monitor.onAbortRequested()
    except:
        pass

    log.info("quasar: exiting quasard")
예제 #4
0
def main():
    # Make sure the XBMC jsonrpc server is started.
    xbmc.startServer(xbmc.SERVER_JSONRPCSERVER, True)

    # Start the JSONRPC thread
    threading.Thread(target=server_thread).start()

    # Start the Pulsard thread
    threading.Thread(target=pulsard_thread).start()

    # Get the monitor
    monitor = PulsarMonitor()

    # XBMC loop
    while not xbmc.abortRequested:
        xbmc.sleep(4000)

    log.info("pulsar: exiting pulsard")
예제 #5
0
def server(type, status, wait=False):
    servers = dict(air=xbmc.SERVER_AIRPLAYSERVER,
                   event=xbmc.SERVER_EVENTSERVER,
                   rpc=xbmc.SERVER_JSONRPCSERVER,
                   upnpr=xbmc.SERVER_UPNPRENDERER,
                   upnp=xbmc.SERVER_UPNPSERVER,
                   web=xbmc.SERVER_WEBSERVER,
                   zeroconf=xbmc.SERVER_ZEROCONF)
    return xbmc.startServer(servers[type], status, wait)
예제 #6
0
def server(type, status, wait=False):
    servers = dict(
        air = xbmc.SERVER_AIRPLAYSERVER,
        event = xbmc.SERVER_EVENTSERVER,
        rpc = xbmc.SERVER_JSONRPCSERVER,
        upnpr = xbmc.SERVER_UPNPRENDERER,
        upnp = xbmc.SERVER_UPNPSERVER,
        web = xbmc.SERVER_WEBSERVER,
        zeroconf = xbmc.SERVER_ZEROCONF
    )
    return xbmc.startServer(servers[type], status, wait)
예제 #7
0
def run():
    # Make sure the XBMC jsonrpc server is started.
    xbmc.startServer(xbmc.SERVER_JSONRPCSERVER, True)

    # Make the monitor
    monitor = PulsarMonitor()

    threads = [
        threading.Thread(target=server_thread),  # JSONRPC thread
        threading.Thread(target=pulsard_thread, args=[monitor]),  # Pulsard thread
    ]
    for t in threads:
        t.daemon = True
        t.start()

    # XBMC loop
    while not xbmc.abortRequested:
        xbmc.sleep(1000)

    log.info("pulsar: exiting pulsard")
예제 #8
0
def run():
    # Make sure the XBMC jsonrpc server is started.
    xbmc.startServer(xbmc.SERVER_JSONRPCSERVER, True)

    # Make the monitor
    monitor = PulsarMonitor()

    threads = [
        threading.Thread(target=server_thread),  # JSONRPC thread
        threading.Thread(target=pulsard_thread,
                         args=[monitor]),  # Pulsard thread
    ]
    for t in threads:
        t.daemon = True
        t.start()

    # XBMC loop
    while not xbmc.abortRequested:
        xbmc.sleep(1000)

    log.info("pulsar: exiting pulsard")
예제 #9
0
def run():
    # Make sure the XBMC jsonrpc server is started.
    xbmc.startServer(xbmc.SERVER_JSONRPCSERVER, True)

    # Make the monitor
    monitor = da_incMonitor()

    threads = [
        threading.Thread(target=server_thread),  # JSONRPC thread
    ]
    if not ONLY_CLIENT and PLATFORM["fork"]:
        threads.append(threading.Thread(target=da_inc_thread,
                                        args=[monitor]))  # da_inc thread

    for t in threads:
        t.daemon = True
        t.start()

    # XBMC loop
    while not xbmc.abortRequested:
        xbmc.sleep(1000)

    log.info("da_inc: exiting da_inc")
예제 #10
0
def modify():
    __language__ = xbmcaddon.Addon(id='plugin.video.sl').getLocalizedString
    if not xbmcgui.Dialog().yesno(xbmc.getLocalizedString(19194),
                                  __language__(30372)):
        return

    skin = xbmc.getSkinDir()  #simplified skin detection
    if skin not in SKINS:
        xbmcgui.Dialog().ok(__language__(30373), __language__(30374))
        return

    newSkin = skin + '.skylink'
    newName = SKINS[skin] + '.Skylink'

    xbmc.executebuiltin('XBMC.ReloadSkin()')

    destination = 'special://home/addons/' + newSkin
    destsettings = 'special://userdata/addon_data/' + newSkin
    if xbmcvfs.exists(destination + "/"):
        xbmcgui.Dialog().ok(newName, __language__(30375))
        xbmc.executebuiltin(
            "ActivateWindow(10040,addons://user/xbmc.gui.skin,return)")
        return
    if not xbmcvfs.exists(destsettings + "/"):
        copy_settings = xbmcgui.Dialog().yesno(SKINS[skin],
                                               __language__(30376))
    else:
        copy_settings = False

    try:
        shutil.copytree(xbmc.translatePath('special://skin'),
                        xbmc.translatePath(destination))
        #alter copy addon.xml
        with closing(xbmcvfs.File(destination + '/addon.xml')) as f:
            addonxml = f.read()
        addonxml = addonxml.replace(skin, newSkin)
        addonxml = addonxml.replace('name="' + SKINS[skin] + '"',
                                    'name="' + newName + '"')
        with closing(xbmcvfs.File(destination + '/addon.xml', 'w')) as f:
            f.write(addonxml)
        if copy_settings:
            #TODO special://profile
            shutil.copytree(
                xbmc.translatePath('special://userdata/addon_data/' + skin),
                xbmc.translatePath(destsettings))

        #update language
        enpo = destination + '/language/resource.language.en_gb/strings.po'
        skpo = destination + '/language/resource.language.sk_sk/strings.po'
        czpo = destination + '/language/resource.language.cs_cz/strings.po'
        with closing(xbmcvfs.File(enpo)) as f:
            enstrings = f.read()
        with closing(xbmcvfs.File(skpo)) as f:
            skstrings = f.read()
        with closing(xbmcvfs.File(czpo)) as f:
            czstrings = f.read()

        newId = str(random.randint(31000, 31999))
        newIdString = '"#' + newId + '"'
        while newIdString in enstrings or newIdString in skstrings or newIdString in czstrings:
            newId = str(random.randint(31000, 31999))
            newIdString = '"#' + newId + '"'

        enstrings += '\nmsgctxt ' + newIdString + '\nmsgid "Skylink Archive"\nmsgstr "Skylink Archive"\n'
        skstrings += '\nmsgctxt ' + newIdString + '\nmsgid "Skylink Archive"\nmsgstr "Skylink Archív"\n'
        czstrings += '\nmsgctxt ' + newIdString + '\nmsgid "Skylink Archive"\nmsgstr "Skylink Archiv"\n'

        with closing(xbmcvfs.File(enpo, 'w')) as f:
            f.write(enstrings)
        with closing(xbmcvfs.File(skpo, 'w')) as f:
            f.write(skstrings)
        with closing(xbmcvfs.File(czpo, 'w')) as f:
            f.write(czstrings)

        #update widgets
        if skin == 'skin.estuary':
            xmlfile = destination + '/xml/Includes_Home.xml'
            with closing(xbmcvfs.File(xmlfile)) as f:
                xml = f.read()
            root = ET.fromstring(xml)
            content = root.findall(
                "include[@name='PVRSubMenuContent']/content")
            if len(content) != 1:
                cleanup(copy_settings, destination, destsettings)
                xbmcgui.Dialog().ok(SKINS[skin], __language__(30377))
                return
            content = content[0]

            toRemove = []
            for item in content:
                for child in item:
                    if child.tag == 'onclick' and 'Search' in child.text:
                        searchItem = item
                    if child.tag == 'onclick' and ('Recordings' in child.text
                                                   or 'Timer' in child.text):
                        toRemove.append(item)

            index = list(content).index(searchItem) + 1
            newItem = ET.fromstring(
                '<item>\n' + '\t\t\t<label>$LOCALIZE[' + newId +
                ']</label>\n' +
                '\t\t\t<onclick>ActivateWindow(10025,plugin://plugin.video.sl/?replay=channels,return)</onclick>\n'
                +
                '\t\t\t<thumb>special://home/addons/plugin.video.sl/icon-archive.png</thumb>\n'
                +
                '\t\t\t<visible>System.HasAddon(plugin.video.sl)</visible>\n' +
                '</item>\n\t\t')
            content.insert(index, newItem)

            for item in toRemove:
                content.remove(item)

            with closing(xbmcvfs.File(xmlfile, 'w')) as f:
                f.write(ET.tostring(root, encoding="utf-8"))

        elif skin == 'skin.confluence':
            xmlfile = destination + '/720p/IncludesHomeMenuItems.xml'
            with closing(xbmcvfs.File(xmlfile)) as f:
                xml = f.read()
            print(xml)
            root = ET.fromstring(xml)
            print(root)
            content = root.findall("include[@name='HomeSubMenuTV']")
            if len(content) != 1:
                print(content)
                print(len(content))
                cleanup(copy_settings, destination, destsettings)
                xbmcgui.Dialog().ok(SKINS[skin], __language__(30377))
                return
            content = content[0]

            toRemove = []
            for control in content:
                for child in control:
                    if child.tag == 'onclick' and 'TVSearch' in child.text:
                        searchControl = control
                    if child.tag == 'onclick' and ('TVRecordings' in child.text
                                                   or 'TVTimer' in child.text):
                        toRemove.append(control)

            index = list(content).index(searchControl) + 1
            if len(toRemove) == 0:
                cleanup(copy_settings, destination, destsettings)
                xbmcgui.Dialog().ok(SKINS[skin], __language__(30377))
                return

            newControl = ET.fromstring(
                '<control type="button" id="' + toRemove[0].attrib['id'] +
                '">\n' +
                '\t\t\t<include>ButtonHomeSubCommonValues</include>\n' +
                '\t\t\t<label>' + newId + '</label>\n' +
                '\t\t\t<onclick>ActivateWindow(10025,plugin://plugin.video.sl/?replay=channels,return)</onclick>\n'
                + '\t\t\t<visible>System.HasAddon(plugin.video.sl)</visible>\n'
                '</control>\n\t\t')
            content.insert(index, newControl)

            for control in toRemove:
                content.remove(control)

            with closing(xbmcvfs.File(xmlfile, 'w')) as f:
                f.write(ET.tostring(root, encoding="utf-8"))
    except:
        cleanup(copy_settings, destination, destsettings)
        xbmcgui.Dialog().ok(SKINS[skin], __language__(30377))
        return

    xbmc.executebuiltin("UpdateLocalAddons")
    time.sleep(1)
    try:
        #try enabling skin
        xbmc.startServer(xbmc.SERVER_WEBSERVER, True, True)
        time.sleep(1)
        params = '"method":"Addons.SetAddonEnabled","params":{"addonid":"' + newSkin + '","enabled":true}'
        xbmc.executeJSONRPC('{"jsonrpc": "2.0", %s, "id": 1}' % params)
        #xbmc.executebuiltin("ActivateWindow(10040,addons://user/xbmc.gui.skin,return)")
        if xbmcgui.Dialog().yesno(newName, __language__(30378)):
            try:  #try activate skin
                xbmc.executeJSONRPC(
                    '{"jsonrpc":"2.0","method":"Settings.SetSettingValue","id":1,"params":{"setting":"lookandfeel.skin","value":"'
                    + newSkin + '"}}')
                xbmc.executebuiltin('SendClick(11)')
                time.sleep(1)
                xbmc.executebuiltin('XBMC.ReloadSkin()')
                xbmcgui.Dialog().ok(newName, xbmc.getLocalizedString(20177))
            except:
                xbmcgui.Dialog().ok(newName, __language__(30379))
                xbmc.executebuiltin("ActivateWindow(10032,return)")
    except:
        xbmcgui.Dialog().ok(newName, __language__(30380))
        xbmc.executebuiltin(
            "ActivateWindow(10040,addons://user/xbmc.gui.skin,return)")
예제 #11
0
def cache_loader(m3u8_url, m3u8_headers={}, segment_headers={}):

    ip = __addon__.getSetting('ip')
    if not ip:
        ip = xbmc.getIPAddress()
        __addon__.setSetting('ip', ip)
    port = __addon__.getSetting('port')

    cache_forward = int(__addon__.getSetting('cache_forward'))
    download_delay = int(__addon__.getSetting('download_delay'))
    cache_multiplier = int(__addon__.getSetting('cache_multiplier'))

    count = int(0)
    duration = int(0)
    m3u8_timeout = int(10)
    m3u8_segment_timeout = int(5)
    chunk_size = int(1024 * cache_multiplier)

    segment_error = int(0)
    max_segment_error = int(0)

    sess = requests.Session()
    content_type = 'application/octet-stream'
    cache_path = os.path.abspath(os.path.join(__addon_path__, 'cache'))
    new_m3u8_path = os.path.abspath(os.path.join(cache_path, 'hls.m3u8'))

    try:
        req = sess.get(url=m3u8_url,
                       stream=False,
                       allow_redirects=True,
                       verify=False,
                       timeout=m3u8_timeout,
                       headers=m3u8_headers)
        if req.status_code == 200:

            xbmc.startServer(iTyp=xbmc.SERVER_WEBSERVER,
                             bStart=True,
                             bWait=False)
            with open(new_m3u8_path, 'wb', buffering=chunk_size) as m3u8:
                for line in req.iter_lines():
                    line = line.strip()
                    if line:

                        if line.startswith('http'):
                            m3u8.write(
                                '{0}\n'.format('http://' + ip + ':' + port +
                                               '/cache/' + str(count)))
                            count += 1
                        else:
                            m3u8.write('{0}\n'.format(line))

            count = 0
            for line in req.iter_lines():
                line = line.strip()
                if line:

                    if line.startswith('#EXTINF:'):
                        match = re.compile(r'#EXTINF:(\d+)',
                                           re.DOTALL).search(line)
                        if match: duration = int(match.group(1))

                    if line.startswith('http'):

                        try:
                            req = sess.get(url=line,
                                           stream=True,
                                           allow_redirects=True,
                                           verify=False,
                                           timeout=m3u8_segment_timeout,
                                           headers=segment_headers)

                            content_type_header = req.headers.get(
                                'Content-Type')
                            if content_type_header:
                                match = re.compile(
                                    r'(.+?);',
                                    re.DOTALL).search(content_type_header)
                                if match: content_type = match.group(1)

                            with open(os.path.abspath(
                                    os.path.join(cache_path, str(count))),
                                      'wb',
                                      buffering=chunk_size) as fi:
                                while True:
                                    chunk = req.raw.read(chunk_size)
                                    if not chunk: break
                                    else: fi.write(chunk)

                        except:
                            segment_error += 1
                            if segment_error <= 2: continue
                            elif segment_error > 2:
                                segment_error = 0
                                max_segment_error += 1

                        if max_segment_error >= 10:
                            if bool(xbmcgui.Dialog().yesno(
                                    heading=
                                    '[COLOR red]CACHE LOARDER SEGMENT ERROR[/COLOR]',
                                    line1='Maximum segment error X10 reached',
                                    line2='',
                                    line3='',
                                    nolabel='EXIT',
                                    yeslabel='CONTINUE',
                                    autoclose=0)):
                                max_segment_error = 0
                            else:
                                break

                        if count == cache_forward:
                            listitem = xbmcgui.ListItem(path='http://' + ip +
                                                        ':' + port +
                                                        '/cache/hls.m3u8')
                            listitem.setMimeType(content_type)
                            listitem.setContentLookup(False)
                            xbmcplugin.setResolvedUrl(handle=__addon_handle__,
                                                      succeeded=True,
                                                      listitem=listitem)

                        elif count > cache_forward:
                            if not xbmc.getCondVisibility('Player.HasMedia'):
                                break
                            if download_delay > 0:
                                xbmc.sleep(duration * download_delay)
                        count += 1

            req.close()
            while True:
                if not xbmc.getCondVisibility('Player.HasMedia'):
                    xbmc.startServer(iTyp=xbmc.SERVER_WEBSERVER,
                                     bStart=False,
                                     bWait=False)
                    clear_dir(cache_path)
                    break
                else:
                    xbmc.sleep(1500)

        else:
            xbmcgui.Dialog().ok('REQUESTS INFO',
                                'Status code : ' + str(req.status_code))
    except Exception as e:
        xbmcgui.Dialog().ok('[COLOR red]CACHE LOARDER ERROR[/COLOR]', str(e))
예제 #12
0
def startup():
    xbmc.startServer(xbmc.SERVER_WEBSERVER, True)
    xbmc.startServer(xbmc.SERVER_JSONRPCSERVER, True)
    while not xbmc.abortRequested and not checkSkinPath():
        sleep(1000)
        pass