Skip to content

Commit 24c638a

Browse files
Cosmetic changes from AML.
1 parent 0437106 commit 24c638a

File tree

3 files changed

+62
-59
lines changed

3 files changed

+62
-59
lines changed

resources/constants.py

Lines changed: 55 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@
5353
JSON_INDENT = 1
5454
JSON_SEP = (', ', ': ')
5555

56+
# -------------------------------------------------------------------------------------------------
57+
# CUSTOM/DEBUG/TEST settings
58+
# -------------------------------------------------------------------------------------------------
5659
# An integer number incremented whenever there is a change in the ROM storage format.
5760
# This enables easy migrations, at least in theory.
5861
AEL_STORAGE_FORMAT = 1
@@ -68,6 +71,58 @@
6871
KC_BLUEVIOLET = '[COLOR blueviolet]'
6972
KC_END = '[/COLOR]'
7073

74+
# -------------------------------------------------------------------------------------------------
75+
# Image file constants.
76+
# -------------------------------------------------------------------------------------------------
77+
# Supported image files in:
78+
# 1. misc_identify_image_id_by_contents()
79+
# 2. misc_identify_image_id_by_ext()
80+
IMAGE_PNG_ID = 'PNG'
81+
IMAGE_JPEG_ID = 'JPEG'
82+
IMAGE_GIF_ID = 'GIF'
83+
IMAGE_BMP_ID = 'BMP'
84+
IMAGE_TIFF_ID = 'TIFF'
85+
IMAGE_UKNOWN_ID = 'Image unknown'
86+
IMAGE_CORRUPT_ID = 'Image corrupt'
87+
88+
IMAGE_IDS = [
89+
IMAGE_PNG_ID,
90+
IMAGE_JPEG_ID,
91+
IMAGE_GIF_ID,
92+
IMAGE_BMP_ID,
93+
IMAGE_TIFF_ID,
94+
]
95+
96+
IMAGE_EXTENSIONS = {
97+
IMAGE_PNG_ID : ['png'],
98+
IMAGE_JPEG_ID : ['jpg', 'jpeg'],
99+
IMAGE_GIF_ID : ['gif'],
100+
IMAGE_BMP_ID : ['bmp'],
101+
IMAGE_TIFF_ID : ['tif', 'tiff'],
102+
}
103+
104+
# Image file magic numbers. All at file offset 0.
105+
# See https://en.wikipedia.org/wiki/List_of_file_signatures
106+
# b prefix is a byte string in both Python 2 and 3.
107+
IMAGE_MAGIC_DIC = {
108+
IMAGE_PNG_ID : [ b'\x89\x50\x4E\x47\x0D\x0A\x1A\x0A' ],
109+
IMAGE_JPEG_ID : [
110+
b'\xFF\xD8\xFF\xDB',
111+
b'\xFF\xD8\xFF\xE0\x00\x10\x4A\x46\x49\x46\x00\x01',
112+
b'\xFF\xD8\xFF\xEE',
113+
b'\xFF\xD8\xFF\xE1',
114+
],
115+
IMAGE_GIF_ID : [
116+
b'\x47\x49\x46\x38\x37\x61',
117+
b'\x47\x49\x46\x38\x39\x61',
118+
],
119+
IMAGE_BMP_ID : [ b'\x42\x4D' ],
120+
IMAGE_TIFF_ID : [
121+
b'\x49\x49\x2A\x00',
122+
b'\x4D\x4D\x00\x2A',
123+
]
124+
}
125+
71126
# -------------------------------------------------------------------------------------------------
72127
# Addon constants
73128
# -------------------------------------------------------------------------------------------------
@@ -336,33 +391,6 @@
336391
ASSET_TRAILER_ID,
337392
]
338393

339-
# Supported image files in:
340-
# 1. misc_identify_image_id_by_contents()
341-
# 2. misc_identify_image_id_by_ext()
342-
IMAGE_PNG_ID = 'PNG'
343-
IMAGE_JPEG_ID = 'JPEG'
344-
IMAGE_GIF_ID = 'GIF'
345-
IMAGE_BMP_ID = 'BMP'
346-
IMAGE_TIFF_ID = 'TIFF'
347-
IMAGE_UKNOWN_ID = 'Image unknown'
348-
IMAGE_CORRUPT_ID = 'Image corrupt'
349-
350-
IMAGE_IDS = [
351-
IMAGE_PNG_ID,
352-
IMAGE_JPEG_ID,
353-
IMAGE_GIF_ID,
354-
IMAGE_BMP_ID,
355-
IMAGE_TIFF_ID,
356-
]
357-
358-
IMAGE_EXTENSIONS = {
359-
IMAGE_PNG_ID : ['png'],
360-
IMAGE_JPEG_ID : ['jpg', 'jpeg'],
361-
IMAGE_GIF_ID : ['gif'],
362-
IMAGE_BMP_ID : ['bmp'],
363-
IMAGE_TIFF_ID : ['tif', 'tiff'],
364-
}
365-
366394
# --- Addon will search these file extensions for assets ---
367395
# Check http://kodi.wiki/view/advancedsettings.xml#videoextensions
368396
IMAGE_EXTENSION_LIST = ['png', 'jpg', 'jpeg', 'gif', 'bmp', 'tif', 'tiff']

resources/misc.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -688,28 +688,6 @@ def misc_replace_fav(dict_in, old_item_key, new_item_key, new_value):
688688
else:
689689
raise TypeError
690690

691-
# Image file magic numbers. All at file offset 0.
692-
# See https://en.wikipedia.org/wiki/List_of_file_signatures
693-
# b prefix is a byte string in both Pyhton 2 and 3.
694-
IMAGE_MAGIC_DIC = {
695-
IMAGE_PNG_ID : [ b'\x89\x50\x4E\x47\x0D\x0A\x1A\x0A' ],
696-
IMAGE_JPEG_ID : [
697-
b'\xFF\xD8\xFF\xDB',
698-
b'\xFF\xD8\xFF\xE0\x00\x10\x4A\x46\x49\x46\x00\x01',
699-
b'\xFF\xD8\xFF\xEE',
700-
b'\xFF\xD8\xFF\xE1',
701-
],
702-
IMAGE_GIF_ID : [
703-
b'\x47\x49\x46\x38\x37\x61',
704-
b'\x47\x49\x46\x38\x39\x61',
705-
],
706-
IMAGE_BMP_ID : [ b'\x42\x4D' ],
707-
IMAGE_TIFF_ID : [
708-
b'\x49\x49\x2A\x00',
709-
b'\x4D\x4D\x00\x2A',
710-
]
711-
}
712-
713691
# Inspects an image file and determine its type by using the magic numbers,
714692
# Returns an image id defined in list IMAGE_IDS or IMAGE_UKNOWN_ID.
715693
def misc_identify_image_id_by_contents(asset_fname):

resources/utils.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
import sys
6565
import threading
6666
import time
67-
import xml
67+
import xml.etree.ElementTree
6868
import zlib
6969

7070
# --- Determine interpreter running platform ---
@@ -331,15 +331,12 @@ def utils_load_XML_to_ET(filename):
331331
# log_debug(text_type(ex.errno.errorcode))
332332
# No such file or directory
333333
if ex.errno == errno.ENOENT:
334-
log_error('utils_load_XML_to_ET() (IOError) No such file or directory.')
334+
log_error('utils_load_XML_to_ET() (IOError) ENOENT No such file or directory.')
335335
else:
336336
log_error('utils_load_XML_to_ET() (IOError) Unhandled errno value.')
337337
except xml.etree.ElementTree.ParseError as ex:
338-
log_error('utils_load_XML_to_ET() (ParseError) Exception parsing XML categories.xml')
338+
log_error('utils_load_XML_to_ET() (ParseError) Exception parsing {}'.format(filename))
339339
log_error('utils_load_XML_to_ET() (ParseError) {}'.format(text_type(ex)))
340-
# kodi_dialog_OK('(ET.ParseError) when reading categories.xml. '
341-
# 'XML file is corrupt or contains invalid characters.')
342-
343340
return xml_tree
344341

345342
# -------------------------------------------------------------------------------------------------
@@ -350,15 +347,15 @@ def utils_load_JSON_file(json_filename, default_obj = {}, verbose = True):
350347
# If file does not exist return default object (usually empty object)
351348
json_data = default_obj
352349
if not os.path.isfile(json_filename):
353-
log_warning('utils_load_JSON_file_dic() Not found "{}"'.format(json_filename))
350+
log_warning('utils_load_JSON_file() Not found "{}"'.format(json_filename))
354351
return json_data
355352
# Load and parse JSON file.
356-
if verbose: log_debug('utils_load_JSON_file_dic() "{}"'.format(json_filename))
353+
if verbose: log_debug('utils_load_JSON_file() "{}"'.format(json_filename))
357354
with io.open(json_filename, 'rt', encoding = 'utf-8') as file:
358355
try:
359356
json_data = json.load(file)
360357
except ValueError as ex:
361-
log_error('utils_load_JSON_file_dic() ValueError exception in json.load() function')
358+
log_error('utils_load_JSON_file() ValueError exception in json.load() function')
362359

363360
return json_data
364361

@@ -432,7 +429,7 @@ def __init__(self, json_filename):
432429
self.json_filename = json_filename
433430

434431
def run(self):
435-
self.output_dic = utils_load_JSON_file_dic(self.json_filename)
432+
self.output_dic = utils_load_JSON_file(self.json_filename)
436433

437434
# -------------------------------------------------------------------------------------------------
438435
# File cache functions.

0 commit comments

Comments
 (0)