Reading Contents of RAR file for subtitle packages - Printable Version +- Kodi Community Forum (https://forum.kodi.tv) +-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32) +--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26) +--- Thread: Reading Contents of RAR file for subtitle packages (/showthread.php?tid=308853) |
Reading Contents of RAR file for subtitle packages - boogiepop - 2017-03-05 I am working on a subtitle addon and there are some subtitles packed by season in rar format. like subs.rar 1) s1e1.srt 2) s1e2.srt 3) s1e3.srt ... And the files in those packages do not have the same file as the playing video file. What i wan to do for those packages, is to read the contents of rar file, pop up a dialog.select() and let the user chose which subtitle he wants to use. This is OK for zipfiles but rar files dont have pure pythonic extraction. 1) If i directly use this rar file xbmc expects a file in the package which has the same name as the playing video file. So this approach is not working 2) I can read the contents of rarfile with xbmcvfs.listdir(path.to.rar) but i can not access the content inside the package like xbmcvfs.File("path.to.rar" + "/" + "subtitle.srt"). Is there anyway for this approach 3) Since i can not access the file is possible to hack player to change playing listitems path with same name as the selected subtitle. This is hacky and ugly i know but sounds like an option. 4) What does rar:// scheme stand for. Thanks. RE: Reading Contents of RAR file for subtitle packages - boogiepop - 2017-03-06 if i am not mistaken rar filesytem is called with Xbmcvfs.open("rar://strcachepath,strrarpath,strfilepathinrar,strpwd") May be, returned listitem path can ecactly accept rar:// url scheme as well, i will try asap, comment if im wrong ? RE: Reading Contents of RAR file for subtitle packages - boogiepop - 2017-03-06 previous post was the implementaion in 2004, here is the method for current implementation looking at the code /xbmc/filesystem/RarFile.cpp Code: void CRarFile::InitFromUrl(const CURL& url) test.py Code: rarfile = "my/path/to/archive.rar" This works, and i can read contents of RAR file. If anyone needs in future RE: Reading Contents of RAR file for subtitle packages - boogiepop - 2017-03-08 Here is another problem: when i xbmcvfs.listdir("rar://[path.to.file]/path.inside.rar"), on windows it opens and lists,contents however in android, it is trying to urlencode first [ char with %5B, and can not open. normally i use unicode urls, but tried conver to str with utf-8 still result is the same. What can be wrong here? I am stuck. tested in 16.0 in windows, 16.1 in android. Code: 23:11:29 T:18446744073042508080 WARNING: virtual bool XFILE::CRarDirectory::GetDirectory(const CURL&, CFileItemList&): rar lib returned no files in archive [, likely corrupt Code: uri = "%s://[%s]%s" % (ar, fname, path) RE: Reading Contents of RAR file for subtitle packages - ironic_monkey - 2017-03-09 remove the [] dude, that was just placeholder meaning 'url encode this bugger'. RE: Reading Contents of RAR file for subtitle packages - boogiepop - 2017-03-09 ok, ill try when i get back. but there is something i dont quite get. How does URL distguish below url? Quote:rar://dir1/dir2/archive.rar/archive/dir4/file.txt Quote:rarfile = /dir1/dir2/archive.rar or Quote:rarfile = /dir1/dir2/archive.rar/archive (assume that folder has . (archive.rar is a directory) and archive file does not have extension) and it is also weird that [path.to.rar] context works under windows but not under posix and encoded in file /xbmc/URL.cpp Code: void CURL::Parse(const std::string& strURL1) RE: Reading Contents of RAR file for subtitle packages - ironic_monkey - 2017-03-09 that's the whole point of the url encoding: rar://[url encoded path to archive]/[path in archive] this way, the archive is the *hostname* of your bog standard url interpretation. RE: Reading Contents of RAR file for subtitle packages - boogiepop - 2017-03-09 ah i udnerstand now, since path to archive is urlencoded there won't be "/"'s in it, thanks, this should, work, and there would be no need [, ] seperators. To be precise it should be processsed with urllib.quote_plus("my.path.to.arcvive") UPDATE: YES it works like rar://[url encoded path to archive]/[path in archive] without brackets ofc. RE: Reading Contents of RAR file for subtitle packages - ironic_monkey - 2017-03-09 yes, the , thingie was an old url format used before it was beat into shape. RE: Reading Contents of RAR file for subtitle packages - twilight0 - 2017-09-21 (2017-03-09, 15:19)boogiepop Wrote: ah i udnerstand now, since path to archive is urlencoded there won't be "/"'s in it, thanks, this should, work, and there would be no need [, ] seperators. To be precise it should be processsed with urllib.quote_plus("my.path.to.arcvive") quote_plus might raise errors, I found out that plain urllib.quote(uri) works better. RE: Reading Contents of RAR file for subtitle packages - twilight0 - 2017-09-22 (2017-09-21, 19:25)twilight0 Wrote:(2017-03-09, 15:19)boogiepop Wrote: ah i udnerstand now, since path to archive is urlencoded there won't be "/"'s in it, thanks, this should, work, and there would be no need [, ] seperators. To be precise it should be processsed with urllib.quote_plus("my.path.to.arcvive") Correcting myself, after some tests, it appears that windows os requires quote while unix-like platforms require quote_plus. |