• 1(current)
  • 2
  • 3
  • 4
  • 5
  • 10
Starting development on NZB support for XBMC
#1
Information 
Hi,

I have started development on adding support for nzb files to xbmc and hope to have something resembling a working prototype in the next week.

I have done some exploritory work and believe that i can make it work.

Will be implimented as CFileNzb / CNzbDirectory (with supporting classes) types and submitted as a patch to those who are interested... hopefully presuming it works and gets stable, it will make it into trunk.

Scope:
- open an nzb file from a supported url/path (probably typically being initiated from a python script which is outside the scope of what i am doing)
- treat an nzb file as a directory (similar to rar) listing contents of nzb using file mask (if just 1 media file, just play it... maybe take setting from rar setting/behaviour)
- Streaming a file from within an nzb is done by opening a url in the following format (similar to rar):
sample url: nzb://http%3a%2f%2fx.y.com%2fdir%2fnzbfile.nzb/SubjectOfFileToDownloadFromNZB.avi (URL Encoded Part = http://x.y.com/dir/nzbfile.nzb)

- stream media content in nzb file via nntp
- yDecode, etc on the fly (part by part - generally < parts 500k i think so doable)
- rar files?? see section on Issues i really don't know about yet
- the idea is that this a streaming solution - not downloading
- this will not save downloaded content anywhere (except maybe temp files - see below)
- might need to save yenc parts temporarilly on HD to avoid taking up too much RAM if there will be a couple of threads downloading
- Settings page for nntp settings (maybe incl. number of threads to run - or maybe better to derive number of threads from size of internet streaming cache/nzb/yEnc part size, or possibly hard code to 2 (current/next) )

Not in Scope
- I will not be creating any nzb site scraper type thing for the moment, although this functionality will rely on a python script like this to really be useful
- This is not a download tool like the SABnzb script, etc.... it's more of a filesystem/driver type thing. The SABnzb script could probably be modified however to use this instead of SABnzb. (i don't know any python however but it could be a nice learning project! Smile )

Issues i think i can solve:

- NZB files can list rar parts in any old order - need to sort to download in correct order to stream
- NNTP isn't supported by cUrl... need to write this (nntp is easy tho so shouldn't be difficult i hope Wink )
- Need to store nntp server and authentication details somewhere - will probably add this to settings page (or is this a source?)
- After a part is downloaded, it needs to be decoded... this could make for a skip if multi-threading isn't used for parts (and buffer isn't big enough)

Issues not thought out fully / tested / know about yet (feedback appreciated Smile ):

- Broken/incomplete usenet posts are common; hence the existance of par files. Seeking will probably not be an option day 1 so a broken post will result in playback stopping and it being impossible to seek to your original position... maybe can detect broken posts/parts and skip forward to next rar / part, making for a jump and some lost viewing time... suspect any fix/workaround will not be in initial release!
- Using temp files feels like a nice solution for allowing CFileRar, etc to handle streamed rar files... i understand that CFileRar needs a real file handle for the underlying magic to be able to work. My initial thought was that streaming really means no temp files but there seems to be a lot of positive reasons for using temp files
- yEnc parts need to be downloaded in full before they can be decoded so we will never be streaming raw data from the internet but rather downloading a 500k part (size is an example), decoding that part, unraring that part (as part of a bigger rar file & set) and passing decoded & unrared bytes to the mplayer buffer
- if a rar file can be written to and read from at the same (ish) time, this will work (don't know if locking will be a problem with this, but i know xbmc can play partial rars) (this might be a long shot) (can always download and play full rar files (usually 15mb/file)- but this hardly qualifies as streaming... but it would work ok!
- temp files would also solve how to handle multi-part archives
- CFIleNzb would contain and manage a CFile member pointing to the the temp file
- This would make the nzb support much more managable by not duplicating portions of the rar support specifically for unraring in memory within the nzb code. The issues surrounding unraring in memory (and handling multi-part, etc) sound complicated so would be nice to side step that one!! Smile
- this would probably require a minimum of 30MB of space for temp files (for current and next rar)
- Not using temp files implies the following
- need enough ram available for two downloaded parts & whatever it takes to decode and unrar (part size could vary)
- need to impliment code to unrar from memory, either by extending CFileRar or using RarManager / unrar dlls directory (not sure exactly what this will take)... this feels like a complicated coding job & would result in duplication of some functionality surrounding rar files = not too managable
- Many NZB sites use cookie authentication and/or get/post variables to access an nzb... need to be able to work with/around this somehow while staying nzb site neutral (haven't looked at how to manage this at all yet... may or may not already be addressed somewhere else for another application... pointers appreciated)
- Rar file recursion, etc... need to figure out how to handle rar files in rar files, etc and exceptions to the norm of rar files containing avi/mp3 files, etc...

I spoke briefly with cptspiff in the IRC channel about this functionality and he mentioned that to his knowledge, this has not been done before; and in particular that it had not been tried and failed for a good reason... if i'm wasting my time here, please let me know!

As i've been writing this, i've been figuring out things, and figuring out that there's a lot i don't know! If there are stupid statements above, or things which just miss the point, please let me know but be gentle!! Hopefully, i'll get this working and it will be a useful addon! Smile

Regards,
Patrick
Reply
#2
You really are going for it arent you..I've replied to your other thread by the way...Good Luck
Server: FreeNas 9 NAS: 6*3TB - Kodi Sql Database
Kodi Systems: Nvidia Shield Pro, G-Box Q (OpenElec), RikoMagic MK802 IV[
Skin: reFocus
Reply
#3
This would be an awsome addition. Once this is implemented i could help you with the python!
Reply
#4
thanks guys!

hopefully i'm not full of crap and will follow through and get this done! hehe Big Grin

I'll keep this thread up to date with progress anyway...

To date, i've implimented the CFileNzb and CNzbDirectory classes, adding the necessary code to the factory classes (for nzb:// support), etc to open an nzb file using the CFile class and inbuilt xml libraries and list the files in it like a directory. have also implimented the stub for opening the files within the nzb... the Open method, etc just quit immediately until i can get the magic behind this working (i.e. they return false).

Separately, i can download articles from newsgroups using a telnet session and understand how it works. Should be a relatively easy bit of socket programming to download the parts of an nzb.

I also got a c function for yDecoding (http://www.yenc.org/ydecode-c.txt) which is the next step to get working!

Am thinking at this point that for a first release, whether or not its possible to stream from RAM, i'll be saving temp files on the HD to open with CFile and play from there. i still have my fingers crossed that i'll be able to save on the HD, and read from the same file at the same time... worst case scenario if i can't do that is that playback starts when the first full rar is down. for a first version at least, i can live with that.

Lots of fun! Smile

Patrick
Reply
#5
oh yeah - and i got my debugger working... sooooooo cool the way it works! could spend ages watching the xbox watson thing Smile (very sad i know)
Reply
#6
I think you do have to have atleast the first rar complete to be able to open it.
Server: FreeNas 9 NAS: 6*3TB - Kodi Sql Database
Kodi Systems: Nvidia Shield Pro, G-Box Q (OpenElec), RikoMagic MK802 IV[
Skin: reFocus
Reply
#7
Having to have the first rar completed to start is not that bad!
Reply
#8
I certainly think i can live with downloading complete rar files for a first release... I've rarely noticed an nzb posting for media content with a rar size of larger than 15mb... i have a 3Mb link at home so should only take a couple of minutes to get started playing... and z: can handle 30MB (this is an assumption really). hopefully, the second file would be downloaded and yDecoded before the first one is finished.. it couldn't possibly be a long wait though.

giganews always maxes out my pipe, and the pipe is often (anecdotally) about twice the spead of the avi stream requres.

Regards progress, i've started porting a line based socket class on top of which which i'll impliment an NNTP class (but it could be used for other line based socket things too - SMTP, TELNET, etc).

Am writing the NNTP part primarally (rather than simply porting) in order to allow downloading the first couple of lines of an article, to find out the name of the attachment file in the post (and then abort), in order to give a accurate file listing from an NZB. The hint in the header to get the name of the file in the post is the subject (which is in the NZB anyway). The only thing that can be trusted about the subject is that it must contain the text yEnc... filenames, etc while usually provided accurately are at the discression of the user and/or their usenet posting software.

I'm not sure what to do about other encodings... from my experience, i have only ever seen yEnc used for media so i'm going to focus primarally on that... but i will abstract the support to some extent to make adding more encodings at least some bit managable in the future.
Reply
#9
What are you going to do about the problem of corrupted files ? I don't think on-the-fly reparing with those .PAR files is possible and it is pretty common to have those. The only thing that might work would be checking the new rar files that are incoming on the fly and repair them before the playing video gets to the point where it needs them - but that doens't really seem feasonable, and I could imagine that is needs alot of memory/cpu time.
Reply
#10
I suspect that repairing using par files will just be a non-starter for a couple of reasons...

1) you need enough blocks from the whole set for the par maths to work so, you need practically the whole movie downloaded to do any type of repair so it really doesn't fit in with

2) i believe (but i stand ready to be corrected on this) that restoring using par files uses some heavy maths. I don't know for sure if the main burdon of processing pars is on disk io, or cpu usage (or ram) but i would have a concern that an xbox might not have the power for it.

For now, i am going to ignore the problem until i have something functional and playing streams from nzbs. Hopfeully any python scripts that use this functionality will be able to identify from the nzb sites they reference when a set is corrupted. (from user feedback identifying such posts).

Maybe in the future, it will be possible to identify incomplete rars, etc and still keep the stream playing, with a skip, or black screen or something. I'm still a bit sketchy tho on the exact internal mechanics of how xbmc moves from one rar part to another, and i know nothing about the internal composition of avi files to allow something like this... i've kinda decided for the sake of my sanity not to think about this until the nntp & yenc stuff can stream one working rar/avi from nntp and play it... i'll then see if there is just some magic in the background that will use CFile factory to open the next file in the set from the nzb:// filesystem without my having to code anything in particular. (CFileCurl, etc seem to manage like this afaik)

Hopefully broken posts won't be a complaint that will make this unusable. It would be cool if a python script that used an nzb listing site could post back information about broken posts automatically, thereby stopping others from downloading the same broken script. (i think most sites allow feedback about nzb posts) woudl need to account for posts that are just incomplete because they are not fully uploaded/propogated yet tho.
Reply
#11
Yeah, it's probably the best thing to just not worry about it until you have something working Smile Good luck to you Big Grin
Reply
#12
I think for the scope of this project should be just getting the streaming to work ASSUMING that the rar files are complete. It should be up to the python script to do the rest. I think if you can get that done that would be one of the bigger improvements to xbmc in a LONG time! I definitely think that this would be a huge asset to xbmc.
Reply
#13
Many movies I download are 50mb in size, just for your info.
(And in my experience, about 1/3 of the posted media is corrupted and needs repairing).


Rgs H2Deetoo,
Reply
#14
thanks for the support nate!!

Things are moving along btw.. the nzb parsing stuff is done now and im working on the nntp stuff. Has been a while since i did anything with c++ sockets so is a bit of a learning curve but im getting there! i think that i might be in a position today to actually play a video from an nzb... it won't be pretty tho!
Reply
#15
H2Deetoo Wrote:Many movies I download are 50mb in size, just for your info.

Yeah - you're right,.. a lot of them do seem to be 50MB.

Thinking more about it, maybe it will be possible to just save individual decoded yEnc parts as seperate temp files on the HD, and somehow manipulate a filepointer to load from the parts while looking like its loading from a rar (or whatever)... This type of solution brings the NZB support back to (practically) streaming the content no matter what the size of the content being downloaded is. Each yEnc part is only a couple of hundred kilobytes usually so content can be available to mplayer in a couple of seconds!

I think this will work.... so for the moment, i'm going to proceed using this method... fingers crossed!
Reply
  • 1(current)
  • 2
  • 3
  • 4
  • 5
  • 10

Logout Mark Read Team Forum Stats Members Help
Starting development on NZB support for XBMC1