From 5479ba2775d7c151bd36870540e75d0030ddf594 Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 22 Feb 2020 23:23:14 -0500 Subject: [PATCH 1/2] Make commands python 2/3 compatible --- jellyfin_kodi/downloader.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/jellyfin_kodi/downloader.py b/jellyfin_kodi/downloader.py index 3b734deb..02ca60bb 100644 --- a/jellyfin_kodi/downloader.py +++ b/jellyfin_kodi/downloader.py @@ -15,6 +15,14 @@ from jellyfin import Jellyfin from jellyfin import api from jellyfin.exceptions import HTTPException +# Python 2/3 Compatible things +import sys +if sys.version.startswith('3'): + xrange = range + izip = zip +else: + from itertools import izip + ################################################################################################# LOG = logging.getLogger("JELLYFIN." + __name__) @@ -269,7 +277,6 @@ def _get_items(query, server_id=None): query_params = [get_query_params(params, offset, LIMIT) \ for offset in xrange(params['StartIndex'], items['TotalRecordCount'], LIMIT)] - from itertools import izip # multiprocessing.dummy.Pool completes all requests in multiple threads but has to # 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 From 19ec48cd5bdc379bd30a7ad793722c22a4f6d926 Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 23 Feb 2020 00:07:44 -0500 Subject: [PATCH 2/2] Use six library instead of checking sys version --- jellyfin_kodi/downloader.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/jellyfin_kodi/downloader.py b/jellyfin_kodi/downloader.py index 02ca60bb..fc3a1125 100644 --- a/jellyfin_kodi/downloader.py +++ b/jellyfin_kodi/downloader.py @@ -6,7 +6,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera import logging import threading -from six.moves import queue as Queue +from six.moves import range, queue as Queue, zip from kodi_six import xbmc import requests @@ -15,14 +15,6 @@ from jellyfin import Jellyfin from jellyfin import api from jellyfin.exceptions import HTTPException -# Python 2/3 Compatible things -import sys -if sys.version.startswith('3'): - xrange = range - izip = zip -else: - from itertools import izip - ################################################################################################# LOG = logging.getLogger("JELLYFIN." + __name__) @@ -275,9 +267,9 @@ def _get_items(query, server_id=None): return params_copy query_params = [get_query_params(params, offset, LIMIT) \ - for offset in xrange(params['StartIndex'], items['TotalRecordCount'], LIMIT)] + for offset in range(params['StartIndex'], items['TotalRecordCount'], LIMIT)] - # multiprocessing.dummy.Pool completes all requests in multiple threads but has to + # multiprocessing.dummy.Pool completes all requests in multiple threads but has to # 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 @@ -286,7 +278,7 @@ def _get_items(query, server_id=None): results = p.map(lambda params: _get(url, params, server_id=server_id), query_params) - for params, result in izip(query_params, results): + for params, result in zip(query_params, results): query['params'] = params result = result or {'Items': []}