示例#1
0
def remove_item(item_task, library_home=None):
    """Remove an item from the library and delete if from disk"""
    # pylint: disable=unused-argument, broad-except
    if item_task[
            'is_strm']:  # We don't take care of a tvshow.nfo task if we are running an update
        common.debug('Removing {} from library'.format(item_task['title']))
        if not is_in_library(item_task['videoid']):
            common.warn('cannot remove {}, item not in library'.format(
                item_task['title']))
            return
        id_path = item_task['videoid'].to_list()
        exported_filename = xbmc.translatePath(
            common.get_path(id_path, g.library())['file']).decode("utf-8")
        parent_folder = os.path.dirname(exported_filename)
        try:
            xbmcvfs.delete(
                xbmc.translatePath(exported_filename).decode("utf-8"))
            # Remove the NFO files if exists
            nfo_file = os.path.splitext(
                xbmc.translatePath(exported_filename).decode(
                    "utf-8"))[0] + '.nfo'
            if xbmcvfs.exists(nfo_file):
                xbmcvfs.delete(nfo_file)
            dirs, files = xbmcvfs.listdir(
                xbmc.translatePath(parent_folder).decode("utf-8"))
            tvshow_nfo_file = xbmc.makeLegalFilename(
                os.path.join(
                    xbmc.translatePath(parent_folder).decode("utf-8"),
                    'tvshow.nfo'))
            # Remove tvshow_nfo_file only when is the last file (users have the option of removing even single seasons)
            if xbmcvfs.exists(tvshow_nfo_file) and not dirs and len(
                    files) == 1:
                xbmcvfs.delete(tvshow_nfo_file)
                # Delete parent folder
                xbmcvfs.rmdir(
                    xbmc.translatePath(parent_folder).decode("utf-8"))
            # Delete parent folder when empty
            if not dirs and not files:
                xbmcvfs.rmdir(
                    xbmc.translatePath(parent_folder).decode("utf-8"))
        except Exception:
            common.debug('Cannot delete {}, file does not exist'.format(
                exported_filename))
        common.remove_path(id_path, g.library(),
                           lambda e: e.keys() == ['videoid'])
        g.save_library()
示例#2
0
def remove_item(item_task, library_home=None):
    """Remove an item from the library and delete if from disk"""
    # pylint: disable=unused-argument, broad-except
    common.debug('Removing {} from library'.format(item_task['title']))
    if not is_in_library(item_task['videoid']):
        common.warn('cannot remove {}, item not in library'.format(
            item_task['title']))
        return
    id_path = item_task['videoid'].to_list()
    exported_filename = xbmc.translatePath(
        common.get_path(id_path, g.library())['file']).decode("utf-8")
    parent_folder = os.path.dirname(exported_filename)
    try:
        xbmcvfs.delete(xbmc.translatePath(exported_filename).decode("utf-8"))
        if not os.listdir(parent_folder):
            os.rmdir(parent_folder)
    except Exception:
        common.debug(
            'Cannot delete {}, file does not exist'.format(exported_filename))
    common.remove_path(id_path, g.library(), lambda e: e.keys() == ['videoid'])
    g.save_library()