Skip to content

Commit

Permalink
Add octolapse support, send video
Browse files Browse the repository at this point in the history
This pull request adds support for the plugin_octolapse_movie_done event, generated by Octolapse. In addition, timelapse files are now sent in video format and not in file format, improving the user experience.
Closes fabianonline#369 and fabianonline#370 .
  • Loading branch information
David committed Jul 8, 2021
1 parent 7d4cbc8 commit 7f77cc3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 6 additions & 4 deletions octoprint_telegram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1809,6 +1809,8 @@ def _send_msg(
if with_gif: # giloser 05/05/19
try:
sendOneInLoop = False
if kwargs["event"] == "plugin_octolapse_movie_done":
kwargs["event"] = "MovieDone"
if kwargs["event"] == "MovieDone":
ret = kwargs["movie"]
# file = self._file_manager.path_on_disk(octoprint.filemanager.FileDestinations.LOCAL, ret)
Expand Down Expand Up @@ -1893,8 +1895,8 @@ def _send_msg(
ret = self.create_gif_new(chatID, 0, 0)

if ret != "" and not sendOneInLoop:
self._logger.debug("send_file whith message: " + str(ret))
self.send_file(chatID, ret, message)
self._logger.debug("send_video with message: " + str(ret))
self.send_video(chatID, ret, message)
# ret = self.create_gif_new(chatID,0,0)
# if ret != "":
# self.send_file(chatID, ret,message)
Expand Down Expand Up @@ -2256,15 +2258,15 @@ def delete_msg(self, chat_id, message_id):
except Exception as ex:
pass

def send_video(self, message, video_file):
def send_video(self, chatID, video_file, message):
if not self.send_messages:
return

files = {"video": open(video_file, "rb")}
r = requests.post(
self.bot_url + "/sendVideo",
files=files,
data={"chat_id": self._settings.get(["chat"]), "caption": message},
data={"chat_id": chatID, "caption": message},
proxies=self.getProxies(),
)
self._logger.debug(
Expand Down
7 changes: 7 additions & 0 deletions octoprint_telegram/telegramNotifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def is_in_python_2_7():
"no_setting": True,
},
"StatusPrinting": {"bind_msg": "ZChange", "no_setting": True},
"plugin_octolapse_movie_done": {"bind_msg": "MovieDone", "no_setting": True},
"plugin_pause_for_user_event_notify": {
"text": "{emo:warning} "
+ gettext(
Expand Down Expand Up @@ -232,6 +233,7 @@ def __init__(self, main):
"gCode_M600": self.msgColorChangeRequested,
"Error": self.msgPrinterError,
"MovieDone": self.msgMovieDone,
"plugin_octolapse_movie_done": self.msgMovieDone,
"UserNotif": self.msgUserNotif,
"Connected": self.msgConnected,
"Disconnected": self.msgConnected,
Expand Down Expand Up @@ -280,6 +282,8 @@ def msgPrintFailed(self, payload, **kwargs):
self._sendNotification(payload, **kwargs)

def msgMovieDone(self, payload, **kwargs):
if kwargs["event"] == "plugin_octolapse_movie_done":
kwargs["event"] == "MovieDone"
self._sendNotification(payload, **kwargs)

def msgPrinterError(self, payload, **kwargs):
Expand Down Expand Up @@ -423,6 +427,8 @@ def _sendNotification(self, payload, **kwargs):
self._logger.exception("Exception on getting thumbnail: " + str(ex))

try:
if event == "plugin_octolapse_movie_done":
event = "MovieDone"
if event == "MovieDone":
if "movie" in payload:
kwargs["movie"] = payload["movie"]
Expand Down Expand Up @@ -469,6 +475,7 @@ def _sendNotification(self, payload, **kwargs):
+ "'."
)
self._logger.debug("Sending Notification: " + message)
self._logger.debug(kwargs)
# Do we want to send with Markup?
kwargs["markup"] = self.main._settings.get(
["messages", kwargs["event"], "markup"]
Expand Down

0 comments on commit 7f77cc3

Please sign in to comment.