Elektordi / obs-websocket-py

Python library to communicate with an obs-websocket server (for OBS Studio)
MIT License
235 stars 59 forks source link

No support for calling Virtual Camera on and off? #71

Closed coleswarner closed 1 year ago

coleswarner commented 2 years ago

I noticed there doesn't seem to be the ability to control the Virtual Camera start and stopping. When I run GetStreamingStatus it returns a T/F value for the Vitrual camera but I couldn't call it on and off. I know it said not to edit the files but I was able to add Virtual Camera support with the addition of a few extra lines in the events and requests .py. Not sure if I did this completely correct but it's enabled control for me.

Events.py, pasted before "class StreamStarting(Baseevents):"

class VirtualCamStarted(Baseevents):
    """VirtualCam started successfully.

    """

    def __init__(self):
        Baseevents.__init__(self)
        self.name = 'VirtualCamStarted'

class VirtualCamStopped(Baseevents):
    """VirtualCam stopped successfully.

    """

    def __init__(self):
        Baseevents.__init__(self)
        self.name = 'VirtualCamStopped'

requests .py, note edits are marked

class GetStreamingStatus(Baserequests):
    """Get current streaming and recording status.

    :Returns:
       *streaming*
            type: boolean
            Current streaming status.
       *recording*
            type: boolean
            Current recording status.
       *stream_timecode*
            type: String (optional)
            Time elapsed since streaming started (only present if currently streaming).
       *rec_timecode*
            type: String (optional)
            Time elapsed since recording started (only present if currently recording).
       *preview_only*
            type: boolean
            Always false. Retrocompatibility with OBSRemote.
    """

    def __init__(self):
        Baserequests.__init__(self)
        self.name = 'GetStreamingStatus'
        self.datain['streaming'] = None
        self.datain['recording'] = None
# Start Edit
        self.datain['virtualcam'] = None
# End Edit
        self.datain['stream-timecode'] = None
        self.datain['rec-timecode'] = None
        self.datain['preview-only'] = None

    def getStreaming(self):
        return self.datain['streaming']

    def getRecording(self):
        return self.datain['recording']

# Start Edit
    def getVirtualCam(self):
        return self.datain['virtualcam']
# End Edit

    def getStreamTimecode(self):
        return self.datain['stream-timecode']

    def getRecTimecode(self):
        return self.datain['rec-timecode']

    def getPreviewOnly(self):
        return self.datain['preview-only']

# Start Edit

class StartStopVirtualCam(Baserequests):
    """Toggle Virtual Camera on or off (depending on the current stream state).

    """

    def __init__(self):
        Baserequests.__init__(self)
        self.name = 'StartStopVirtualCam'

class StartVirtualCam(Baserequests):
    """Start Virtualcam.
Will return an `error` if cam is already active.

    :Arguments:

    """

    def __init__(self, stream=None):
        Baserequests.__init__(self)
        self.name = 'StartVirtualCam'

class StopVirtualCam(Baserequests):
    """Stop Virtualcam.
Will return an `error` if cam is not active.

    """

    def __init__(self):
        Baserequests.__init__(self)
        self.name = 'StopVirtualCam'
# End Edit
Elektordi commented 1 year ago

Fixed by #36