2019-02-21, 01:17
Edit. I figured out that Kodi is looking for a trailing slash in the directory stucture.
For anyone else interested, here is an 'extract all' python code for use with libarchive. This code expects you have installed 'Archive Support' (vfs.libarchive) addon from the Kodi repository.
For anyone else interested, here is an 'extract all' python code for use with libarchive. This code expects you have installed 'Archive Support' (vfs.libarchive) addon from the Kodi repository.
python:
from urllib import quote_plus as url_quote
def extract_all_libarchive(archive_file,directory_to):
overall_success = True
files_out = list()
if 'archive://' in archive_file:
archive_path = archive_file
else:
archive_path = 'archive://%(archive_file)s' % {'archive_file': url_quote(xbmc.translatePath(archive_file))}
dirs_in_archive, files_in_archive = xbmcvfs.listdir(archive_path)
for ff in files_in_archive:
file_from = os.path.join(archive_path,ff).replace('\\','/') #Windows unexpectedly requires a forward slash in the path
success = xbmcvfs.copy(file_from,os.path.join(xbmc.translatePath(directory_to),ff)) #Attempt to move the file first
if not success:
xbmc.log(msg='Error extracting file %(ff)s from archive %(archive_file)s' % {'ff': ff,'archive_file':archive_file}, level=xbmc.LOGDEBUG)
overall_success = False
else:
xbmc.log(msg='Extracted file %(ff)s from archive %(archive_file)s' % {'ff': ff,'archive_file':archive_file}, level=xbmc.LOGDEBUG)
files_out.append(os.path.join(xbmc.translatePath(directory_to),ff))
for dd in dirs_in_archive:
if xbmcvfs.mkdir(os.path.join(xbmc.translatePath(directory_to),dd)):
xbmc.log(msg='Created folder %(dd)s for archive %(archive_file)s' % {'dd': os.path.join(xbmc.translatePath(directory_to),dd,''),'archive_file':archive_file}, level=xbmc.LOGDEBUG)
files_out2, success2 = extract_all_libarchive(os.path.join(archive_path,dd,'').replace('\\','/'),os.path.join(directory_to,dd))
if success2:
files_out = files_out + files_out2
else:
overall_success = False
else:
overall_success = False
xbmc.log(msg='Unable to create the folder %(dir_from)s for libarchive extraction' % {'dir_from': os.path.join(xbmc.translatePath(directory_to),dd)}, level=xbmc.LOGDEBUG)
return files_out, overall_success