66e40ff077
- Create .env file for environment variables - Implement mediascheduler.py for managing TV shows in Plex and Sonarr - Add mediatask.py for processing series and movies with Telegram notifications
96 lines
3.1 KiB
Python
96 lines
3.1 KiB
Python
import requests
|
|
import datetime
|
|
import telegram
|
|
|
|
# Configuration
|
|
SONARR_API_URL = 'http://localhost:8989/api'
|
|
SONARR_API_KEY = 'your_sonarr_api_key'
|
|
RADARR_API_URL = 'http://localhost:7878/api'
|
|
RADARR_API_KEY = 'your_radarr_api_key'
|
|
PLEX_API_URL = 'http://localhost:32400'
|
|
PLEX_API_KEY = 'your_plex_api_key'
|
|
TELEGRAM_BOT_TOKEN = 'your_telegram_bot_token'
|
|
TELEGRAM_CHAT_ID = 'your_telegram_chat_id'
|
|
EXCEPTION_SERIES = ['Series1', 'Series2'] # Add your exception series here
|
|
|
|
# Initialize Telegram bot
|
|
bot = telegram.Bot(token=TELEGRAM_BOT_TOKEN)
|
|
|
|
def get_plex_last_watched():
|
|
# Implement function to get last watched date from Plex
|
|
pass
|
|
|
|
def disable_series_in_sonarr(series_id):
|
|
url = f"{SONARR_API_URL}/series/{series_id}"
|
|
headers = {'X-Api-Key': SONARR_API_KEY}
|
|
data = {'monitored': False}
|
|
response = requests.put(url, json=data, headers=headers)
|
|
return response.status_code == 200
|
|
|
|
def disable_movie_in_radarr(movie_id):
|
|
url = f"{RADARR_API_URL}/movie/{movie_id}"
|
|
headers = {'X-Api-Key': RADARR_API_KEY}
|
|
data = {'monitored': False}
|
|
response = requests.put(url, json=data, headers=headers)
|
|
return response.status_code == 200
|
|
|
|
def list_non_hd_movies():
|
|
# Implement function to list non-HD movies from Radarr
|
|
pass
|
|
|
|
def send_telegram_message(message):
|
|
bot.send_message(chat_id=TELEGRAM_CHAT_ID, text=message, parse_mode=telegram.ParseMode.MARKDOWN)
|
|
|
|
def process_series():
|
|
# Get all series from Sonarr
|
|
response = requests.get(f"{SONARR_API_URL}/series", headers={'X-Api-Key': SONARR_API_KEY})
|
|
series_list = response.json()
|
|
|
|
processed_series = []
|
|
for series in series_list:
|
|
if series['title'] in EXCEPTION_SERIES:
|
|
continue
|
|
last_watched = get_plex_last_watched(series['title'])
|
|
if last_watched and (datetime.datetime.now() - last_watched).days > 90:
|
|
if disable_series_in_sonarr(series['id']):
|
|
processed_series.append(series['title'])
|
|
|
|
return processed_series
|
|
|
|
def process_movies():
|
|
# Get all movies from Radarr
|
|
response = requests.get(f"{RADARR_API_URL}/movie", headers={'X-Api-Key': RADARR_API_KEY})
|
|
movie_list = response.json()
|
|
|
|
processed_movies = []
|
|
for movie in movie_list:
|
|
if get_plex_last_watched(movie['title']):
|
|
if disable_movie_in_radarr(movie['id']):
|
|
processed_movies.append(movie['title'])
|
|
|
|
return processed_movies
|
|
|
|
def main():
|
|
# Process series and movies
|
|
processed_series = process_series()
|
|
processed_movies = process_movies()
|
|
|
|
# List non-HD movies
|
|
non_hd_movies = list_non_hd_movies()
|
|
|
|
# Send Telegram message
|
|
message = "*Processed TV Series and Movies*\n\n"
|
|
message += "*TV Series:*\n"
|
|
for i, series in enumerate(processed_series, 1):
|
|
message += f"{i}. {series}\n"
|
|
message += "\n*Movies:*\n"
|
|
for i, movie in enumerate(processed_movies, 1):
|
|
message += f"{i}. {movie}\n"
|
|
message += "\n*Non-HD Movies:*\n"
|
|
for movie in non_hd_movies:
|
|
message += f"- {movie}\n"
|
|
|
|
send_telegram_message(message)
|
|
|
|
if __name__ == "__main__":
|
|
main() |