From 5c93a06e9b6842797420d58982c1d4df69cd6b13 Mon Sep 17 00:00:00 2001 From: Abby Gourlay Date: Sun, 15 Mar 2020 01:27:07 +0000 Subject: [PATCH 1/3] Added mitigation for #216 for when the year data from the server is invalid --- jellyfin_kodi/downloader.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/jellyfin_kodi/downloader.py b/jellyfin_kodi/downloader.py index fc3a1125..2f034f03 100644 --- a/jellyfin_kodi/downloader.py +++ b/jellyfin_kodi/downloader.py @@ -282,6 +282,17 @@ def _get_items(query, server_id=None): query['params'] = params result = result or {'Items': []} + + # Mitigates #216 till the server validates the date provided is valid + for count in range(0, len(result["Items"])): + if result["Items"][count].get('ProductionYear'): + try: + from datetime import date + date(result["Items"][count]["ProductionYear"], 1, 1) + except ValueError: + LOG.info("#216 mitigation triggered. Setting ProductionYear to None") + result["Items"][count]["ProductionYear"] = None + items['Items'].extend(result['Items']) # Using items to return data and communicate a restore point back to the callee is # a violation of the SRP. TODO: Seperate responsibilities. From 1df9f158592c28721b3c9844e4a1096e26c75f9d Mon Sep 17 00:00:00 2001 From: Abby Gourlay Date: Wed, 18 Mar 2020 01:18:19 +0000 Subject: [PATCH 2/3] Resolved suggestions --- jellyfin_kodi/downloader.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/jellyfin_kodi/downloader.py b/jellyfin_kodi/downloader.py index 2f034f03..b6d3c3d6 100644 --- a/jellyfin_kodi/downloader.py +++ b/jellyfin_kodi/downloader.py @@ -5,6 +5,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera import logging import threading +import concurrent.futures from six.moves import range, queue as Queue, zip @@ -273,7 +274,6 @@ def _get_items(query, server_id=None): # complete all tasks before allowing any results to be processed. ThreadPoolExecutor # allows for completed tasks to be processed while other tasks are completed on other # threads. Dont be a dummy.Pool, be a ThreadPoolExecutor - import concurrent.futures p = concurrent.futures.ThreadPoolExecutor(DTHREADS) results = p.map(lambda params: _get(url, params, server_id=server_id), query_params) @@ -284,14 +284,12 @@ def _get_items(query, server_id=None): result = result or {'Items': []} # Mitigates #216 till the server validates the date provided is valid - for count in range(0, len(result["Items"])): - if result["Items"][count].get('ProductionYear'): - try: - from datetime import date - date(result["Items"][count]["ProductionYear"], 1, 1) - except ValueError: - LOG.info("#216 mitigation triggered. Setting ProductionYear to None") - result["Items"][count]["ProductionYear"] = None + if result['Items'][0].get('ProductionYear'): + try: + date(result['Items'][0]['ProductionYear'], 1, 1) + except ValueError: + LOG.info('#216 mitigation triggered. Setting ProductionYear to None') + result['Items'][0]['ProductionYear'] = None items['Items'].extend(result['Items']) # Using items to return data and communicate a restore point back to the callee is From 9cb0f637499d9a44e040bc84bdd1948f6f264016 Mon Sep 17 00:00:00 2001 From: Abby Gourlay Date: Wed, 18 Mar 2020 01:20:22 +0000 Subject: [PATCH 3/3] Left an import in the clipboard --- jellyfin_kodi/downloader.py | 1 + 1 file changed, 1 insertion(+) diff --git a/jellyfin_kodi/downloader.py b/jellyfin_kodi/downloader.py index b6d3c3d6..1efd9ddb 100644 --- a/jellyfin_kodi/downloader.py +++ b/jellyfin_kodi/downloader.py @@ -6,6 +6,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera import logging import threading import concurrent.futures +from datetime import date from six.moves import range, queue as Queue, zip