pablodz / pipewire_python

Python controller, player and recorder via pipewire's commands
https://pablodz.github.io/pipewire_python/html/
MIT License
22 stars 7 forks source link

Considerations for a "link" Submodule for Controlling `pw-link` #14

Closed engineerjoe440 closed 1 year ago

engineerjoe440 commented 1 year ago

I am planning to begin developing a few Python class objects to manage connecting and listing Pipewire devices by way of the pw-link CLI, and I came across your project. I thought this would be a better place to store/share some of these features (rather than carving out my own project).

I was considering an interface similar to the following:

from typing import Union
from enum import Enum

class ChannelType(Enum):
    INPUT = 1
    OUTPUT = 2

class Channel:
    name: str
    id: int
    channel_type: ChannelType

    def connect(self, other: "Channel"):
        """Connect this channel to another channel."""

    def disconnect(self, other: "Channel"):
        """Disconnect this channel from another."""

class Input:
    left: Channel
    right: Channel

    def connect(self, output: Output) -> Union[Link, None]:
        """Connect this input to an output."""

    def disconnect(self, output: Output | Link):
        """Disconnect this input from an output."""

class Output:
    left: Channel
    right: Channel

    def connect(self, output: Input) -> Union[Link, None]:
        """Connect this input to an output."""

    def disconnect(self, output: Input | Link):
        """Disconnect this input from an output."""

class Link:
    input: Input
    output: Output

    def disconnect(self):
        """Disconnect the Link."""

def list_inputs() -> list[Input]:
    """List the Inputs."""

def list_outputs() -> list[Output]:
    """List the Outputs."""

def list_links() -> list[Link]:
    """List the Links."""

Sample of pw-link Help

Impetus of this work is wrapping the pw-link command in Python objects for convenient management.

joestan@joestan-lx-desktop ~> pw-link --help
pw-link : PipeWire port and link manager.
Generic: pw-link [options]
  -h, --help                            Show this help
      --version                         Show version
  -r, --remote=NAME                     Remote daemon name
List: pw-link [options] [out-pattern] [in-pattern]
  -o, --output                          List output ports
  -i, --input                           List input ports
  -l, --links                           List links
  -m, --monitor                         Monitor links and ports
  -I, --id                              List IDs
  -v, --verbose                         Verbose port properties
Connect: pw-link [options] output input
  -L, --linger                          Linger (default, unless -m is used)
  -P, --passive                         Passive link
  -p, --props=PROPS                     Properties as JSON object
Disconnect: pw-link -d [options] output input
            pw-link -d [options] link-id
  -d, --disconnect                      Disconnect ports

What are your thoughts?

engineerjoe440 commented 1 year ago

FWIW, I've started prototyping here: https://github.com/engineerjoe440/pipewire_python/blob/main/pipewire_python/link.py

pablodz commented 1 year ago

PRs are welcome, sounds great to me, tag me when finish please

engineerjoe440 commented 1 year ago

Hi @pablodz! I've got something ready to open a PR for. I couldn't find the dev branch that the README documents (to avoid kicking off undue documentation builds). So I created a draft PR here: https://github.com/pablodz/pipewire_python/pull/15

Let me know if you have any questions!

pablodz commented 1 year ago

merged, sorry for the long delay, was on vacations

pablodz commented 1 year ago

I will try to fix automatics github workflows and release the new version

engineerjoe440 commented 1 year ago

merged, sorry for the long delay, was on vacations

Don't apologize for your time off! I hope it was a great vacation. Thank you!