Skip to content

Commit

Permalink
Merge pull request #316 from giloser/Test_Gif
Browse files Browse the repository at this point in the history
change again the way to create the gif and also change the way to send image with multicam so all the images are first and the text message is with the last image
  • Loading branch information
giloser authored Nov 13, 2020
2 parents d033b5a + ace9b75 commit 163bcef
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions octoprint_telegram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1211,24 +1211,6 @@ def _send_msg(self, message="", with_image=False,with_gif=False,responses=None,
message = "[ERR GET IMAGE]\n\n" + message
image_data = None

r = None

if image_data:
self._logger.debug("Sending with image.. " + str(chatID))
files = {'photo':("image.jpg", image_data)}
self._logger.debug("files so far: " + str(files))
if message is not "":
data['caption'] = message
r = requests.post(self.bot_url + "/sendPhoto", files=files, data=data)

self._logger.debug("Sending finished. " + str(r.status_code))
else:
self._logger.debug("Sending without image.. " + str(chatID))
data['text'] = message
r =requests.post(self.bot_url + "/sendMessage", data=data)
self._logger.debug("Sending finished. " + str(r.status_code))

if with_image:
try:
files={}
sendOneInLoop = False
Expand All @@ -1252,10 +1234,10 @@ def _send_msg(self, message="", with_image=False,with_gif=False,responses=None,

self._logger.debug("Snapshot URL: " + str(snapshot_url))
if snapshot_url != self._settings.global_get(["webcam", "snapshot"]):
image_data = self.take_image(snapshot_url)
if image_data != "":
image_data2 = self.take_image(snapshot_url)
if image_data2 != "":
self._logger.debug("Image for " + str(li.get("name")))
files = {'photo':("image.jpg", image_data)}
files = {'photo':("image.jpg", image_data2)}
data2 = data
data2['caption'] = ""
r = requests.post(self.bot_url + "/sendPhoto", files=files, data=data2)
Expand All @@ -1271,6 +1253,24 @@ def _send_msg(self, message="", with_image=False,with_gif=False,responses=None,
except Exception as ex:
self._logger.exception("Exception occured on getting multicam plugin: "+ str(ex) )

r = None

if image_data:
self._logger.debug("Sending with image.. " + str(chatID))
files = {'photo':("image.jpg", image_data)}
self._logger.debug("files so far: " + str(files))
if message is not "":
data['caption'] = message
r = requests.post(self.bot_url + "/sendPhoto", files=files, data=data)

self._logger.debug("Sending finished. " + str(r.status_code))
else:
self._logger.debug("Sending without image.. " + str(chatID))
data['text'] = message
r =requests.post(self.bot_url + "/sendMessage", data=data)
self._logger.debug("Sending finished. " + str(r.status_code))


if r is not None and inline:
r.raise_for_status()
myJson = r.json()
Expand Down Expand Up @@ -1560,16 +1560,20 @@ def create_gif_new(self,chatID,sec=7,multicam_prof=0):
params.append( stream_url)
params.append( '-t')
params.append( timeSec)
params.append( '-pix_fmt')
params.append( 'yuv420p')
#work on android but seems to be a problem on some Iphone
#params.append( '-c:v')
#params.append( 'mpeg4')
#params.append( '-c:a' )
#params.append( 'mpeg4')
params.append( '-b:v')
params.append( '0')
params.append( '-crf')
params.append( '25')
params.append( '-movflags')
params.append( 'faststart')
#works on iphone but seems to be a problem on some android
#params.append( '-b:v')
#params.append( '0')
#params.append( '-crf')
#params.append( '25')
#params.append( '-movflags')
#params.append( 'faststart')

if multicam_prof != 0:
flipH = multicam_prof.get("flipH")
Expand Down

0 comments on commit 163bcef

Please sign in to comment.