Skip to content

Commit d0a672a

Browse files
Improvements from the Pyhton 3 branch.
1 parent 641dbd4 commit d0a672a

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

resources/main.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9850,6 +9850,7 @@ def _gui_edit_asset(self, object_kind, asset_ID, object_dic, categoryID = '', la
98509850

98519851
# --- Link to a local image ---
98529852
if mindex == 0:
9853+
log_debug('_gui_edit_asset() Linking local image...')
98539854
image_dir = FileName(object_dic[AInfo.key]).getDir() if object_dic[AInfo.key] else ''
98549855
log_debug('_gui_edit_asset() Initial path "{}"'.format(image_dir))
98559856
if asset_ID == ASSET_MANUAL_ID or asset_ID == ASSET_TRAILER_ID:
@@ -9869,18 +9870,20 @@ def _gui_edit_asset(self, object_kind, asset_ID, object_dic, categoryID = '', la
98699870
log_info('_gui_edit_asset() Linked {} {} "{}"'.format(object_name,
98709871
AInfo.name, image_file_path.getOriginalPath()))
98719872

9872-
# --- Update Kodi image cache ---
9873-
kodi_update_image_cache(image_file_path.getOriginalPath())
9873+
# Update Kodi image cache.
9874+
# TODO Only update mtime for local files and not for Kodi VFS files.
9875+
utils_update_file_mtime(image_file_path.getPath())
98749876

98759877
# --- Import an image ---
98769878
# Copy and rename a local image into asset directory.
98779879
elif mindex == 1:
9880+
log_debug('_gui_edit_asset() Importing image...')
98789881
# If assets exists start file dialog from current asset directory
98799882
image_dir = ''
98809883
if object_dic[AInfo.key]: image_dir = FileName(object_dic[AInfo.key]).getDir()
98819884
log_debug('_gui_edit_asset() Initial path "{}"'.format(image_dir))
9882-
image_file = kodi_dialog_get_image('Select {} image'.format(AInfo.name),
9883-
AInfo.exts_dialog, image_dir)
9885+
t = 'Select {} image'.format(AInfo.name)
9886+
image_file = kodi_dialog_get_image(t, AInfo.exts_dialog, image_dir)
98849887
image_FileName = FileName(image_file)
98859888
if not image_FileName.exists(): return False
98869889

@@ -9915,16 +9918,19 @@ def _gui_edit_asset(self, object_kind, asset_ID, object_dic, categoryID = '', la
99159918
AInfo.name, dest_path_FileName.getOriginalPath()))
99169919

99179920
# Update Kodi image cache.
9918-
kodi_update_image_cache(dest_path_FileName.getOriginalPath())
9921+
utils_update_file_mtime(dest_path_FileName.getPath())
99199922

99209923
# --- Unset asset ---
99219924
elif mindex == 2:
9925+
log_debug('_gui_edit_asset() Unsetting asset...')
99229926
object_dic[AInfo.key] = ''
99239927
kodi_notify('{} {} has been unset'.format(object_name, AInfo.name))
99249928
log_info('_gui_edit_asset() Unset {} {}'.format(object_name, AInfo.name))
99259929

99269930
# --- Manual scrape and choose from a list of images ---
99279931
elif mindex >= 3:
9932+
log_debug('_gui_edit_asset() Scraping image...')
9933+
99289934
# --- Create ScrapeFactory object ---
99299935
scraper_index = mindex - len(common_menu_list)
99309936
log_debug('_gui_edit_asset() Scraper index {}'.format(scraper_index))

resources/utils.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,19 @@ def utils_look_for_file(rootPath, filename_noext, file_exts):
519519
if file_path.exists(): return file_path
520520
return None
521521

522+
# Updates the mtime of a local file.
523+
# This is to force and update of the image cache.
524+
# stat.ST_MTIME is the time in seconds since the epoch.
525+
def utils_update_file_mtime(fname_str):
526+
log_debug('utils_update_file_mtime() Updating "{}"'.format(fname_str))
527+
filestat = os.stat(fname_str)
528+
time_str = time.ctime(filestat.st_mtime)
529+
log_debug('utils_update_file_mtime() Old mtime "{}"'.format(time_str))
530+
os.utime(fname_str)
531+
filestat = os.stat(fname_str)
532+
time_str = time.ctime(filestat.st_mtime)
533+
log_debug('utils_update_file_mtime() Current mtime "{}"'.format(time_str))
534+
522535
# -------------------------------------------------------------------------------------------------
523536
# Logging functions.
524537
# AEL never uses LOG_FATAL. Fatal error in my addons use LOG_ERROR. When an ERROR message is
@@ -1233,18 +1246,16 @@ def kodi_display_exception(ex):
12331246
# image_path is a Unicode string.
12341247
# cache_file_path is a Unicode string.
12351248
def kodi_get_cached_image_FN(image_path):
1236-
THUMBS_CACHE_PATH = os.path.join(xbmc.translatePath('special://profile/' ), 'Thumbnails')
1237-
1238-
# --- Get the Kodi cached image ---
1249+
THUMBS_CACHE_PATH = os.path.join(xbmc.translatePath('special://profile/'), 'Thumbnails')
12391250
# This function return the cache file base name
12401251
base_name = xbmc.getCacheThumbName(image_path)
12411252
cache_file_path = os.path.join(THUMBS_CACHE_PATH, base_name[0], base_name)
1242-
12431253
return cache_file_path
12441254

1255+
# *** Experimental code not used for releases ***
12451256
# Updates Kodi image cache for the image provided in img_path.
12461257
# In other words, copies the image img_path into Kodi cache entry.
1247-
# Needles to say, only update image cache if image already was on the cache.
1258+
# Needles to say, only update the image cache if the image already was on the cache.
12481259
# img_path is a Unicode string
12491260
def kodi_update_image_cache(img_path):
12501261
# What if image is not cached?

0 commit comments

Comments
 (0)