Procházet zdrojové kódy

fix task_kill imports + now use obs websocket to change slides in next_song.py

Noah Vogt před 7 měsíci
rodič
revize
c3fb65c67d

+ 9 - 6
README.md

@@ -343,16 +343,20 @@ which for example can look like this:
     2023-11-05
     3
 
-It then increments the value up to `OBS_MIN_SUBDIRS` and cycles back to 1. After each increment, it writes to the cachefile and by default sends a hotkey `Ctrl + Shift + F${value}` with the `$value` being the just incremented variable - which can be intercepted by OBS to change to the respecting scene for the song. You can change the hotkey prefix, but not the last part with the function keys, for example the configuration to use `Ctrl + Alt + F${value}` would be
+It then increments the value up to `OBS_MIN_SUBDIRS` and cycles back to 1. After each increment, it writes to the cachefile and switches to the respecting OBS Scene. With the configuration
 
 ```python
-OBS_SWITCH_TO_SCENE_HOTKEY_PREFIX = ["ctrl", "alt"]
+OBS_SONG_SCENE_PREFIX = "Song "
 ```
 
-To transition to the new song, it sends another hotkey defined by the following default:
+it would switch to the OBS Scene "Song 1" for the first song, "Song 2" for the second etc.
+
+To connect to OBS, it uses a OBS Websocket Connection. Here an example configuration with an empty password:
 
 ```python
-OBS_TRANSITION_HOTKEY = ["ctrl", "shift", "f12"]
+OBS_WEBSOCKET_HOSTNAME = "localhost"
+OBS_WEBSOCKET_PORT = 4444
+OBS_WEBSOCKET_PASSWORD = ""
 ```
 
 ### previous_song.py
@@ -375,11 +379,10 @@ These are some issues and possible changes that will be addressed or at least co
 - add tests
 - use smarter multi slide splitter algorithm: either by pattern recognition like line matching or rhymes of the last word or by incorporating some sort of sub-song-structures in the body.
 - add warnings that indicate potential problems with rclone syncing
-- Use obs websocket connection, cleaner that transition hotkeys. Also to deprecate pyautogui.
 - add (semantic) versioning, maybe even display on program run as text
 - add not-yet-public streaming workflow scripts
 - for sermon segment generating: Check if file duration and type roughly match the target to avoid useless regenerating. Also, parallelization.
-- make multiplatform ejecting of cd drives possible
+- make multiplatform ejecting of cd drives possible / fix win32 popup after ejecting
 - fix cd recording edge cases when:
     - a new day starts during the recording
     - changing timezone

+ 2 - 2
os_agnostic/tasks.py

@@ -16,9 +16,9 @@
 import os
 
 if os.name == "nt":
-    from signal import SIGTERM
-else:
     from subprocess import call
+else:
+    from signal import SIGTERM
 
 
 def kill_process(pid: int) -> None:

+ 1 - 1
requirements-unix.txt

@@ -1,7 +1,7 @@
 wand
 termcolor
 colorama
-pyautogui
+obsws_python
 PyQt5
 pycdio
 soundfile

+ 1 - 1
requirements-win32.txt

@@ -1,7 +1,7 @@
 wand
 termcolor
 colorama
-pyautogui
+obsws_python
 PyQt5
 wmi
 soundfile

+ 10 - 8
song_switcher/obs.py

@@ -14,14 +14,16 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
-from time import sleep
+import obsws_python as obs
 
-from pyautogui import keyDown, keyUp
+import config as const
 
 
-def safe_send_hotkey(hotkey: list, sleep_time=0.1) -> None:
-    for key in hotkey:
-        keyDown(key)
-    sleep(sleep_time)
-    for key in hotkey:
-        keyUp(key)
+def change_to_song_scene(song_number: int) -> None:
+    cl = obs.ReqClient(
+        host=const.OBS_WEBSOCKET_HOSTNAME,
+        port=const.OBS_WEBSOCKET_PORT,
+        password=const.OBS_WEBSOCKET_PASSWORD,
+        timeout=3,
+    )
+    cl.set_current_program_scene(f"{const.OBS_SONG_SCENE_PREFIX}{song_number}")

+ 2 - 9
song_switcher/switch.py

@@ -29,7 +29,7 @@ from utils import (
 )
 from input import get_cachefile_content
 import config as const
-from .obs import safe_send_hotkey
+from .obs import change_to_song_scene
 
 
 class SongDirection(Enum):
@@ -61,14 +61,7 @@ def switch_to_song(song_number: int) -> None:
         song_number = 1
     if song_number < 1:
         song_number = const.OBS_MIN_SUBDIRS
-    log("sending hotkey to switch to scene {}".format(song_number), "cyan")
-    scene_switch_hotkey = list(const.OBS_SWITCH_TO_SCENE_HOTKEY_PREFIX)
-    scene_switch_hotkey.append("f{}".format(song_number))
-    safe_send_hotkey(scene_switch_hotkey)
-
-    log("sending hotkey to transition to scene {}".format(song_number), "cyan")
-    safe_send_hotkey(const.OBS_TRANSITION_HOTKEY)
-
+    change_to_song_scene(song_number)
     create_cachfile_for_song(song_number)