I’m developing an addon for my personal usage and I need to extract a rar archive via this script.
So I’ve installed unrar on CE (via ENTWARE package).
I connect via SSH and verified that unrar is well installed and is working fine.
Now, back in my script, I’m calling unrar via subprocess.call():
result = subprocess.Popen(“unrar e /source/to/my/rar/archive.rar /my/target/dir/”, shell=True, stdout=subprocess.PIPE).stdout.read()
log(sys._getframe().f_code.co_name, result)
but nothing happened and result is empty.
So I verify if unrar command exist by doing:
result = subprocess.Popen(“type unrar”, shell=True, stdout=subprocess.PIPE).stdout.read()
log(sys._getframe().f_code.co_name, result)
And this type, result return: unrar: not found
so I found the solution:
result = subprocess.Popen(“/opt/bin/unrar e /source/to/my/rar/archive.rar /my/target/dir/”, shell=True, stdout=subprocess.PIPE).stdout.read()
But now I’m facing another issue:
My rar file contains files with non ASCII characters and when using unrar in subprocess.Popen() fails as these characters are not properly recognized.
For example, the rar archive contains a file:
xxxx.简体.srt
When I try to extract it, i got:
xxxx.??.srt
Program aborted
(I have no problem extracting the file via ssh => non ASCII characters are well recognized)
Thanks, I will investigate, it’s surely an encoding/decoding issue.
When i run locale via ssh, everything is set to UTF-8 (which is good), but when i run the same command in subprocess, everything is POSIX, which is may the root cause. So I need to figure out how to run subprocess in UTF-8…
I need to install Locale addon to get UTF-8 support.
Then I installed System-tools addon which includes newer unrar program than entware.
And with unrar from addon I could unpacked provided sample file.
How do you run Python script? I run it in ssh and there it works.
which version is your unrar ? mine is 5.61
I have no issue extracting my file via ssh. It’s really when i run unrar cmb in subprocress.call() in python.
The python script is actually a kodi subtitle addon i’m writting for myself. So the script is called via kodi interface (video OSD).
result = subprocess.Popen(“unrar x -o+ /storage/downloads/python/subtitles.rar /storage/downloads/python/unpacked/”, shell=True, stdout=subprocess.PIPE).stdout.read()
Did you installed Locale addon? And which CE version you are using?
You don’t need entware packages for this.
Unrar is in CoreELEC System-tools addon and locales are in Locale addon. After reboot your python script should unpack .rar file successfully.