This repository has been archived on 2024-10-14. You can view files and clone it, but cannot push or open issues or pull requests.
arr-misskey/arr-mastodon.py

50 lines
1.5 KiB
Python
Executable File

#!/usr/bin/python3
# https://wiki.servarr.com/en/sonarr/custom-scripts
import os
import configparser
import requests
config = configparser.ConfigParser()
config.read(os.path.dirname(__file__) + '/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('radarr_eventtype'):
if os.getenv('radarr_eventtype') == 'Download':
body = "New content added to Jellyfin: \n"
body += "Movie: " + os.getenv('radarr_movie_title') + '\n'
toot(server_url, body, server_token)
if os.getenv('sonarr_eventtype'):
if os.getenv('sonarr_eventtype') == 'Download':
body = "New content added to Jellyfin: \n"
series_title = os.getenv('sonarr_series_title')
season_number = os.getenv('sonarr_episodefile_seasonnumber')
episode_number = os.getenv('sonarr_episodefile_episodenumbers')
episode_title = os.getenv('sonarr_episodefile_episodetitles')
release_quality = os.getenv('sonarr_episodefile_quality')
body += "%s - S%sE%s - %s [%s]\n" % (series_title, season_number, episode_number, episode_title, release_quality)
toot(server_url, body, server_token)
if os.getenv('sonarr_eventtype') == 'Test':
toot(server_url, "Test message", server_token)