commit 7af24ce70148c142a4e9c561f640b593f3ad7805 Author: sevi-kun Date: Wed Jun 1 19:39:54 2022 +0200 initial commit diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..2fa7ce7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +config.ini diff --git a/README.md b/README.md new file mode 100755 index 0000000..d96bbcf --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# arr-mastodon + +> Pushes new content notification from sonarr and radarr to mastodon. diff --git a/arr-mastodon.py b/arr-mastodon.py new file mode 100755 index 0000000..31b65bd --- /dev/null +++ b/arr-mastodon.py @@ -0,0 +1,40 @@ +#!/usr/bin/python3 + +# https://wiki.servarr.com/en/sonarr/custom-scripts + +import os +import configparser +import requests +from bs4 import BeautifulSoup + + +config = configparser.ConfigParser() +config.read('config.ini') + +server_token = config['server']['token'] +server_url = config['server']['url'] + +def toot(mastodon_url: str, body: str, mastodon_token: str): + headers = {} + headers["Authorization"] = f"Bearer {mastodon_token}" + + data = {} + data["status"] = body + + response = requests.post( + url=f"{mastodon_url}/api/v1/statuses", data=data, headers=headers + ) + + +if os.getenv('sonarr_eventtype') == 'Download': + body = "New content added to Jellyfin: \n" + body += 'Series: ' + os.getenv('sonarr_series_title') + '\n' + body += 'Season: ' + os.getenv('sonarr_episodefile_seasonnumber') + '\n' + body += 'Episode: ' + os.getenv('sonarr_episodefile_episodecount') + '\n' + toot(server_url, body, server_token) + + +if os.getenv('sonarr_eventtype') == 'Test': + f.write('Sonarr: Test') + toot(server_url, "Test message", server_token) +