diff --git a/plexpy/datatables.py b/plexpy/datatables.py index 0cc94760..49dedacc 100644 --- a/plexpy/datatables.py +++ b/plexpy/datatables.py @@ -144,14 +144,17 @@ def build_custom_where(custom_where=[]): and_or = ' OR ' if w[0].endswith('OR') else ' AND ' w[0] = w[0].rstrip(' OR') - if isinstance(w[1], (list, tuple)) and len(w[1]): + if w[0].endswith(' IN') and isinstance(w[1], (list, tuple)) and len(w[1]): + c_where += w[0] + '(' + ','.join(['?'] * len(w[1])) + ')' + and_or + args += w[1] + elif isinstance(w[1], (list, tuple)) and len(w[1]): c_where += '(' for w_ in w[1]: if w_ is None: c_where += w[0] + ' IS NULL' - elif str(w_).startswith('LIKE '): - c_where += w[0] + ' LIKE ?' - args.append(w_[5:]) + elif w[0].endswith(' LIKE'): + c_where += w[0] + ' ?' + args.append(w_) elif w[0].endswith('<') or w[0].endswith('>'): c_where += w[0] + '= ?' args.append(w_) @@ -163,9 +166,9 @@ def build_custom_where(custom_where=[]): else: if w[1] is None: c_where += w[0] + ' IS NULL' - elif str(w[1]).startswith('LIKE '): - c_where += w[0] + ' LIKE ?' - args.append(w[1][5:]) + elif w[0].endswith(' LIKE'): + c_where += w[0] + ' ?' + args.append(w[1]) elif w[0].endswith('<') or w[0].endswith('>'): c_where += w[0] + '= ?' args.append(w[1]) diff --git a/plexpy/webserve.py b/plexpy/webserve.py index 3f8890cc..c402092f 100644 --- a/plexpy/webserve.py +++ b/plexpy/webserve.py @@ -1978,9 +1978,9 @@ class WebInterface(object): pms_connect = pmsconnect.PmsConnect() result = pms_connect.get_item_children(rating_key=kwargs.pop('rating_key'), media_type=kwargs.pop('media_type')) rating_keys = [child['rating_key'] for child in result['children_list']] - custom_where.append(['session_history_metadata.rating_key OR', rating_keys]) - custom_where.append(['session_history_metadata.parent_rating_key OR', rating_keys]) - custom_where.append(['session_history_metadata.grandparent_rating_key OR', rating_keys]) + custom_where.append(['session_history_metadata.rating_key IN OR', rating_keys]) + custom_where.append(['session_history_metadata.parent_rating_key IN OR', rating_keys]) + custom_where.append(['session_history_metadata.grandparent_rating_key IN OR', rating_keys]) else: rating_key = helpers.split_strip(kwargs.pop('rating_key', '')) if rating_key: @@ -2024,7 +2024,7 @@ class WebInterface(object): if 'guid' in kwargs: guid = helpers.split_strip(kwargs.pop('guid', '').split('?')[0]) if guid: - custom_where.append(['session_history_metadata.guid', ['LIKE ' + g + '%' for g in guid]]) + custom_where.append(['session_history_metadata.guid LIKE', [f"{g}%" for g in guid]]) data_factory = datafactory.DataFactory() history = data_factory.get_datatables_history(kwargs=kwargs, custom_where=custom_where,