def generate_pairing_code():
    monitor = Monitor()
    progress = DialogProgress()
    progress.create(get_string(32000), get_string(32001))
    chromecast = YoutubeCastV1()
    pairing_code = chromecast.pair()

    i = 0

    if PY3:
        progress.update(i,
                        message="{} {}".format(get_string(32002),
                                               pairing_code))
    else:
        progress.update(i, get_string(32002), pairing_code)

    start_time = time.time()
    while not monitor.abortRequested(
    ) and not chromecast.has_client and not progress.iscanceled() and not (
            time.time() - start_time) > (60 * 1):
        i += 10
        if i > 100:
            i = 0

        if PY3:
            progress.update(i,
                            message="{} {}".format(get_string(32002),
                                                   pairing_code))
        else:
            progress.update(i, get_string(32002), pairing_code)

        monitor.waitForAbort(2)
    progress.close()
Beispiel #2
0
class UpNextPlayer(Player):
    """Service class for playback monitoring"""
    last_file = None
    track = False

    def __init__(self):
        self.api = Api()
        self.state = State()
        self.monitor = Monitor()
        Player.__init__(self)

    def set_last_file(self, filename):
        self.state.last_file = filename

    def get_last_file(self):
        return self.state.last_file

    def is_tracking(self):
        return self.state.track

    def disable_tracking(self):
        self.state.track = False

    def reset_queue(self):
        if self.state.queued:
            self.api.reset_queue()
            self.state.queued = False

    def onPlayBackStarted(self):  # pylint: disable=invalid-name
        """Will be called when kodi starts playing a file"""
        self.monitor.waitForAbort(5)
        if not getCondVisibility('videoplayer.content(episodes)'):
            return
        self.state.track = True
        self.reset_queue()

    def onPlayBackPaused(self):  # pylint: disable=invalid-name
        self.state.pause = True

    def onPlayBackResumed(self):  # pylint: disable=invalid-name
        self.state.pause = False

    def onPlayBackStopped(self):  # pylint: disable=invalid-name
        """Will be called when user stops playing a file"""
        self.reset_queue()
        self.api.reset_addon_data()
        self.state = State()  # Reset state

    def onPlayBackEnded(self):  # pylint: disable=invalid-name
        """Will be called when Kodi has ended playing a file"""
        self.reset_queue()
        self.api.reset_addon_data()
        self.state = State()  # Reset state

    def onPlayBackError(self):  # pylint: disable=invalid-name
        """Will be called when when playback stops due to an error"""
        self.reset_queue()
        self.api.reset_addon_data()
        self.state = State()  # Reset state
Beispiel #3
0
def test_popup(window):
    popup = TestPopup(window, addon_path(), 'default', '1080i')
    popup.show()
    step = 0
    wait = 100
    wait_s = wait / 1000
    timeout = 10000
    monitor = Monitor()
    while popup and step < timeout and not monitor.abortRequested():
        if popup.pause:
            continue
        monitor.waitForAbort(wait_s)
        popup.update_progress_control(timeout, wait)
        step += wait
def _skin_widget_call(window_cls):
    """
    Workaround to intercept calls made by the Skin Widgets currently in use.
    Currently, the Skin widgets associated with add-ons are executed at Kodi startup immediately
    without respecting any services needed by the add-ons. This is causing different
    kinds of problems like widgets not loaded, add-on warning message, etc...
    this loop freeze the add-on instance until the service is ready.
    """
    # Note to "Window.IsMedia":
    # All widgets will be either on Home or in a Custom Window, so "Window.IsMedia" will be false
    # When the user is browsing the plugin, Window.IsMedia will be true because video add-ons open
    # in MyVideoNav.xml (which is a Media window)
    # This is not a safe solution, because DEPENDS ON WHICH WINDOW IS OPEN,
    # for example it can fail if you open add-on video browser while widget is still loading.
    # Needed a proper solution by script.skinshortcuts / script.skin.helper.service, and forks
    limit_sec = 10
    if not getCondVisibility("Window.IsMedia"):
        monitor = Monitor()
        sec_elapsed = 0
        while not window_cls.getProperty('nf_service_status') == 'running':
            if sec_elapsed >= limit_sec or monitor.abortRequested() or monitor.waitForAbort(0.5):
                break
            sec_elapsed += 0.5
        debug('Skin widget workaround enabled - time elapsed: {}', sec_elapsed)
        return True
    return False
Beispiel #5
0
def wait_for_metadata(info_hash):
    close_busy_dialog()
    percent = 0
    timeout = get_metadata_timeout()
    start_time = time.time()
    monitor = Monitor()
    progress = DialogProgress()
    progress.create(ADDON_NAME, translate(30237))

    try:
        while not api.torrent_status(info_hash).has_metadata:
            if monitor.waitForAbort(0.5):
                raise PlayError("Abort requested")
            passed_time = time.time() - start_time
            if 0 < timeout:
                if timeout < passed_time:
                    notification(translate(30238))
                    raise PlayError("No metadata after timeout")
                percent = int(100 * passed_time / timeout)
            else:
                percent = 0 if percent == 100 else (percent + 5)
            progress.update(percent)
            if progress.iscanceled():
                raise CanceledError("User canceled metadata", info_hash)
    finally:
        progress.close()
def _check_addon_external_call(window_cls, prop_nf_service_status):
    """Check system to verify if the calls to the add-on are originated externally"""
    # The calls that are made from outside do not respect and do not check whether the services required
    # for the add-on are actually working and operational, causing problems with the execution of the frontend.

    # A clear example are the Skin widgets, that are executed at Kodi startup immediately and this is cause of different
    # kinds of problems like widgets not loaded, add-on warning message, etc...

    # Cases where it can happen:
    # - Calls made by the Skin Widgets, Scripts, Kodi library
    # - Calls made by others Kodi windows (like file browser)
    # - Calls made by other add-ons

    # To try to solve the problem, when the service is not ready a loop will be started to freeze the add-on instance
    # until the service will be ready.

    is_other_plugin_name = getInfoLabel(
        'Container.PluginName') != g.ADDON.getAddonInfo('id')
    limit_sec = 10

    # Note to Kodi boolean condition "Window.IsMedia":
    # All widgets will be either on Home or in a Custom Window, so "Window.IsMedia" will be false
    # When the user is browsing the plugin, Window.IsMedia will be true because video add-ons open
    # in MyVideoNav.xml (which is a Media window)
    # This is not a safe solution, because DEPENDS ON WHICH WINDOW IS OPEN,
    # for example it can fail if you open add-on video browser while widget is still loading.
    # Needed a proper solution by script.skinshortcuts / script.skin.helper.service, and forks
    if is_other_plugin_name or not getCondVisibility("Window.IsMedia"):
        monitor = Monitor()
        sec_elapsed = 0
        while not _get_service_status(
                window_cls, prop_nf_service_status).get('status') == 'running':
            if sec_elapsed >= limit_sec or monitor.abortRequested(
            ) or monitor.waitForAbort(0.5):
                break
            sec_elapsed += 0.5
        debug(
            'Add-on was initiated by an external call - workaround enabled time elapsed {}s',
            sec_elapsed)
        g.IS_ADDON_EXTERNAL_CALL = True
        return True
    return False
Beispiel #7
0
def play_info_hash(info_hash, timeout=30, buffer=True):
    start_time = time.time()
    monitor = Monitor()
    progress = DialogProgress()
    progress.create(ADDON_NAME, translate(30237))

    try:
        while not api.torrent_status(info_hash).has_metadata:
            if monitor.waitForAbort(0.5):
                raise PlayError("Abort requested")
            passed_time = time.time() - start_time
            if 0 < timeout < passed_time:
                notification(translate(30238))
                raise PlayError("No metadata after timeout")
            progress.update(int(100 * passed_time / timeout))
            if progress.iscanceled():
                raise PlayError("User canceled metadata")
    finally:
        progress.close()

    files = api.files(info_hash, status=False)
    min_candidate_size = get_min_candidate_size() * 1024 * 1024
    candidate_files = [
        f for f in files if is_video(f.path) and f.length >= min_candidate_size
    ]
    if not candidate_files:
        notification(translate(30239))
        raise PlayError("No candidate files found for {}".format(info_hash))
    elif len(candidate_files) == 1:
        chosen_file = candidate_files[0]
    else:
        sort_files(candidate_files)
        chosen_index = Dialog().select(translate(30240),
                                       [f.name for f in candidate_files])
        if chosen_index < 0:
            raise PlayError("User canceled dialog select")
        chosen_file = candidate_files[chosen_index]

    if buffer:
        buffer_and_play(info_hash, chosen_file.id)
    else:
        play(info_hash, chosen_file.id)
Beispiel #8
0
def buffer_and_play(info_hash, file_id):
    api.download_file(info_hash, file_id, buffer=True)

    monitor = Monitor()
    progress = DialogProgress()
    progress.create(ADDON_NAME)

    try:
        timeout = get_buffering_timeout()
        start_time = time.time()
        last_time = 0
        last_done = 0
        while True:
            current_time = time.time()
            status = api.file_status(info_hash, file_id)
            if status.buffering_progress >= 100:
                break

            total_done = status.buffering_total * status.buffering_progress / 100
            speed = float(total_done - last_done) / (current_time - last_time)
            last_time = current_time
            last_done = total_done
            progress.update(
                int(status.buffering_progress),
                "{} - {:.2f}%\n{} {} {} - {}/s\n\n".format(
                    get_state_string(status.state), status.buffering_progress,
                    sizeof_fmt(total_done), translate(30244),
                    sizeof_fmt(status.buffering_total), sizeof_fmt(speed)))

            if progress.iscanceled():
                raise PlayError("User canceled buffering")
            if 0 < timeout < current_time - start_time:
                notification(translate(30236))
                raise PlayError("Buffering timeout reached")
            if monitor.waitForAbort(1):
                raise PlayError("Abort requested")
    finally:
        progress.close()

    play(info_hash, file_id)
Beispiel #9
0
def wait_for_buffering_completion(info_hash, file_id):
    close_busy_dialog()
    info = api.file_info(info_hash, file_id)
    of = translate(30244)
    timeout = get_buffering_timeout()
    last_time = last_done = 0
    start_time = time.time()

    monitor = Monitor()
    progress = DialogProgress()
    progress.create(ADDON_NAME)

    try:
        while True:
            current_time = time.time()
            status = api.file_status(info_hash, file_id)
            if status.buffering_progress >= 100:
                break

            total_done = status.buffering_total * status.buffering_progress / 100
            speed = float(total_done - last_done) / (current_time - last_time)
            last_time = current_time
            last_done = total_done
            progress.update(
                int(status.buffering_progress),
                "{} - {:.2f}%\n{} {} {} - {}/s\n{}\n".format(
                    get_state_string(status.state), status.buffering_progress,
                    sizeof_fmt(total_done), of,
                    sizeof_fmt(status.buffering_total), sizeof_fmt(speed),
                    info.name))

            if progress.iscanceled():
                raise CanceledError("User canceled buffering", info_hash)
            if 0 < timeout < current_time - start_time:
                notification(translate(30236))
                raise PlayError("Buffering timeout reached")
            if monitor.waitForAbort(1):
                raise PlayError("Abort requested")
    finally:
        progress.close()
Beispiel #10
0
                except IOError as ioe:
                    log("removing unresponsive light %s" % light.label, level=LOGWARNING)
                    unresponsive.append(light)
            for light in unresponsive:
                del self.lights[light]

def log(msg, level=LOGNOTICE):
    xbmc.log("lifxbmc - %s" % msg.replace("\0", ""), level=level) # strings returned from lights sometimes have null chars

if __name__ == '__main__':
    monitor = Monitor()
    player = LifxPlayer()
    
    log("inited")    
     
    while not monitor.abortRequested():
        if monitor.waitForAbort(10):
            break
        
        try:
            lifx = LifxLAN()
            for light, color in lifx.get_color_all_lights():
                if len(addon.getSetting("group_filter")) > 0:
                    pass
                if light not in player:
                    log("discovered new light %s" % light.get_label())
                    player.add_light(light, color)
        except Exception as e:
            log("Exception while discovering lights: %s" % e, level=LOGERROR)

Beispiel #11
0
if __name__ == '__main__':
    monitor = Monitor()

    # start thread for MLS servie
    msl_thread = threading.Thread(target=msl_server.serve_forever)
    msl_thread.daemon = True
    msl_thread.start()

    # start thread for Netflix HTTP service
    nd_thread = threading.Thread(target=nd_server.serve_forever)
    nd_thread.daemon = True
    nd_thread.start()

    # kill the services if kodi monitor tells us to
    while not monitor.abortRequested():
        if monitor.waitForAbort(5):
            msl_server.shutdown()
            nd_server.shutdown()
            break

    # MSL service shutdown sequence
    msl_server.server_close()
    msl_server.socket.close()
    msl_server.shutdown()
    kodi_helper.log(msg='Stopped MSL Service')

    # Netflix service shutdown sequence
    nd_server.server_close()
    nd_server.socket.close()
    nd_server.shutdown()
    kodi_helper.log(msg='Stopped HTTP Service')
Beispiel #12
0
        handler.serve_forever()
    except Exception as e:
        Script.log(e, lvl=Script.DEBUG)
        pass


ThreadingTCPServer.allow_reuse_address = True
_PORT = 48996
handler = ThreadingTCPServer(("", _PORT), proxy.JioTVProxy)
t = threading.Thread(target=serveForever, args=(handler, ))
t.setDaemon(True)
t.start()

if not Settings.get_boolean("popup"):
    xbmcgui.Dialog().ok(
        "JioTV Notification",
        "Now you can create your custom playlist from BotAllen Dashboard. [CR]Find out more at [B]https://botallen.com/#dashboard[/B] [CR][CR]If you like this add-on then consider donating from [B]https://botallen.com/#donate[/B] [CR][CR]Github: [B]https://github.com/botallen/repository.botallen[/B] [CR]Discord: [B]https://botallen.com/discord[/B] [CR][CR][I]You can disable this popup from settings[/I]"
    )

if Settings.get_boolean("m3ugen"):
    executebuiltin(
        "RunPlugin(plugin://plugin.video.jiotv/resources/lib/main/m3ugen/?notify=no)"
    )

monitor = Monitor()
while not monitor.abortRequested():
    if monitor.waitForAbort(10):
        handler.shutdown()
        handler.server_close()
        break
Beispiel #13
0
thumb_req_port = select_unused_port()
ADDON.setSetting('thumbmail_port', str(thumb_req_port))

thumb_req_server = TCPServer(('127.0.0.1', thumb_req_port),
                             ThumbRequestHandler)
thumb_req_server.server_activate()
thumb_req_server.timeout = 1
utils.log('Started 7Plus Thumbnail HTTP server on port {0}'
          .format(thumb_req_port))

if __name__ == '__main__':
    mon = Monitor()

    # start thread for thumbnail HTTP service
    thumb_req_thread = threading.Thread(target=thumb_req_server.serve_forever)
    thumb_req_thread.daemon = True
    thumb_req_thread.start()

    # kill the services if kodi monitor tells us to
    while not mon.abortRequested():
        if mon.waitForAbort(5):
            thumb_req_server.shutdown()
            break

    # Netflix service shutdown sequence
    thumb_req_server.server_close()
    thumb_req_server.socket.close()
    thumb_req_server.shutdown()
    utils.log('Stopped 7Plus Thumbnail HTTP server')
Beispiel #14
0
# pick & store a port for the proxy service
wv_proxy_port = select_unused_port()
helper.set_setting('wv_proxy_port', str(wv_proxy_port))
helper.log('Port {0} selected'.format(str(wv_proxy_port)))

# server defaults
SocketServer.TCPServer.allow_reuse_address = True
# configure the proxy server
wv_proxy = SocketServer.TCPServer(('127.0.0.1', wv_proxy_port), WidevineHTTPRequestHandler)
wv_proxy.server_activate()
wv_proxy.timeout = 1

if __name__ == '__main__':
    monitor = Monitor()
    # start thread for proxy server
    proxy_thread = threading.Thread(target=wv_proxy.serve_forever)
    proxy_thread.daemon = True
    proxy_thread.start()

    # kill the services if kodi monitor tells us to
    while not monitor.abortRequested():
        if monitor.waitForAbort(5):
            wv_proxy.shutdown()
            break

    # wv-proxy service shutdown sequence
    wv_proxy.server_close()
    wv_proxy.socket.close()
    wv_proxy.shutdown()
    helper.log('wv-proxy stopped')
Beispiel #15
0
if __name__ == '__main__':
    MONITOR = Monitor()

    # start thread for MLS servie
    MSL_THREAD = threading.Thread(target=MSL_SERVER.serve_forever)
    MSL_THREAD.daemon = True
    MSL_THREAD.start()

    # start thread for Netflix HTTP service
    NS_THREAD = threading.Thread(target=NS_SERVER.serve_forever)
    NS_THREAD.daemon = True
    NS_THREAD.start()

    # kill the services if kodi monitor tells us to
    while not MONITOR.abortRequested():
        if MONITOR.waitForAbort(5):
            MSL_SERVER.shutdown()
            NS_SERVER.shutdown()
            break

    # MSL service shutdown sequence
    MSL_SERVER.server_close()
    MSL_SERVER.socket.close()
    MSL_SERVER.shutdown()
    KODI_HELPER.log(msg='Stopped MSL Service')

    # Netflix service shutdown sequence
    NS_SERVER.server_close()
    NS_SERVER.socket.close()
    NS_SERVER.shutdown()
    KODI_HELPER.log(msg='Stopped HTTP Service')