Browse Source

automatically find OBS configuration

master
Shiz 1 year ago
parent
commit
e68eb9bced
3 changed files with 61 additions and 17 deletions
  1. +48
    -16
      src/overlay/__main__.py
  2. +1
    -1
      src/overlay/obs/__init__.py
  3. +12
    -0
      src/overlay/obs/base.py

+ 48
- 16
src/overlay/__main__.py View File

@ -1,30 +1,62 @@
import argparse
import sys, os
import subprocess
import shlex
import threading
import argparse
from .obs import OBSProfile, OBSScene
from .twitch_chat import make_twitch_chat
from .obs import OBSSettings, OBSProfile, OBSScene
parser = argparse.ArgumentParser()
parser.add_argument('profile', type=argparse.FileType('r'), help='profile description file')
parser.add_argument('scene', type=argparse.FileType('r'), help='scene description file')
parser.add_argument('--nick-font', default='/Users/partynorge/down/Montserrat/Montserrat-Bold.ttf')
parser.add_argument('--chat-font', default='/Users/partynorge/down/Montserrat/Montserrat-Light.ttf')
parser.add_argument('-n', '--nickname', help='Twitch chat nickname', default='shizacular')
parser.add_argument('-t', '--token', help='Twitch OAuth token')
parser.add_argument('channel', help='Twitch channel')
parser.add_argument('args', nargs=argparse.REMAINDER, help='arguments to be passed through to ffmpeg')
parser.add_argument('-d', '--obs-dir', help='OBS config directory')
parser.add_argument('-p', '--profile', help='profile name')
parser.add_argument('-P', '--profile-file', type=argparse.FileType('r'), help='profile description file')
parser.add_argument('-s', '--scene', help='scene name')
parser.add_argument('-S', '--scene-file', type=argparse.FileType('r'), help='scene description file')
parser.add_argument('args', nargs='*', help='arguments to be passed through to ffmpeg')
args = parser.parse_args()
# Load profile and scene
if not args.obs_dir:
if sys.platform == 'win32':
obs_dir = r'{appdata}\\obs-studio'.format(appdata=os.getenv('AppData'))
elif sys.platform == 'darwin':
obs_dir = os.path.expanduser('~/Library/Application Support/obs-studio')
else:
obs_dir = os.path.expanduser('~/.config/obs-studio')
else:
obs_dir = args.obs_dir
# Load settings
settings_path = os.path.join(obs_dir, 'global.ini')
settings = OBSSettings()
with open(settings_path, 'r') as f:
settings.load(f)
# Load profile
if args.profile_file:
profile_path = args.profile_file
else:
if args.profile:
profile_name = args.profile
else:
profile_name = settings.profile_path
profile_path = os.path.join(obs_dir, 'basic', 'profiles', profile_name, 'basic.ini')
profile = OBSProfile()
profile.load(args.profile)
with open(profile_path, 'r') as f:
profile.load(f)
# Load scene
if args.scene_file:
scene_path = args.scene_file
else:
if args.scene:
scene_name = args.scene
else:
scene_name = settings.scene_path
scene_path = os.path.join(obs_dir, 'basic', 'scenes', profile_name + '.json')
scene = OBSScene(profile)
scene.load(args.scene)
with open(scene_path, 'r') as f:
scene.load(f)
# Convert scene graph
graph = scene.to_ffmpeg()


+ 1
- 1
src/overlay/obs/__init__.py View File

@ -1,2 +1,2 @@
from .base import OBSProfile, OBSSource, OBSScene
from .base import OBSSettings, OBSProfile, OBSSource, OBSScene
from . import cef_browser, scene, text, video

+ 12
- 0
src/overlay/obs/base.py View File

@ -25,6 +25,18 @@ class configproperty:
def __set__(self, instance, value):
self.get_section(instance.data)[self.name] = value
class OBSSettings:
def __init__(self):
self.data = configparser.ConfigParser()
def load(self, fd):
self.data.read_file(fd)
profile = configproperty('Basic.Profile')
profile_path = configproperty('Basic.ProfileDir')
scene = configproperty('Basic.SceneCollection')
scene_path = configproperty('Basic.SceneCollectionFile')
class OBSProfile:
def __init__(self, name='Untitled'):
self.data = configparser.ConfigParser()


Loading…
Cancel
Save