Notification to telegram IM

I changed the script from ls to stat because ls prints different in shell than bash. However the stat from OSX is BSD, is different from the linux one.

The variable size change it to this one for osx

size=$(stat “$sonarr_episodefile_path” | awk ‘{print $8}’)

I don’t know. What OS do you use? Ubuntu?

working fine. made my day :slightly_smiling:

thanks

debian linux

I use debian also, I tested bash, dash, busy box in alpine (sonarr runs here), Ubuntu, in all worked fine.
The only different is osx, since is bsd it had trouble gathering the size.
But if it works for you. Leave it like that.

:wink: yeah … meanwhile busy with nodejs to get it working also …
:wink:

I’ll work fine for now, but if you want multiple recipients in the future you’ll have to correct it so the send message can be called multi times with different chatid

for my purpose this is ok :wink:

would be nice to have this builtin in Sonarr

I’ve installed Sonarr on my Raspberry Pi that’s running OSMC. I also want to create a feature with custom connections. I’ve created a file subtitles.sh that i want to download the correct subtitles. In the Sonarr log I see that the file is being executed. But the file subtitles.log isn’t being created. If I execute subtitles.sh myself it is creating the file. subtitles.log is executable.

How can I debug what’s going wrong? Thanks for your help so far :slightly_smiling:

subtitles.sh

#!/bin/sh
echo "some data for the file: $sonarr_series_title\n" >> subtitles.log

Log

16-3-3 19:57:42.0|Debug|CustomScriptService|Executing external script: /home/osmc/subtitles.sh
16-3-3 19:57:42.2|Debug|subtitles.sh|Starting /home/osmc/subtitles.sh 
16-3-3 19:57:42.3|Debug|CustomScriptService|Executed external script: /home/osmc/subtitles.sh - Status: 0
16-3-3 19:57:42.3|Debug|CustomScriptService|Script Output:

First the variable and new line won’t expand without the -e switch in echo.

Second you’re redirecting the echo to a file, also point this file to an absolute path not plain subtitle.log
You won’t see anything in the log of sonarr

1 Like

Latest develop version enabled OnGrab button for custom scripts, here is a simple notification.

#!/bin/sh

TOKEN='TELEGRAM_TOKEN'
URL='https://api.telegram.org/bot'$TOKEN
MSG_URL=$URL'/sendMessage?chat_id='
UPD_URL=$URL'/getUpdates?offset='


send_telegram_message () {
  curl -s --data-urlencode "text=$2" --data-urlencode "parse_mode=Markdown" "$MSG_URL$1&"
}

generate_message () {
case $sonarr_eventtype in
  Grab)
    size=$( expr "${sonarr_release_size}" / 1048576 )
    msg=$(printf "*Episode Grabbed* \n*Source:* ${sonarr_release_title} | ${size} MB \n*Indexer:* ${sonarr_release_indexer}")
  ;;
  Download)
    size=$( expr `stat -c "%s" "${sonarr_episodefile_path}"` / 1048576  )
    msg=$(printf "*Episode Imported* \n*Source:* ${sonarr_episodefile_scenename} | ${size} MB \n*Destination:* ${sonarr_episodefile_path} ")
    send_message "13611883" "$msg"
  ;;
esac
}

generate_message
send_telegram_message "110642629" "${msg}"

Edit: I changed the script to something that can be used in both cases grab/download.

note that if you have in your indexer name with an underscore character like “_” (example speedcd_HD) the message on grab will fail, because underscore gets parsed as markdown character, so change underscores to something else

Thanks :slight_smile:

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.