How to use the catt.error.CliError function in catt

To help you get started, we’ve selected a few catt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github skorokithakis / catt / catt / cli.py View on Github external
def fail_if_no_ip(ipaddr):
    if not ipaddr:
        raise CliError("Local IP-address could not be determined")
github skorokithakis / catt / catt / cli.py View on Github external
def write_config(settings):
    if settings.get("device"):
        if not get_chromecast(settings["device"]):
            raise CliError("Specified device not found")
        writeconfig(settings)
    else:
        raise CliError("No device specified")
github skorokithakis / catt / catt / cli.py View on Github external
def process_url(ctx, param, value):
    if value == "-":
        stdin_text = click.get_text_stream("stdin")
        if not stdin_text.isatty():
            value = stdin_text.read().strip()
        else:
            raise CliError("No input received from stdin")
    if "://" not in value:
        if ctx.info_name != "cast":
            raise CliError("Local file not allowed as argument to this command")
        if not Path(value).is_file():
            raise CliError("The chosen file does not exist")
    return value
github skorokithakis / catt / catt / cli.py View on Github external
def write_config(settings):
    if settings.get("device"):
        if not get_chromecast(settings["device"]):
            raise CliError("Specified device not found")
        writeconfig(settings)
    else:
        raise CliError("No device specified")
github skorokithakis / catt / catt / cli.py View on Github external
playlist_playback = False
    st_thr = su_thr = subs = None
    cst, stream = setup_cast(
        settings["device"], video_url=video_url, prep="app", controller=controller, ytdl_options=ytdl_option
    )
    media_is_image = stream.guessed_content_category == "image"

    if stream.is_local_file:
        fail_if_no_ip(stream.local_ip)
        st_thr = create_server_thread(
            video_url, stream.local_ip, stream.port, stream.guessed_content_type, single_req=media_is_image
        )
    elif stream.is_playlist and not (no_playlist and stream.video_id):
        if stream.playlist_length == 0:
            cst.kill(idle_only=True)
            raise CliError("Playlist is empty")
        if not random_play and cst.playlist_capability and stream.playlist_all_ids:
            playlist_playback = True
        else:
            if random_play:
                entry = random.randrange(0, stream.playlist_length)
            else:
                warning("Playlist playback not possible, playing first video")
                entry = 0
            stream.set_playlist_entry(entry)

    if playlist_playback:
        click.echo("Casting remote playlist {}...".format(video_url))
        video_id = stream.video_id or stream.playlist_all_ids[0]
        cst.play_playlist(stream.playlist_id, video_id=video_id)
    else:
        if not subtitles and not no_subs and stream.is_local_file:
github skorokithakis / catt / catt / cli.py View on Github external
def restore(settings, path):
    if not path and not STATE_PATH.is_file():
        raise CliError("Save file in config dir has not been created")
    cst = setup_cast(settings["device"])
    state = CastState(path or STATE_PATH, StateMode.READ)
    try:
        data = state.get_data(cst.cc_name if not path else None)
    except StateFileError:
        raise CliError("The chosen file is not a valid save file")
    if not data:
        raise CliError("No save data found for this device")

    print_status(data["data"])
    click.echo("Restoring...")
    cst = setup_cast(settings["device"], prep="app", controller=data["controller"])
    cst.restore(data["data"])
github skorokithakis / catt / catt / cli.py View on Github external
def restore(settings, path):
    if not path and not STATE_PATH.is_file():
        raise CliError("Save file in config dir has not been created")
    cst = setup_cast(settings["device"])
    state = CastState(path or STATE_PATH, StateMode.READ)
    try:
        data = state.get_data(cst.cc_name if not path else None)
    except StateFileError:
        raise CliError("The chosen file is not a valid save file")
    if not data:
        raise CliError("No save data found for this device")

    print_status(data["data"])
    click.echo("Restoring...")
    cst = setup_cast(settings["device"], prep="app", controller=data["controller"])
    cst.restore(data["data"])
github skorokithakis / catt / catt / cli.py View on Github external
def add(settings, video_url, play_next):
    cst, stream = setup_cast(settings["device"], video_url=video_url, action="add", prep="control")
    if cst.name != stream.extractor or not (stream.is_remote_file or stream.is_playlist_with_active_entry):
        raise CliError("This url cannot be added to the queue")
    click.echo('Adding video id "{}" to the queue.'.format(stream.video_id))
    if play_next:
        cst.add_next(stream.video_id)
    else:
        cst.add(stream.video_id)
github skorokithakis / catt / catt / cli.py View on Github external
def remove(settings, video_url):
    cst, stream = setup_cast(settings["device"], video_url=video_url, action="remove", prep="control")
    if cst.name != stream.extractor or not stream.is_remote_file:
        raise CliError("This url cannot be removed from the queue")
    click.echo('Removing video id "{}" from the queue.'.format(stream.video_id))
    cst.remove(stream.video_id)
github skorokithakis / catt / catt / cli.py View on Github external
def process_path(ctx, param, value):
    path = Path(value) if value else None
    if path and (path.is_dir() or not path.parent.exists()):
        raise CliError("The specified path is invalid")
    return path