morphic.shared¶
Constants, utilities, and helpers shared across all morphic modules.
Constants¶
Shared constants for morphic – extension sets, exclusion lists, defaults.
Merges constants from both the converter and dupfinder modules so that every part of the project works with a single canonical set of supported file types.
Utilities¶
Shared utility helpers used across morphic modules.
- morphic.shared.utils.normalise_ext(ext)[source]¶
Lowercase and unify aliases (.jpeg -> .jpg, .tiff -> .tif).
- morphic.shared.utils.format_file_size(size_bytes)[source]¶
Format file size in human-readable format.
- morphic.shared.utils.is_excluded_path(file_path, excluded_folders=frozenset({'$recycle', '$recycle.bin', '.cache', '.ds_store', '.fseventsd', '.git', '.hg', '.spotlight-v100', '.svn', '.thumb', '.thumbnails', '.trash', '.trashes', '.venv', '@eadir', '__pycache__', 'appdata', 'lost+found', 'node_modules', 'recycled', 'recycler', 'system volume information', 'thumbs', 'trash', 'venv', 'windows'}))[source]¶
Check if a file path contains any excluded folder.
- morphic.shared.utils.find_files_by_extension(folder, extensions, excluded_folders=frozenset({'$recycle', '$recycle.bin', '.cache', '.ds_store', '.fseventsd', '.git', '.hg', '.spotlight-v100', '.svn', '.thumb', '.thumbnails', '.trash', '.trashes', '.venv', '@eadir', '__pycache__', 'appdata', 'lost+found', 'node_modules', 'recycled', 'recycler', 'system volume information', 'thumbs', 'trash', 'venv', 'windows'}))[source]¶
Find all files with given extensions in folder recursively.
File Browser¶
Native OS file/folder dialog support.
Attempts to open a native folder picker on Linux, macOS, and Windows. Falls back gracefully when no GUI toolkit is available (e.g. headless server).
- morphic.shared.file_browser.open_native_folder_dialog(initial_dir=None)[source]¶
Open the native OS folder picker dialog.
Returns the selected folder path, or
Noneif cancelled / unavailable.Tries, in order:
tkinter
filedialog.askdirectory()zenity — GNOME / GTK-based Linux
kdialog — KDE Linux
osascript — macOS
powershell — Windows
Thumbnails¶
Thumbnail generation shared by converter and dupfinder frontends.
Generates JPEG thumbnails for images (Pillow) and videos (ffmpeg subprocess).
- morphic.shared.thumbnails.generate_image_thumbnail(file_path, size=300)[source]¶
Create a JPEG thumbnail for an image file.
- Parameters:
- Returns:
JPEG image bytes (seeked to 0).
- Return type:
- morphic.shared.thumbnails.generate_video_thumbnail(file_path, size=300)[source]¶
Extract a single frame from a video and return it as a JPEG thumbnail.
Uses
ffmpegpiped to stdout. ReturnsNoneon failure.- Parameters:
- Returns:
JPEG image bytes (seeked to 0), or
None.- Return type:
io.BytesIO | None