nxtools is a set of various tools and helpers used by Nebula and other software.
Warning nxtools 2 (current develop) is not compatible with nxtools 1.x.
pip install nxtools
unidecode
for full unicode transliterationcolorama
for colored log output even on Windows
CasparCG client object
Caspar query response object
An object representing a file on the filesystem.
The class provides a number of utility methods and properties for easy access to file metadata.
Log an error message and exit program.
Convert a YYYY-MM-DD
string to an unix timestamp.
By default, start of the day (midnight) is returned.
Args:
datestr (str):
`YYYY-MM-DD` string
hh (int):
Hour (default: 0)
mm (int):
Minute (default: 0)
ss (int):
Second (default: 0)
Returns:
int:
Parsed unix timestamp
Convert frames to an SMPTE timecode
Args:
frames (int):
Frame count
base (float):
Frame rate (default: 25)
Returns:
str:
SMPTE timecode (`HH:MM:SS:FF`)
FFMpeg wrapper with progress and error handling
Args:
*args (list[any]):
List of ffmpeg command line arguments.
Each argument is converted to a string.
progress_handler (function):
Function to be called with the current position (seconds) as argument.
stdin (file):
File object to be used as stdin.
Default is subprocess.PIPE
stdout (file):
File object to be used as stdout.
Default is None
stderr (file):
File object to be used as stderr.
Default is subprocess.PIPE (used to compute progress).
debug (bool):
Enable debug mode (write ffmpeg output to stderr).
Returns:
boolean: indicate if the process was successful
Extract metadata from a media file using ffprobe and returns a dictionary object with the result
Args:
input_file (str):
Path to the media file
verbose (bool):
Log the ffprobe command. Default is False
Returns:
dict: metadata
Attempt to un-slugify a file name
Aspect ratio convertor. you must specify output size and source aspect ratio (as float)
Yadif deinterlace
Attempt to find a given executable and return its path
Args:
file_name (str): The name of the executable to find
Returns:
str: The path to the executable
Return a human readable filesize for a given byte count
Format an Unix timestamp as a local or GMT time
Args:
timestamp (int):
input unix timestamp
time_format (str):
strftime specification
(default: "%Y-%m-%d %H:%M:%S" - the correct one)
never_placeholder (str):
text used when timestamp is not specified (default: "never")
gmt (bool):
Use GMT time instead of local time (default: False)
Returns:
str:
Formatted time
Strip a directory and extension from a given path.
/etc/foo/bar.baz
becomes bar
Args:
file_name (str): path-like object, string or FileObject
Returns:
str
Crawl a given directory
For each file found in base_path
yield a FileObject object.
Args:
base_path (str):
Path to the directory to be crawled
recursive (bool):
Crawl recursively (default: False)
hidden (bool):
Yield hidden (dot)files too (default: False)
exts (list):
If specified, yields only files matching given extensions
case_sensitive_exts (bool):
Do not ignore cases when `exts` list is used (default: False)
Return a GUID
Returns: str: GUID
For each file found in input_dir
and yield a tuple of (input_path, output_path)
This function is useful for batch conversion, when you need to process files
from input_dir
and output the result to output_dir
.
Most arguments are the same as for get_files
. You can also specify a target extension,
and use a slugifier for the output path.
Args:
target_ext (str):
target_slugify (bool): (default: False)
Return a path to a temporary file
Args:
extension (str)
root (str)
Indent a multi-line text
Joins multiple filters
Log the current exception traceback
Convert seconds to an SMPTE timecode
Args:
secs (float):
Number of seconds
base (float):
Frame rate (default: 25)
Returns:
str:
SMPTE timecode (`HH:MM:SS:FF`)
Convert seconds to time
Args:
secs (float):
show_secs (bool):
Show seconds (default: True)
show_fracs (bool):
Show centiseconds (default: True)
Returns:
str:
`HH:MM` / `HH:MM:SS` / `HH:MM:SS.CS` string
Create a textual (english) representation of given number of seconds.
This function is useful for showing estimated time of a process.
Args:
secs (int):
Number of seconds
Returns:
str:
Textual information
Slugify a text string
This function removes transliterates input string to ASCII, removes special characters and use join resulting elemets using specified separator.
Args:
input_string (str):
Input string to slugify
separator (str):
A string used to separate returned elements (default: "-")
lower (bool):
Convert to lower-case (default: True)
make_set (bool):
Return "set" object instead of string
min_length (int):
Minimal length of an element (word)
slug_whitelist (str):
Characters allowed in the output
(default: ascii letters, digits and the separator)
split_chars (str):
Set of characters used for word splitting (there is a sane default)
Generate more or less unique color for a given string
Convert an SMPTE timecode (HH:MM:SS:FF) to number of seconds
Args:
tc (str):
Source timecode
base (float):
Frame rate (default: 25)
Returns:
float:
Resulting value in seconds
Remove accents and/or transliterate non-ascii characters
Parse an XML string using ElementTree
Args:
data (str): The XML document to parse
Returns:
ElementTree.Element: The root element of the parsed XML string