Kodi Community Forum

Full Version: how to extract zips on kodi?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
how to extract zips in kodi either by script or command?, i need it to be compatible with kodi 18.9 and 19.2 Matrix

Edit: it was suffered but I found it

Code:

import six
from kodi_six import xbmc, xbmcvfs, xbmcgui, xbmcplugin, xbmcaddon
try:
    from urllib.parse import urlparse, parse_qs, quote, unquote, quote_plus, unquote_plus, urlencode #python 3
except ImportError:    
    from urlparse import urlparse, parse_qs #python 2
    from urllib import quote, unquote, quote_plus, unquote_plus, urlencode


def unzip(path, dest, format):
    path = quote_plus(path)
    root = format + '://' + path + '/'
    dirs, files = xbmcvfs.listdir(root)
    if dirs:
        unzip_recursive(root, dirs, dest)
    for file in files:
        if six.PY3:
            unzip_file(os.path.join(root, file), os.path.join(dest, file))
        else:
            unzip_file(os.path.join(root, file.decode('utf-8')), os.path.join(dest, file.decode('utf-8')))

def unzip_recursive(path, dirs, dest):
    for directory in dirs:
        if six.PY3:
            dirs_dir = os.path.join(path, directory)
            dest_dir = os.path.join(dest, directory)
        else:
            dirs_dir = os.path.join(path, directory.decode('utf-8'))
            dest_dir = os.path.join(dest, directory.decode('utf-8'))            
        xbmcvfs.mkdir(dest_dir)

        dirs2, files = xbmcvfs.listdir(dirs_dir)

        if dirs2:
            unzip_recursive(dirs_dir, dirs2, dest_dir)
        for file in files:
            if six.PY3:
                unzip_file(os.path.join(dirs_dir, file), os.path.join(dest_dir, file))
            else:
                unzip_file(os.path.join(dirs_dir, file.decode('utf-8')), os.path.join(dest_dir, file.decode('utf-8')))

def unzip_file(path, dest):
    ''' Unzip specific file. Path should start with zip://
    '''
    xbmcvfs.copy(path, dest)

Example:
    file = path+'/file.zip'
    if file.endswith(".zip"):
        unzip('path_zip','destination','zip')
    elif file.endswith(".rar"):
        unzip('path_rar','destination','rar')

(2021-10-22, 03:37)mitomitoso Wrote: [ -> ]i need it to be compatible with kodi 18.9 and 19.2 Matrix

In case you didn't know, Kodi 18 and 19 each support a different Python version. That could be important, but I'm not sure at this point.
Other than that, which type of files in zips does Kodi need to extract?
(2021-10-22, 08:14)Klojum Wrote: [ -> ]
(2021-10-22, 03:37)mitomitoso Wrote: [ -> ]i need it to be compatible with kodi 18.9 and 19.2 Matrix

In case you didn't know, Kodi 18 and 19 each support a different Python version. That could be important, but I'm not sure at this point.
Other than that, which type of files in zips does Kodi need to extract?

could show me separately, I have a subtitle addon that I'm making compatible with kodi 18.9 and 19.2 using "kodi-six" and "six" modules, I need code to extract .zip and another to extract .rar
(2021-10-22, 08:14)Klojum Wrote: [ -> ]
(2021-10-22, 03:37)mitomitoso Wrote: [ -> ]i need it to be compatible with kodi 18.9 and 19.2 Matrix

In case you didn't know, Kodi 18 and 19 each support a different Python version. That could be important, but I'm not sure at this point.
Other than that, which type of files in zips does Kodi need to extract?
I already found it, tank you
(2021-10-22, 23:49)mitomitoso Wrote: [ -> ]I already found it, tank you

Perhaps you can also outline the solutions in case others have the same problem.