mendevi.utils¶
Provide simple tools.
Functions
|
Return the closest profile name. |
|
Compute the checksum of the video. |
|
Copy the file into /dev/shm is there is enougth free space, otherwise in /tmp. |
|
Alias to cutcutcodec func. |
Return the absolute project root folder. |
|
|
Alias to cutcutcodec func. |
|
Alias to cutcutcodec func. |
|
Convert the md5 binary hash value into an urlsafe string. |
|
Convert the string signature into the md5 checksum. |
|
Explore recursively the folders to find the video path. |
|
Return a uniform floating-point number between [0 and 1[. |
Details
- mendevi.utils.best_profile(height: Integral, width: Integral) str[source]
Return the closest profile name.
Examples¶
>>> from mendevi.utils import best_profile >>> best_profile(1080, 1920) 'fhd' >>>
- mendevi.utils.compute_video_hash(videos: str | bytes | Path | Iterable[str | bytes | Path], *, fast: bool = True) 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.
- fastboolean, default=True
If the hash appears in the file name, it is returned immediately. If False, the actual checksum is systematically recalculated.
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.cp_shm(file: Path, threshold: float) Path[source]
Copy the file into /dev/shm is there is enougth free space, otherwise in /tmp.
- 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.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~") 'd41d8cd98f00b204e9800998ecf8427e' >>>
- 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("d41d8cd98f00b204e9800998ecf8427e") b'\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\t\x98\xec\xf8B~' >>> signature_to_hash("2qoyzwmpaczaj2mabgmoz6ccpy") # mendevi < 1.2.2 b'\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\t\x98\xec\xf8B~' >>>