Simple Python script to set all downloaded movies to unmonitored after X days (default 30
).
Edit the APIKEY
, URL
and DAYS
to your liking. Run on a daily/weekly basis.
Simple Python script to set all downloaded movies to unmonitored after X days (default 30
).
Edit the APIKEY
, URL
and DAYS
to your liking. Run on a daily/weekly basis.
#!/usr/bin/env python3 | |
#-*- coding: utf-8 -*- | |
import json | |
import requests | |
import sys | |
import datetime | |
APIKEY='YOUR-API-KEY-HERE' | |
URL='http://localhost:7878/api' | |
DAYS='30' | |
def unmonitor_movie(id): | |
movie_url = '{}/movie/{}?APIKEY={}'.format(URL, m['id'], APIKEY) | |
try: | |
data = requests.get(movie_url) | |
except Exception as e: | |
print('⛔ Something went wrong: {}'.format(str(e))) | |
sys.exit(1) | |
if data.status_code == 200: | |
movie = data.json() | |
movie['monitored'] = False | |
else: | |
print('⛔ Failed. Response: {}'.format(str(data.json()))) | |
sys.exit(1) | |
r = requests.put(movie_url, data=json.dumps(movie)) | |
if r.status_code != 202: | |
print('⛔ Failed. Response: {}'.format(str(r.json()))) | |
sys.exit(1) | |
print('▶️ Attempting to fetch data from the API: {}'.format(URL)) | |
try: | |
data = requests.get('{}/movie/?APIKEY={}'.format(URL, APIKEY)) | |
except Exception as e: | |
print('⛔ Something wwent wrong: {}'.format(str(e))) | |
sys.exit(1) | |
if data.status_code != 200: | |
print('⛔ Failed. Response: {}'.format(mdatajson())) | |
sys.exit(1) | |
else: | |
movies = data.json() | |
for m in movies: | |
if m['downloaded'] and m['monitored']: | |
print('[{:>5}] {}'.format(m['id'], m['title'])) | |
if m['movieFile'] and m['movieFile']['dateAdded']: | |
date_added = datetime.datetime.strptime(m['movieFile']['dateAdded'], "%Y-%m-%dT%H:%M:%S.%fZ") | |
tdelta = datetime.datetime.now() - date_added | |
if tdelta.days > int(DAYS): | |
print('Downloaded {} days ago. Setting to "unmonitored"'.format(tdelta.days)) | |
unmonitor_movie(m['id']) | |
# vim: set sw=2 : |