Merge pull request #52 from daghaian/feature-rating

Feature: Add RT (Rotten Tomatoes) Rating Threshold When Adding Movies Through CLI/Automatic
pull/57/head
desimaniac 6 years ago committed by GitHub
commit c94f3e5742
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -218,7 +218,8 @@ You can repeat this process for as many users as you like.
"blacklisted_max_year": 2019,
"blacklisted_min_runtime": 60,
"blacklisted_min_year": 2000,
"blacklisted_tmdb_ids": []
"blacklisted_tmdb_ids": [],
"rating_limit": ""
},
"shows": {
"disabled_for": [],
@ -291,6 +292,9 @@ You can repeat this process for as many users as you like.
"trakt": {
"client_id": "",
"client_secret": ""
},
"omdb": {
"api_key": ""
}
}
```
@ -496,7 +500,8 @@ Use filters to specify the movie/shows's country of origin or blacklist (i.e. fi
"blacklisted_max_year": 2019,
"blacklisted_min_runtime": 60,
"blacklisted_min_year": 2000,
"blacklisted_tmdb_ids": []
"blacklisted_tmdb_ids": [],
"rating_limit": ""
},
```
@ -542,6 +547,8 @@ Example:
`blacklisted_tmdb_ids` - Blacklist certain movies with their TMDB IDs.
`rating_limit` - Only add movies above this Rotten Tomatoes score.
### Shows
```json
@ -782,7 +789,16 @@ Trakt Authentication info:
`client_secret` - Fill in your Trakt Secret key (_Client Secret_)
## OMDB
OMDB Authentication info:
```json
"omdb": {
"api_key":""
}
```
`api_key` - Fill in your OMDB API key (*This is only needed if you wish to use rating filtering on adding movies from command line/automatic*)
# Usage
## Automatic (Scheduled)
@ -927,6 +943,8 @@ Options:
[default: 2.5]
-s, --sort [votes|rating|release]
Sort list to process.
-r, --rating INTEGER Only add movies above this rating according to Rotten Tomatoese Score
[default: 0]
-g, --genre TEXT Only add movies from this genre to Radarr.
-f, --folder TEXT Add movies with this root folder to Radarr.
--no-search Disable search when adding movies to Radarr.
@ -971,6 +989,10 @@ Options:
- Example: `-s release`
`-r`, `--rating` - Only add movies above this Rotten Tomatoes score.
- Example: `-r 75`
`-g`, `--genre` - Only add movies from this genre to Radarr.
- Can find a list [here](list_of_movie_genres.md).
@ -1137,6 +1159,11 @@ Options:
traktarr movies -t https://trakt.tv/users/user1/lists/private-movies-list --authenticate-user=user1
```
- Add movies, from the trending list, with a minimum rating of 80% on Rotten Tomatoes.
```
traktarr movies -t trending -r 80
```
### Shows

@ -0,0 +1,30 @@
from misc.log import logger
import json
import requests
log = logger.get_logger(__name__)
def get_rating(apikey,movie):
imdbID = movie['movie']['ids']['imdb']
if(imdbID):
log.debug("Requesting ratings from OMDB for %s (%d) | Genres: %s | Country: %s | imdbID: %s",movie['movie']['title'], movie['movie']['year'],
', '.join(movie['movie']['genres']), movie['movie']['country'].upper(),imdbID)
r = requests.get('http://www.omdbapi.com/?i=' + imdbID + '&apikey=' + apikey)
if(r.status_code == 200):
log.debug("Successfully requested ratings from OMDB for %s (%d) | Genres: %s | Country: %s | imdbID: %s",
movie['movie']['title'], movie['movie']['year'],
', '.join(movie['movie']['genres']), movie['movie']['country'].upper(), imdbID)
for source in json.loads(r.text)["Ratings"]:
if(source['Source'] == 'Rotten Tomatoes'):
log.debug("Rotten Tomatoes shows rating: %s for %s (%d) | Genres: %s | Country: %s | imdbID: %s ",source['Value'],movie['movie']['title'], movie['movie']['year'],
', '.join(movie['movie']['genres']), movie['movie']['country'].upper(),imdbID)
return int(source['Value'].split('%')[0])
else:
log.debug("Error encountered when requesting ratings from OMDB for %s (%d) | Genres: %s | Country: %s | imdbID: %s",
movie['movie']['title'], movie['movie']['year'],
', '.join(movie['movie']['genres']), movie['movie']['country'].upper(), imdbID)
else:
log.debug("Skipping %s (%d) | Genres: %s | Country: %s as it does not have an imdbID",
movie['movie']['title'], movie['movie']['year'],
', '.join(movie['movie']['genres']), movie['movie']['country'].upper())
return -1

@ -55,6 +55,9 @@ class Config(object, metaclass=Singleton):
'profile': 'HD-1080p',
'root_folder': '/movies/'
},
'omdb': {
'api_key': ''
},
'filters': {
'shows': {
'disabled_for': [],
@ -76,7 +79,8 @@ class Config(object, metaclass=Singleton):
'blacklist_title_keywords': [],
'blacklisted_tmdb_ids': [],
'allowed_countries': [],
'allowed_languages': []
'allowed_languages': [],
'rating_limit':""
}
},
'automatic': {

@ -394,6 +394,7 @@ def movie(movie_id, folder=None, no_search=False):
@click.option('--add-delay', '-d', default=2.5, help='Seconds between each add request to Radarr.', show_default=True)
@click.option('--sort', '-s', default='votes', type=click.Choice(['votes', 'rating', 'release']),
help='Sort list to process.')
@click.option('--rating','-r',default=None,type=(int),help='Set a minimum rating threshold (according to Rotten Tomatoes)')
@click.option('--genre', '-g', default=None, help='Only add movies from this genre to Radarr.')
@click.option('--folder', '-f', default=None, help='Add movies with this root folder to Radarr.')
@click.option('--actor', '-a', default=None, help='Only add movies from this actor to Radarr.')
@ -404,13 +405,14 @@ def movie(movie_id, folder=None, no_search=False):
@click.option('--ignore-blacklist', is_flag=True, help='Ignores the blacklist when running the command.')
@click.option('--remove-rejected-from-recommended', is_flag=True,
help='Removes rejected/existing movies from recommended.')
def movies(list_type, add_limit=0, add_delay=2.5, sort='votes', genre=None, folder=None, actor=None, no_search=False,
def movies(list_type, add_limit=0, add_delay=2.5, sort='votes', rating=None, genre=None, folder=None, actor=None, no_search=False,
notifications=False, authenticate_user=None, ignore_blacklist=False, remove_rejected_from_recommended=False):
from media.radarr import Radarr
from media.trakt import Trakt
from helpers import misc as misc_helper
from helpers import radarr as radarr_helper
from helpers import trakt as trakt_helper
from helpers import rating as rating_helper
added_movies = 0
@ -518,18 +520,30 @@ def movies(list_type, add_limit=0, add_delay=2.5, sort='votes', genre=None, fold
if not trakt_helper.is_movie_blacklisted(movie, cfg.filters.movies, ignore_blacklist,
callback_remove_recommended if remove_rejected_from_recommended
else None):
log.info("Adding: %s (%d) | Genres: %s | Country: %s", movie['movie']['title'], movie['movie']['year'],
', '.join(movie['movie']['genres']), movie['movie']['country'].upper())
# add movie to radarr
if radarr.add_movie(movie['movie']['ids']['tmdb'], movie['movie']['title'], movie['movie']['year'],
movie['movie']['ids']['slug'], profile_id, cfg.radarr.root_folder, not no_search):
log.info("ADDED %s (%d)", movie['movie']['title'], movie['movie']['year'])
if notifications:
callback_notify({'event': 'add_movie', 'list_type': list_type, 'movie': movie['movie']})
added_movies += 1
# Assuming the movie is not blacklisted, proceed to pull RT score if the user wishes to restrict
movieRating = None
if (rating != None and cfg['omdb']['api_key'] != ''):
movieRating = rating_helper.get_rating(cfg['omdb']['api_key'],movie)
if (movieRating == -1):
log.debug("Skipping: %s because it did not have a rating/lacked imdbID",
movie['movie']['title'])
continue
if (rating == None or movieRating >= rating):
log.info("Adding: %s (%d) | Genres: %s | Country: %s", movie['movie']['title'], movie['movie']['year'],
', '.join(movie['movie']['genres']), movie['movie']['country'].upper())
# add movie to radarr
if radarr.add_movie(movie['movie']['ids']['tmdb'], movie['movie']['title'], movie['movie']['year'],
movie['movie']['ids']['slug'], profile_id, cfg.radarr.root_folder, not no_search):
log.info("ADDED %s (%d)", movie['movie']['title'], movie['movie']['year'])
if notifications:
callback_notify({'event': 'add_movie', 'list_type': list_type, 'movie': movie['movie']})
added_movies += 1
else:
log.error("FAILED adding %s (%d)", movie['movie']['title'], movie['movie']['year'])
else:
log.error("FAILED adding %s (%d)", movie['movie']['title'], movie['movie']['year'])
log.info("SKIPPING: %s (%d) | Genres: %s | Country: %s", movie['movie']['title'],
movie['movie']['year'],
', '.join(movie['movie']['genres']), movie['movie']['country'].upper())
# stop adding movies, if added_movies >= add_limit
if add_limit and added_movies >= add_limit:
break
@ -691,7 +705,7 @@ def automatic_shows(add_delay=2.5, sort='votes', no_search=False, notifications=
return
def automatic_movies(add_delay=2.5, sort='votes', no_search=False, notifications=False, ignore_blacklist=False):
def automatic_movies(add_delay=2.5, sort='votes', no_search=False, notifications=False, ignore_blacklist=False,rating_limit=None):
from media.trakt import Trakt
total_movies_added = 0
@ -722,7 +736,7 @@ def automatic_movies(add_delay=2.5, sort='votes', no_search=False, notifications
# run movies
added_movies = movies.callback(list_type=list_type, add_limit=limit,
add_delay=add_delay, sort=sort, no_search=no_search,
notifications=notifications)
notifications=notifications,rating=rating_limit)
elif list_type.lower() == 'watchlist':
for authenticate_user, limit in value.items():
if limit <= 0:
@ -740,7 +754,7 @@ def automatic_movies(add_delay=2.5, sort='votes', no_search=False, notifications
added_movies = movies.callback(list_type=list_type, add_limit=limit,
add_delay=add_delay, sort=sort, no_search=no_search,
notifications=notifications, authenticate_user=authenticate_user,
ignore_blacklist=local_ignore_blacklist)
ignore_blacklist=local_ignore_blacklist,rating=rating_limit)
elif list_type.lower() == 'lists':
for list, v in value.items():
if isinstance(v, dict):
@ -759,7 +773,7 @@ def automatic_movies(add_delay=2.5, sort='votes', no_search=False, notifications
added_movies = movies.callback(list_type=list, add_limit=limit,
add_delay=add_delay, sort=sort, no_search=no_search,
notifications=notifications, authenticate_user=authenticate_user,
ignore_blacklist=local_ignore_blacklist)
ignore_blacklist=local_ignore_blacklist,rating=rating_limit)
if added_movies is None:
log.error("Failed adding movies from Trakt's %s list", list_type)
@ -800,7 +814,8 @@ def run(add_delay=2.5, sort='votes', no_search=False, run_now=False, no_notifica
sort,
no_search,
not no_notifications,
ignore_blacklist
ignore_blacklist,
int(cfg.filters.movies.rating_limit) if cfg.filters.movies.rating_limit != "" else None
)
if run_now:
movie_schedule.run()

Loading…
Cancel
Save