#parser #usenet #nzb

nzb-rs

A spec compliant parser for NZB files

6 releases

new 0.4.2 Jan 29, 2025
0.4.1 Jan 28, 2025
0.3.1 Jan 23, 2025
0.2.0 Jan 20, 2025
0.1.3 Jan 19, 2025

#601 in Parser implementations

Download history 123/week @ 2025-01-15 820/week @ 2025-01-22

943 downloads per month

MIT/Apache

30KB
407 lines

nzb-rs

Tests Latest Version Documentation License

nzb-rs is a spec compliant parser for NZB files.

This library is a partial port of the Python nzb library.
While the parser API is similar to the original, it is not identical. Additionally, the meta editor API has not been implemented.

Installation

To install nzb-rs, add the following to your Cargo.toml:

[dependencies]
nzb-rs = "0.4.1"

Optional features:

  • serde: Enables serialization and deserialization via serde.

Example

The heart of this library is the Nzb::parse method, which handles parsing NZB files into structured data.

use nzb_rs::{InvalidNzbError, Nzb};

fn main() -> Result<(), InvalidNzbError> {
    let xml = r#"
        <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE nzb PUBLIC "-//newzBin//DTD NZB 1.1//EN" "http://www.newzbin.com/DTD/nzb/nzb-1.1.dtd">
        <nzb
            xmlns="http://www.newzbin.com/DTD/2003/nzb">
            <file poster="John &lt;nzb@nowhere.example&gt;" date="1706440708" subject="[1/1] - &quot;Big Buck Bunny - S01E01.mkv&quot; yEnc (1/2) 1478616">
                <groups>
                    <group>alt.binaries.boneless</group>
                </groups>
                <segments>
                    <segment bytes="739067" number="1">9cacde4c986547369becbf97003fb2c5-9483514693959@example</segment>
                    <segment bytes="739549" number="2">70a3a038ce324e618e2751e063d6a036-7285710986748@example</segment>
                </segments>
            </file>
        </nzb>
        "#;
    let nzb = Nzb::parse(xml)?;
    println!("{:#?}", nzb);
    assert_eq!(nzb.file().name(), Some("Big Buck Bunny - S01E01.mkv"));
    Ok(())
}

Safety

  • This library must not panic. Any panic should be considered a bug and reported.
  • This library uses roxmltree for parsing the NZB. roxmltree is written entirely in safe Rust, so by Rust's guarantees the worst that a malicious NZB can do is to cause a panic.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~4–6MB
~102K SLoC