Bug XBMC.Extract
#31
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.

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
Reply
#32
Still trying to fix service.subtitles.legendastv ...

The goal is to extract zip or rar files with subtitles that, sometimes, could be inside directories.

I've managed to make it work with vfs.libarchive 1.0.5 on Leia (18.2) on Windows, using the above extract_all_libarchive (thank you very much @zachmorris !)
But the same code didn't work on Android (MiBox) and LibreElec (RPi)

The xbmcvfs.listdir throws:
Code:
GetDirectory - Error getting archive://storage/.kodi/userdata/addon_data/service.subtitles.legendastv/temp/5bcdcef91b7f4e3ab28efc2dddd4a5d9.rar

I’ve tried to read some other threads with similar problems but they point to different solutions: reboot, use vfs.libarchive combined with vfs.rar or never use both together, install additional O.S. packages, use external command line programs..,

And now I’m confused!

Please, can anyone answer these questions to help me understand:

1- Is vfs.libarchive 1.0.5 supposed to work on all systems to extract zip/rar with directories?
2- Is so, is there any additional installation/configuration besides the installation of the addon from Kodi repo?
3- Is reboot required? (didn’t fix on Android)
4- Do I need vfs.rar if I only use archive:// urls on extract_all_libarchive? Is there any change on xbmcvfs.listdir or copy behavior ? (I guess not but people said otherwise on other threads)
Reply
#33
Got it!!

The problem was at the URL quote function
I was using urllib.quote and it only worked on Windows.
Changed to urllib.quote_plus and now it works on all systems!


Guess I'll answer my own questions...
 
Quote:1- Is vfs.libarchive 1.0.5 supposed to work on all systems to extract zip/rar with directories?

Yes!!!

 
Quote:2- Is so, is there any additional installation/configuration besides the installation of the addon from Kodi repo?
 
No. Everything works out of the box. Just install "Archive Support" from Kodi oficial repo
 
Quote:3- Is reboot required? (didn’t fix on Android)
 
No
 
Quote:4- Do I need vfs.rar if I only use archive:// urls on extract_all_libarchive? Is there any change on xbmcvfs.listdir or copy behavior ? (I guess not but people said otherwise on other threads)
 
No.
Reply
#34
(2019-05-15, 03:04)henricos Wrote: Got it!!

The problem was at the URL quote function
I was using urllib.quote and it only worked on Windows.
Changed to urllib.quote_plus and now it works on all systems!

Good deal, I updated the code to make that clear
Reply
 
Thread Rating:
  • 0 Vote(s) - 0 Average



Logout Mark Read Team Forum Stats Members Help
XBMC.Extract00