python-gopro 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pygopro/__init__.py +67 -0
- pygopro/__main__.py +3 -0
- pygopro/ble.py +451 -0
- pygopro/cli.py +144 -0
- pygopro/const.py +235 -0
- pygopro/exceptions.py +38 -0
- pygopro/firmware.py +60 -0
- pygopro/http.py +373 -0
- pygopro/models.py +228 -0
- pygopro/protocol.py +189 -0
- pygopro/schema.py +163 -0
- python_gopro-0.1.0.dist-info/METADATA +103 -0
- python_gopro-0.1.0.dist-info/RECORD +16 -0
- python_gopro-0.1.0.dist-info/WHEEL +4 -0
- python_gopro-0.1.0.dist-info/entry_points.txt +2 -0
- python_gopro-0.1.0.dist-info/licenses/LICENSE +21 -0
pygopro/const.py
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"""Protocol constants (Open GoPro + firmware reverse engineering)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from enum import IntEnum
|
|
6
|
+
|
|
7
|
+
# --- BLE -------------------------------------------------------------------------------------------
|
|
8
|
+
GOPRO_MANUFACTURER_ID = 0x02F2 # 754
|
|
9
|
+
GOPRO_SERVICE_UUID = "0000fea6-0000-1000-8000-00805f9b34fb"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _u(n: str) -> str:
|
|
13
|
+
return f"b5f9{n}-aa8d-11e3-9046-0002a5d5c51b"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
UUID_AP_SSID = _u("0002")
|
|
17
|
+
UUID_AP_PASSWORD = _u("0003")
|
|
18
|
+
UUID_AP_POWER = _u("0004")
|
|
19
|
+
UUID_AP_STATE = _u("0005")
|
|
20
|
+
UUID_COMMAND = _u("0072")
|
|
21
|
+
UUID_COMMAND_RESP = _u("0073")
|
|
22
|
+
UUID_SETTINGS = _u("0074")
|
|
23
|
+
UUID_SETTINGS_RESP = _u("0075")
|
|
24
|
+
UUID_QUERY = _u("0076")
|
|
25
|
+
UUID_QUERY_RESP = _u("0077")
|
|
26
|
+
UUID_NETWORK = _u("0091")
|
|
27
|
+
UUID_NETWORK_RESP = _u("0092")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class BleCommand(IntEnum):
|
|
31
|
+
"""TLV command ids written to UUID_COMMAND."""
|
|
32
|
+
|
|
33
|
+
SET_SHUTTER = 0x01
|
|
34
|
+
SLEEP = 0x05
|
|
35
|
+
SET_DATE_TIME = 0x0D
|
|
36
|
+
GET_DATE_TIME = 0x0E
|
|
37
|
+
SET_LOCAL_DATE_TIME = 0x0F
|
|
38
|
+
GET_LOCAL_DATE_TIME = 0x10
|
|
39
|
+
SET_AP_CONTROL = 0x17
|
|
40
|
+
HILIGHT_MOMENT = 0x18
|
|
41
|
+
GET_HARDWARE_INFO = 0x3C
|
|
42
|
+
LOAD_PRESET_GROUP = 0x3E
|
|
43
|
+
LOAD_PRESET = 0x40
|
|
44
|
+
SET_THIRD_PARTY_CLIENT = 0x50
|
|
45
|
+
GET_OPEN_GOPRO_VERSION = 0x51
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class BleQuery(IntEnum):
|
|
49
|
+
"""TLV query ids written to UUID_QUERY."""
|
|
50
|
+
|
|
51
|
+
GET_SETTING_VALUES = 0x12
|
|
52
|
+
GET_STATUS_VALUES = 0x13
|
|
53
|
+
GET_SETTING_CAPABILITIES = 0x32
|
|
54
|
+
REGISTER_SETTING_VALUES = 0x52
|
|
55
|
+
REGISTER_STATUS_VALUES = 0x53
|
|
56
|
+
REGISTER_SETTING_CAPABILITIES = 0x62
|
|
57
|
+
UNREGISTER_SETTING_VALUES = 0x72
|
|
58
|
+
UNREGISTER_STATUS_VALUES = 0x73
|
|
59
|
+
NOTIF_SETTING_VALUE = 0x92
|
|
60
|
+
NOTIF_STATUS_VALUE = 0x93
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
# Protobuf feature ids (first byte) and action ids (second byte); responses are action | 0x80.
|
|
64
|
+
FEATURE_NETWORK = 0x02
|
|
65
|
+
FEATURE_COMMAND = 0xF1
|
|
66
|
+
FEATURE_QUERY = 0xF5
|
|
67
|
+
|
|
68
|
+
ACTION_SCAN_START = 0x02
|
|
69
|
+
ACTION_SCAN_ENTRIES = 0x03
|
|
70
|
+
ACTION_CONNECT = 0x04
|
|
71
|
+
ACTION_CONNECT_NEW = 0x05
|
|
72
|
+
ACTION_NOTIF_SCAN = 0x0B
|
|
73
|
+
ACTION_NOTIF_PROVISIONING = 0x0C
|
|
74
|
+
ACTION_SET_COHN_SETTING = 0x65
|
|
75
|
+
ACTION_CLEAR_COHN_CERT = 0x66
|
|
76
|
+
ACTION_CREATE_COHN_CERT = 0x67
|
|
77
|
+
ACTION_SET_CAMERA_CONTROL = 0x69
|
|
78
|
+
ACTION_SET_TURBO = 0x6B
|
|
79
|
+
ACTION_GET_LAST_MEDIA = 0x6D
|
|
80
|
+
ACTION_GET_COHN_CERT = 0x6E
|
|
81
|
+
ACTION_GET_COHN_STATUS = 0x6F
|
|
82
|
+
ACTION_GET_PRESET_STATUS = 0x72
|
|
83
|
+
|
|
84
|
+
# Setting 91 = "keep alive" (write 66 every few seconds).
|
|
85
|
+
KEEP_ALIVE_SETTING = 91
|
|
86
|
+
KEEP_ALIVE_VALUE = 66
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class ProvisioningState(IntEnum):
|
|
90
|
+
"""EnumProvisioning (NotifProvisioningState.provisioning_state)."""
|
|
91
|
+
|
|
92
|
+
UNKNOWN = 0
|
|
93
|
+
NEVER_STARTED = 1
|
|
94
|
+
STARTED = 2
|
|
95
|
+
ABORTED_BY_SYSTEM = 3
|
|
96
|
+
CANCELLED_BY_USER = 4
|
|
97
|
+
SUCCESS_NEW_AP = 5
|
|
98
|
+
SUCCESS_OLD_AP = 6
|
|
99
|
+
ERROR_FAILED_TO_ASSOCIATE = 7
|
|
100
|
+
ERROR_PASSWORD_AUTH = 8
|
|
101
|
+
ERROR_EULA_BLOCKING = 9
|
|
102
|
+
ERROR_NO_INTERNET = 10
|
|
103
|
+
ERROR_UNSUPPORTED_TYPE = 11
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
class CohnState(IntEnum):
|
|
107
|
+
"""EnumCOHNNetworkState."""
|
|
108
|
+
|
|
109
|
+
INIT = 0
|
|
110
|
+
ERROR = 1
|
|
111
|
+
EXIT = 2
|
|
112
|
+
IDLE = 5
|
|
113
|
+
NETWORK_CONNECTED = 27
|
|
114
|
+
NETWORK_DISCONNECTED = 28
|
|
115
|
+
CONNECTING_TO_NETWORK = 29
|
|
116
|
+
INVALID = 30
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
# --- HTTP ------------------------------------------------------------------------------------------
|
|
120
|
+
# Endpoints that are known to wedge the camera. Never call them from automation.
|
|
121
|
+
# GET /gopro/camera/control/wired_usb hung for 6 s on a MAX2 and left every /gopro/* route answering
|
|
122
|
+
# 503 until the battery was pulled.
|
|
123
|
+
DANGEROUS_PATHS = ("/gopro/camera/control/wired_usb", "/gp/gpControl/command/system/wired_usb")
|
|
124
|
+
|
|
125
|
+
CONTROLLER_UNAVAILABLE_MARKER = "settings controller"
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
class Status(IntEnum):
|
|
129
|
+
"""Well known status ids (names follow the camera's own schema)."""
|
|
130
|
+
|
|
131
|
+
INTERNAL_BATTERY_PRESENT = 1
|
|
132
|
+
INTERNAL_BATTERY_LEVEL = 2
|
|
133
|
+
EXTERNAL_BATTERY_PRESENT = 3
|
|
134
|
+
EXTERNAL_BATTERY_LEVEL = 4
|
|
135
|
+
SYSTEM_HOT = 6
|
|
136
|
+
SYSTEM_BUSY = 8
|
|
137
|
+
QUICK_CAPTURE_ACTIVE = 9
|
|
138
|
+
ENCODING_ACTIVE = 10
|
|
139
|
+
LCD_LOCK_ACTIVE = 11
|
|
140
|
+
VIDEO_PROGRESS_COUNTER = 13
|
|
141
|
+
BROADCAST_PROGRESS_COUNTER = 14
|
|
142
|
+
WIRELESS_ENABLE = 17
|
|
143
|
+
PAIR_STATE = 19
|
|
144
|
+
PAIR_TYPE = 20
|
|
145
|
+
SCAN_STATE = 22
|
|
146
|
+
SCAN_TIME_MSEC = 23
|
|
147
|
+
PROVISION_STATUS = 24
|
|
148
|
+
REMOTE_CONTROL_CONNECTED = 27
|
|
149
|
+
WLAN_SSID = 29
|
|
150
|
+
AP_SSID = 30
|
|
151
|
+
APP_COUNT = 31
|
|
152
|
+
SD_STATUS = 33
|
|
153
|
+
REMAINING_PHOTOS = 34
|
|
154
|
+
REMAINING_VIDEO_TIME = 35
|
|
155
|
+
NUM_TOTAL_PHOTOS = 38
|
|
156
|
+
NUM_TOTAL_VIDEOS = 39
|
|
157
|
+
OTA_STATUS = 41
|
|
158
|
+
DOWNLOAD_CANCEL_PENDING = 42
|
|
159
|
+
CAMERA_LOCATE_ACTIVE = 45
|
|
160
|
+
MULTI_SHOT_COUNT_DOWN = 49
|
|
161
|
+
REMAINING_SPACE = 54
|
|
162
|
+
STREAM_SUPPORTED = 55
|
|
163
|
+
WIFI_BARS = 56
|
|
164
|
+
NUM_HILIGHTS = 58
|
|
165
|
+
LAST_HILIGHT_TIME_MSEC = 59
|
|
166
|
+
NEXT_POLL_MSEC = 60
|
|
167
|
+
ANALYTICS_READY = 61
|
|
168
|
+
EXPOSURE_SELECT_TYPE = 65
|
|
169
|
+
EXPOSURE_SELECT_X = 66
|
|
170
|
+
EXPOSURE_SELECT_Y = 67
|
|
171
|
+
GPS_STATUS = 68
|
|
172
|
+
AP_STATE = 69
|
|
173
|
+
INTERNAL_BATTERY_PERCENTAGE = 70
|
|
174
|
+
ACC_MIC_STATUS = 74
|
|
175
|
+
WIRELESS_BAND = 76
|
|
176
|
+
BAND_5GHZ_AVAILABLE = 81
|
|
177
|
+
SYSTEM_READY = 82
|
|
178
|
+
BATTERY_OK_FOR_OTA = 83
|
|
179
|
+
VIDEO_LOW_TEMP_ALERT = 85
|
|
180
|
+
ACTUAL_ORIENTATION = 86
|
|
181
|
+
CURRENT_MODE = 89
|
|
182
|
+
PROTUNE_DEFAULT = 90
|
|
183
|
+
LOGS_READY = 91
|
|
184
|
+
ACTIVE_VIDEO_PRESETS = 93
|
|
185
|
+
ACTIVE_PHOTO_PRESETS = 94
|
|
186
|
+
ACTIVE_TIMELAPSE_PRESETS = 95
|
|
187
|
+
ACTIVE_PRESETS_GROUP = 96
|
|
188
|
+
ACTIVE_PRESET = 97
|
|
189
|
+
PRESET_MODIFIED = 98
|
|
190
|
+
CAPTURE_DELAY_ACTIVE = 101
|
|
191
|
+
MEDIA_MOD_MIC_STATUS = 102
|
|
192
|
+
VIDEO_HINDSIGHT_ACTIVE = 106
|
|
193
|
+
SCHEDULED_PRESET = 107
|
|
194
|
+
SCHEDULED_ENABLED = 108
|
|
195
|
+
CREATING_PRESET = 109
|
|
196
|
+
MEDIA_MOD_STATUS = 110
|
|
197
|
+
SD_RATING_CHECK_ERROR = 111
|
|
198
|
+
SD_WRITE_SPEED_ERROR = 112
|
|
199
|
+
TURBO_TRANSFER = 113
|
|
200
|
+
CAMERA_CONTROL_STATUS = 114
|
|
201
|
+
USB_CONNECTED = 115
|
|
202
|
+
ALLOW_CONTROL_OVER_USB = 116
|
|
203
|
+
TOTAL_SD_SPACE_KB = 117
|
|
204
|
+
INTERVAL_CAPTURE_COUNT = 118
|
|
205
|
+
CAMERA_LENS_MOD = 119
|
|
206
|
+
CAMERA_NAME = 122
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
class PresetGroup(IntEnum):
|
|
210
|
+
"""UI mode groups (``ui_mode_groups`` in the schema)."""
|
|
211
|
+
|
|
212
|
+
VIDEO = 1000
|
|
213
|
+
PHOTO = 1001
|
|
214
|
+
TIMELAPSE = 1002
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
SD_STATUS = {0: "ok", 1: "full", 2: "removed", 3: "format_error", 4: "busy", 8: "swapped", 255: "unknown"}
|
|
218
|
+
ORIENTATION = {0: "upright", 1: "upside_down", 2: "on_right_side", 3: "on_left_side"}
|
|
219
|
+
OTA_STATUS = {
|
|
220
|
+
0: "idle",
|
|
221
|
+
1: "downloading",
|
|
222
|
+
2: "verifying",
|
|
223
|
+
3: "download_failed",
|
|
224
|
+
4: "verify_failed",
|
|
225
|
+
5: "ready",
|
|
226
|
+
6: "gopro_app_downloading",
|
|
227
|
+
7: "gopro_app_verifying",
|
|
228
|
+
8: "gopro_app_download_failed",
|
|
229
|
+
9: "gopro_app_verify_failed",
|
|
230
|
+
10: "gopro_app_ready",
|
|
231
|
+
}
|
|
232
|
+
PAIR_STATE = {0: "never_started", 1: "started", 2: "aborted", 3: "cancelled", 4: "completed"}
|
|
233
|
+
SCAN_STATE = {0: "never_started", 1: "started", 2: "aborted", 3: "cancelled", 4: "completed"}
|
|
234
|
+
CAMERA_CONTROL = {0: "camera_idle", 1: "camera_control", 2: "camera_external_control"}
|
|
235
|
+
WIRELESS_BAND = {0: "2.4ghz", 1: "5ghz"}
|
pygopro/exceptions.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""Exceptions raised by pygopro."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class GoProError(Exception):
|
|
7
|
+
"""Base error."""
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class GoProConnectionError(GoProError):
|
|
11
|
+
"""The camera could not be reached (asleep, off, other network)."""
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class GoProAuthError(GoProError):
|
|
15
|
+
"""COHN credentials or certificate were rejected."""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class GoProControllerUnavailableError(GoProError):
|
|
19
|
+
"""HTTP 503 "Unable to establish comminucation with settings controller".
|
|
20
|
+
|
|
21
|
+
The web server is up but cannot open its POSIX message queue to gpControlD.
|
|
22
|
+
Observed on the MAX2 (H24.02.01.34.00) after a ``wired_usb`` request: the state
|
|
23
|
+
survives the power button (which only suspends the camera) and is cleared only
|
|
24
|
+
by removing the battery.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class GoProCommandError(GoProError):
|
|
29
|
+
"""The camera answered with an error for a specific command."""
|
|
30
|
+
|
|
31
|
+
def __init__(self, message: str, status: int | None = None, body: str | None = None) -> None:
|
|
32
|
+
super().__init__(message)
|
|
33
|
+
self.status = status
|
|
34
|
+
self.body = body
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class GoProBleError(GoProError):
|
|
38
|
+
"""A BLE operation failed (not paired, encryption missing, timeout)."""
|
pygopro/firmware.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""Official firmware catalogue (public, the same one Quik uses)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import html
|
|
6
|
+
import re
|
|
7
|
+
|
|
8
|
+
import aiohttp
|
|
9
|
+
|
|
10
|
+
from .exceptions import GoProConnectionError
|
|
11
|
+
from .models import FirmwareRelease
|
|
12
|
+
|
|
13
|
+
CATALOG_URL = "https://api.gopro.com/firmware/v2/catalog"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
async def fetch_catalog(session: aiohttp.ClientSession | None = None) -> list[FirmwareRelease]:
|
|
17
|
+
own = session is None
|
|
18
|
+
session = session or aiohttp.ClientSession()
|
|
19
|
+
try:
|
|
20
|
+
async with session.get(CATALOG_URL, timeout=aiohttp.ClientTimeout(total=30)) as resp:
|
|
21
|
+
resp.raise_for_status()
|
|
22
|
+
data = await resp.json(content_type=None)
|
|
23
|
+
except aiohttp.ClientError as err:
|
|
24
|
+
raise GoProConnectionError(f"firmware catalogue: {err}") from err
|
|
25
|
+
finally:
|
|
26
|
+
if own:
|
|
27
|
+
await session.close()
|
|
28
|
+
out = []
|
|
29
|
+
for c in data.get("cameras") or []:
|
|
30
|
+
out.append(
|
|
31
|
+
FirmwareRelease(
|
|
32
|
+
model_number=int(c.get("model") or 0),
|
|
33
|
+
model_string=str(c.get("model_string") or ""),
|
|
34
|
+
name=str(c.get("name") or ""),
|
|
35
|
+
version=str(c.get("version") or ""),
|
|
36
|
+
url=str(c.get("url") or ""),
|
|
37
|
+
release_date=str(c.get("release_date") or ""),
|
|
38
|
+
sha1=str(c.get("sha1") or ""),
|
|
39
|
+
release_html=str(c.get("release_html") or ""),
|
|
40
|
+
)
|
|
41
|
+
)
|
|
42
|
+
return out
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
async def latest_for(model_number: int, session: aiohttp.ClientSession | None = None) -> FirmwareRelease | None:
|
|
46
|
+
for rel in await fetch_catalog(session):
|
|
47
|
+
if rel.model_number == model_number:
|
|
48
|
+
return rel
|
|
49
|
+
return None
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def html_to_text(text: str) -> str:
|
|
53
|
+
"""Very small HTML -> text for release notes."""
|
|
54
|
+
text = re.sub(r"(?is)<(script|style|head).*?</\1>", "", text)
|
|
55
|
+
text = re.sub(r"(?i)<li[^>]*>", "\n- ", text)
|
|
56
|
+
text = re.sub(r"(?i)<br\s*/?>|</p>|</h\d>|</div>", "\n", text)
|
|
57
|
+
text = re.sub(r"<[^>]+>", "", text)
|
|
58
|
+
text = html.unescape(text)
|
|
59
|
+
lines = [ln.strip() for ln in text.splitlines()]
|
|
60
|
+
return "\n".join(ln for ln in lines if ln)
|