Extractors Module¶
Video source extraction from Photos library and folders.
Photos Extractor¶
photos_extractor
¶
Photos library integration module.
This module provides read-only access to the macOS Photos library for querying video assets using the osxphotos library.
SDS Reference: SDS-P01-004 SRS Reference: SRS-301 (Photos Library Integration)
Example
library = PhotosLibrary() if library.check_permissions(): ... print(f"Found {library.get_video_count()} videos") ... else: ... print("Access denied")
PhotosLibraryError
¶
Bases: Exception
Base exception for Photos library operations.
PhotosAccessDeniedError
¶
Bases: PhotosLibraryError
Raised when access to Photos library is denied.
This typically occurs when the application doesn't have Full Disk Access permission in System Settings.
Initialize with optional custom message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str | None
|
Custom error message. If None, uses default. |
None
|
Source code in src/video_converter/extractors/photos_extractor.py
PhotosLibraryNotFoundError
¶
Bases: PhotosLibraryError
Raised when Photos library cannot be found.
Initialize with optional library path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | None
|
Path that was attempted if custom path was specified. |
None
|
Source code in src/video_converter/extractors/photos_extractor.py
VideoNotAvailableError
¶
Bases: PhotosLibraryError
Raised when video is not available locally (iCloud only).
This exception indicates that the video file exists only in iCloud and must be downloaded first using the Photos app.
Initialize with video filename.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Name of the unavailable video file. |
required |
Source code in src/video_converter/extractors/photos_extractor.py
ExportError
¶
Bases: PhotosLibraryError
Raised when video export fails.
This exception covers various export failures including file copy errors, permission issues, and insufficient disk space.
Initialize with error message and optional filename.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Description of what failed. |
required |
filename
|
str | None
|
Name of the video file if applicable. |
None
|
Source code in src/video_converter/extractors/photos_extractor.py
MediaType
¶
Bases: Enum
Media types available in Photos library.
Attributes:
| Name | Type | Description |
|---|---|---|
VIDEO |
Video files (mov, mp4, etc.). |
|
PHOTO |
Photo files (jpg, heic, etc.). |
|
ALL |
All media types. |
PhotosVideoInfo
dataclass
¶
PhotosVideoInfo(uuid, filename, path, date, date_modified, duration, favorite=False, hidden=False, in_cloud=False, location=None, albums=list(), codec=None, size=0)
Information about a video in the Photos library.
Attributes:
| Name | Type | Description |
|---|---|---|
uuid |
str
|
Unique identifier for the asset in Photos. |
filename |
str
|
Original filename of the video. |
path |
Path | None
|
Path to the video file (may be None if in iCloud). |
date |
datetime | None
|
Creation date of the video. |
date_modified |
datetime | None
|
Last modification date. |
duration |
float
|
Video duration in seconds. |
favorite |
bool
|
Whether the video is marked as favorite. |
hidden |
bool
|
Whether the video is hidden. |
in_cloud |
bool
|
Whether the video is stored in iCloud. |
location |
tuple[float, float] | None
|
GPS coordinates (latitude, longitude) if available. |
albums |
list[str]
|
List of album names containing this video. |
codec |
str | None
|
Video codec name (e.g., "h264", "hevc"). |
size |
int
|
File size in bytes. |
is_available_locally
property
¶
Check if the video file is available locally.
Returns:
| Type | Description |
|---|---|
bool
|
True if the file exists locally, False if in iCloud only. |
is_h264
property
¶
Check if video codec is H.264/AVC.
Returns:
| Type | Description |
|---|---|
bool
|
True if the codec is any variant of H.264. |
is_hevc
property
¶
Check if video codec is H.265/HEVC.
Returns:
| Type | Description |
|---|---|
bool
|
True if the codec is any variant of H.265/HEVC. |
needs_conversion
property
¶
Check if video needs H.265 conversion.
A video needs conversion if: - It is locally available (not iCloud-only) - Its codec is H.264
Returns:
| Type | Description |
|---|---|
bool
|
True if the video should be converted to H.265. |
PhotosLibrary
¶
Interface to macOS Photos library via osxphotos.
This class provides a high-level interface for querying videos from the macOS Photos library. It handles library initialization, permission checking, and provides caching for performance.
SDS Reference: SDS-P01-004
Example
library = PhotosLibrary() if library.check_permissions(): ... videos = library.get_videos() ... for video in videos: ... print(f"{video.filename}: {video.duration}s")
Attributes:
| Name | Type | Description |
|---|---|---|
library_path |
Path
|
Path to the Photos library (None for default). |
Initialize Photos library connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
library_path
|
Path | None
|
Custom library path. None uses the default system Photos library. |
None
|
Raises:
| Type | Description |
|---|---|
PhotosLibraryNotFoundError
|
If specified library path doesn't exist. |
Source code in src/video_converter/extractors/photos_extractor.py
library_path
property
¶
Get the Photos library path.
Returns:
| Type | Description |
|---|---|
Path
|
Path to the Photos library (default or custom). |
db
property
¶
Get the PhotosDB instance (lazy-loaded).
Returns:
| Type | Description |
|---|---|
PhotosDB
|
osxphotos.PhotosDB instance. |
Raises:
| Type | Description |
|---|---|
PhotosAccessDeniedError
|
If access is denied. |
PhotosLibraryNotFoundError
|
If library cannot be found. |
check_permissions
¶
Check if we have access to the Photos library.
This method attempts to open the Photos library to verify permissions. The result is cached for subsequent calls.
Returns:
| Type | Description |
|---|---|
bool
|
True if access is granted, False otherwise. |
Source code in src/video_converter/extractors/photos_extractor.py
get_library_info
¶
Get information about the Photos library.
Returns:
| Type | Description |
|---|---|
dict[str, str | int]
|
Dictionary with library information: - path: Library path - photo_count: Total number of photos - video_count: Total number of videos |
Raises:
| Type | Description |
|---|---|
PhotosAccessDeniedError
|
If access is denied. |
Source code in src/video_converter/extractors/photos_extractor.py
get_video_count
¶
Get the total number of videos in the library.
Returns:
| Type | Description |
|---|---|
int
|
Number of videos in the Photos library. |
Raises:
| Type | Description |
|---|---|
PhotosAccessDeniedError
|
If access is denied. |
Source code in src/video_converter/extractors/photos_extractor.py
get_videos
¶
get_videos(*, from_date=None, to_date=None, albums=None, favorites_only=False, include_hidden=False)
Get videos from the Photos library.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_date
|
datetime | None
|
Only include videos created on or after this date. |
None
|
to_date
|
datetime | None
|
Only include videos created on or before this date. |
None
|
albums
|
list[str] | None
|
Filter by album names (None for all albums). |
None
|
favorites_only
|
bool
|
Only include favorite videos. |
False
|
include_hidden
|
bool
|
Include hidden videos. |
False
|
Returns:
| Type | Description |
|---|---|
list[PhotosVideoInfo]
|
List of PhotosVideoInfo objects. |
Raises:
| Type | Description |
|---|---|
PhotosAccessDeniedError
|
If access is denied. |
Source code in src/video_converter/extractors/photos_extractor.py
get_video_by_uuid
¶
Get a specific video by its UUID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid
|
str
|
The UUID of the video asset. |
required |
Returns:
| Type | Description |
|---|---|
PhotosVideoInfo | None
|
PhotosVideoInfo if found, None otherwise. |
Raises:
| Type | Description |
|---|---|
PhotosAccessDeniedError
|
If access is denied. |
Source code in src/video_converter/extractors/photos_extractor.py
close
¶
Close the Photos library connection.
This releases any resources held by the connection. The library can be reopened by accessing the db property.
Source code in src/video_converter/extractors/photos_extractor.py
__enter__
¶
__exit__
¶
Context manager exit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exc_type
|
type[BaseException] | None
|
Exception type if an exception occurred. |
required |
exc_val
|
BaseException | None
|
Exception value if an exception occurred. |
required |
exc_tb
|
object | None
|
Exception traceback if an exception occurred. |
required |
Source code in src/video_converter/extractors/photos_extractor.py
LibraryStats
dataclass
¶
Statistics about videos in the Photos library.
Attributes:
| Name | Type | Description |
|---|---|---|
total |
int
|
Total number of videos. |
h264 |
int
|
Number of H.264 encoded videos. |
hevc |
int
|
Number of H.265/HEVC encoded videos. |
other |
int
|
Number of videos with other codecs. |
in_cloud |
int
|
Number of videos stored in iCloud only. |
total_size_h264 |
int
|
Total size of H.264 videos in bytes. |
estimated_savings |
int
|
Estimated storage savings after conversion in bytes. |
estimated_savings
property
¶
Estimate storage savings after H.265 conversion.
Assumes approximately 50% size reduction with H.265.
Returns:
| Type | Description |
|---|---|
int
|
Estimated bytes that could be saved. |
estimated_savings_gb
property
¶
Get estimated savings in gigabytes.
Returns:
| Type | Description |
|---|---|
float
|
Estimated savings in GB. |
PhotosVideoFilter
¶
Filter Photos library videos for conversion candidates.
This class provides filtering capabilities to identify H.264 videos that need conversion to H.265/HEVC, with support for album-based and date-based filtering.
SDS Reference: SDS-P01-005 SRS Reference: SRS-302 (Video Filtering)
Example
library = PhotosLibrary() filter = PhotosVideoFilter( ... library, ... exclude_albums=["Screenshots", "Bursts"] ... ) candidates = filter.get_conversion_candidates(limit=100) print(f"Found {len(candidates)} videos to convert")
Initialize PhotosVideoFilter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
library
|
PhotosLibrary
|
PhotosLibrary instance to filter. |
required |
include_albums
|
list[str] | None
|
Only include videos from these albums. If None, includes all albums. |
None
|
exclude_albums
|
list[str] | None
|
Exclude videos from these albums. If None, uses DEFAULT_EXCLUDE_ALBUMS. |
None
|
Source code in src/video_converter/extractors/photos_extractor.py
codec_detector
property
¶
Get or create codec detector instance.
Returns:
| Type | Description |
|---|---|
CodecDetector
|
CodecDetector for analyzing video codecs. |
get_conversion_candidates
¶
Get videos that need conversion from H.264 to H.265.
This method filters Photos library videos to find candidates for conversion, applying album and date filters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_date
|
datetime | None
|
Only include videos created after this date. |
None
|
to_date
|
datetime | None
|
Only include videos created before this date. |
None
|
limit
|
int | None
|
Maximum number of candidates to return. |
None
|
Returns:
| Type | Description |
|---|---|
list[PhotosVideoInfo]
|
List of PhotosVideoInfo for videos that need conversion. |
Source code in src/video_converter/extractors/photos_extractor.py
764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 | |
get_stats
¶
Get statistics about videos in the library.
Analyzes all videos in the library to provide statistics about codec distribution and potential storage savings.
Returns:
| Type | Description |
|---|---|
LibraryStats
|
LibraryStats with codec distribution and size information. |
Source code in src/video_converter/extractors/photos_extractor.py
VideoExporter
¶
Export videos from Photos library to temporary directory.
This class provides functionality to export original quality videos from the Photos library to a temporary directory for conversion, with support for progress tracking and cleanup.
SDS Reference: SDS-P01-006 SRS Reference: SRS-303 (Video Export)
Example
exporter = VideoExporter() video = library.get_video_by_uuid("some-uuid") if video and video.is_available_locally: ... exported_path = exporter.export(video) ... # ... do conversion ... ... exporter.cleanup(exported_path) exporter.cleanup_all()
Attributes:
| Name | Type | Description |
|---|---|---|
temp_dir |
Path
|
Directory where exported files are stored. |
Initialize video exporter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
temp_dir
|
Path | None
|
Custom temporary directory for exports. If None, creates a system temporary directory. |
None
|
Source code in src/video_converter/extractors/photos_extractor.py
temp_dir
property
¶
Get the temporary directory path.
Returns:
| Type | Description |
|---|---|
Path
|
Path to the temporary directory. |
export
¶
Export video to temporary directory.
Copies the original video file to the temporary directory, preserving file metadata (modification times).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video
|
PhotosVideoInfo
|
Video information from Photos library. |
required |
on_progress
|
Callable[[float], None] | None
|
Optional callback for progress updates. Called with progress value from 0.0 to 1.0. |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the exported video file. |
Raises:
| Type | Description |
|---|---|
VideoNotAvailableError
|
Video is in iCloud and not downloaded. |
ExportError
|
Export failed due to file system error. |
Source code in src/video_converter/extractors/photos_extractor.py
cleanup
¶
Remove a single exported file.
Only removes files that are within the temporary directory and were exported by this exporter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the exported file to remove. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if file was removed, False otherwise. |
Source code in src/video_converter/extractors/photos_extractor.py
cleanup_all
¶
Remove all exported files and the temporary directory.
Only removes the temporary directory if it was created by this exporter (not a custom directory).
Returns:
| Type | Description |
|---|---|
int
|
Number of files removed. |
Source code in src/video_converter/extractors/photos_extractor.py
get_exported_count
¶
Get the number of currently exported files.
Returns:
| Type | Description |
|---|---|
int
|
Number of files in the exported files set. |
get_temp_dir_size
¶
Get total size of files in the temporary directory.
Returns:
| Type | Description |
|---|---|
int
|
Total size in bytes. |
Source code in src/video_converter/extractors/photos_extractor.py
__enter__
¶
__exit__
¶
Context manager exit - cleanup all exported files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exc_type
|
type[BaseException] | None
|
Exception type if an exception occurred. |
required |
exc_val
|
BaseException | None
|
Exception value if an exception occurred. |
required |
exc_tb
|
object | None
|
Exception traceback if an exception occurred. |
required |
Source code in src/video_converter/extractors/photos_extractor.py
get_permission_instructions
¶
Get instructions for granting Photos library access.
Returns:
| Type | Description |
|---|---|
str
|
Multi-line string with detailed instructions for granting |
str
|
Full Disk Access permission. |
Source code in src/video_converter/extractors/photos_extractor.py
Folder Extractor¶
folder_extractor
¶
Folder-based video extractor module.
This module provides video extraction from filesystem directories, allowing users to convert videos stored in regular folders instead of the macOS Photos library.
SDS Reference: SDS-E01-003 SRS Reference: SRS-304 (Folder-based Video Extraction)
Example
extractor = FolderExtractor(Path("~/Videos/iPhone")) for video in extractor.scan(): ... print(f"Found: {video}") ... candidates = extractor.get_conversion_candidates() print(f"Found {len(candidates)} H.264 videos to convert")
FolderExtractorError
¶
Bases: Exception
Base exception for folder extractor operations.
FolderNotFoundError
¶
Bases: FolderExtractorError
Raised when the specified folder does not exist.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
The path that was not found. |
Initialize with the missing folder path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the folder that was not found. |
required |
Source code in src/video_converter/extractors/folder_extractor.py
FolderAccessDeniedError
¶
Bases: FolderExtractorError
Raised when access to a folder is denied.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
The path that could not be accessed. |
Initialize with the inaccessible folder path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the folder that could not be accessed. |
required |
Source code in src/video_converter/extractors/folder_extractor.py
InvalidVideoFileError
¶
Bases: FolderExtractorError
Raised when a video file cannot be read or analyzed.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
Path to the invalid video file. |
|
reason |
Description of why the file is invalid. |
Initialize with the invalid file path and reason.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the invalid video file. |
required |
reason
|
str
|
Description of why the file is invalid. |
'Invalid or corrupted video file'
|
Source code in src/video_converter/extractors/folder_extractor.py
FolderVideoInfo
dataclass
¶
FolderVideoInfo(path, filename, size, modified_time, created_time=None, codec=None, duration=0.0, width=0, height=0, fps=0.0, bitrate=0, container='', in_cloud=False, stub_path=None)
Information about a video file in a folder.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
Path
|
Absolute path to the video file (original path, not stub). |
filename |
str
|
Name of the video file. |
size |
int
|
File size in bytes. |
modified_time |
datetime
|
Last modification time. |
created_time |
datetime | None
|
Creation time (if available). |
codec |
str | None
|
Video codec name (e.g., "h264", "hevc"). |
duration |
float
|
Video duration in seconds. |
width |
int
|
Video width in pixels. |
height |
int
|
Video height in pixels. |
fps |
float
|
Frames per second. |
bitrate |
int
|
Video bitrate in bits per second. |
container |
str
|
Container format (e.g., "mp4", "mov"). |
in_cloud |
bool
|
Whether file is stored in iCloud (stub file exists locally). |
stub_path |
Path | None
|
Path to iCloud stub file if in_cloud is True. |
is_h264
property
¶
Check if video codec is H.264/AVC.
Returns:
| Type | Description |
|---|---|
bool
|
True if the codec is any variant of H.264. |
is_hevc
property
¶
Check if video codec is H.265/HEVC.
Returns:
| Type | Description |
|---|---|
bool
|
True if the codec is any variant of H.265/HEVC. |
needs_conversion
property
¶
Check if video needs H.265 conversion.
A video needs conversion if its codec is H.264.
Returns:
| Type | Description |
|---|---|
bool
|
True if the video should be converted to H.265. |
resolution_label
property
¶
Get human-readable resolution label.
Returns:
| Type | Description |
|---|---|
str
|
Resolution label like "4K", "1080p", "720p", etc. |
size_mb
property
¶
Get file size in megabytes.
Returns:
| Type | Description |
|---|---|
float
|
File size in MB. |
size_gb
property
¶
Get file size in gigabytes.
Returns:
| Type | Description |
|---|---|
float
|
File size in GB. |
__str__
¶
Return human-readable summary.
FolderStats
dataclass
¶
Statistics about videos in a folder.
Attributes:
| Name | Type | Description |
|---|---|---|
total |
int
|
Total number of video files. |
h264 |
int
|
Number of H.264 encoded videos. |
hevc |
int
|
Number of H.265/HEVC encoded videos. |
other |
int
|
Number of videos with other codecs. |
errors |
int
|
Number of files that could not be analyzed. |
total_size |
int
|
Total size of all videos in bytes. |
h264_size |
int
|
Total size of H.264 videos in bytes. |
in_cloud |
int
|
Number of videos stored in iCloud (stub files only). |
estimated_savings
property
¶
Estimate storage savings after H.265 conversion.
Assumes approximately 50% size reduction with H.265.
Returns:
| Type | Description |
|---|---|
int
|
Estimated bytes that could be saved. |
estimated_savings_gb
property
¶
Get estimated savings in gigabytes.
Returns:
| Type | Description |
|---|---|
float
|
Estimated savings in GB. |
total_size_gb
property
¶
Get total size in gigabytes.
Returns:
| Type | Description |
|---|---|
float
|
Total size in GB. |
FolderExtractor
¶
FolderExtractor(root_path, *, recursive=True, include_patterns=None, exclude_patterns=None, video_extensions=None)
Extract videos from filesystem folders.
This class provides video extraction from regular filesystem directories, with support for recursive scanning, file filtering, codec detection, and iCloud stub file detection.
SDS Reference: SDS-E01-003 SRS Reference: SRS-304 (Folder-based Video Extraction)
Example
extractor = FolderExtractor( ... root_path=Path("~/Videos/iPhone"), ... recursive=True, ... exclude_patterns=[".tmp", "._"] ... ) candidates = extractor.get_conversion_candidates() for video in candidates: ... print(f"{video.filename}: {video.codec} (in_cloud={video.in_cloud})")
Attributes:
| Name | Type | Description |
|---|---|---|
root_path |
Path
|
Root directory for scanning. |
recursive |
bool
|
Whether to scan subdirectories. |
include_patterns |
bool
|
Glob patterns to include. |
exclude_patterns |
bool
|
Glob patterns to exclude. |
Initialize folder extractor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root_path
|
Path | str
|
Root directory to scan for videos. |
required |
recursive
|
bool
|
Scan subdirectories if True. |
True
|
include_patterns
|
list[str] | None
|
Glob patterns to include (e.g., ["vacation*"]). If None, includes all files matching video extensions. |
None
|
exclude_patterns
|
list[str] | None
|
Glob patterns to exclude (e.g., ["*.tmp"]). If None, uses DEFAULT_EXCLUDE_PATTERNS. |
None
|
video_extensions
|
set[str] | None
|
Custom set of video file extensions. If None, uses VIDEO_EXTENSIONS. |
None
|
Raises:
| Type | Description |
|---|---|
FolderNotFoundError
|
If root_path does not exist. |
FolderAccessDeniedError
|
If root_path is not readable. |
Source code in src/video_converter/extractors/folder_extractor.py
root_path
property
¶
Get the root directory path.
Returns:
| Type | Description |
|---|---|
Path
|
Path to the root directory. |
recursive
property
¶
Check if recursive scanning is enabled.
Returns:
| Type | Description |
|---|---|
bool
|
True if scanning subdirectories. |
codec_detector
property
¶
Get or create codec detector instance.
Returns:
| Type | Description |
|---|---|
CodecDetector
|
CodecDetector for analyzing video codecs. |
scan
¶
Scan for video files in the root directory.
Yields video file paths that match the configured filters. When iCloud stub files are found, the original file path is yielded instead of the stub path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_icloud
|
bool
|
Whether to include iCloud stub files in scan. Default is True. |
True
|
Yields:
| Type | Description |
|---|---|
Path
|
Path to each video file found (original path for iCloud files). |
Example
extractor = FolderExtractor(Path("~/Videos")) for video_path in extractor.scan(): ... print(video_path)
Source code in src/video_converter/extractors/folder_extractor.py
get_video_info
¶
Get video information for a single file.
Handles both local files and iCloud stub files. For iCloud files, the path parameter should be the original file path (not stub path).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the video file (original path, not stub). |
required |
Returns:
| Type | Description |
|---|---|
FolderVideoInfo
|
FolderVideoInfo with file and video properties. |
FolderVideoInfo
|
For iCloud files, in_cloud=True and stub_path is set. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If neither the file nor its stub exists. |
InvalidVideoFileError
|
If the file cannot be analyzed. |
Source code in src/video_converter/extractors/folder_extractor.py
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 | |
get_videos
¶
Get all videos with their information.
Scans the folder and retrieves detailed information for each video.
Returns:
| Type | Description |
|---|---|
list[FolderVideoInfo]
|
List of FolderVideoInfo for all videos found. |
Example
extractor = FolderExtractor(Path("~/Videos")) videos = extractor.get_videos() for video in videos: ... print(f"{video.filename}: {video.codec}")
Source code in src/video_converter/extractors/folder_extractor.py
get_conversion_candidates
¶
Get videos that need conversion from H.264 to H.265.
This method scans the folder and identifies H.264 videos that are candidates for conversion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
int | None
|
Maximum number of candidates to return. |
None
|
Returns:
| Type | Description |
|---|---|
list[FolderVideoInfo]
|
List of FolderVideoInfo for H.264 videos. |
Example
extractor = FolderExtractor(Path("~/Videos")) candidates = extractor.get_conversion_candidates(limit=10) print(f"Found {len(candidates)} videos to convert")
Source code in src/video_converter/extractors/folder_extractor.py
get_stats
¶
Get statistics about videos in the folder.
Analyzes all videos to provide statistics about codec distribution, potential storage savings, and iCloud status.
Returns:
| Type | Description |
|---|---|
FolderStats
|
FolderStats with codec distribution, size, and iCloud information. |
Example
extractor = FolderExtractor(Path("~/Videos")) stats = extractor.get_stats() print(f"Found {stats.h264} H.264 videos") print(f"In iCloud: {stats.in_cloud}") print(f"Estimated savings: {stats.estimated_savings_gb:.1f} GB")
Source code in src/video_converter/extractors/folder_extractor.py
get_video_count
¶
Get the total number of video files in the folder.
Returns:
| Type | Description |
|---|---|
int
|
Number of video files matching the configured filters. |
__enter__
¶
__exit__
¶
Context manager exit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exc_type
|
type[BaseException] | None
|
Exception type if an exception occurred. |
required |
exc_val
|
BaseException | None
|
Exception value if an exception occurred. |
required |
exc_tb
|
object | None
|
Exception traceback if an exception occurred. |
required |
Source code in src/video_converter/extractors/folder_extractor.py
iCloud Handler¶
icloud_handler
¶
iCloud video download handling module.
This module provides functionality for detecting and downloading videos stored in iCloud, including download triggering, progress tracking, and wait-for-download functionality.
SDS Reference: SDS-P01-007 SRS Reference: SRS-304 (iCloud Download Handling)
Example
from video_converter.extractors.icloud_handler import iCloudHandler from video_converter.extractors.photos_extractor import PhotosVideoInfo handler = iCloudHandler(timeout=1800) status = handler.get_status(video) if status == CloudStatus.CLOUD_ONLY: ... success = handler.download_and_wait(video)
iCloudError
¶
Bases: Exception
Base exception for iCloud operations.
iCloudDownloadError
¶
Bases: iCloudError
Raised when iCloud download fails.
This exception indicates that a video file could not be downloaded from iCloud, either due to network issues, timeout, or other errors.
Initialize with video filename and failure reason.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Name of the video file that failed to download. |
required |
reason
|
str
|
Description of why the download failed. |
'Unknown error'
|
Source code in src/video_converter/extractors/icloud_handler.py
iCloudTimeoutError
¶
Bases: iCloudError
Raised when iCloud download times out.
This exception indicates that the download did not complete within the specified timeout period.
Initialize with video filename and timeout duration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Name of the video file. |
required |
timeout
|
int
|
Timeout duration in seconds. |
required |
Source code in src/video_converter/extractors/icloud_handler.py
CloudStatus
¶
Bases: Enum
iCloud storage status for a video file.
Attributes:
| Name | Type | Description |
|---|---|---|
LOCAL |
Full file is available locally. |
|
CLOUD_ONLY |
File is stored in iCloud only (stub file locally). |
|
DOWNLOADING |
File is currently being downloaded from iCloud. |
|
FAILED |
Download attempt failed. |
|
UNKNOWN |
Status cannot be determined. |
DownloadProgress
dataclass
¶
DownloadProgress(filename, status, progress=-1.0, bytes_downloaded=0, bytes_total=0, elapsed_seconds=0.0)
Progress information for iCloud download.
Attributes:
| Name | Type | Description |
|---|---|---|
filename |
str
|
Name of the file being downloaded. |
status |
CloudStatus
|
Current download status. |
progress |
float
|
Download progress percentage (0-100), -1 if indeterminate. |
bytes_downloaded |
int
|
Bytes downloaded so far. |
bytes_total |
int
|
Total file size in bytes. |
elapsed_seconds |
float
|
Time elapsed since download started. |
iCloudHandler
¶
Handle iCloud video downloads.
This class provides functionality to detect, trigger, and monitor downloads of videos stored in iCloud. It uses the macOS brctl command-line tool to interact with the Bird (iCloud daemon).
SDS Reference: SDS-P01-007 SRS Reference: SRS-304 (iCloud Download Handling)
Example
handler = iCloudHandler(timeout=1800) # 30 min timeout for video in candidates: ... status = handler.get_status(video) ... if status == CloudStatus.CLOUD_ONLY: ... print(f"Downloading {video.filename} from iCloud...") ... success = handler.download_and_wait( ... video, ... on_progress=lambda p: print(f" {p.progress:.1f}%") ... ) ... if not success: ... print(f" Failed to download, skipping") ... continue ... # Proceed with conversion ... convert(video)
Attributes:
| Name | Type | Description |
|---|---|---|
timeout |
Maximum time to wait for download in seconds. |
|
poll_interval |
Time between status checks in seconds. |
Initialize iCloud handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
int
|
Maximum time to wait for downloads in seconds. |
ICLOUD_DOWNLOAD_TIMEOUT
|
poll_interval
|
float
|
Time between status checks in seconds. |
ICLOUD_POLL_INTERVAL
|
Source code in src/video_converter/extractors/icloud_handler.py
get_status
¶
Check iCloud status of a video.
Determines whether the video file is available locally, stored only in iCloud, or currently downloading.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video
|
PhotosVideoInfo
|
Video information from Photos library. |
required |
Returns:
| Type | Description |
|---|---|
CloudStatus
|
CloudStatus indicating the current state of the file. |
Source code in src/video_converter/extractors/icloud_handler.py
trigger_download
¶
Trigger iCloud download for a video.
Uses the macOS brctl command to request file download from iCloud. This is available on macOS 12 (Monterey) and later.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video
|
PhotosVideoInfo
|
Video information with path to download. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if download was triggered successfully, False otherwise. |
Source code in src/video_converter/extractors/icloud_handler.py
wait_for_download
¶
Wait for iCloud download to complete.
Polls the file status until the download completes, fails, or the timeout is reached.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video
|
PhotosVideoInfo
|
Video to wait for. |
required |
on_progress
|
Callable[[DownloadProgress], None] | None
|
Optional callback for progress updates. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if download completed successfully, False otherwise. |
Source code in src/video_converter/extractors/icloud_handler.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | |
download_and_wait
¶
Trigger download and wait for completion.
Combined convenience method that triggers a download if needed and waits for it to complete.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video
|
PhotosVideoInfo
|
Video to download and wait for. |
required |
on_progress
|
Callable[[DownloadProgress], None] | None
|
Optional callback for progress updates. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the video is now available locally, False otherwise. |
Source code in src/video_converter/extractors/icloud_handler.py
evict
¶
Evict a video from local storage (keep in iCloud only).
Uses the macOS brctl command to remove the local copy while keeping the file in iCloud. This frees up local disk space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video
|
PhotosVideoInfo
|
Video to evict from local storage. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if eviction was successful, False otherwise. |