mendevi.utils

Provide simple tools.

Functions

best_profile(height, width)

Return the closest profile name.

compute_video_hash(videos)

Compute the checksum of the video.

get_pix_fmt(*args)

Alias to cutcutcodec func.

get_project_root()

Return the absolute project root folder.

get_rate_video(*args)

Alias to cutcutcodec func.

get_resolution(*args)

Alias to cutcutcodec func.

hash_to_signature(checksum)

Convert the md5 binary hash value into an urlsafe string.

signature_to_hash(signature)

Convert the string signature into the md5 checksum.

unfold_video_files(paths)

Explore recursively the folders to find the video path.

Details

mendevi.utils.best_profile(height: Integral, width: Integral) str[source]

Return the closest profile name.

mendevi.utils.compute_video_hash(videos: str | bytes | Path | Iterable[str | bytes | Path]) bytes | dict[Path, bytes][source]

Compute the checksum of the video.

For \(n\) hash of \(b\) bits, the proba of the colision \(C\) is \(p(C) = 1 - \left(\frac{2^k-1}{2^k}\right)^{\frac{n(n-1)}{2}}\).

The md5 hash uses \(b = 128\) bits. If we add one video per second durring 10 years, the proba of colision is about \(p(C) \approx 1.46*10^{-22}\).

That’s why the md5 hash is used to identify the video files.

Parameters

videospathlike or list[pathlike]

The single or set of video you want to compute the signature.

Returns

signatures

The md5 checksum of the video file. In the case of a multiple file, a dictionary containing the file and the hash is returned rather a single hash. If the file does not exists, return None.

mendevi.utils.get_pix_fmt(*args)[source]

Alias to cutcutcodec func.

mendevi.utils.get_project_root() Path[source]

Return the absolute project root folder.

Examples

>>> from mendevi.utils import get_project_root
>>> root = get_project_root()
>>> root.is_dir()
True
>>> root.name
'mendevi'
>>> sorted(p.name for p in root.iterdir())
['__init__.py', '__main__.py', ...]
>>>
mendevi.utils.get_rate_video(*args)[source]

Alias to cutcutcodec func.

mendevi.utils.get_resolution(*args)[source]

Alias to cutcutcodec func.

mendevi.utils.hash_to_signature(checksum: bytes) str[source]

Convert the md5 binary hash value into an urlsafe string.

Bijection of signature_to_hash().

Parameters

checksumbytes

The 128 bit binary hash value.

Returns

signaturestr

The 26 ascii [2-7a-z] symbols string of the converted checksum.

Examples

>>> from mendevi.utils import hash_to_signature
>>> hash_to_signature(b"\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\t\x98\xec\xf8B~")
'2qoyzwmpaczaj2mabgmoz6ccpy'
>>>
mendevi.utils.signature_to_hash(signature: str) bytes[source]

Convert the string signature into the md5 checksum.

Bijection of hash_to_signature().

Parameters

signaturestr

The 26 ascii [2-7a-z] symbols string of the converted checksum.

Returns

checksumbytes

The 128 bit binary hash value.

Examples

>>> from mendevi.utils import signature_to_hash
>>> signature_to_hash("2qoyzwmpaczaj2mabgmoz6ccpy")
b'\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\t\x98\xec\xf8B~'
>>>
mendevi.utils.unfold_video_files(paths: Iterable[str | bytes | Path]) Iterable[Path][source]

Explore recursively the folders to find the video path.

Parameters

pathslist[pathlike]

All the folders, files, glob or recursive glob expression.

Yields

filenamepathlib.Path

The path of the video.