mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-25 10:16:11 +00:00
Fix read timeout
This commit is contained in:
parent
2fa16ddffb
commit
d037092701
1 changed files with 44 additions and 24 deletions
|
@ -50,7 +50,23 @@ def _http(action, url, request={}):
|
||||||
#request.update({'type': action, 'url': url})
|
#request.update({'type': action, 'url': url})
|
||||||
#return HTTP.request_url(request)
|
#return HTTP.request_url(request)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
|
||||||
|
try:
|
||||||
return do.downloadUrl(url, action_type=action, parameters=request['params'])
|
return do.downloadUrl(url, action_type=action, parameters=request['params'])
|
||||||
|
except downloadutils.HTTPException as error:
|
||||||
|
|
||||||
|
if error.status is None:
|
||||||
|
while True:
|
||||||
|
|
||||||
|
if xbmc.Monitor().waitForAbort(15):
|
||||||
|
raise
|
||||||
|
|
||||||
|
if window('emby_online') == "true":
|
||||||
|
log.info("Retrying http query...")
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
||||||
def _get(handler, params=None):
|
def _get(handler, params=None):
|
||||||
return _http("GET", get_embyserver_url(handler), {'params': params})
|
return _http("GET", get_embyserver_url(handler), {'params': params})
|
||||||
|
@ -122,6 +138,7 @@ def get_seasons(self, show_id):
|
||||||
def get_all(generator):
|
def get_all(generator):
|
||||||
|
|
||||||
items = []
|
items = []
|
||||||
|
|
||||||
for item in generator:
|
for item in generator:
|
||||||
items.extend(item['Items'])
|
items.extend(item['Items'])
|
||||||
|
|
||||||
|
@ -148,7 +165,8 @@ def get_items(parent_id, item_type=None, basic=False, params=None):
|
||||||
|
|
||||||
def get_item_list(item_list, basic=False):
|
def get_item_list(item_list, basic=False):
|
||||||
|
|
||||||
for item_ids in _split_list(item_list, limit):
|
for item_ids in _split_list(item_list[:], limit):
|
||||||
|
|
||||||
query = {
|
query = {
|
||||||
'url': "Users/{UserId}/Items",
|
'url': "Users/{UserId}/Items",
|
||||||
'params': {
|
'params': {
|
||||||
|
@ -156,6 +174,7 @@ def get_item_list(item_list, basic=False):
|
||||||
'Fields': basic_info() if basic else complete_info()
|
'Fields': basic_info() if basic else complete_info()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for items in _get_items(query):
|
for items in _get_items(query):
|
||||||
yield items
|
yield items
|
||||||
|
|
||||||
|
@ -204,6 +223,17 @@ def _split_list(item_list, size):
|
||||||
# Split up list in pieces of size. Will generate a list of lists
|
# Split up list in pieces of size. Will generate a list of lists
|
||||||
return [item_list[i:i + size] for i in range(0, len(item_list), size)]
|
return [item_list[i:i + size] for i in range(0, len(item_list), size)]
|
||||||
|
|
||||||
|
def _test_params(url, params):
|
||||||
|
|
||||||
|
params['Limit'] = 1
|
||||||
|
params['EnableTotalRecordCount'] = True
|
||||||
|
|
||||||
|
try:
|
||||||
|
return _get(url, params)
|
||||||
|
|
||||||
|
except Exception as error:
|
||||||
|
raise
|
||||||
|
|
||||||
def _get_items(query):
|
def _get_items(query):
|
||||||
|
|
||||||
''' query = {
|
''' query = {
|
||||||
|
@ -228,17 +258,8 @@ def _get_items(query):
|
||||||
'Recursive': True
|
'Recursive': True
|
||||||
})
|
})
|
||||||
|
|
||||||
try:
|
items['TotalRecordCount'] = _test_params(url, dict(params))['TotalRecordCount']
|
||||||
test_params = dict(params)
|
|
||||||
test_params['Limit'] = 1
|
|
||||||
test_params['EnableTotalRecordCount'] = True
|
|
||||||
|
|
||||||
items['TotalRecordCount'] = _get(url, test_params)['TotalRecordCount']
|
|
||||||
|
|
||||||
except Exception as error:
|
|
||||||
log.error("Failed to retrieve the server response %s: %s params:%s", url, error, params)
|
|
||||||
|
|
||||||
else:
|
|
||||||
index = params.get('StartIndex', 0)
|
index = params.get('StartIndex', 0)
|
||||||
total = items['TotalRecordCount']
|
total = items['TotalRecordCount']
|
||||||
|
|
||||||
|
@ -246,7 +267,7 @@ def _get_items(query):
|
||||||
|
|
||||||
params['StartIndex'] = index
|
params['StartIndex'] = index
|
||||||
params['Limit'] = limit
|
params['Limit'] = limit
|
||||||
result = _get(url, params)
|
result = _get(url, params) # Could raise an HTTP error.
|
||||||
|
|
||||||
items['Items'].extend(result['Items'])
|
items['Items'].extend(result['Items'])
|
||||||
items['RestorePoint'] = query
|
items['RestorePoint'] = query
|
||||||
|
@ -254,4 +275,3 @@ def _get_items(query):
|
||||||
|
|
||||||
del items['Items'][:]
|
del items['Items'][:]
|
||||||
index += limit
|
index += limit
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue