2022-06-01 19:39:54 +02:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
# https://wiki.servarr.com/en/sonarr/custom-scripts
|
|
|
|
|
|
|
|
import os
|
2022-06-13 22:45:07 +02:00
|
|
|
from os import environ
|
2022-06-01 19:39:54 +02:00
|
|
|
import configparser
|
|
|
|
import requests
|
|
|
|
|
|
|
|
config = configparser.ConfigParser()
|
2022-06-01 19:51:46 +02:00
|
|
|
config.read(os.path.dirname(__file__) + '/config.ini')
|
2022-06-01 19:39:54 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
)
|
|
|
|
|
2022-06-01 20:19:35 +02:00
|
|
|
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"
|
2022-06-13 22:45:07 +02:00
|
|
|
|
|
|
|
series_title = environ.get('Sonarr_Series_Title')
|
|
|
|
season_number = environ.get('Sonarr_EpisodeFile_SeasonNumber')
|
|
|
|
episode_number = environ.get('Sonarr_EpisodeFile_EpisodeNumbers')
|
|
|
|
episode_title = environ.get('Sonarr_EpisodeFile_EpisodeTitles')
|
|
|
|
release_quality = environ.get('Sonarr_EpisodeFile_Quality')
|
|
|
|
body += "%s - S%sE%s - %s [%s]\n" % (series_title, season_number, episode_number, episode_title, release_quality)
|
|
|
|
|
|
|
|
|
2022-06-01 20:19:35 +02:00
|
|
|
toot(server_url, body, server_token)
|
2022-06-01 19:39:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
if os.getenv('sonarr_eventtype') == 'Test':
|
|
|
|
toot(server_url, "Test message", server_token)
|