Esempio n. 1
0
 def import_library(self, path):
     """
     Imports an already existing exported STRM library into the add-on library database,
     allows you to restore an existing library, by avoiding to recreate it from scratch.
     This operations also update the missing tv shows seasons and episodes, and automatically
     converts old STRM format type from add-on version 0.13.x or before 1.7.0 to new format.
     """
     # If set ask to user if want to export NFO files
     nfo_settings = nfo.NFOSettings()
     nfo_settings.show_export_dialog()
     LOG.info('Start importing Kodi library')
     remove_folders = [
     ]  # List of failed imports paths to be optionally removed
     remove_titles = [
     ]  # List of failed imports titles to be optionally removed
     # Start importing STRM files
     folders = get_library_subfolders(FOLDER_NAME_MOVIES,
                                      path) + get_library_subfolders(
                                          FOLDER_NAME_SHOWS, path)
     with ui.ProgressDialog(True, max_value=len(folders)) as progress_bar:
         for folder_path in folders:
             folder_name = os.path.basename(
                 G.py2_decode(translatePath(folder_path)))
             progress_bar.set_message(folder_name)
             try:
                 videoid = self.import_videoid_from_existing_strm(
                     folder_path, folder_name)
                 if videoid is None:
                     # Failed to import, add folder to remove list
                     remove_folders.append(folder_path)
                     remove_titles.append(folder_name)
                     continue
                 # Successfully imported, Execute the task
                 for index, total_tasks, title in self.execute_library_task(
                         videoid,
                         self.export_item,
                         nfo_settings=nfo_settings,
                         notify_errors=True):
                     label_partial_op = ' ({}/{})'.format(
                         index + 1, total_tasks) if total_tasks > 1 else ''
                     progress_bar.set_message(title + label_partial_op)
                 if progress_bar.is_cancelled():
                     LOG.warn('Import library interrupted by User')
                     return
                 if self.monitor.abortRequested():
                     LOG.warn('Import library interrupted by Kodi')
                     return
             except ImportWarning:
                 # Ignore it, something was wrong in STRM file (see _import_videoid in library_jobs.py)
                 pass
             progress_bar.perform_step()
             progress_bar.set_wait_message()
             delay_anti_ban()
     ret = self._import_library_remove(remove_titles, remove_folders)
     request_kodi_library_update(scan=True, clean=ret)
Esempio n. 2
0
    def auto_update_library(self, sync_with_mylist, show_prg_dialog=True, show_nfo_dialog=False, clear_on_cancel=False,
                            update_profiles=False):
        """
        Perform an auto update of the exported items in to Kodi library.
        - The main purpose is check if there are new seasons/episodes.
        - In the case "Sync Kodi library with My list" feature is enabled, will be also synchronized with My List.
        :param sync_with_mylist: if True, sync the Kodi library with Netflix My List
        :param show_prg_dialog: if True, will be show a progress dialog window and the errors will be notified to user
        :param show_nfo_dialog: if True, ask to user if want export NFO files (override custom NFO actions for videoid)
        :param clear_on_cancel: if True, when the user cancel the operations will be cleared the entire library
        :param update_profiles: if True, before perform sync_with_mylist will be updated the profiles
        """
        if is_auto_update_library_running(show_prg_dialog):
            return
        LOG.info('Start auto-updating of Kodi library {}', '(with sync of My List)' if sync_with_mylist else '')
        G.SHARED_DB.set_value('library_auto_update_is_running', True)
        G.SHARED_DB.set_value('library_auto_update_start_time', datetime.now())
        try:
            # Get the full list of the exported tvshows/movies as id (VideoId.value)
            exp_tvshows_videoids_values = G.SHARED_DB.get_tvshows_id_list()
            exp_movies_videoids_values = G.SHARED_DB.get_movies_id_list()

            # Get the exported tv shows (to be updated) as dict (key=videoid, value=type of task)
            videoids_tasks = {
                common.VideoId.from_path([common.VideoId.SHOW, videoid_value]): self.export_new_item
                for videoid_value in G.SHARED_DB.get_tvshows_id_list(VidLibProp['exclude_update'], False)
            }
            if sync_with_mylist and update_profiles:
                # Before do the sync with My list try to update the profiles in the database,
                # to do a sanity check of the features that are linked to the profiles
                self.ext_func_req_profiles_info(update_database=True)  # pylint: disable=not-callable
                sync_with_mylist = G.ADDON.getSettingBool('lib_sync_mylist')
            # If enabled sync the Kodi library with Netflix My List
            if sync_with_mylist:
                self._sync_my_list_ops(videoids_tasks, exp_tvshows_videoids_values, exp_movies_videoids_values)

            # Show a warning message when there are more than 100 titles to be updated, making too many metadata
            # requests may cause blocking of http communication from the server or temporary ban of the account
            if show_prg_dialog:
                total_titles_upd = sum(task != self.remove_item for task in videoids_tasks.values())
                if total_titles_upd >= 100 and not ui.ask_for_confirmation(
                        common.get_local_string(30122),
                        common.get_local_string(30059).format(total_titles_upd)):
                    return
            # Start the update operations
            ret = self._update_library(videoids_tasks, exp_tvshows_videoids_values, show_prg_dialog, show_nfo_dialog,
                                       clear_on_cancel)
            if not ret:
                return
            request_kodi_library_update(scan=True, clean=True)
            # Save date for completed operation to compute next update schedule (used in library_updater.py)
            G.SHARED_DB.set_value('library_auto_update_last_start', datetime.now())
            LOG.info('Auto update of the Kodi library completed')
            if not G.ADDON.getSettingBool('lib_auto_upd_disable_notification'):
                ui.show_notification(common.get_local_string(30220), time=5000)
        except Exception as exc:  # pylint: disable=broad-except
            import traceback
            LOG.error('An error has occurred in the library auto update: {}', exc)
            LOG.error(G.py2_decode(traceback.format_exc(), 'latin-1'))
        finally:
            G.SHARED_DB.set_value('library_auto_update_is_running', False)