-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a6157da
Showing
13 changed files
with
884 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Release | ||
on: | ||
push: | ||
tags: | ||
- "v*.*.*" | ||
workflow_dispatch: | ||
inputs: | ||
tag: | ||
required: true | ||
type: string | ||
prerelease: | ||
required: true | ||
type: boolean | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Publish Release | ||
uses: softprops/[email protected] | ||
with: | ||
generate_release_notes: true | ||
fail_on_unmatched_files: true | ||
tag_name: ${{ github.event.inputs.tag || github.ref }} | ||
prerelease: ${{ github.event.inputs.prerelease }} | ||
draft: ${{ github.event_name != 'workflow_dispatch' }} | ||
files: | | ||
custom-browser-events.py |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# OBS 浏览器源自定义 JS 事件 | ||
|
||
这是一个针对 OBS 的 Python 脚本,可以让你用快捷键在当前场景组中所有的浏览器源上触发自定义的 JavaScript 事件。 | ||
|
||
## 用法 | ||
|
||
1. 启动 OBS Studio。在“**工具 > 脚本**”中, 选择“**Python 设置**”一栏。选中 Python 的安装位置。请确保 Python 已经安装好,且体系结构与 OBS 相同(如 64 位的 OBS 就要装 64 位的 Python,不能装 32 位的 Python)。 | ||
|
||
![在“Python 设置”中的“Python 安装路径”中打开正确的文件夹。OBS 会显示自己是多少位的。选好了正确的位置后,下方会显示“已加载 Python 版本:3.xx”。](images/1z.png) | ||
|
||
2. 仍然在“脚本”窗口中,回到“**脚本**”一栏,点击左下角的加号按钮。选中 `custom-browser-events.py` 文件。 | ||
|
||
![加号按钮鼠标悬浮时会显示“添加脚本”。](images/2z.png) | ||
|
||
3. 脚本加载好后,右边会出现“**Events**”框,可以用来管理您的自定义事件。 | ||
|
||
![窗口右侧会出现本脚本的说明和“Events”框。初始会有三个默认事件,“obsCustomEvent1”到“obsCustomEvent3”.](images/3z.png) | ||
|
||
4. 设置好事件名称后,您可以关闭“**脚本**”窗口,前往“**文件 > 设置 > 快捷键**”设置快捷键。自定义事件会出现在第一个小标题上面。 | ||
|
||
![每个自定义事件都会有一个对应的新指令,叫做“Custom browser event”加上事件名称。](images/4z.png) | ||
|
||
5. 要侦听自定义事件,只需在浏览器源的页面的 JavaScript 代码中添加: | ||
|
||
~~~js | ||
window.addEventListener("obsCustomEvent1", function (ev) { | ||
document.body.append("Hello, world!") | ||
}) | ||
~~~ | ||
|
||
或者使用函数定义: | ||
|
||
~~~js | ||
function doSomething(ev) { | ||
// ... | ||
} | ||
window.addEventListener("obsCustomEvent1", doSomething) | ||
~~~ | ||
|
||
您也可以省略“`window.`”。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Custom JavaScript events for OBS Studio browser sources <br> OBS 浏览器源自定义 JS 事件 | ||
|
||
[简体中文 · Read in Simplified Chinese](README-zh.md) | ||
|
||
This Python script for OBS Studio allows you to trigger custom JavaScript events on all browser sources (in the current scene collection) using hotkeys. | ||
|
||
## Usage | ||
|
||
1. Launch OBS Studio. Under **Tools > Scripts**, open the **Python Settings** tab. Choose the installation folder of Python. Make sure you have Python installed and it has the same architecture as OBS studio (e.g. for 64-bit OBS Studio install 64-bit Python, not 32-bit Python). | ||
|
||
![Browse to the correct path using the “Python Install Path” box in “Python Settings”. It will tell you your OBS Studio architecture. Once the correct path is selected, you should see the line “Loaded Python Version: 3.xx”.](images/1.png) | ||
|
||
2. In the same window, navigate back to the **Scripts** tab and click on the plus button in the bottom left. Choose the `custom-browser-events.py` file. | ||
|
||
![The plus button says “Add Scripts” when hovered.](images/2.png) | ||
|
||
3. After the script is loaded, you should see the **Events** box to the right. Here you can manage your custom events. | ||
|
||
![A description of the script and the “Events” box show up in the right side of the window. There are three default events, “obsCustomEvent1” through “obsCustomEvent3”.](images/3.png) | ||
|
||
4. Once you are happy with the event names, you can close the **Scripts** window and go to **Files > Settings > Hotkeys** to set your hotkeys. The custom events will appear at the bottom of the topmost section, above the sections for specific scenes. | ||
|
||
![You will see new available actions labeled “Custom browser event” followed by your event names.](images/4.png) | ||
|
||
5. To listen for custom events, simply add something like this in the JavaScript code for your browser page: | ||
|
||
~~~js | ||
window.addEventListener("obsCustomEvent1", function (ev) { | ||
document.body.append("Hello, world!") | ||
}) | ||
~~~ | ||
|
||
Or with a function declaration: | ||
|
||
~~~js | ||
function doSomething(ev) { | ||
// ... | ||
} | ||
window.addEventListener("obsCustomEvent1", doSomething) | ||
~~~ | ||
|
||
Omit “`window.`” if you like. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# Custom JavaScript events for OBS Studio browser sources | ||
# Copyright (C) 2023 DGCK81LNN | ||
# Documentation can be found at https://github.com/DGCK81LNN/obs_custom-browser-events.py | ||
# | ||
# This program is free software: you can redistribute and/or modify it | ||
# under the terms of the GNU General Public License version 3. | ||
# | ||
# This program is distributed WITHOUT ANY WARRANTY; | ||
# See the GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
import obspython as obs | ||
from datetime import datetime | ||
|
||
def obs_data_get_string_array(data, name): | ||
items = [] | ||
array = obs.obs_data_get_array(data, name) | ||
for i in range(obs.obs_data_array_count(array)): | ||
item = obs.obs_data_array_item(array, i) | ||
items.append(obs.obs_data_get_string(item, "value")) | ||
obs.obs_data_release(item) | ||
obs.obs_data_array_release(array) | ||
return items | ||
|
||
events = [] | ||
hotkey_ids = {} | ||
hotkey_callbacks = [] | ||
|
||
def script_description(): | ||
return "Assign hotkeys to custom browser events. Set hotkeys in OBS settings.\n\nby DGCK81LNN <https://github.com/DGCK81LNN>" | ||
|
||
def script_defaults(settings): | ||
array = obs.obs_data_array_create() | ||
for i in range(3): | ||
item = obs.obs_data_create() | ||
obs.obs_data_set_string(item, "value", "obsCustomEvent%d" % (i + 1)) | ||
obs.obs_data_array_insert(array, obs.obs_data_array_count(array), item) | ||
obs.obs_data_release(item) | ||
obs.obs_data_set_default_array(settings, "events", array) | ||
obs.obs_data_array_release(array) | ||
|
||
def script_properties(): | ||
props = obs.obs_properties_create() | ||
obs.obs_properties_add_editable_list(props, "events", "Events", obs.OBS_EDITABLE_LIST_TYPE_STRINGS, None, None) | ||
return props | ||
|
||
def script_load(settings): | ||
global events, hotkey_ids | ||
events = obs_data_get_string_array(settings, "events") | ||
hotkey_ids = {} | ||
|
||
for event_name in events: | ||
hotkey_callback = callback_for(event_name) | ||
hotkey_id = obs.obs_hotkey_register_frontend( | ||
script_path() + "//" + event_name, | ||
"Custom browser event %r" % event_name, | ||
hotkey_callback | ||
) | ||
hotkey_callbacks.append(hotkey_callback) | ||
hotkey_save_array = obs.obs_data_get_array(settings, event_name) | ||
obs.obs_hotkey_load(hotkey_id, hotkey_save_array) | ||
obs.obs_data_array_release(hotkey_save_array) | ||
hotkey_ids[event_name] = hotkey_id | ||
|
||
def script_unload(): | ||
for callback in hotkey_callbacks: | ||
obs.obs_hotkey_unregister(callback) | ||
hotkey_callbacks.clear() | ||
|
||
def script_update(settings): | ||
if obs_data_get_string_array(settings, "events") != events: | ||
script_unload() | ||
script_load(settings) | ||
|
||
def script_save(settings): | ||
for event_name in events: | ||
hotkey_save_array = obs.obs_hotkey_save(hotkey_ids[event_name]) | ||
obs.obs_data_set_array(settings, event_name, hotkey_save_array) | ||
obs.obs_data_array_release(hotkey_save_array) | ||
|
||
def callback_for(event_name): | ||
return lambda pressed: trigger(event_name) if pressed else None | ||
|
||
def trigger(event_name): | ||
print( | ||
"[%s] Triggered event %r" % ( | ||
datetime.now().astimezone().isoformat(timespec="seconds"), | ||
event_name | ||
) | ||
) | ||
for src in obs.obs_enum_sources(): | ||
if obs.obs_source_get_id(src) == "browser_source": | ||
cd = obs.calldata_create() | ||
obs.calldata_set_string(cd, "eventName", event_name) | ||
obs.calldata_set_string(cd, "jsonString", "{}") | ||
obs.proc_handler_call(obs.obs_source_get_proc_handler(src), "javascript_event", cd) | ||
obs.calldata_destroy(cd) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.