Filters: Add support for relative years

pull/132/head
desimaniac 5 years ago
parent f0425c5837
commit b1143f2f73

@ -633,9 +633,17 @@ Use filters to specify the movie/shows's country of origin or blacklist (i.e. fi
- Has to be longer than `blacklisted_min_runtime` or else it will be ignored. - Has to be longer than `blacklisted_min_runtime` or else it will be ignored.
`blacklisted_min_year` - Blacklist release dates before specified year. `blacklisted_min_year` - Blacklist release dates before specified year. This can be a 4 digit year, `0`, or `-<number of years to go back>` format.
`blacklisted_max_year` - Blacklist release dates after specified year. - If `0`, blacklist movies that came out before the current year.
- If `-10`, blacklist movies that came out 10 years before the current year.
`blacklisted_max_year` - Blacklist release dates after specified year. This can be a 4 digit year, `0`, or `+<number of years to go forward>` format.
- If `0`, blacklist movies that are coming out after the current year.
- If `+1`, blacklist movies that are coming out after 1 year from current year.
`blacklisted_title_keywords` - Blacklist certain words in titles. `blacklisted_title_keywords` - Blacklist certain words in titles.
@ -753,9 +761,17 @@ Use filters to specify the movie/shows's country of origin or blacklist (i.e. fi
- Has to be longer than `blacklisted_min_runtime` or else it will be ignored. - Has to be longer than `blacklisted_min_runtime` or else it will be ignored.
`blacklisted_min_year` - Blacklist release dates before specified year. `blacklisted_min_year` - Blacklist release dates before specified year. This can be a 4 digit year, `0`, or `-<number of years to go back>` format.
- If `0`, blacklist shows that came out before the current year.
- If `-10`, blacklist shows that came out 10 years before the current year.
`blacklisted_max_year` - Blacklist release dates after specified year. This can be a 4 digit year, `0`, or `+<number of years to go forward>` format.
`blacklisted_max_year` - Blacklist release dates after specified year. - If `0`, blacklist shows that are coming out after the current year.
- If `+1`, blacklist shows that are coming out after 1 year from current year.
`blacklisted_title_keywords` - Blacklist certain words in titles. `blacklisted_title_keywords` - Blacklist certain words in titles.
@ -1214,6 +1230,8 @@ Options:
-s, --sort [rating|release|votes] -s, --sort [rating|release|votes]
Sort list to process. [default: votes] Sort list to process. [default: votes]
-rt, --rotten_tomatoes INTEGER Set a minimum Rotten Tomatoes score. -rt, --rotten_tomatoes INTEGER Set a minimum Rotten Tomatoes score.
-y, --year, --years TEXT Can be a specific year or a range of years to search. For
example, '2000' or '2000-2010'.
-g, --genres TEXT Only add movies from this genre to Radarr. Multiple genres are -g, --genres TEXT Only add movies from this genre to Radarr. Multiple genres are
specified as a comma-separated list. Use 'ignore' to add movies specified as a comma-separated list. Use 'ignore' to add movies
from any genre, including ones with no genre specified. from any genre, including ones with no genre specified.
@ -1275,6 +1293,10 @@ Choices are: `anticipated`, `trending`, `popular`, `boxoffice`, `watched`, `play
- Example: `-rt 75` - Example: `-rt 75`
`-y`, `--year`, `--years` - Only add movies from from a specific year or range of years.
- Examples: `-y 2010`, `--years 2010-2020`
`-g`, `--genres` - Only add movies from these genre(s) to Radarr. `-g`, `--genres` - Only add movies from these genre(s) to Radarr.
- Multiple genres are passed as comma-separated lists. The effect of this is equivalent of boolean OR. (ie. include items from any of these genres). - Multiple genres are passed as comma-separated lists. The effect of this is equivalent of boolean OR. (ie. include items from any of these genres).
@ -1347,22 +1369,21 @@ Usage: traktarr shows [OPTIONS]
Add multiple shows to Sonarr. Add multiple shows to Sonarr.
Options: Options:
-t, --list-type TEXT Trakt list to process. -t, --list-type TEXT Trakt list to process. For example, 'anticipated', 'trending',
For example, 'anticipated', 'trending',
'popular', 'person', 'watched', 'played', 'recommended', 'popular', 'person', 'watched', 'played', 'recommended',
'watchlist', or any URL to a list. [required] 'watchlist', or any URL to a list. [required]
-l, --add-limit INTEGER Limit number of shows added to Sonarr. -l, --add-limit INTEGER Limit number of shows added to Sonarr.
-d, --add-delay FLOAT Seconds between each add request to Sonarr. [default: 2.5] -d, --add-delay FLOAT Seconds between each add request to Sonarr. [default: 2.5]
-s, --sort [rating|release|votes] -s, --sort [rating|release|votes]
Sort list to process. [default: votes] Sort list to process. [default: votes]
-y, --year, --years TEXT Can be a specific year or a range of years to search. For
example, '2000' or '2000-2010'.
-g, --genres TEXT Only add shows from this genre to Sonarr. Multiple genres are -g, --genres TEXT Only add shows from this genre to Sonarr. Multiple genres are
specified as a comma-separated list. specified as a comma-separated list. Use 'ignore' to add shows
Use 'ignore' to add shows
from any genre, including ones with no genre specified. from any genre, including ones with no genre specified.
-f, --folder TEXT Add shows with this root folder to Sonarr. -f, --folder TEXT Add shows with this root folder to Sonarr.
-a, --actor TEXT Only add movies from this actor to Radarr. Only one actor can be -a, --actor TEXT Only add movies from this actor to Radarr. Only one actor can be
specified. specified. Requires the 'person' list option.
Requires the 'person' list option.
--include-non-acting-roles Include non-acting roles such as 'As Himself', 'Narrator', etc. --include-non-acting-roles Include non-acting roles such as 'As Himself', 'Narrator', etc.
Requires the 'person' list option with the 'actor' argument. Requires the 'person' list option with the 'actor' argument.
--no-search Disable search when adding shows to Sonarr. --no-search Disable search when adding shows to Sonarr.
@ -1412,6 +1433,10 @@ Choices are: `anticipated`, `trending`, `popular`, `watched`, `played`, `URL` (T
- Example: `-s release` - Example: `-s release`
`-y`, `--year`, `--years` - Only add shows from from a specific year or range of years.
- Examples: `-y 2010`, `--years 2010-2020`
`-g`, `--genres` - Only add shows from this genre(s) to Sonarr. `-g`, `--genres` - Only add shows from this genre(s) to Sonarr.
- Multiple genres are passed as comma-separated lists. The effect of this is equivalent of boolean OR. (ie. include items from any of these genres). - Multiple genres are passed as comma-separated lists. The effect of this is equivalent of boolean OR. (ie. include items from any of these genres).
@ -1493,6 +1518,12 @@ Choices are: `anticipated`, `trending`, `popular`, `watched`, `played`, `URL` (T
traktarr movies -t trending -rt 80 traktarr movies -t trending -rt 80
``` ```
- Add movies, from the trending list, from the year 2020.
```
traktarr movies -t trending -y 2020
```
- Add movies, with actor 'Keanu Reeves', limited to 10 items. - Add movies, with actor 'Keanu Reeves', limited to 10 items.
``` ```

@ -0,0 +1,55 @@
import time
import re
import operator
def years(param_years: str, config_min_year: int, config_max_year: int):
def operations(_year):
_year = str(_year)
current_year = time.localtime().tm_year
ops = {"+": operator.add, "-": operator.sub} # https://stackoverflow.com/a/1740759
if r1.match(_year):
return int(_year)
elif _year == '0':
return current_year
# add/subtract value from year
elif r3.match(_year):
_year_op = _year[0:1]
_year_value = int(_year[1:])
return ops[_year_op](current_year, _year_value)
else:
return None
r1 = re.compile('^[0-9]{4}$')
r2 = re.compile('^[0-9]{4}-[0-9]{4}$')
r3 = re.compile('^[+|-][0-9]+$')
# return param_years if it is in proper format
if param_years:
if r1.match(param_years):
return str(param_years), int(param_years), int(param_years)
elif r2.match(param_years):
return str(param_years), int(param_years.split('-')[0]), int(param_years.split('-')[1])
if config_min_year is not None:
new_min_year = operations(config_min_year)
else:
new_min_year = None
if config_max_year is not None:
new_max_year = operations(config_max_year)
else:
new_max_year = None
if new_min_year and new_max_year:
new_years = str(new_min_year) + '-' + str(new_max_year)
elif new_min_year:
new_years = str(new_min_year)
elif new_max_year:
new_years = str(new_max_year)
else:
new_years = None
return new_years, new_min_year, new_max_year

@ -3,7 +3,6 @@ import os.path
import signal import signal
import sys import sys
import time import time
import re
import click import click
import schedule import schedule
@ -294,9 +293,9 @@ def show(
help='Sort list to process.', help='Sort list to process.',
show_default=True) show_default=True)
@click.option( @click.option(
'--years', '-y', '--year', '--years', '-y',
default=None, default=None,
help='Range of years to search. For example, \'2000-2010\'.') help='Can be a specific year or a range of years to search. For example, \'2000\' or \'2000-2010\'.')
@click.option( @click.option(
'--genres', '-g', '--genres', '-g',
default=None, default=None,
@ -362,6 +361,7 @@ def shows(
from helpers import sonarr as sonarr_helper from helpers import sonarr as sonarr_helper
from helpers import trakt as trakt_helper from helpers import trakt as trakt_helper
from helpers import tvdb as tvdb_helper from helpers import tvdb as tvdb_helper
from helpers import parameter as parameter_helper
added_shows = 0 added_shows = 0
@ -392,16 +392,15 @@ def shows(
misc_helper.unblacklist_genres(genres, cfg['filters']['shows']['blacklisted_genres']) misc_helper.unblacklist_genres(genres, cfg['filters']['shows']['blacklisted_genres'])
log.debug("Filter Trakt results with genre(s): %s", ', '.join(map(lambda x: x.title(), genres))) log.debug("Filter Trakt results with genre(s): %s", ', '.join(map(lambda x: x.title(), genres)))
# set years range # process years parameter
r = re.compile('[0-9]{4}-[0-9]{4}') years, new_min_year, new_max_year = parameter_helper.years(
years,
cfg.filters.shows.blacklisted_min_year,
cfg.filters.shows.blacklisted_max_year,
)
if years and r.match(years): cfg['filters']['shows']['blacklisted_min_year'] = new_min_year
cfg['filters']['shows']['blacklisted_min_year'] = int(years.split('-')[0]) cfg['filters']['shows']['blacklisted_max_year'] = new_max_year
cfg['filters']['shows']['blacklisted_max_year'] = int(years.split('-')[1])
elif cfg.filters.shows.blacklisted_min_year and cfg.filters.shows.blacklisted_max_year:
years = str(cfg.filters.shows.blacklisted_min_year) + '-' + str(cfg.filters.shows.blacklisted_max_year)
else:
years = None
# runtimes range # runtimes range
if cfg.filters.shows.blacklisted_min_runtime: if cfg.filters.shows.blacklisted_min_runtime:
@ -801,9 +800,9 @@ def movie(
type=int, type=int,
help='Set a minimum Rotten Tomatoes score.') help='Set a minimum Rotten Tomatoes score.')
@click.option( @click.option(
'--years', '-y', '--year', '--years', '-y',
default=None, default=None,
help='Range of years to search. For example, \'2000-2010\'.') help='Can be a specific year or a range of years to search. For example, \'2000\' or \'2000-2010\'.')
@click.option( @click.option(
'--genres', '-g', '--genres', '-g',
default=None, default=None,
@ -875,6 +874,7 @@ def movies(
from helpers import trakt as trakt_helper from helpers import trakt as trakt_helper
from helpers import omdb as omdb_helper from helpers import omdb as omdb_helper
from helpers import tmdb as tmdb_helper from helpers import tmdb as tmdb_helper
from helpers import parameter as parameter_helper
added_movies = 0 added_movies = 0
@ -906,16 +906,15 @@ def movies(
misc_helper.unblacklist_genres(genres, cfg['filters']['movies']['blacklisted_genres']) misc_helper.unblacklist_genres(genres, cfg['filters']['movies']['blacklisted_genres'])
log.debug("Filter Trakt results with genre(s): %s", ', '.join(map(lambda x: x.title(), genres))) log.debug("Filter Trakt results with genre(s): %s", ', '.join(map(lambda x: x.title(), genres)))
# set years range # process years parameter
r = re.compile('[0-9]{4}-[0-9]{4}') years, new_min_year, new_max_year = parameter_helper.years(
years,
cfg.filters.movies.blacklisted_min_year,
cfg.filters.movies.blacklisted_max_year,
)
if years and r.match(years): cfg['filters']['movies']['blacklisted_min_year'] = new_min_year
cfg['filters']['movies']['blacklisted_min_year'] = int(years.split('-')[0]) cfg['filters']['movies']['blacklisted_max_year'] = new_max_year
cfg['filters']['movies']['blacklisted_max_year'] = int(years.split('-')[1])
elif cfg.filters.movies.blacklisted_min_year and cfg.filters.movies.blacklisted_max_year:
years = str(cfg.filters.movies.blacklisted_min_year) + '-' + str(cfg.filters.movies.blacklisted_max_year)
else:
years = None
# runtimes range # runtimes range
if cfg.filters.movies.blacklisted_min_runtime: if cfg.filters.movies.blacklisted_min_runtime:

Loading…
Cancel
Save