Skip to content

Commit

Permalink
v5 URL string fix
Browse files Browse the repository at this point in the history
Updates to yaml config checker
Updates to compare module
Change query filter defaults
  • Loading branch information
terrelsa13 committed Jan 2, 2024
1 parent 3002fa2 commit 41b2136
Show file tree
Hide file tree
Showing 5 changed files with 465 additions and 776 deletions.
53 changes: 28 additions & 25 deletions mumc_modules/mumc_compare_items.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,45 @@

import multiprocessing
from collections.abc import Mapping
from mumc_modules.mumc_output import appendTo_DEBUG_log


#Check if *keys (nested) exists in `element` (dict or list).
def keys_exist(the_element, *keys_indexes):
def is_instance(the_element):
if not isinstance(the_element, Mapping):
raise TypeError('keys_exist() expects a dict-like object as the first argument.')


if (not (isinstance(the_element, dict) or isinstance(the_element, multiprocessing.managers.DictProxy))):
raise AttributeError('keys_exist() expects dict as first argument.')
if len(keys_indexes) == 0:
raise AttributeError('keys_exist() expects at least two arguments, one given.')
def keys_exist(the_element, *keys_indexes):
is_instance(the_element)
if not keys_indexes:
raise ValueError('keys_exist() expects at least one key/index argument.')

temp_element = the_element
for key_index in keys_indexes:
try:
temp_element = temp_element[key_index]
except KeyError:
if key_index not in temp_element:
return False
temp_element = temp_element[key_index]
return True


#Check if *keys (nested) exists in `element` (dict or list).
def return_key_value(the_element, *keys_indexes):

if not isinstance(the_element, dict):
raise AttributeError('return_key_value() expects dict as first argument.')
if len(keys_indexes) == 0:
raise AttributeError('return_key_value() expects at least two arguments, one given.')
is_instance(the_element)
if len(keys_indexes) < 1:
raise IndexError('return_key_value() expects at least one key/index argument.')

temp_element = the_element
for key_index in keys_indexes:
try:
temp_element = temp_element[key_index]
except KeyError:
except (KeyError, IndexError):
return None
return temp_element


def keys_exist_return_value(the_element, *keys_indexes):
if (keys_exist(the_element, *keys_indexes)):
return return_key_value(the_element, *keys_indexes)
return None


#Check if json index exists
def does_index_exist(item, indexvalue, the_dict):
try:
Expand Down Expand Up @@ -70,13 +73,13 @@ def get_isItemMatching_doesItemStartWith(item_one,item_two,the_dict):
if (the_dict['DEBUG']):
appendTo_DEBUG_log('\nComparing the below two items',3,the_dict)
appendTo_DEBUG_log('\n\'' + str(single_item_one) + '\'' + ':' + '\'' + str(single_item_two) + '\'',3,the_dict)
if ((not (single_item_one == '')) and (not (single_item_two == '')) and
(not (single_item_one == "''")) and (not (single_item_two == "''")) and
(not (single_item_one == '""')) and (not (single_item_two == '""'))):
if (single_item_one == single_item_two):
#found a match; return true and the matching value
return True,single_item_one
elif (single_item_two.startswith(single_item_one)):

#if ((not (single_item_one == '')) and (not (single_item_two == '')) and
#(not (single_item_one == "''")) and (not (single_item_two == "''")) and
#(not (single_item_one == '""')) and (not (single_item_two == '""'))):
if (single_item_one and single_item_two):
if ((single_item_one == single_item_two) or
single_item_two.startswith(single_item_one)):
#found a match; return true and the matching value
return True,single_item_one

Expand Down
8 changes: 4 additions & 4 deletions mumc_modules/mumc_configuration_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,26 @@ def yaml_configurationBuilder(the_dict):

config_data['advanced_settings']['filter_statements']['movie']['query_filter']['favorited']=True
config_data['advanced_settings']['filter_statements']['movie']['query_filter']['whitetagged']=False
config_data['advanced_settings']['filter_statements']['movie']['query_filter']['blacktagged']=False
config_data['advanced_settings']['filter_statements']['movie']['query_filter']['blacktagged']=True
config_data['advanced_settings']['filter_statements']['movie']['query_filter']['whitelisted']=False
config_data['advanced_settings']['filter_statements']['movie']['query_filter']['blacklisted']=True

config_data['advanced_settings']['filter_statements']['episode']['query_filter']['favorited']=True
config_data['advanced_settings']['filter_statements']['episode']['query_filter']['whitetagged']=False
config_data['advanced_settings']['filter_statements']['episode']['query_filter']['blacktagged']=False
config_data['advanced_settings']['filter_statements']['episode']['query_filter']['blacktagged']=True
config_data['advanced_settings']['filter_statements']['episode']['query_filter']['whitelisted']=False
config_data['advanced_settings']['filter_statements']['episode']['query_filter']['blacklisted']=True

config_data['advanced_settings']['filter_statements']['audio']['query_filter']['favorited']=True
config_data['advanced_settings']['filter_statements']['audio']['query_filter']['whitetagged']=False
config_data['advanced_settings']['filter_statements']['audio']['query_filter']['blacktagged']=False
config_data['advanced_settings']['filter_statements']['audio']['query_filter']['blacktagged']=True
config_data['advanced_settings']['filter_statements']['audio']['query_filter']['whitelisted']=False
config_data['advanced_settings']['filter_statements']['audio']['query_filter']['blacklisted']=True

if (config_data['admin_settings']['server']['brand'] == 'jellyfin'):
config_data['advanced_settings']['filter_statements']['audiobook']['query_filter']['favorited']=True
config_data['advanced_settings']['filter_statements']['audiobook']['query_filter']['whitetagged']=False
config_data['advanced_settings']['filter_statements']['audiobook']['query_filter']['blacktagged']=False
config_data['advanced_settings']['filter_statements']['audiobook']['query_filter']['blacktagged']=True
config_data['advanced_settings']['filter_statements']['audiobook']['query_filter']['whitelisted']=False
config_data['advanced_settings']['filter_statements']['audiobook']['query_filter']['blacklisted']=True

Expand Down
36 changes: 18 additions & 18 deletions mumc_modules/mumc_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ def api_query_handler(suffix_str,var_dict,the_dict):


#send url request
def requestURL(url, debugState, reqeustDebugMessage, retries, the_dict):
def requestURL(url, debugState, requestDebugMessage, retries, the_dict):

if (debugState):
#Double newline for better debug file readablilty
appendTo_DEBUG_log("\n\n" + reqeustDebugMessage + ' - url request:',2,the_dict)
appendTo_DEBUG_log("\n\n" + requestDebugMessage + ' - url request:',2,the_dict)
appendTo_DEBUG_log("\n" + str(url),3,the_dict)

#first delay if needed
Expand Down Expand Up @@ -80,15 +80,15 @@ def requestURL(url, debugState, reqeustDebugMessage, retries, the_dict):
#wait 20% of the delay value
time.sleep(doubling_delay/5)
if (debugState):
appendTo_DEBUG_log("\nWaiting for server to return data from the " + str(reqeustDebugMessage) + " Request; then trying again...",2,the_dict)
appendTo_DEBUG_log("\nWaiting for server to return data from the " + str(requestDebugMessage) + " Request; then trying again...",2,the_dict)
if (response.getcode() == 200):
try:
source = response.read()
data = json.loads(source)
the_dict['cached_data'].addEntryToCache(url,data)
getdata = False
if (debugState):
appendTo_DEBUG_log("\nData Returned From The " + str(reqeustDebugMessage) + " Request:\n",2,the_dict)
appendTo_DEBUG_log("\nData Returned From The " + str(requestDebugMessage) + " Request:\n",2,the_dict)
appendTo_DEBUG_log(convert2json(data) + "\n",4,the_dict)
except Exception as err:
if (err.msg == 'Unauthorized'):
Expand All @@ -104,8 +104,8 @@ def requestURL(url, debugState, reqeustDebugMessage, retries, the_dict):
doubling_delay += doubling_delay
if (doubling_delay >= (2**retryAttempts)):
if (debugState):
appendTo_DEBUG_log("\nAn error occured, a maximum of " + str(retryAttempts) + " attempts met, and no data retrieved from the \"" + reqeustDebugMessage + "\" lookup.",2,the_dict)
print("\nAn error occured, a maximum of " + str(retryAttempts) + " attempts met, and no data retrieved from the \"" + reqeustDebugMessage + "\" lookup.")
appendTo_DEBUG_log("\nAn error occured, a maximum of " + str(retryAttempts) + " attempts met, and no data retrieved from the \"" + requestDebugMessage + "\" lookup.",2,the_dict)
print("\nAn error occured, a maximum of " + str(retryAttempts) + " attempts met, and no data retrieved from the \"" + requestDebugMessage + "\" lookup.")
print('\n URL: ' + url + '')
exit(0)
elif (response.getcode() == 204):
Expand All @@ -115,28 +115,28 @@ def requestURL(url, debugState, reqeustDebugMessage, retries, the_dict):
the_dict['cached_data'].addEntryToCache(url,data)
getdata = False
if (debugState):
appendTo_DEBUG_log("\nOptional for server to return data for the " + str(reqeustDebugMessage) + " request:",2,the_dict)
appendTo_DEBUG_log("\nOptional for server to return data for the " + str(requestDebugMessage) + " request:",2,the_dict)
if (data):
appendTo_DEBUG_log("\n" + data,4,the_dict)
else:
appendTo_DEBUG_log("\nNo data returned",4,the_dict)
else:
getdata = False
if (debugState):
appendTo_DEBUG_log("\nAn error occurred while attempting to retrieve data from the API.\nAttempt to get data at: " + reqeustDebugMessage + ". Server responded with code: " + str(response.getcode()),2,the_dict)
print("\nAn error occurred while attempting to retrieve data from the API.\nAttempt to get data at: " + reqeustDebugMessage + ". Server responded with code: " + str(response.getcode()))
appendTo_DEBUG_log("\nAn error occurred while attempting to retrieve data from the API.\nAttempt to get data at: " + requestDebugMessage + ". Server responded with code: " + str(response.getcode()),2,the_dict)
print("\nAn error occurred while attempting to retrieve data from the API.\nAttempt to get data at: " + requestDebugMessage + ". Server responded with code: " + str(response.getcode()))
print('\n URL: ' + url + '')
exit(0)
except HTTPError as err:
time.sleep(doubling_delay)
#doubling_delay value doubles each time the same API request is resent
doubling_delay += doubling_delay
if (doubling_delay >= (2**retryAttempts)):
print('\nHTTPError: Unable to get information from server during processing of: ' + reqeustDebugMessage)
print('\n URL: ' + url + '')
print('\nHTTPError: Unable to get information from server during processing of: ' + requestDebugMessage)
print('\n URL: ' + str(url) + '')
print('\n' + str(err.status) + '\n' + str(err.reason))
if(debugState):
appendTo_DEBUG_log('\nHTTPError: Unable to get information from server during processing of: ' + reqeustDebugMessage,2,the_dict)
appendTo_DEBUG_log('\nHTTPError: Unable to get information from server during processing of: ' + requestDebugMessage,2,the_dict)
appendTo_DEBUG_log('\n URL: ' + url + '',2,the_dict)
appendTo_DEBUG_log('\n' + str(err.status) + '\n' + str(err.reason),2,the_dict)
exit(0)
Expand All @@ -145,11 +145,11 @@ def requestURL(url, debugState, reqeustDebugMessage, retries, the_dict):
#doubling_delay value doubles each time the same API request is resent
doubling_delay += doubling_delay
if (doubling_delay >= (2**retryAttempts)):
print('\nURLError: Unable to get information from server during processing of: ' + reqeustDebugMessage)
print('\n URL: ' + url + '')
print('\nURLError: Unable to get information from server during processing of: ' + requestDebugMessage)
print('\n URL: ' + str(url) + '')
print('\n' + str(err.reason))
if(debugState):
appendTo_DEBUG_log('\nURLError: Unable to get information from server during processing of: ' + reqeustDebugMessage,2,the_dict)
appendTo_DEBUG_log('\nURLError: Unable to get information from server during processing of: ' + requestDebugMessage,2,the_dict)
appendTo_DEBUG_log('\n URL: ' + url + '',2,the_dict)
appendTo_DEBUG_log('\n' + str(err.reason),2,the_dict)
exit(0)
Expand All @@ -158,11 +158,11 @@ def requestURL(url, debugState, reqeustDebugMessage, retries, the_dict):
#doubling_delay value doubles each time the same API request is resent
doubling_delay += doubling_delay
if (doubling_delay >= (2**retryAttempts)):
print('\nTimeoutError: Unable to get information from server during processing of: ' + reqeustDebugMessage)
print('\n URL: ' + url + '')
print('\nTimeoutError: Unable to get information from server during processing of: ' + requestDebugMessage)
print('\n URL: ' + str(url) + '')
print('\nTimeout - Request taking too long')
if(debugState):
appendTo_DEBUG_log('\nTimeoutError: Unable to get information from server during processing of: ' + reqeustDebugMessage,2,the_dict)
appendTo_DEBUG_log('\nTimeoutError: Unable to get information from server during processing of: ' + requestDebugMessage,2,the_dict)
appendTo_DEBUG_log('\n URL: ' + url + '',2,the_dict)
appendTo_DEBUG_log('\nTimeout - Request taking too long',2,the_dict)
exit(0)
Expand Down
2 changes: 1 addition & 1 deletion mumc_modules/mumc_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#Get the current script version
def get_script_version():
return '5.3.13'
return '5.3.14'


#Get the min config version
Expand Down
Loading

0 comments on commit 41b2136

Please sign in to comment.