def migrate_library(): # Migrate the Kodi library to the new format of STRM path # - Old STRM: '/play/show/xxxxxxxx/season/xxxxxxxx/episode/xxxxxxxx/' (used before ver 1.7.0) # - New STRM: '/play_strm/show/xxxxxxxx/season/xxxxxxxx/episode/xxxxxxxx/' (used from ver 1.7.0) folders = get_library_subfolders( FOLDER_NAME_MOVIES) + get_library_subfolders(FOLDER_NAME_SHOWS) if not folders: return debug('Start migrating STRM files') try: with ui.ProgressDialog(True, title='Migrating library to new format', max_value=len(folders)) as progress_bar: for folder_path in folders: folder_name = os.path.basename( G.py2_decode(xbmc.translatePath(folder_path))) progress_bar.set_message('PLEASE WAIT - Migrating: ' + folder_name) _migrate_strm_files(folder_path) except Exception as exc: # pylint: disable=broad-except error('Migrating failed: {}', exc) import traceback error(G.py2_decode(traceback.format_exc(), 'latin-1')) ui.show_ok_dialog('Migrating library to new format', ( 'Library migration has failed.[CR]' 'Before try play a Netflix video from library, you must run manually the library migration, ' 'otherwise you will have add-on malfunctions.[CR][CR]' 'Open add-on settings on "Library" section, and select "Import existing library".' ))
def _perform_local_db_changes(current_version, upgrade_to_version): """Perform database actions for a db version change""" if current_version is not None: debug( 'Initialization of local database updates from version {} to {})', current_version, upgrade_to_version) run_local_db_updates(current_version, upgrade_to_version) g.LOCAL_DB.set_value('local_db_version', upgrade_to_version)
def _perform_addon_changes(previous_ver, current_ver): """Perform actions for an version bump""" debug('Initialize addon upgrade operations, from version {} to {})', previous_ver, current_ver) if previous_ver and is_less_version(previous_ver, '0.15.9'): import resources.lib.kodi.ui as ui msg = ('This update resets the settings to auto-update library.\r\n' 'Therefore only in case you are using auto-update must be reconfigured.') ui.show_ok_dialog('Netflix upgrade', msg) # Always leave this to last - After the operations set current version g.LOCAL_DB.set_value('addon_previous_version', current_ver)
def delete_cache_folder(): # Delete cache folder in the add-on userdata (no more needed with the new cache management) cache_path = os.path.join(g.DATA_PATH, 'cache') if not os.path.exists(g.py2_decode(xbmc.translatePath(cache_path))): return debug('Deleting the cache folder from add-on userdata folder') try: delete_folder_contents(cache_path, True) xbmc.sleep(80) xbmcvfs.rmdir(cache_path) except Exception: # pylint: disable=broad-except import traceback error(g.py2_decode(traceback.format_exc(), 'latin-1'))
def _perform_service_changes(previous_ver, current_ver): """Perform actions for an version bump""" debug('Initialize service upgrade operations, from version {} to {})', previous_ver, current_ver) if previous_ver and is_less_version(previous_ver, '1.2.0'): # In the version 1.2.0 has been implemented a new cache management from resources.lib.upgrade_actions import delete_cache_folder delete_cache_folder() # In the version 1.2.0 has been implemented in auto-update mode setting the option to disable the feature lib_auto_upd_mode = g.ADDON.getSettingInt('lib_auto_upd_mode') g.ADDON.setSettingInt('lib_auto_upd_mode', lib_auto_upd_mode + 1) # Always leave this to last - After the operations set current version g.LOCAL_DB.set_value('service_previous_version', current_ver)
def _perform_shared_db_changes(current_version, upgrade_to_version): """Perform database actions for a db version change""" # This is a temporary bug fix, to be removed on future addon versions, # this because a previous oversight never saved the current version # Init fix service_previous_ver = g.LOCAL_DB.get_value('service_previous_version', None) if service_previous_ver is not None and\ current_version is None and\ not is_minimum_version(service_previous_ver, '0.17.0'): current_version = '0.1' # End fix if current_version is not None: debug('Initialization of shared databases updates from version {} to {})', current_version, upgrade_to_version) run_shared_db_updates(current_version, upgrade_to_version) g.LOCAL_DB.set_value('shared_db_version', upgrade_to_version)
def _perform_service_changes(previous_ver, current_ver): """Perform actions for an version bump""" debug('Initialize service upgrade operations, from version {} to {})', previous_ver, current_ver) # Clear cache (prevents problems when netflix change data structures) g.CACHE.clear() if previous_ver and is_less_version(previous_ver, '1.2.0'): # In the version 1.2.0 has been implemented a new cache management from resources.lib.upgrade_actions import delete_cache_folder delete_cache_folder() # In the version 1.2.0 has been implemented in auto-update mode setting the option to disable the feature try: lib_auto_upd_mode = g.ADDON.getSettingInt('lib_auto_upd_mode') g.ADDON.setSettingInt('lib_auto_upd_mode', lib_auto_upd_mode + 1) except TypeError: # In case of a previous rollback this could fails g.ADDON.setSettingInt('lib_auto_upd_mode', 1) # Always leave this to last - After the operations set current version g.LOCAL_DB.set_value('service_previous_version', current_ver)