Meta Editor
NzbMetaEditor
NzbMetaEditor(nzb: str)
Create an NzbMetaEditor instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nzb
|
str
|
NZB content as a string. |
required |
Raises:
Type | Description |
---|---|
InvalidNzbError
|
If the string cannot be parsed as valid XML. |
Note
This does not validate the given NZB.
Example
from nzb import NzbMetaEditor
text = '''
<?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">
<head>
<meta type="title">Big Buck Bunny - S01E01.mkv</meta>
<meta type="password">secret</meta>
<meta type="tag">HD</meta>
<meta type="category">TV</meta>
</head>
<file poster="John <nzb@nowhere.example>" date="1706440708" subject="[1/1] - "Big Buck Bunny - S01E01.mkv" 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>
'''
editor = NzbMetaEditor(text)
edited = editor.set(title="Big Buck Bunny").append(tags="1080p").to_str()
print(edited)
Source code in src/nzb/_core.py
append
append(
*,
passwords: Iterable[str] | str | None = None,
tags: Iterable[str] | str | None = None,
) -> Self
Append metadata fields to the existing metadata in the NZB.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
passwords
|
Iterable[str] | str
|
Password(s) for the NZB file. |
None
|
tags
|
Iterable[str] | str
|
Tag(s) associated with the NZB file. |
None
|
Returns:
Type | Description |
---|---|
Self
|
Returns itself. |
Source code in src/nzb/_core.py
clear
clear() -> Self
from_file
classmethod
remove
Remove a metadata field from the NZB. If the same field is present multiple times, this will remove them all.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
Literal['title', 'password', 'tag', 'category'] | str
|
The metadata field to remove. |
required |
Returns:
Type | Description |
---|---|
Self
|
Returns itself. |
Source code in src/nzb/_core.py
set
set(
*,
title: str | None = None,
passwords: Iterable[str] | str | None = None,
tags: Iterable[str] | str | None = None,
category: str | None = None,
) -> Self
Set metadata fields in the NZB. Provided fields are replaced entirely if they already exist. Fields that aren't provided remain unchanged.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
title
|
str
|
The title metadata field. |
None
|
passwords
|
Iterable[str] | str
|
Password(s) for the NZB file. |
None
|
tags
|
Iterable[str] | str
|
Tag(s) associated with the NZB file. |
None
|
category
|
str
|
Category of the NZB file. |
None
|
Returns:
Type | Description |
---|---|
Self
|
Returns itself. |
Source code in src/nzb/_core.py
to_file
Save the edited NZB to a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
StrPath
|
Destination path for saving the NZB. This will also create the path if it doesn't exist already. |
required |
overwrite
|
bool
|
Whether to overwrite the file if it exists, defaults to |
False
|
Returns:
Type | Description |
---|---|
Path
|
The path to the saved file. |
Raises:
Type | Description |
---|---|
FileExistsError
|
If the file exists and overwrite is |
Source code in src/nzb/_core.py
to_str
to_str() -> str
Return the edited NZB as a string.
Returns:
Type | Description |
---|---|
str
|
Edited NZB. |