2021-10-22, 03:37
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
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')