-
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 8b70344
Showing
18 changed files
with
522 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,18 @@ | ||
# This file is for unifying the coding style for different editors and IDEs | ||
# editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
charset = utf-8 | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[**.py] | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
[**.js] | ||
indent_style = space | ||
indent_size = 4 |
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,9 @@ | ||
*.pyc | ||
*.swp | ||
.idea | ||
*.iml | ||
build | ||
dist | ||
*.egg* | ||
.DS_Store | ||
*.zip |
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,5 @@ | ||
{ | ||
"python.analysis.diagnosticSeverityOverrides": { | ||
"reportMissingImports": "none" | ||
} | ||
} |
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,4 @@ | ||
include README.md | ||
recursive-include octoprint_obswebsocket/templates * | ||
recursive-include octoprint_obswebsocket/translations * | ||
recursive-include octoprint_obswebsocket/static * |
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,17 @@ | ||
# OctoPrint-OBSWebsocket | ||
|
||
**TODO:** Describe what your plugin does. | ||
|
||
## Setup | ||
|
||
Install via the bundled [Plugin Manager](https://docs.octoprint.org/en/master/bundledplugins/pluginmanager.html) | ||
or manually using this URL: | ||
|
||
https://github.com/aetaric/OctoPrint-OBSWebsocket/archive/master.zip | ||
|
||
**TODO:** Describe how to install your plugin, if more needs to be done than just installing it via pip or through | ||
the plugin manager. | ||
|
||
## Configuration | ||
|
||
**TODO:** Describe your plugin's configuration options (if any). |
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,8 @@ | ||
[python: */**.py] | ||
|
||
[jinja2: */**.jinja2] | ||
silent=false | ||
extensions=jinja2.ext.autoescape, jinja2.ext.with_, jinja2.ext.do, octoprint.util.jinja.trycatch | ||
|
||
[javascript: */**.js] | ||
extract_messages = gettext, ngettext |
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,8 @@ | ||
Currently Cookiecutter generates the following helpful extras to this folder: | ||
|
||
obswebsocket.md | ||
Data file for plugins.octoprint.org. Fill in the missing TODOs once your | ||
plugin is ready for release and file a PR as described at | ||
http://plugins.octoprint.org/help/registering/ to get it published. | ||
|
||
This folder may be safely removed if you don't need it. |
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,65 @@ | ||
--- | ||
layout: plugin | ||
|
||
id: obswebsocket | ||
title: OctoPrint-OBSWebsocket | ||
description: Push information from OctoPrint to OBS | ||
authors: | ||
- Dustin Essington | ||
license: AGPLv3 | ||
|
||
# TODO | ||
date: today's date in format YYYY-MM-DD, e.g. 2015-04-21 | ||
|
||
homepage: https://github.com/aetaric/OctoPrint-OBSWebsocket | ||
source: https://github.com/aetaric/OctoPrint-OBSWebsocket | ||
archive: https://github.com/aetaric/OctoPrint-OBSWebsocket/archive/master.zip | ||
|
||
# TODO | ||
# Set this to true if your plugin uses the dependency_links setup parameter to include | ||
# library versions not yet published on PyPi. SHOULD ONLY BE USED IF THERE IS NO OTHER OPTION! | ||
#follow_dependency_links: false | ||
|
||
# TODO | ||
tags: | ||
- a list | ||
- of tags | ||
- that apply | ||
- to your plugin | ||
- (take a look at the existing plugins for what makes sense here) | ||
|
||
# TODO | ||
# When registering a plugin on plugins.octoprint.org, all screenshots should be uploaded not linked from external sites. | ||
screenshots: | ||
- url: url of a screenshot, /assets/img/... | ||
alt: alt-text of a screenshot | ||
caption: caption of a screenshot | ||
- url: url of another screenshot, /assets/img/... | ||
alt: alt-text of another screenshot | ||
caption: caption of another screenshot | ||
- ... | ||
|
||
# TODO | ||
featuredimage: url of a featured image for your plugin, /assets/img/... | ||
|
||
# TODO | ||
# You only need the following if your plugin requires specific OctoPrint versions or | ||
# specific operating systems to function - you can safely remove the whole | ||
# "compatibility" block if this is not the case. | ||
|
||
compatibility: | ||
|
||
# Compatible Python version | ||
# | ||
# It is recommended to only support Python 3 for new plugins, in which case this should be ">=3,<4" | ||
# | ||
# Plugins that wish to support both Python 2 and 3 should set it to ">=2.7,<4". | ||
# | ||
# Plugins that only support Python 2 will not be accepted into the plugin repository. | ||
|
||
python: ">=3,<4" | ||
|
||
--- | ||
|
||
**TODO**: Longer description of your plugin, configuration examples etc. This part will be visible on the page at | ||
http://plugins.octoprint.org/plugin/obswebsocket/ |
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,174 @@ | ||
# coding=utf-8 | ||
from __future__ import absolute_import, unicode_literals | ||
|
||
import octoprint.plugin, octoprint.util | ||
|
||
from obswebsocket import obsws, requests, events | ||
|
||
import logging, time | ||
|
||
class ObswebsocketPlugin( | ||
octoprint.plugin.StartupPlugin, | ||
octoprint.plugin.EventHandlerPlugin, | ||
octoprint.plugin.ShutdownPlugin, | ||
octoprint.plugin.ProgressPlugin, | ||
octoprint.plugin.SettingsPlugin, | ||
octoprint.plugin.TemplatePlugin, | ||
octoprint.plugin.RestartNeedingPlugin): | ||
|
||
def __init__(self): | ||
self._logger = logging.getLogger(__name__) | ||
|
||
self.websocket = None | ||
self.streaming = False | ||
self.progress = 0 | ||
self.temps = None | ||
self.tempthread = None | ||
|
||
def on_startup(self, host, port): | ||
self._logger.info("OBS Websocket Plugin Connecting to OBS") | ||
self.websocket = obsws( | ||
self._settings.get(["host"]), | ||
self._settings.get(["port"]), | ||
self._settings.get(["password"])) | ||
self.websocket.register(self.on_streamup, events.StreamStarted) | ||
self.websocket.register(self.on_streamdown, events.StreamStopped) | ||
self._logger.info("Registered OBS events") | ||
self.websocket.connect() | ||
self._logger.info("Connected to OBS Version: %s" % | ||
self.websocket.call(requests.GetVersion()).getObsStudioVersion()) | ||
self._logger.info("OBS Websocket Plugin Started") | ||
|
||
def on_streamup(self, event): | ||
self.streaming = True | ||
self._logger.info("Stream Started") | ||
|
||
def on_streamdown(self, event): | ||
self.streaming = False | ||
self._logger.info("Stream Stopped") | ||
|
||
def on_after_startup(self): | ||
self.tempthread = octoprint.util.RepeatedTimer(2.0, self.update_temps) | ||
time.sleep(1) | ||
self.tempthread.start() | ||
|
||
def on_shutdown(self): | ||
self._logger.info("OBS Websocket Plugin Stopping") | ||
self.websocket.call(requests.StopStreaming()) | ||
self.websocket.disconnect() | ||
self._logger.info("Disconnected from OBS") | ||
self.progress = 0 | ||
self.websocket = None | ||
self.streaming = False | ||
|
||
def on_print_progress(self, storage, path, progress): | ||
self.progress = progress | ||
self.temps = self._printer.get_current_temperatures() | ||
if not self._settings.get(["progress"]) == "": | ||
if self._settings.get(["os"]) == "windows": | ||
self.websocket.call(requests.SetTextGDIPlusProperties( | ||
source="progress", text="Progress: %d%%" % self.progress)) | ||
elif self._settings.get(["os"]) == "mac" or self._settings.get(["os"]) == "linux": | ||
self.websocket.call(requests.SetTextFreetype2Properties( | ||
source="progress", text="Progress: %d%%" % self.progress)) | ||
self._logger.debug("Updated progress") | ||
|
||
def on_event(self, event, payload): | ||
if event == "PrintStarted": | ||
if not self.streaming: | ||
self.websocket.call(requests.StartStreaming()) | ||
elif event in ["PrintDone","PrintCanceled"]: | ||
if self.streaming: | ||
self.websocket.call(requests.StopStreaming()) | ||
|
||
def update_temps(self): | ||
if self.websocket.ws.connected: | ||
self.temps = self._printer.get_current_temperatures() | ||
if self._settings.get(["os"]) == "windows": | ||
if not self._settings.get(["tool-temp"]) == "": | ||
self.websocket.call(requests.SetTextGDIPlusProperties(source="tool-temp", | ||
text="Tool: %.1f°C/%.1f°C" % | ||
(self.temps["tool0"]["actual"], self.temps["tool0"]["target"]))) | ||
if not self._settings.get(["bed-temp"]) == "": | ||
self.websocket.call(requests.SetTextGDIPlusProperties(source="bed-temp", | ||
text="Bed: %.1f°C/%.1f°C" % | ||
(self.temps["bed"]["actual"], self.temps["bed"]["target"]))) | ||
self._logger.debug("Updated temps") | ||
elif self._settings.get(["os"]) == "mac" or self._settings.get(["os"]) == "linux": | ||
if not self._settings.get(["tool-temp"]) == "": | ||
self.websocket.call(requests.SetTextFreetype2Properties(source="tool-temp", | ||
text="Tool: %.1f°C/%.1f°C" % | ||
(self.temps["tool0"]["actual"], self.temps["tool0"]["target"]))) | ||
if not self._settings.get(["bed-temp"]) == "": | ||
self.websocket.call(requests.SetTextFreetype2Properties(source="bed-temp", | ||
text="Bed: %.1f°C/%.1f°C" % | ||
(self.temps["bed"]["actual"], self.temps["bed"]["target"]))) | ||
self._logger.debug("Updated temps") | ||
else: | ||
self.websocket.connect() | ||
|
||
def get_settings_defaults(self): | ||
return dict( | ||
port = 4444, | ||
password = "password", | ||
host = "127.0.0.1", | ||
os = "windows", | ||
progress = "progress", | ||
tool = "tool-temp", | ||
bed = "bed-temp" | ||
) | ||
|
||
def on_settings_save(self, data): | ||
octoprint.plugin.SettingsPlugin.on_settings_save(self, data) | ||
self._logger.info("Settings Saved") | ||
|
||
self.websocket.disconnect() | ||
self.websocket = obsws( | ||
self._settings.get(["host"]), | ||
self._settings.get(["port"]), | ||
self._settings.get(["password"])) | ||
self.websocket.register(self.on_streamup, events.StreamStarted) | ||
self.websocket.register(self.on_streamdown, events.StreamStopped) | ||
self.websocket.connect() | ||
|
||
self.tempthread = octoprint.util.RepeatedTimer(2.0, self.update_temps) | ||
time.sleep(1) | ||
self.tempthread.start() | ||
|
||
self._logger.info("Reconnected to OBS") | ||
|
||
def get_template_configs(self): | ||
return [ | ||
dict(type="settings", custom_bindings=False) | ||
] | ||
|
||
def get_update_information(self): | ||
# Define the configuration for your plugin to use with the Software Update | ||
# Plugin here. See https://docs.octoprint.org/en/master/bundledplugins/softwareupdate.html | ||
# for details. | ||
return { | ||
"obswebsocket": { | ||
"displayName": "Obswebsocket Plugin", | ||
"displayVersion": self._plugin_version, | ||
|
||
# version check: github repository | ||
"type": "github_release", | ||
"user": "aetaric", | ||
"repo": "OctoPrint-OBSWebsocket", | ||
"current": self._plugin_version, | ||
|
||
# update method: pip | ||
"pip": "https://github.com/aetaric/OctoPrint-OBSWebsocket/archive/{target_version}.zip", | ||
} | ||
} | ||
|
||
__plugin_pythoncompat__ = ">=3,<4" # Only Python 3 | ||
|
||
def __plugin_load__(): | ||
global __plugin_implementation__ | ||
__plugin_implementation__ = ObswebsocketPlugin() | ||
|
||
global __plugin_hooks__ | ||
__plugin_hooks__ = { | ||
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information | ||
} |
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 @@ | ||
/* TODO: Have your plugin's CSS files generated to here. */ |
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 @@ | ||
/* | ||
* View model for OctoPrint-OBSWebsocket | ||
* | ||
* Author: Dustin Essington | ||
* License: AGPLv3 | ||
*/ | ||
$(function() { | ||
function ObswebsocketViewModel(parameters) { | ||
var self = this; | ||
|
||
// assign the injected parameters, e.g.: | ||
// self.loginStateViewModel = parameters[0]; | ||
// self.settingsViewModel = parameters[1]; | ||
|
||
// TODO: Implement your plugin's view model here. | ||
} | ||
|
||
/* view model class, parameters for constructor, container to bind to | ||
* Please see http://docs.octoprint.org/en/master/plugins/viewmodels.html#registering-custom-viewmodels for more details | ||
* and a full list of the available options. | ||
*/ | ||
OCTOPRINT_VIEWMODELS.push({ | ||
construct: ObswebsocketViewModel, | ||
// ViewModels your plugin depends on, e.g. loginStateViewModel, settingsViewModel, ... | ||
dependencies: [ /* "loginStateViewModel", "settingsViewModel" */ ], | ||
// Elements to bind to, e.g. #settings_plugin_obswebsocket, #tab_plugin_obswebsocket, ... | ||
elements: [ /* ... */ ] | ||
}); | ||
}); |
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 @@ | ||
// TODO: Put your plugin's LESS here, have it generated to ../css. |
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 @@ | ||
Put your plugin's Jinja2 templates here. |
39 changes: 39 additions & 0 deletions
39
octoprint_obswebsocket/templates/obswebsocket_settings.jinja2
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,39 @@ | ||
<form class="form-horizontal"> | ||
<div class="control-group"> | ||
<label class="control-label">{{ _('Host') }}</label> | ||
<div class="controls"> | ||
<input type="text" class="input-block-level" data-bind="value: settings.plugins.obswebsocket.host"> | ||
</div> | ||
<label class="control-label">{{ _('Port') }}</label> | ||
<div class="controls"> | ||
<input type="text" class="input-block-level" data-bind="value: settings.plugins.obswebsocket.port"> | ||
</div> | ||
<label class="control-label">{{ _('Password') }}</label> | ||
<div class="controls"> | ||
<input type="text" class="input-block-level" data-bind="value: settings.plugins.obswebsocket.password"> | ||
</div> | ||
<label class="control-label">{{ _('OS') }}</label> | ||
<div class="controls"> | ||
<select data-bind="value: settings.plugins.obswebsocket.os"> | ||
<option value="windows">Windows</option> | ||
<option value="mac">Mac</option> | ||
<option value="linux">Linux</option> | ||
</select> | ||
</div> | ||
<label class="control-label">{{ _('Progress') }}</label> | ||
<div class="controls"> | ||
<input type="text" class="input-block-level" data-bind="value: settings.plugins.obswebsocket.progress"> | ||
<span class="help-inline">{{ _('Name of the progress text source. Unset this to not send progress.') }}</span> | ||
</div> | ||
<label class="control-label">{{ _('Tool') }}</label> | ||
<div class="controls"> | ||
<input type="text" class="input-block-level" data-bind="value: settings.plugins.obswebsocket.tool"> | ||
<span class="help-inline">{{ _('Name of the tool temp text source. Unset this to not send tool temp.') }}</span> | ||
</div> | ||
<label class="control-label">{{ _('Bed') }}</label> | ||
<div class="controls"> | ||
<input type="text" class="input-block-level" data-bind="value: settings.plugins.obswebsocket.bed"> | ||
<span class="help-inline">{{ _('Name of the bed temp text source. Unset this to not send bed temp.') }}</span> | ||
</div> | ||
</div> | ||
</form> |
Oops, something went wrong.