Utils
Pure helper functions for GoPro media selection, naming, and I/O.
gopro_api.utils.is_video_filename(filename)
Return whether the filename looks like MP4 video.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Basename or path ending (extension is checked case-insensitively). |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in gopro_api/utils.py
24 25 26 27 28 29 30 31 32 33 34 | |
gopro_api.utils.select_video_variation(variations, *, target_height=None, target_width=None)
Pick the best variation from variations.
When neither target is set, returns the variation with the greatest height.
Otherwise scores each candidate by the sum of squared deltas for the requested
dimensions; ties break toward the larger (height, width).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variations
|
list[GoProMediaDownloadVariation]
|
Candidate renditions from the API download metadata. |
required |
target_height
|
int | None
|
Desired height in pixels, or |
None
|
target_width
|
int | None
|
Desired width in pixels, or |
None
|
Returns:
| Type | Description |
|---|---|
GoProMediaDownloadVariation
|
The selected |
Raises:
| Type | Description |
|---|---|
NoVariationsError
|
If |
Source code in gopro_api/utils.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
gopro_api.utils.get_file_name(root_name, item_number)
Build a part filename by inserting a zero-padded index before the extension.
Example: get_file_name("GX010001.MP4", 2) → "GX010001002.MP4".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root_name
|
str
|
Original media filename including extension. |
required |
item_number
|
int
|
Non-negative part index (three-digit zero padding). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Derived filename string. |
Source code in gopro_api/utils.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
gopro_api.utils.pull_assets_for_response(result, *, target_height=None, target_width=None)
Map output filenames to assets to download for result.
Video (.mp4): picks one variation via select_video_variation.
Non-video: returns every file in _embedded.files in enumeration order
(no available filtering, preserving CLI behaviour for burst sets).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
GoProMediaDownloadResponse
|
Parsed download-metadata response for one media id. |
required |
target_height
|
int | None
|
Optional preferred video height for variation scoring. |
None
|
target_width
|
int | None
|
Optional preferred video width for variation scoring. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, DownloadAsset]
|
Mapping of local filename to downloadable file or variation row. |
Raises:
| Type | Description |
|---|---|
NoVariationsError
|
For video media when no variations are present. |
Source code in gopro_api/utils.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
gopro_api.utils.write_bytes(path, data)
Write binary data to a path (blocking I/O).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Destination file path. |
required |
data
|
bytes
|
Raw bytes to persist. |
required |
Raises:
| Type | Description |
|---|---|
OSError
|
If the file cannot be opened or written. |
Source code in gopro_api/utils.py
130 131 132 133 134 135 136 137 138 139 140 141 | |