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 1 commit
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
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,11 @@ You can create a collection based on the Plex search feature using the `plex_sea
- `actor` (Gets every movie with the specified actor) (Movie libraries only)
- `tmdb_actor` (Gets every movie with the specified actor as well as the added TMDb [metadata](#tmdb-people-list-type)) (Movie libraries only)
- `country` (Gets every movie with the specified country) (Movie libraries only)
- `decade` (Gets every movie from the specified year + the 9 that follow i.e. 1990 will get you 1990-1999) (Movie libraries only)
- `director` (Gets every movie with the specified director) (Movie libraries only)
- `tmdb_director` (Gets every movie with the specified director as well as the added TMDb [metadata](#tmdb-people-list-type)) (Movie libraries only)
- `genre` (Gets every movie/show with the specified genre)
- `studio` (Gets every movie/show with the specified studio)
- `year` (Gets every movie/show with the specified year)
- `year` (Gets every movie/show with the specified year) (Put a `-` between two years for a range i.e. `year: 1990-1999` or end with `NOW` to go till current i.e. `year: 2000-NOW`)
Copy link
Owner

Choose a reason for hiding this comment

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

Can we keep undocumented support for decade?

Copy link
Author

Choose a reason for hiding this comment

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

well i took out decade in favor of the year range i added just do year: 1990-1999 i can add it back in if needed but i figured the range would be less confusing and not bog down the user with another option plus the range isn't limited to 10 years either

Copy link
Author

Choose a reason for hiding this comment

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

Did you want me to add decade back or is year range ok?

Copy link
Owner

Choose a reason for hiding this comment

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

I prefer to keep it

Copy link
Author

Choose a reason for hiding this comment

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

ok ill add it back silently

- `writer` (Gets every movie with the specified writer) (Movie libraries only)
- `tmdb_writer` (Gets every movie with the specified writer as well as the added TMDb [metadata](#tmdb-people-list-type)) (Movie libraries only)

Expand Down Expand Up @@ -223,15 +222,21 @@ collections:
collections:
90s Movies:
plex_search:
decade: 1990
year: 1990-1999
```
```yaml
collections:
2010+ Movies:
plex_search:
year: 2010-NOW
```

Note if you only want to search using a single attribute you can do so without `plex_search`.

```yaml
collections:
90s Movies:
decade: 1990
year: 1990-1999
```

Notes:
Expand Down
63 changes: 46 additions & 17 deletions app/plex_auto_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys
import threading
import glob
import datetime
from plexapi.server import PlexServer
from plexapi.video import Movie
from plexapi.video import Show
Expand Down Expand Up @@ -58,16 +59,46 @@ def get_method_pair_int(method_to_parse, values_to_parse, id_type):
return (method_to_parse, get_int_attribute_list(method_to_parse, values_to_parse, id_type))

def get_method_pair_tmdb(method_to_parse, values_to_parse, id_type):
ids = get_int_attribute_list(method_to_parse, values_to_parse, id_type)
values = get_attribute_list(values_to_parse)
new_ids = []
for id in ids:
for v in values:
try:
id = regex_first_int(v, method_to_parse, id_type)
tmdb_get_metadata(config_path, id, "overview")
new_ids.append(id)
except ValueError as e:
print(e)
return (method_to_parse, new_ids)


def get_method_pair_year(method_to_parse, values_to_parse):
years = get_attribute_list(values_to_parse)
final_years = []
current_year = datetime.datetime.now().year
for year in years:
try:
year_range = re.search('(\\d{4})-(\\d{4}|NOW)', str(year))
start = year_range.group(1)
end = year_range.group(2)
if end == "NOW":
end = current_year
if int(start) < 1800 or int(start) > current_year:
print("| Config Error: Skipping {} starting year {} must be between 1800 and {}".format(method_to_parse, start, current_year))
elif int(end) < 1800 or int(end) > current_year:
print("| Config Error: Skipping {} ending year {} must be between 1800 and {}".format(method_to_parse, end, current_year))
elif int(start) > int(end):
print("| Config Error: Skipping {} starting year {} cannot be greater then ending year {}".format(method_to_parse, start, end))
else:
for i in range(int(start), int(end) + 1):
final_years.append(i)
except AttributeError:
try:
id = re.search('(\\d+)', str(year)).group(1)
if len(str(id)) != len(str(year)):
print("| Config Warning: {} can be replaced with {}".format(year, id))
final_years.append(id)
except AttributeError:
print("| Config Error: Skipping {} failed to parse year from {}".format(method_to_parse, year))
return (method_to_parse, final_years)


def update_from_config(config_path, plex, headless=False, no_meta=False, no_images=False):
Expand All @@ -83,7 +114,6 @@ def update_from_config(config_path, plex, headless=False, no_meta=False, no_imag
"actors": "actor", "role": "actor", "roles": "actor",
"content_ratings": "content_rating", "contentRating": "content_rating", "contentRatings": "content_rating",
"countries": "country",
"decades": "decade",
"directors": "director",
"genres": "genre",
"studios": "studio", "network": "studio", "networks": "studio",
Expand Down Expand Up @@ -118,7 +148,6 @@ def update_from_config(config_path, plex, headless=False, no_meta=False, no_imag
plex_searches = [
"actor", #"actor.not", # Waiting on PlexAPI to fix issue
"country", #"country.not",
"decade", #"decade.not",
"director", #"director.not",
"genre", #"genre.not",
"studio", #"studio.not",
Expand All @@ -142,7 +171,6 @@ def update_from_config(config_path, plex, headless=False, no_meta=False, no_imag
movie_only_searches = [
"actor", #"actor.not", # Waiting on PlexAPI to fix issue
"country", #"country.not",
"decade", #"decade.not",
"director", #"director.not",
"writer", #"writer.not",
"tmdb_actor", "tmdb_director", "tmdb_writer"
Expand Down Expand Up @@ -325,21 +353,23 @@ def check_details(check_name, check_value):
print("| Config Error: {} plex search attribute only works for movie libraries".format(final_attr))
elif (final_attr[:-4] if final_attr.endswith(".not") else final_attr) in searches_used:
print("| Config Error: Only one instance of {} can be used try using it as a filter instead".format(final_attr))
elif final_attr in ["decade", "decade.not", "year", "year.not"]:
searches_used.append(final_attr[:-4] if final_attr.endswith(".not") else final_attr)
search.append(get_method_pair_int(final_attr, collections[c][m][search_attr], final_attr[:-4] if final_attr.endswith(".not") else final_attr))
elif final_attr in ["year", "year.not"]:
year_pair = get_method_pair_year(final_attr, collections[c][m][search_attr])
if len(year_pair[1]) > 0:
searches_used.append(final_attr[:-4] if final_attr.endswith(".not") else final_attr)
search.append(get_method_pair_int(final_attr, collections[c][m][search_attr], final_attr[:-4] if final_attr.endswith(".not") else final_attr))
elif final_attr in plex_searches:
if final_attr.startswith("tmdb_"):
final_attr = final_attr[5:]
searches_used.append(final_attr[:-4] if final_attr.endswith(".not") else final_attr)
search.append((final_attr, get_attribute_list(collections[c][m][search_attr])))
else:
print("| Config Error: {} plex search attribute not supported".format(search_attr))
methods.append((method_name, search))
methods.append((method_name, [search]))
elif method_name in movie_only_searches and libtype == "show":
print("| Config Error: {} plex search only works for movie libraries".format(method_name))
elif method_name in ["decade", "decade.not", "year", "year.not"]:
methods.append(("plex_search", [get_method_pair_int(method_name, collections[c][m], method_name[:-4] if method_name.endswith(".not") else method_name)]))
elif method_name in ["year", "year.not"]:
methods.append(("plex_search", [[get_method_pair_year(method_name, collections[c][m])]]))
elif method_name in ["tmdb_actor", "tmdb_director", "tmdb_writer"]:
ids = get_int_attribute_list(method_name, collections[c][m], "TMDb Person ID")
new_ids = []
Expand All @@ -359,7 +389,7 @@ def check_details(check_name, check_value):
print(e)
methods.append(("plex_search", [(method_name[5:], new_ids)]))
elif method_name in plex_searches:
methods.append(("plex_search", [(method_name, get_attribute_list(collections[c][m]))]))
methods.append(("plex_search", [[(method_name, get_attribute_list(collections[c][m]))]]))
elif method_name == "tmdb_collection":
methods.append(get_method_pair_tmdb(method_name, collections[c][m], "TMDb Collection ID"))
elif method_name == "tmdb_id":
Expand Down Expand Up @@ -399,17 +429,17 @@ def check_details(check_name, check_value):
print("| Config Error: {} attribute not supported".format(method_name))
else:
print("| Config Error: {} attribute is blank".format(m))
print("| ")

#TODO: Display Filters Better
for filter in filters:
print("| Collection Filter {}: {}".format(filter[0], filter[1]))
print("| ")

# Loops though and actually processes the methods
for m, values in methods:
for v in values:
if method_name == "plex_search":
print("| \n| Processing {}:".format(m))
else:
if m != "plex_search":
print("| \n| Processing {}: {}".format(m, v))
try:
missing, map = add_to_collection(config_path, plex, m, v, c, map, filters)
Expand Down Expand Up @@ -784,7 +814,6 @@ def append_collection(config_path, config_update=None):
update_from_config(config_path, plex, True, args.no_meta, args.no_images)
sys.exit(0)


config = Config(config_path)
plex = Plex(config_path)

Expand Down
2 changes: 1 addition & 1 deletion app/plex_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def search_plex():
ors = ""
for param in attr_pair[1]:
ors = ors + (" OR " if len(ors) > 0 else attr_pair[0] + "(") + str(param)
output = output + ("\n|\tAND " if len(output) > 0 else "|\t ") + ors + ")"
output = output + ("\n|\t\t AND " if len(output) > 0 else "| Processing Plex Search: ") + ors + ")"
print(output)
return plex.Library.search(**search_terms)

Expand Down