framefile
Python library for parsing and matching file name patterns like IMG_####.JPG or
IMG_%04d.JPG.
Such files are often created by cameras and video production software.
As a rule, this is a set of images with consecutive numbers,
like IMG_0001.JPG, IMG_0002.JPG, IMG_0003.JPG and so on.
To handle files such as video sequences, Blender
and AE use patterns like
IMG_####.JPG. ffmpeg uses patterns like
IMG_%04d.JPG.
This package can create and parse patterns in both formats.
Install
pip3 install framefile
other options
Install pre-release from GitHub:
pip3 install git+https://github.com/rtmigo/framefile_py@staging#egg=framefile
Use
Guess pattern from file name
from framefile import filename_to_pattern, Format
print(filename_to_pattern(Format.hash, "IMG_4567.JPG")) # IMG_####.JPG
print(filename_to_pattern(Format.percent, "IMG_4567.JPG")) # IMG_%04d.JPG
Any names with numbers in them are supported. The path can also be part of the file name.
from framefile import filename_to_pattern, Format
print(filename_to_pattern(Format.hash, "/video/frame-01234.png"))
# /video/frame-#####.png
If there are several number sequences in the file name, only the last of them will be considered a pattern. And only if its length is more than one digit.
from framefile import filename_to_pattern, Format
print(filename_to_pattern(Format.hash, "/video/take505_frame01234.cr2"))
# /video/take505_frame#####.cr2
Guess pattern from directory path
The directory_to_pattern function returns the most common file name pattern
found in particular directory.
from pathlib import Path
from framefile import directory_to_pattern, Format
print(directory_to_pattern(Format.hash, Path("/path/to/my_timelapse")))
# /path/to/my_timelapse/img####.jpg
print(directory_to_pattern(Format.percent, Path("/path/to/my_timelapse")))
# /path/to/my_timelapse/img%04d.jpg
Find files by pattern
import glob
import framefile
# print all files matching /path/to/img####.jpg
file_mask = framefile.hash_pattern_to_glob('/path/to/img####.jpg')
print(glob.glob(file_mask))
# print all files matching /path/to/img%04d.jpg
file_mask = framefile.pct_pattern_to_glob('/path/to/img%04d.jpg')
print(glob.glob(file_mask))
Match file names as strings
import re
import framefile
regex = framefile.hash_pattern_to_regex('img####.jpg')
# or framefile.pct_pattern_to_regex('img%04d.jpg')
a = re.match(regex, 'img0023.jpg')
print(a.group(0)) # img0023.jpg
print(a.group(1)) # 0023
b = re.match(regex, 'anything.txt')
print(b) # None
Extract number from file name
import framefile
x: int = framefile.hash_extract_number("img####.jpg", "img0023.jpg")
print(x) # 23
y: int = framefile.pct_extract_number("img%04d.jpg", "img0023.jpg")
print(y) # 23
If the name does not match the pattern, both functions throw the same PatternMismatchError.
import framefile
try:
z = framefile.hash_extract_number("img####.jpg", "thumbs.db")
except framefile.PatternMismatchError:
print("Oops!")
Metadata
Release files for framefile 0.0.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| framefile-0.0.9.tar.gz | 5.5 kB | Without provenance | Details for framefile-0.0.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| framefile-0.0.9-py3-none-any.whl | Python 3 | none | any | Details for framefile-0.0.9-py3-none-any.whl |
Total release size: 11.7 kB
Release files / framefile-0.0.9.tar.gz
| Download URL | framefile-0.0.9.tar.gz |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7fbab08c12ec90846356880bbda1b16064aaf278a290542ee6a782284c5cd729
|
|
BLAKE2b-256 checksum How to use checksums |
44708ae95a43c7030865b8b883060c37db9ffab5838bf3132879a1ec1efd556b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0
|
Release files / framefile-0.0.9-py3-none-any.whl
| Download URL | framefile-0.0.9-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f80975c53b7c811e9d09695e51b44f0e72c21545b8d2be74f65a57ca2056a66e
|
|
BLAKE2b-256 checksum How to use checksums |
bfe800aafb6b568ed1487b5d9d80fea3111aebc577a972d712fd70f7ff1e0e75
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0
|
Security for framefile 0.0.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.