def setup_next_run(self, now):
        new_run_time = self.next_run
        schedule_type = int(utils.setting("schedule_interval"))

        if self.next_run <= now:
            if schedule_type == 0:
                new_run_time = now + SECONDS_PER_HOUR
            else:
                hour_of_day = int(utils.setting("schedule_time")[0:2])

                delay_map = {
                    1: 24,
                    2: 3 * 24,
                    3: 7 * 24
                }

                dt = datetime.datetime.fromtimestamp(now).replace(hour=hour_of_day)
                dt += datetime.timedelta(hours=delay_map[schedule_type])
                new_run_time = time.mktime(dt.timetuple())

        if new_run_time != self.next_run:
            self.next_run = new_run_time
            next_run = datetime.datetime.fromtimestamp(self.next_run).strftime('%m-%d-%Y %H:%M')
            utils.show_notification(utils.l10n(30050) % next_run)
            utils.log("Scheduler will run again on " + next_run)
def run_converter(silent=False):
    utils.log("Running the converter")

    if utils.setting("address_selection") == '0':
        host_address = BroadwayFinder.find_hostname()
    else:
        host_address = utils.setting("ip_address")

    utils.log("Using Broadway host-address %s" % host_address)

    try:
        connection = Connector(host_address, utils.setting("pin"))
        utils.log("Connection with Broadway is established")
    except Exception as e:
        utils.log("Failed connecting to Broadway, caused by " + str(e),
                  loglevel=xbmc.LOGERROR)
        if not silent:
            xbmcgui.Dialog().ok(utils.l10n(30010), utils.l10n(30101))
            utils.open_settings()

        return

    path = xbmc.translatePath(utils.setting("target_directory"))
    utils.log("Creating Channels & EPG below %s" % path)

    if not os.path.exists(path):
        utils.log(
            "Aborting conversion: The output directory '%s' doesn't exist." %
            path,
            loglevel=xbmc.LOGERROR)
        if not silent:
            xbmcgui.Dialog().ok(utils.l10n(30010), utils.l10n(30102))
            utils.open_settings()
        return

    converter = Converter(connection)

    utils.show_notification(utils.l10n(30060) % __channels_file_name)
    utils.log("Writing '%s'" % __channels_file_name)
    converter.write_channels_m3u(path + os.sep + __channels_file_name)

    utils.show_notification(utils.l10n(30060) % __epg_file_name)
    utils.log("Writing '%s'" % __epg_file_name)
    converter.write_epg(path + os.sep + __epg_file_name)

    utils.show_notification(utils.l10n(30100))
def run_converter(silent=False):
    utils.log("Running the converter")

    if utils.setting("address_selection") == '0':
        host_address = BroadwayFinder.find_hostname()
    else:
        host_address = utils.setting("ip_address")

    utils.log("Using Broadway host-address %s" % host_address)

    try:
        connection = Connector(host_address, utils.setting("pin"))
        utils.log("Connection with Broadway is established")
    except Exception as e:
        utils.log("Failed connecting to Broadway, caused by " + str(e), loglevel=xbmc.LOGERROR)
        if not silent:
            xbmcgui.Dialog().ok(utils.l10n(30010), utils.l10n(30101))
            utils.open_settings()

        return

    path = xbmc.translatePath(utils.setting("target_directory"))
    utils.log("Creating Channels & EPG below %s" % path)

    if not os.path.exists(path):
        utils.log("Aborting conversion: The output directory '%s' doesn't exist." % path, loglevel=xbmc.LOGERROR)
        if not silent:
            xbmcgui.Dialog().ok(utils.l10n(30010), utils.l10n(30102))
            utils.open_settings()
        return

    converter = Converter(connection)

    utils.show_notification(utils.l10n(30060) % __channels_file_name)
    utils.log("Writing '%s'" % __channels_file_name)
    converter.write_channels_m3u(path + os.sep + __channels_file_name)

    utils.show_notification(utils.l10n(30060) % __epg_file_name)
    utils.log("Writing '%s'" % __epg_file_name)
    converter.write_epg(path + os.sep + __epg_file_name)

    utils.show_notification(utils.l10n(30100))