Esempio n. 1
0
def _update_library(videoids_to_update, exported_tvshows_videoids_values,
                    silent):
    execute_lib_tasks_method = execute_library_tasks_silently if silent else execute_library_tasks
    # Get the list of the Tv Shows exported to exclude from updates
    excluded_videoids_values = g.SHARED_DB.get_tvshows_id_list(
        VidLibProp['exclude_update'], True)
    for videoid in videoids_to_update:
        # Check if current videoid is excluded from updates
        if videoid.value in excluded_videoids_values:
            continue
        if videoid.value in exported_tvshows_videoids_values:
            # It is possible that the user has chosen not to export NFO files for a tv show
            nfo_export = g.SHARED_DB.get_tvshow_property(
                videoid.value, VidLibProp['nfo_export'], False)
            nfo_settings = nfo.NFOSettings(nfo_export)
        else:
            nfo_settings = nfo.NFOSettings()
        if videoid.mediatype == common.VideoId.SHOW:
            export_new_episodes(videoid, silent, nfo_settings)
        if videoid.mediatype == common.VideoId.MOVIE:
            execute_lib_tasks_method(videoid, [export_item],
                                     sync_mylist=False,
                                     nfo_settings=nfo_settings)
        # Add some randomness between operations to limit servers load and ban risks
        xbmc.sleep(random.randint(1000, 5001))
Esempio n. 2
0
 def _update_library(self, videoids_tasks, exp_tvshows_videoids_values,
                     show_prg_dialog, show_nfo_dialog, clear_on_cancel):
     # If set ask to user if want to export NFO files (override user custom NFO settings for videoids)
     nfo_settings_override = None
     if show_nfo_dialog:
         nfo_settings_override = nfo.NFOSettings()
         nfo_settings_override.show_export_dialog()
     # Get the exported tvshows, but to be excluded from the updates
     excluded_videoids_values = G.SHARED_DB.get_tvshows_id_list(
         VidLibProp['exclude_update'], True)
     # Start the update operations
     with ui.ProgressDialog(show_prg_dialog,
                            max_value=len(videoids_tasks)) as progress_bar:
         for videoid, task_handler in iteritems(videoids_tasks):
             # Check if current videoid is excluded from updates
             if int(videoid.value) in excluded_videoids_values:
                 continue
             # Get the NFO settings for the current videoid
             if not nfo_settings_override and int(
                     videoid.value) in exp_tvshows_videoids_values:
                 # User custom NFO setting
                 # it is possible that the user has chosen not to export NFO files for a specific tv show
                 nfo_export = G.SHARED_DB.get_tvshow_property(
                     videoid.value, VidLibProp['nfo_export'], False)
                 nfo_settings = nfo.NFOSettings(nfo_export)
             else:
                 nfo_settings = nfo_settings_override or nfo.NFOSettings()
             # Execute the task
             for index, total_tasks, title in self.execute_library_task(
                     videoid,
                     task_handler,
                     nfo_settings=nfo_settings,
                     notify_errors=show_prg_dialog):
                 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(
                     'Auto update of the Kodi library interrupted by User')
                 if clear_on_cancel:
                     self.clear_library(True)
                 return False
             if self.monitor.abortRequested():
                 LOG.warn(
                     'Auto update of the Kodi library interrupted by Kodi')
                 return False
             progress_bar.perform_step()
             progress_bar.set_wait_message()
             delay_anti_ban()
     common.clean_library(show_prg_dialog)
     return True
 def initial_mylist_sync(self, pathitems):
     """Perform an initial sync of My List and the Kodi library"""
     # pylint: disable=unused-argument
     from resources.lib.cache import CACHE_COMMON
     # This is a temporary workaround to prevent sync from mylist of non owner account profiles
     # TODO: in the future you can also add the possibility to synchronize from a chosen profile
     is_account_owner = g.LOCAL_DB.get_profile_config(
         'isAccountOwner', False)
     if not is_account_owner:
         ui.show_ok_dialog('Netflix', common.get_local_string(30223))
         return
     do_it = ui.ask_for_confirmation(common.get_local_string(30122),
                                     common.get_local_string(30123))
     if not do_it:
         return
     common.debug('Performing full sync from My List to Kodi library')
     library.purge()
     nfo_settings = nfo.NFOSettings()
     nfo_settings.show_export_dialog()
     # Invalidate my-list cached data to force to obtain new data
     g.CACHE.invalidate_entry(CACHE_COMMON, 'my_list_items')
     for videoid in api.mylist_items():
         library.execute_library_tasks(videoid, [library.export_item],
                                       common.get_local_string(30018),
                                       sync_mylist=False,
                                       nfo_settings=nfo_settings)
def _create_new_episodes_tasks(videoid, metadata, nfo_settings=None):
    tasks = []
    if metadata and 'seasons' in metadata[0]:
        for season in metadata[0]['seasons']:
            if not nfo_settings:
                nfo_export = g.SHARED_DB.get_tvshow_property(
                    videoid.value, VidLibProp['nfo_export'], False)
                nfo_settings = nfo.NFOSettings(nfo_export)

            if g.SHARED_DB.season_id_exists(videoid.value, season['id']):
                # The season exists, try to find any missing episode
                for episode in season['episodes']:
                    if not g.SHARED_DB.episode_id_exists(
                            videoid.value, season['id'], episode['id']):
                        tasks.append(
                            _create_export_episode_task(
                                videoid=videoid.derive_season(
                                    season['id']).derive_episode(
                                        episode['id']),
                                episode=episode,
                                season=season,
                                show=metadata[0],
                                nfo_settings=nfo_settings))
                        common.debug('Auto exporting episode {}',
                                     episode['id'])
            else:
                # The season does not exist, build task for the season
                tasks += _compile_export_season_tasks(
                    videoid=videoid.derive_season(season['id']),
                    show=metadata[0],
                    season=season,
                    nfo_settings=nfo_settings)
                common.debug('Auto exporting season {}', season['id'])
    return tasks
Esempio n. 5
0
 def export(self, videoid):
     """Export an item to the Kodi library"""
     nfo_settings = nfo.NFOSettings()
     nfo_settings.show_export_dialog(videoid.mediatype)
     library.execute_library_tasks(videoid, [library.export_item],
                                   common.get_local_string(30018),
                                   nfo_settings=nfo_settings)
Esempio n. 6
0
 def update(self, videoid):
     """Update an item in the Kodi library"""
     nfo_settings = nfo.NFOSettings()
     nfo_settings.show_export_dialog(videoid.mediatype)
     library.execute_library_tasks(videoid,
                                   [library.remove_item, library.export_item],
                                   common.get_local_string(30061),
                                   nfo_settings=nfo_settings)
     common.refresh_container()
Esempio n. 7
0
def _create_new_episodes_tasks(videoid, metadata, nfo_settings=None):
    tasks = []
    if metadata and 'seasons' in metadata[0]:
        for season in metadata[0]['seasons']:
            if not nfo_settings:
                nfo_export = g.SHARED_DB.get_tvshow_property(videoid.value, VidLibProp['nfo_export'], False)
                nfo_settings = nfo.NFOSettings(nfo_export)
            # Check and add missing seasons and episodes
            _add_missing_items(tasks, season, videoid, metadata, nfo_settings)
    return tasks
Esempio n. 8
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. 9
0
 def export_silent(self, videoid):
     """Silently export an item to the Kodi library
     (without GUI feedback). This will ignore the setting for syncing my
     list and Kodi library and do no sync, if not explicitly asked to.
     Will only ask for NFO export based on user settings"""
     # pylint: disable=broad-except
     nfo_settings = nfo.NFOSettings()
     nfo_settings.show_export_dialog(videoid.mediatype,
                                     common.get_local_string(30191))
     library.execute_library_tasks_silently(videoid, [library.export_item],
                                            nfo_settings=nfo_settings)
Esempio n. 10
0
 def export_to_library(self, videoid, show_prg_dialog=True):
     """
     Export an item to the Kodi library
     :param videoid: the videoid
     :param show_prg_dialog: if True show progress dialog, otherwise, a background progress bar
     """
     LOG.info('Start exporting {} to the library', videoid)
     nfo_settings = nfo.NFOSettings()
     nfo_settings.show_export_dialog(videoid.mediatype)
     self.execute_library_task_gui(videoid,
                                   self.export_item,
                                   title=common.get_local_string(30018),
                                   nfo_settings=nfo_settings,
                                   show_prg_dialog=show_prg_dialog)
Esempio n. 11
0
def sync_mylist_to_library():
    """
    Perform a full sync of Netflix "My List" with the Kodi library
    by deleting everything that was previously exported
    """
    common.info(
        'Performing full sync of Netflix "My List" with the Kodi library')
    purge()
    nfo_settings = nfo.NFOSettings()
    nfo_settings.show_export_dialog()
    for videoid in api.mylist_items_switch_profiles():
        execute_library_tasks(videoid, [export_item],
                              common.get_local_string(30018),
                              sync_mylist=False,
                              nfo_settings=nfo_settings)
Esempio n. 12
0
 def initial_mylist_sync(self, pathitems):
     """Perform an initial sync of My List and the Kodi library"""
     # pylint: disable=unused-argument
     do_it = ui.ask_for_confirmation(common.get_local_string(30122),
                                     common.get_local_string(30123))
     if not do_it or not g.ADDON.getSettingBool('mylist_library_sync'):
         return
     common.debug('Performing full sync from My List to Kodi library')
     library.purge()
     nfo_settings = nfo.NFOSettings()
     nfo_settings.show_export_dialog()
     for videoid in api.video_list(api.list_id_for_type('queue')).videoids:
         library.execute_library_tasks(videoid, [library.export_item],
                                       common.get_local_string(30018),
                                       sync_mylist=False,
                                       nfo_settings=nfo_settings)
Esempio n. 13
0
 def export_to_library_new_episodes(self, videoid, show_prg_dialog=True):
     """
     Export new episodes for a tv show by it's videoid
     :param videoid: The videoid of the tv show to process
     :param show_prg_dialog: if True show progress dialog, otherwise, a background progress bar
     """
     LOG.info('Start exporting new episodes for {}', videoid)
     if videoid.mediatype != common.VideoId.SHOW:
         LOG.warn('{} is not a tv show, the operation is cancelled', videoid)
         return
     nfo_settings = nfo.NFOSettings()
     nfo_settings.show_export_dialog(videoid.mediatype)
     self.execute_library_task_gui(videoid,
                                   self.export_new_item,
                                   title=common.get_local_string(30198),
                                   nfo_settings=nfo_settings,
                                   show_prg_dialog=show_prg_dialog)
Esempio n. 14
0
 def initial_mylist_sync(self, pathitems):
     """Perform an initial sync of My List and the Kodi library"""
     # pylint: disable=unused-argument
     from resources.lib.cache import CACHE_COMMON
     do_it = ui.ask_for_confirmation(common.get_local_string(30122),
                                     common.get_local_string(30123))
     if not do_it:
         return
     common.debug('Performing full sync from My List to Kodi library')
     library.purge()
     nfo_settings = nfo.NFOSettings()
     nfo_settings.show_export_dialog()
     # Invalidate my-list cached data to force to obtain new data
     g.CACHE.invalidate_entry(CACHE_COMMON, 'my_list_items')
     for videoid in api.mylist_items():
         library.execute_library_tasks(videoid, [library.export_item],
                                       common.get_local_string(30018),
                                       sync_mylist=False,
                                       nfo_settings=nfo_settings)
Esempio n. 15
0
 def update_library(self, videoid, show_prg_dialog=True):
     """
     Update items in the Kodi library
     :param videoid: the videoid
     :param show_prg_dialog: if True show progress dialog, otherwise, a background progress bar
     """
     common.info('Start updating {} in the library', videoid)
     nfo_settings = nfo.NFOSettings()
     nfo_settings.show_export_dialog(videoid.mediatype)
     self.execute_library_task_gui(videoid,
                                   self.remove_item,
                                   title=common.get_local_string(30061),
                                   nfo_settings=nfo_settings,
                                   show_prg_dialog=show_prg_dialog)
     self.execute_library_task_gui(videoid,
                                   self.export_item,
                                   title=common.get_local_string(30061),
                                   nfo_settings=nfo_settings,
                                   show_prg_dialog=show_prg_dialog)
 def _create_export_new_episodes_jobs(self,
                                      videoid,
                                      metadata,
                                      nfo_settings=None):
     """Create jobs data to export missing seasons and episodes"""
     tasks = []
     if metadata and 'seasons' in metadata[0]:
         for season in metadata[0]['seasons']:
             if not nfo_settings:
                 nfo_export = G.SHARED_DB.get_tvshow_property(
                     videoid.value, VidLibProp['nfo_export'], False)
                 nfo_settings = nfo.NFOSettings(nfo_export)
             # Check and add missing seasons and episodes
             self._add_missing_items(tasks, season, videoid, metadata,
                                     nfo_settings)
         if nfo_settings and nfo_settings.export_full_tvshow:
             job = self._create_export_tvshow_nfo_job(videoid, metadata)
             if job:
                 tasks.append(job)
     return tasks
Esempio n. 17
0
def sync_mylist_to_library():
    """
    Perform a full sync of Netflix "My List" with the Kodi library
    by deleting everything that was previously exported
    """
    common.info(
        'Performing full sync of Netflix "My List" with the Kodi library')
    purge()
    nfo_settings = nfo.NFOSettings()
    nfo_settings.show_export_dialog()

    mylist_video_id_list, mylist_video_id_list_type = common.make_call(
        'get_mylist_videoids_profile_switch')
    for index, video_id in enumerate(mylist_video_id_list):
        videoid = common.VideoId(
            **{
                ('movieid' if (mylist_video_id_list_type[index] == 'movie') else 'tvshowid'):
                video_id
            })
        execute_library_tasks(videoid, [export_item],
                              common.get_local_string(30018),
                              nfo_settings=nfo_settings)
Esempio n. 18
0
def export_all_new_episodes():
    """
    Update the local Kodi library with new episodes of every exported shows
    """
    from resources.lib.cache import CACHE_COMMON
    from resources.lib.database.db_exceptions import ProfilesMissing
    if _export_all_new_episodes_running():
        return
    common.log('Starting to export new episodes for all tv shows')
    g.SHARED_DB.set_value('library_export_new_episodes_running', True)
    g.SHARED_DB.set_value('library_export_new_episode_start_time',
                          datetime.now())
    # Get the list of the tvshows exported to kodi library
    exported_videoids_values = g.SHARED_DB.get_tvshows_id_list()
    # Get the list of the tvshows exported but to exclude from updates
    excluded_videoids_values = g.SHARED_DB.get_tvshows_id_list(
        VidLibProp.exclude_update, True)

    # Before start to get updated mylist items, you have to select the owner account
    # TODO: in the future you can also add the possibility to synchronize from a chosen profile
    try:
        guid_owner_profile = g.LOCAL_DB.get_guid_owner_profile()
    except ProfilesMissing as exc:
        import traceback
        common.error(traceback.format_exc())
        ui.show_addon_error_info(exc)
        return
    if guid_owner_profile != g.LOCAL_DB.get_active_profile_guid():
        common.debug('Switching to owner account profile')
        api.activate_profile(guid_owner_profile)

    # Retrieve updated items from "my list"
    # Invalidate my-list cached data to force to obtain new data
    g.CACHE.invalidate_entry(CACHE_COMMON, 'my_list_items')
    mylist_videoids = api.mylist_items()

    # Check if any tvshow have been removed from the mylist
    for videoid_value in exported_videoids_values:
        if any(videoid.value == unicode(videoid_value)
               for videoid in mylist_videoids):
            continue
        # Tvshow no more exist in mylist so remove it from library
        videoid = common.VideoId.from_path(
            [common.VideoId.SHOW, videoid_value])
        execute_library_tasks_silently(videoid, [remove_item],
                                       sync_mylist=False)

    # Update or add tvshow in kodi library
    for videoid in mylist_videoids:
        # Only tvshows require be updated
        if videoid.mediatype != common.VideoId.SHOW:
            continue
        if videoid.value in excluded_videoids_values:
            continue
        if videoid.value in exported_videoids_values:
            # It is possible that the user has chosen not to export nfo for a tvshow
            nfo_export = g.SHARED_DB.get_tvshow_property(
                videoid.value, VidLibProp.nfo_export, False)
            nfo_settings = nfo.NFOSettings(nfo_export)
        else:
            nfo_settings = nfo.NFOSettings()
        export_new_episodes(videoid, True, nfo_settings)
        # add some randomness between show analysis to limit servers load and ban risks
        xbmc.sleep(random.randint(1000, 5001))

    g.SHARED_DB.set_value('library_export_new_episodes_running', False)
    if not g.ADDON.getSettingBool('disable_library_sync_notification'):
        ui.show_notification(common.get_local_string(30220), time=5000)
    common.debug('Notify service to update the library')
    common.send_signal(common.Signals.LIBRARY_UPDATE_REQUESTED)
def get_nfo_settings():
    """Get the NFO settings, confirmations may be requested to the user if necessary"""
    return nfo.NFOSettings()