Add searching for episodes with multiple filters or searches
This commit is contained in:
parent
672a2abaf4
commit
8edde2242f
@ -274,13 +274,14 @@ def sort_by_dates(video, date_type):
|
|||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def multi_filter_search(keyword_dict, library):
|
def multi_filter_search(keyword_dict, library, search_eps=None):
|
||||||
"""Allowing for multiple filter or search values
|
"""Allowing for multiple filter or search values
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
keyword_dict: dict
|
keyword_dict: dict
|
||||||
library: class
|
library: class
|
||||||
|
search_eps: bool
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
@ -288,6 +289,9 @@ def multi_filter_search(keyword_dict, library):
|
|||||||
items that include all searched or filtered values
|
items that include all searched or filtered values
|
||||||
"""
|
"""
|
||||||
multi_lst = []
|
multi_lst = []
|
||||||
|
ep_lst = []
|
||||||
|
logs = {}
|
||||||
|
ep_logs = []
|
||||||
# How many keywords
|
# How many keywords
|
||||||
keyword_count = len(keyword_dict)
|
keyword_count = len(keyword_dict)
|
||||||
for key, values in keyword_dict.items():
|
for key, values in keyword_dict.items():
|
||||||
@ -296,13 +300,30 @@ def multi_filter_search(keyword_dict, library):
|
|||||||
for value in values:
|
for value in values:
|
||||||
search_dict = {}
|
search_dict = {}
|
||||||
search_dict[key] = value
|
search_dict[key] = value
|
||||||
|
if search_eps:
|
||||||
|
logs["data"] = [{key: value}]
|
||||||
|
for show in library.all():
|
||||||
|
for episode in show.episodes(**search_dict):
|
||||||
|
ep_lst += [episode.ratingKey]
|
||||||
|
ep_logs += [episode.title, episode.summary]
|
||||||
|
|
||||||
|
logs["data"].append({"keys": ep_lst, "info": ep_logs})
|
||||||
|
search_lst = ep_lst
|
||||||
|
else:
|
||||||
search_lst = [item.ratingKey for item in library.all(**search_dict)]
|
search_lst = [item.ratingKey for item in library.all(**search_dict)]
|
||||||
multi_lst += search_lst
|
multi_lst += search_lst
|
||||||
|
else:
|
||||||
|
if search_eps:
|
||||||
|
for show in library.all():
|
||||||
|
for episode in show.episodes(**{key: values}):
|
||||||
|
ep_lst += [episode.ratingKey]
|
||||||
|
multi_lst += ep_lst
|
||||||
|
|
||||||
else:
|
else:
|
||||||
multi_lst += [item.ratingKey for item in library.all(**{key: values})]
|
multi_lst += [item.ratingKey for item in library.all(**{key: values})]
|
||||||
counts = Counter(multi_lst)
|
counts = Counter(multi_lst)
|
||||||
# Use amount of keywords to check that all keywords were found in results
|
# Use amount of keywords to check that all keywords were found in results
|
||||||
search_lst = [id for id in multi_lst if counts[id] == keyword_count]
|
search_lst = [id for id in multi_lst if counts[id] >= keyword_count]
|
||||||
|
|
||||||
return list(set(search_lst))
|
return list(set(search_lst))
|
||||||
|
|
||||||
@ -361,9 +382,7 @@ def get_content(libraries, jbop, filters=None, search=None, limit=None):
|
|||||||
elif library_type == 'show':
|
elif library_type == 'show':
|
||||||
# Decisions to stack filter and search
|
# Decisions to stack filter and search
|
||||||
if keywords:
|
if keywords:
|
||||||
for show in plex_library.all():
|
search_lst = multi_filter_search(keywords, plex_library, search_eps=True)
|
||||||
for episode in show.episodes(**keywords):
|
|
||||||
search_lst += [episode.ratingKey]
|
|
||||||
child_lst += search_lst
|
child_lst += search_lst
|
||||||
if filters:
|
if filters:
|
||||||
# Update filters for tagged filtered keys
|
# Update filters for tagged filtered keys
|
||||||
|
Loading…
Reference in New Issue
Block a user