项目作者: Elektordi

项目描述 :
Python library to communicate with an obs-websocket server (for OBS Studio)
高级语言: Python
项目地址: git://github.com/Elektordi/obs-websocket-py.git
创建时间: 2017-06-17T23:24:54Z
项目社区:https://github.com/Elektordi/obs-websocket-py

开源协议:MIT License

下载


obs-websocket-py

Python3 library to communicate with an obs-websocket server.

Licensed under the MIT License

Project pages

GitHub project: https://github.com/Elektordi/obs-websocket-py

PyPI package: https://pypi.org/project/obs-websocket-py/

Installation

Just run pip3 install obs-websocket-py in your Python venv or directly on your system.

For manual install, git clone the github repo and copy the directory obswebsocket in your python project root.

Requires: websocket-client (from pip)

Usage

See python scripts in the samples directory.

Or take a look at the documentation below:

Output of pydoc obswebsocket.core.obsws:

  1. Help on class obsws in obswebsocket.core:
  2. obswebsocket.core.obsws = class obsws
  3. | Core class for using obs-websocket-py
  4. |
  5. | Simple usage: (v5 api)
  6. | >>> from obswebsocket import obsws, requests
  7. | >>> client = obsws("localhost", 4455, "secret")
  8. | >>> client.connect()
  9. | >>> client.call(requests.GetVersion()).getObsVersion()
  10. | '29.0.0'
  11. | >>> client.disconnect()
  12. |
  13. | Legacy usage: (v4 api)
  14. | >>> from obswebsocket import obsws, requests
  15. | >>> client = obsws("localhost", 4444, "secret", legacy=True)
  16. | >>> client.connect()
  17. | >>> client.call(requests.GetVersion()).getObsStudioVersion()
  18. | '25.0.0'
  19. | >>> client.disconnect()
  20. |
  21. | For advanced usage, including events callback, see the 'samples' directory.
  22. |
  23. | Methods defined here:
  24. |
  25. | __init__(self, host='localhost', port=4444, password='', legacy=None, timeout=60, authreconnect=0, on_connect=None, on_disconnect=None)
  26. | Construct a new obsws wrapper
  27. |
  28. | :param host: Hostname to connect to
  29. | :param port: TCP Port to connect to (Default is 4444)
  30. | :param password: Password for the websocket server (Leave this field empty if auth is not enabled)
  31. | :param legacy: Server is using old obs-websocket protocol (v4). Default is v5 (False) except if port is 4444.
  32. | :param timeout: How much seconds to wait for an answer after sending a request.
  33. | :param authreconnect: Try to reconnect if websocket is closed, value is number of seconds between attemps.
  34. | :param on_connect: Function to call after successful connect, with parameter (obsws)
  35. | :param on_disconnect: Function to call after successful disconnect, with parameter (obsws)
  36. |
  37. | call(self, obj)
  38. | Make a call to the OBS server through the Websocket.
  39. |
  40. | :param obj: Request (class from obswebsocket.requests module) to send
  41. | to the server.
  42. | :return: Request object populated with response data.
  43. |
  44. | connect(self)
  45. | Connect to the websocket server
  46. |
  47. | :return: Nothing
  48. |
  49. | disconnect(self)
  50. | Disconnect from websocket server
  51. |
  52. | :return: Nothing
  53. |
  54. | reconnect(self)
  55. | Restart the connection to the websocket server
  56. |
  57. | :return: Nothing
  58. |
  59. | register(self, func, event=None)
  60. | Register a new hook in the websocket client
  61. |
  62. | :param func: Callback function pointer for the hook
  63. | :param event: Event (class from obswebsocket.events module) to trigger
  64. | the hook on. Default is None, which means trigger on all events.
  65. | :return: Nothing
  66. |
  67. | unregister(self, func, event=None)
  68. | Unregister a new hook in the websocket client
  69. |
  70. | :param func: Callback function pointer for the hook
  71. | :param event: Event (class from obswebsocket.events module) which
  72. | triggered the hook on. Default is None, which means unregister this
  73. | function for all events.
  74. | :return: Nothing

Problems?

Please check on Github project issues, and if nobody else have experienced it before, you can file a new issue.