Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.4.0 Filter/Subfilter Overall, tmdb_director, and tmdb_writer #76

Merged
merged 36 commits into from
Nov 4, 2020
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
656bde3
Merge pull request #5 from mza921/master
meisnate12 Oct 27, 2020
d206f7b
Bump pyyaml from 5.1.2 to 5.3.1
dependabot[bot] Oct 27, 2020
cf43b95
Merge pull request #7 from mza921/master
meisnate12 Oct 28, 2020
1faee56
Merge pull request #6 from meisnate12/dependabot/pip/pyyaml-5.3.1
meisnate12 Oct 28, 2020
cc8e0d5
added method to detail
meisnate12 Oct 28, 2020
7ed0018
combined methods
meisnate12 Oct 28, 2020
51496a7
update trakt_tools
meisnate12 Oct 28, 2020
e6cb027
Merge pull request #8 from mza921/master
meisnate12 Oct 28, 2020
d7d4c68
method rename
meisnate12 Oct 29, 2020
be0a1e1
2.3.0 Revamped Filters and Subfilters
meisnate12 Oct 29, 2020
878a7c3
typo
meisnate12 Oct 29, 2020
392b12e
fixed two errors
meisnate12 Oct 29, 2020
405b6d1
added tmdb_director
meisnate12 Oct 29, 2020
0e2d05f
collection_sort -> collection_order
meisnate12 Oct 30, 2020
5f65bdb
updated CHANGELOG
meisnate12 Oct 30, 2020
9d60c0f
added tmdb_writer
meisnate12 Oct 30, 2020
7b63417
README fix
meisnate12 Oct 30, 2020
22e10a7
README edit
meisnate12 Oct 30, 2020
d79a628
days_from_now -> max_age
meisnate12 Oct 30, 2020
1c19c88
! -> .not
meisnate12 Oct 30, 2020
0827293
check methods first
meisnate12 Oct 30, 2020
47aee95
small fixes
meisnate12 Oct 30, 2020
fe62ae6
Overhaul how the program checks input and .and
meisnate12 Oct 31, 2020
425c881
bug fix
meisnate12 Oct 31, 2020
f741f34
filters->searches subfilters->collection_filters
meisnate12 Nov 1, 2020
d31f169
Bump plexapi from 4.1.2 to 4.2.0
dependabot[bot] Nov 2, 2020
208ffcf
Major Config checks created plex_search
meisnate12 Nov 3, 2020
c57b78b
Merge pull request #9 from meisnate12/dependabot/pip/plexapi-4.2.0
meisnate12 Nov 3, 2020
0b4617b
Bump plexapi from 4.1.2 to 4.2.0
meisnate12 Nov 3, 2020
24a4c7b
README edits
meisnate12 Nov 3, 2020
22ddd65
README fix
meisnate12 Nov 3, 2020
c44982a
typo
meisnate12 Nov 3, 2020
40dba4a
removed decade and fixed bug
meisnate12 Nov 3, 2020
7b14b7a
Merge remote-tracking branch 'upstream/master'
meisnate12 Nov 3, 2020
d53c3c8
decades is back
meisnate12 Nov 4, 2020
b38f082
Merge remote-tracking branch 'upstream/master'
meisnate12 Nov 4, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,22 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.3.0] - 2020-11-02
## [2.4.0] - 2020-11-03
### Added
- Added `plex_search` to AND searches together
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused about this. So if plex_search does an AND, how do I do an OR? How would this README example work:

collections:
  90s Movies:
    plex_search:
      year:
        - 1990
        - 1991
        - 1992
        - 1993
        - 1994
        - 1995
        - 1996
        - 1997
        - 1998
        - 1999

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it ANDs different attributes and ORs multiples of the same attribute I can try and clarify that in the readme. The program will also tell you exactly how it's searching so for your example it would look like this:

| Processing Plex Search: year(1990 OR 1991 OR 1992 OR 1993 OR 1994 OR 1995 OR 1996 OR 1997 OR 1998 OR 1999)

it will show each AND on the subsequent lines

if you want to AND the same attribute you have to use subfilters

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Nice addition to report the actual query.

- Added additional `filters` and allow for use of `.not` for inverse `filters`
- Added `tmdb_director` and `tmdb_writer` which function the same as `tmdb_actor` but for directors and writers
- More compatibility with previous config files.

### Changed
- `Plex Filters` are now listed and have been tested and have been changed to `Plex Searches`
- `subfilters` are now listed and have been tested and have been changed to `filters`

### Fixed
- `collection_order` was in the code as `collection_sort`
- Upgrade PlexAPI dependency to 4.2.0

## [2.3.0] - 2020-11-03
### Added
- Support for the new Plex Movie agent
- Cache database for IMDB/TMDB id lookups
Expand Down
257 changes: 200 additions & 57 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/config_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def check_for_attribute(config, attribute, parent=None, test_list=None, options=
message = message + " using {} as default".format(default)
message = message + endline
if (default is None and not default_is_none) or throw:
if len(options) > 0 and not throw:
if len(options) > 0:
message = message + "\n" + options
sys.exit(message)
if do_print:
Expand Down
68 changes: 23 additions & 45 deletions app/imdb_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def imdb_get_movies(config_path, plex, data):
tree = html.fromstring(r.content)
title_ids.extend(tree.xpath("//div[contains(@class, 'lister-item-image')]"
"//a/img//@data-tconst"))
matched_imbd_movies = []
matched_imdb_movies = []
missing_imdb_movies = []
plex_tools.create_cache(config_path)
if title_ids:
Expand Down Expand Up @@ -90,31 +90,15 @@ def imdb_get_movies(config_path, plex, data):
for imdb_id in title_ids:
movie = imdb_map.pop(imdb_id, None)
if movie:
matched_imbd_movies.append(plex.Server.fetchItem(movie.ratingKey))
matched_imdb_movies.append(plex.Server.fetchItem(movie.ratingKey))
else:
missing_imdb_movies.append(imdb_id)

return matched_imbd_movies, missing_imdb_movies

def tmdb_parse_id(data):
try:
tmdb_id = re.search('.*?(\\d+)', str(data)) # re.search requires a string
tmdb_id = tmdb_id.group(1)
return tmdb_id
except AttributeError: # Bad URL Provided
raise ValueError("| Config Error: TMDb ID: {} is invalid it must be a number".format(data))

def tvdb_parse_id(data):
try:
tvdb_id = re.search('(\\d+)', str(data)) # re.search requires a string
tvdb_id = tvdb_id.group(1)
return tvdb_id
except AttributeError:
raise ValueError("| Config Error: TVDb ID: {} is invalid it must be a number".format(data))
return matched_imdb_movies, missing_imdb_movies


def tmdb_get_movies(config_path, plex, data, is_list=False):
tmdb_id = tmdb_parse_id(data)
tmdb_id = int(data)
t_movs = []
t_movie = Movie()
t_movie.api_key = config_tools.TMDB(config_path).apikey # Set TMDb api key for Movie
Expand Down Expand Up @@ -204,14 +188,9 @@ def tmdb_get_movies(config_path, plex, data, is_list=False):

def get_tautulli(config_path, plex, data):
tautulli = config_tools.Tautulli(config_path)
list_type = config_tools.check_for_attribute(data, "list_type", parent="tautulli", test_list=["popular", "watched"], options="| \tpopular (Most Popular List)\n| \twatched (Most Watched List)", throw=True, save=False)
time_range = config_tools.check_for_attribute(data, "list_days", parent="tautulli", var_type="int", default=30, save=False)
max = config_tools.check_for_attribute(data, "list_size", parent="tautulli", var_type="int", default=10, save=False)
buffer = config_tools.check_for_attribute(data, "list_buffer", parent="tautulli", var_type="int", default=20, save=False)
stats_count = max + buffer

response = requests.get("{}/api/v2?apikey={}&cmd=get_home_stats&time_range={}&stats_count={}".format(tautulli.url, tautulli.apikey, time_range, stats_count)).json()
stat_id = ("popular" if list_type == "popular" else "top") + "_" + ("movies" if plex.library_type == "movie" else "tv")
response = requests.get("{}/api/v2?apikey={}&cmd=get_home_stats&time_range={}&stats_count={}".format(tautulli.url, tautulli.apikey, data["list_days"], int(data["list_size"]) + int(data["list_buffer"]))).json()
stat_id = ("popular" if data["list_type"] == "popular" else "top") + "_" + ("movies" if plex.library_type == "movie" else "tv")

items = None
for entry in response['response']['data']:
Expand All @@ -234,7 +213,7 @@ def get_tautulli(config_path, plex, data):
missing = []
count = 0
for item in items:
if item['section_id'] == section_id and count < max:
if item['section_id'] == section_id and count < int(data["list_size"]):
matched.append(plex.Library.fetchItem(item['rating_key']))
count = count + 1

Expand All @@ -243,18 +222,16 @@ def get_tautulli(config_path, plex, data):
def get_tvdb_id_from_tmdb_id(id):
lookup = trakt.Trakt['search'].lookup(id, 'tmdb', 'show')
if lookup:
if isinstance(lookup, list):
return trakt.Trakt['search'].lookup(id, 'tmdb', 'show')[0].get_key('tvdb')
else:
return trakt.Trakt['search'].lookup(id, 'tmdb', 'show').get_key('tvdb')
lookup = lookup[0] if isinstance(lookup, list) else lookup
return lookup.get_key('tvdb')
else:
return None

def tmdb_get_shows(config_path, plex, data, is_list=False):
config_tools.TraktClient(config_path)
tmdb_id = tmdb_parse_id(data)

tmdb_id = int(data)

t_tvs = []
t_tv = TV()
t_tv.api_key = config_tools.TMDB(config_path).apikey # Set TMDb api key for Movie
Expand Down Expand Up @@ -309,8 +286,8 @@ def tmdb_get_shows(config_path, plex, data, is_list=False):

def tvdb_get_shows(config_path, plex, data, is_list=False):
config_tools.TraktClient(config_path)
id = tvdb_parse_id(data)

id = int(data)

p_tv_map = {}
for item in plex.Library.all():
Expand Down Expand Up @@ -339,10 +316,11 @@ def tvdb_get_shows(config_path, plex, data, is_list=False):

return matched, missing

def tmdb_get_summary(config_path, data, type):
def tmdb_get_metadata(config_path, data, type):
# Instantiate TMDB objects
id = tmdb_parse_id(data)
id = int(data)

tmdb_url_prefix = "https://image.tmdb.org/t/p/original"
api_key = config_tools.TMDB(config_path).apikey
language = config_tools.TMDB(config_path).language
is_movie = config_tools.Plex(config_path).library_type == "movie"
Expand All @@ -355,9 +333,9 @@ def tmdb_get_summary(config_path, data, type):
if type == "overview":
return collection.details(id).overview
elif type == "poster_path":
return collection.details(id).poster_path
return tmdb_url_prefix + collection.details(id).poster_path
elif type == "backdrop_path":
return collection.details(id).backdrop_path
return tmdb_url_prefix + collection.details(id).backdrop_path
except AttributeError:
media = Movie() if is_movie else TV()
media.api_key = api_key
Expand All @@ -366,9 +344,9 @@ def tmdb_get_summary(config_path, data, type):
if type == "overview":
return media.details(id).overview
elif type == "poster_path":
return media.details(id).poster_path
return tmdb_url_prefix + media.details(id).poster_path
elif type == "backdrop_path":
return media.details(id).backdrop_path
return tmdb_url_prefix + media.details(id).backdrop_path
except AttributeError:
raise ValueError("| Config Error: TMBd {} ID: {} not found".format("Movie/Collection" if is_movie else "Show", id))
elif type in ["biography", "profile_path", "name"]:
Expand All @@ -379,10 +357,10 @@ def tmdb_get_summary(config_path, data, type):
if type == "biography":
return person.details(id).biography
elif type == "profile_path":
return person.details(id).profile_path
return tmdb_url_prefix + person.details(id).profile_path
elif type == "name":
return person.details(id).name
except AttributeError:
raise ValueError("| Config Error: TMBd Actor ID: {} not found".format(id))
else:
raise RuntimeError("type {} not yet supported in tmdb_get_summary".format(type))
raise RuntimeError("type {} not yet supported in tmdb_get_metadata".format(type))
Loading