Skip to content

Instantly share code, notes, and snippets.

@nidefawl
Forked from fxthomas/pw-easylink
Last active November 12, 2024 05:30
Show Gist options
  • Save nidefawl/75ca46ba9979062290b066a7c1ee08fd to your computer and use it in GitHub Desktop.
Save nidefawl/75ca46ba9979062290b066a7c1ee08fd to your computer and use it in GitHub Desktop.
Small tool to configure and maintain PipeWire links between sets of input/output port querie
@mrbarletta
Copy link

Thanks a lot, very useful!

Would you consider updating the pipewire_dump function so it doesn't failed when pw-dump emits invalid json?



def pipewire_dump(max_retries=3, delay=1):
    """
    Attempts to dump PipeWire data and returns it as a JSON object.

    Args:
        max_retries (int): The maximum number of times to retry the operation.
        delay (int): The delay in seconds between retries.

    Returns:
        dict: The PipeWire data as a JSON object.
    """
    for attempt in range(max_retries + 1):
        try:
            return json.loads(subprocess.check_output("pw-dump"))
        except json.JSONDecodeError:
            if attempt < max_retries:
                print(f"Invalid JSON on attempt {attempt + 1}. Retrying in {delay} seconds.")
                time.sleep(delay)
            else:
                print(f"Failed to parse JSON after {max_retries} attempts.")
                break

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment