def save_files(files, rename=False, on_finish=None):
    save = plugin.get_setting('save-files', int)
    if not save:
        on_finish()
        return
    src, dst = temp_path(), save_path()
    files_dict = {}
    for old_path in files:
        old_path = ensure_unicode(old_path)
        rel_path = os.path.relpath(old_path, src)
        new_path = os.path.join(dst, rel_path)
        if xbmcvfs.exists(new_path):
            if rename:
                if xbmcvfs.delete(old_path):
                    log.info("File %s deleted.", old_path)
            continue
        files_dict[old_path] = new_path
    if not files_dict:
        if on_finish:
            on_finish()
        return
    files_to_copy = {}
    if save != 2 or xbmcgui.Dialog().yesno(lang(30000),
                                           *lang(40162).split("|")):
        for n, old_path in enumerate(files):
            old_path = ensure_unicode(old_path)
            if old_path not in files_dict:
                continue
            new_path = files_dict[old_path]
            xbmcvfs.mkdirs(os.path.dirname(new_path))
            if rename:
                log.info("Renaming %s to %s...", old_path, new_path)
                if not xbmcvfs.rename(old_path, new_path):
                    log.info(
                        "Renaming failed. Trying to copy and delete old file..."
                    )
                    files_to_copy[old_path] = new_path
                else:
                    log.info("Success.")
            else:
                files_to_copy[old_path] = new_path
    if files_to_copy:
        copy_files(files_to_copy, delete=rename, on_finish=on_finish)
    elif on_finish:
        on_finish()
def ensure_path_local(path):
    path = xbmc.translatePath(path)
    if "://" in path:
        if sys.platform.startswith('win') and path.lower().startswith("smb://"):
            path = path.replace("smb:", "").replace("/", "\\")
        else:
            raise LocalizedError(33030, "Downloading to an unmounted network share is not supported",
                                 check_settings=True)
    return ensure_unicode(path)
Beispiel #3
0
def ensure_path_local(path):
    path = xbmc.translatePath(path)
    if "://" in path:
        if sys.platform.startswith('win') and path.lower().startswith("smb://"):
            path = path.replace("smb:", "").replace("/", "\\")
        else:
            raise LocalizedError(33030, "Downloading to an unmounted network share is not supported",
                                 check_settings=True)
    return ensure_unicode(path)
def save_path(local=False):
    path = plugin.get_setting('save-path', unicode)
    if path == plugin.get_setting('temp-path', unicode):
        raise LocalizedError(33032, "Path for downloaded files and temporary path should not be the same",
                             check_settings=True)
    if not direxists(path):
        raise LocalizedError(33031, "Invalid save path", check_settings=True)
    if local:
        path = ensure_path_local(path)
    return ensure_unicode(path)
def save_files(files, rename=False, on_finish=None):
    save = plugin.get_setting('save-files', int)
    if not save:
        on_finish()
        return
    src, dst = temp_path(), save_path()
    files_dict = {}
    for old_path in files:
        old_path = ensure_unicode(old_path)
        rel_path = os.path.relpath(old_path, src)
        new_path = os.path.join(dst, rel_path)
        if xbmcvfs.exists(new_path):
            if rename:
                if xbmcvfs.delete(old_path):
                    log.info("File %s deleted.", old_path)
            continue
        files_dict[old_path] = new_path
    if not files_dict:
        if on_finish:
            on_finish()
        return
    files_to_copy = {}
    if save != 2 or xbmcgui.Dialog().yesno(lang(30000), *lang(40318).split("|")):
        for n, old_path in enumerate(files):
            old_path = ensure_unicode(old_path)
            if old_path not in files_dict:
                continue
            new_path = files_dict[old_path]
            xbmcvfs.mkdirs(os.path.dirname(new_path))
            if rename:
                log.info("Renaming %s to %s...", old_path, new_path)
                if not xbmcvfs.rename(old_path, new_path):
                    log.info("Renaming failed. Trying to copy and delete old file...")
                    files_to_copy[old_path] = new_path
                else:
                    log.info("Success.")
            else:
                files_to_copy[old_path] = new_path
    if files_to_copy:
        copy_files(files_to_copy, delete=rename, on_finish=on_finish)
    elif on_finish:
        on_finish()
Beispiel #6
0
def save_path(local=False):
    path = plugin.get_setting('save-path', unicode)
    if path == plugin.get_setting('temp-path', unicode):
        raise LocalizedError(33032, "Path for downloaded files and temporary path should not be the same",
                             check_settings=True)
    if not direxists(path):
        raise LocalizedError(33031, "Invalid save path", check_settings=True)
    if local:
        path = ensure_path_local(path)
    path = path.strip("\\/")
    return ensure_unicode(path)