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/protocol.py
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"""Wire helpers: BLE packet framing, TLV payloads and a tiny protobuf codec.
|
|
2
|
+
|
|
3
|
+
ponytail: hand-written protobuf (varint + length-delimited only) instead of depending on the
|
|
4
|
+
generated Open GoPro bindings; the messages we use only carry those two wire types.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from collections.abc import Iterable, Iterator
|
|
10
|
+
from dataclasses import dataclass, field
|
|
11
|
+
|
|
12
|
+
# --- framing ---------------------------------------------------------------------------------------
|
|
13
|
+
|
|
14
|
+
CONTINUATION = 0x80
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def frame_header(length: int) -> bytes:
|
|
18
|
+
"""Header for a message of ``length`` payload bytes (general 5-bit / extended 13 / 16 bit)."""
|
|
19
|
+
if length < 0x20:
|
|
20
|
+
return bytes([length])
|
|
21
|
+
if length < 0x2000:
|
|
22
|
+
return bytes([0x20 | (length >> 8), length & 0xFF])
|
|
23
|
+
if length < 0x10000:
|
|
24
|
+
return bytes([0x40, length >> 8, length & 0xFF])
|
|
25
|
+
raise ValueError("message too long")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def fragment(payload: bytes, packet_size: int = 20) -> list[bytes]:
|
|
29
|
+
"""Split a message into BLE packets.
|
|
30
|
+
|
|
31
|
+
The MAX2 rejects continuation packets written with response (GATT 0xD1), so callers should
|
|
32
|
+
pass the negotiated ``mtu - 3`` as ``packet_size`` and normally get a single packet.
|
|
33
|
+
"""
|
|
34
|
+
msg = frame_header(len(payload)) + payload
|
|
35
|
+
if len(msg) <= packet_size:
|
|
36
|
+
return [msg]
|
|
37
|
+
packets = [msg[:packet_size]]
|
|
38
|
+
rest = msg[packet_size:]
|
|
39
|
+
step = packet_size - 1
|
|
40
|
+
while rest:
|
|
41
|
+
packets.append(bytes([CONTINUATION]) + rest[:step])
|
|
42
|
+
rest = rest[step:]
|
|
43
|
+
return packets
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@dataclass
|
|
47
|
+
class Reassembler:
|
|
48
|
+
"""Rebuilds notification messages from packets."""
|
|
49
|
+
|
|
50
|
+
_buf: bytearray = field(default_factory=bytearray)
|
|
51
|
+
_need: int = 0
|
|
52
|
+
|
|
53
|
+
def feed(self, packet: bytes | bytearray) -> bytes | None:
|
|
54
|
+
"""Feed one notification; returns a complete message or None."""
|
|
55
|
+
if not packet:
|
|
56
|
+
return None
|
|
57
|
+
head = packet[0]
|
|
58
|
+
if head & CONTINUATION:
|
|
59
|
+
self._buf += packet[1:]
|
|
60
|
+
else:
|
|
61
|
+
kind = (head >> 5) & 0x3
|
|
62
|
+
if kind == 0:
|
|
63
|
+
self._need, self._buf = head & 0x1F, bytearray(packet[1:])
|
|
64
|
+
elif kind == 1:
|
|
65
|
+
self._need, self._buf = ((head & 0x1F) << 8) | packet[1], bytearray(packet[2:])
|
|
66
|
+
else:
|
|
67
|
+
self._need, self._buf = (packet[1] << 8) | packet[2], bytearray(packet[3:])
|
|
68
|
+
if len(self._buf) >= self._need:
|
|
69
|
+
done, self._buf, self._need = bytes(self._buf[: self._need]), bytearray(), 0
|
|
70
|
+
return done
|
|
71
|
+
return None
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
# --- TLV -------------------------------------------------------------------------------------------
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def tlv_command(command_id: int, *params: bytes) -> bytes:
|
|
78
|
+
"""``[id][len][value]...`` body used by command/setting/query characteristics."""
|
|
79
|
+
out = bytes([command_id])
|
|
80
|
+
for p in params:
|
|
81
|
+
out += bytes([len(p)]) + p
|
|
82
|
+
return out
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def parse_tlv(data: bytes) -> list[bytes]:
|
|
86
|
+
"""Length-prefixed values (hardware info, AP lists...)."""
|
|
87
|
+
out: list[bytes] = []
|
|
88
|
+
i = 0
|
|
89
|
+
while i < len(data):
|
|
90
|
+
n = data[i]
|
|
91
|
+
out.append(data[i + 1 : i + 1 + n])
|
|
92
|
+
i += 1 + n
|
|
93
|
+
return out
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def parse_id_values(data: bytes) -> dict[int, bytes]:
|
|
97
|
+
"""``[id][len][value]...`` (status / setting query responses)."""
|
|
98
|
+
out: dict[int, bytes] = {}
|
|
99
|
+
i = 0
|
|
100
|
+
while i + 1 < len(data):
|
|
101
|
+
ident, n = data[i], data[i + 1]
|
|
102
|
+
out[ident] = data[i + 2 : i + 2 + n]
|
|
103
|
+
i += 2 + n
|
|
104
|
+
return out
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def as_int(value: bytes) -> int:
|
|
108
|
+
return int.from_bytes(value, "big") if value else 0
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
# --- protobuf --------------------------------------------------------------------------------------
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def _varint(value: int) -> bytes:
|
|
115
|
+
out = bytearray()
|
|
116
|
+
while True:
|
|
117
|
+
b = value & 0x7F
|
|
118
|
+
value >>= 7
|
|
119
|
+
if value:
|
|
120
|
+
out.append(b | 0x80)
|
|
121
|
+
else:
|
|
122
|
+
out.append(b)
|
|
123
|
+
return bytes(out)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def pb_encode(fields: Iterable[tuple[int, int | bool | str | bytes]]) -> bytes:
|
|
127
|
+
"""Encode (field_number, value) pairs; ints/bools as varint, str/bytes length-delimited."""
|
|
128
|
+
out = bytearray()
|
|
129
|
+
for number, value in fields:
|
|
130
|
+
if isinstance(value, (str, bytes, bytearray)):
|
|
131
|
+
raw = value.encode() if isinstance(value, str) else bytes(value)
|
|
132
|
+
out += _varint(number << 3 | 2) + _varint(len(raw)) + raw
|
|
133
|
+
else:
|
|
134
|
+
out += _varint(number << 3) + _varint(int(value))
|
|
135
|
+
return bytes(out)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def _read_varint(data: bytes, i: int) -> tuple[int, int]:
|
|
139
|
+
value = shift = 0
|
|
140
|
+
while True:
|
|
141
|
+
b = data[i]
|
|
142
|
+
i += 1
|
|
143
|
+
value |= (b & 0x7F) << shift
|
|
144
|
+
shift += 7
|
|
145
|
+
if b < 0x80:
|
|
146
|
+
return value, i
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def pb_decode(data: bytes) -> dict[int, list[int | bytes]]:
|
|
150
|
+
"""Decode into {field: [values...]} (repeated-safe). Fixed32/64 are skipped."""
|
|
151
|
+
out: dict[int, list[int | bytes]] = {}
|
|
152
|
+
i = 0
|
|
153
|
+
while i < len(data):
|
|
154
|
+
key, i = _read_varint(data, i)
|
|
155
|
+
number, wire = key >> 3, key & 7
|
|
156
|
+
value: int | bytes
|
|
157
|
+
if wire == 0:
|
|
158
|
+
value, i = _read_varint(data, i)
|
|
159
|
+
elif wire == 2:
|
|
160
|
+
n, i = _read_varint(data, i)
|
|
161
|
+
value = data[i : i + n]
|
|
162
|
+
i += n
|
|
163
|
+
elif wire == 1:
|
|
164
|
+
value, i = int.from_bytes(data[i : i + 8], "little"), i + 8
|
|
165
|
+
elif wire == 5:
|
|
166
|
+
value, i = int.from_bytes(data[i : i + 4], "little"), i + 4
|
|
167
|
+
else:
|
|
168
|
+
raise ValueError(f"unsupported wire type {wire}")
|
|
169
|
+
out.setdefault(number, []).append(value)
|
|
170
|
+
return out
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def pb_first(msg: dict[int, list[int | bytes]], number: int, default=None):
|
|
174
|
+
vals = msg.get(number)
|
|
175
|
+
return vals[0] if vals else default
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def pb_str(msg: dict[int, list[int | bytes]], number: int, default: str = "") -> str:
|
|
179
|
+
v = pb_first(msg, number)
|
|
180
|
+
return v.decode(errors="replace") if isinstance(v, bytes) else default
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def iter_packets(packets: Iterable[bytes]) -> Iterator[bytes]:
|
|
184
|
+
"""Convenience for tests: reassemble a sequence of packets into messages."""
|
|
185
|
+
r = Reassembler()
|
|
186
|
+
for p in packets:
|
|
187
|
+
m = r.feed(p)
|
|
188
|
+
if m is not None:
|
|
189
|
+
yield m
|
pygopro/schema.py
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"""Camera self-description served at ``GET /gp/gpControl``.
|
|
2
|
+
|
|
3
|
+
The firmware ships one ``settings.json`` per model (``/usr/local/gopro/etc/<model>/settings.json``) and
|
|
4
|
+
serves it over HTTP. It lists every setting with its options, every status field with its name,
|
|
5
|
+
the modes, the command catalogue and the *filters* that disable options depending on other
|
|
6
|
+
settings or statuses. Using it means new models/firmwares work without code changes.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from collections import Counter
|
|
12
|
+
from dataclasses import dataclass, field
|
|
13
|
+
from typing import Any
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@dataclass(frozen=True)
|
|
17
|
+
class SettingOption:
|
|
18
|
+
id: int
|
|
19
|
+
name: str
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass(frozen=True)
|
|
23
|
+
class Setting:
|
|
24
|
+
id: int
|
|
25
|
+
name: str
|
|
26
|
+
options: tuple[SettingOption, ...]
|
|
27
|
+
group: str | None = None # display hint group key (GPCAMERA_GROUP_*)
|
|
28
|
+
widget: str | None = None # select / toggle / slider
|
|
29
|
+
|
|
30
|
+
@property
|
|
31
|
+
def option_names(self) -> dict[int, str]:
|
|
32
|
+
"""Option id -> unique display name (duplicates get the id appended)."""
|
|
33
|
+
counts = Counter(o.name for o in self.options)
|
|
34
|
+
return {o.id: (o.name if counts[o.name] == 1 else f"{o.name} ({o.id})") for o in self.options}
|
|
35
|
+
|
|
36
|
+
@property
|
|
37
|
+
def is_toggle(self) -> bool:
|
|
38
|
+
names = {o.name.lower() for o in self.options}
|
|
39
|
+
return len(self.options) == 2 and names == {"on", "off"}
|
|
40
|
+
|
|
41
|
+
def option_id(self, name_or_id: str | int) -> int:
|
|
42
|
+
if isinstance(name_or_id, int) or str(name_or_id).isdigit():
|
|
43
|
+
ident = int(name_or_id)
|
|
44
|
+
if any(o.id == ident for o in self.options):
|
|
45
|
+
return ident
|
|
46
|
+
for ident, label in self.option_names.items():
|
|
47
|
+
if label == name_or_id:
|
|
48
|
+
return ident
|
|
49
|
+
for o in self.options:
|
|
50
|
+
if o.name == name_or_id:
|
|
51
|
+
return o.id
|
|
52
|
+
raise KeyError(f"option {name_or_id!r} not valid for setting {self.id} ({self.name})")
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@dataclass(frozen=True)
|
|
56
|
+
class StatusField:
|
|
57
|
+
id: int
|
|
58
|
+
name: str
|
|
59
|
+
group: str
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@dataclass(frozen=True)
|
|
63
|
+
class Condition:
|
|
64
|
+
setting_id: int | None
|
|
65
|
+
status_id: int | None
|
|
66
|
+
values: frozenset[int]
|
|
67
|
+
|
|
68
|
+
def matches(self, settings: dict[int, int], status: dict[int, Any]) -> bool:
|
|
69
|
+
if self.setting_id is not None:
|
|
70
|
+
return settings.get(self.setting_id) in self.values
|
|
71
|
+
try:
|
|
72
|
+
return int(status.get(self.status_id)) in self.values # type: ignore[arg-type]
|
|
73
|
+
except (TypeError, ValueError):
|
|
74
|
+
return False
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
@dataclass(frozen=True)
|
|
78
|
+
class Filter:
|
|
79
|
+
activated_by: tuple[Condition, ...]
|
|
80
|
+
blacklist: dict[int, frozenset[int]]
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
@dataclass
|
|
84
|
+
class Schema:
|
|
85
|
+
version: int
|
|
86
|
+
schema_version: int
|
|
87
|
+
settings: dict[int, Setting]
|
|
88
|
+
status_fields: dict[int, StatusField]
|
|
89
|
+
modes: dict[int, str]
|
|
90
|
+
mode_groups: dict[int, tuple[str, tuple[int, ...]]]
|
|
91
|
+
commands: dict[str, tuple[str, ...]]
|
|
92
|
+
filters: list[Filter] = field(default_factory=list)
|
|
93
|
+
info: dict[str, Any] = field(default_factory=dict)
|
|
94
|
+
raw: dict[str, Any] = field(default_factory=dict, repr=False)
|
|
95
|
+
|
|
96
|
+
@classmethod
|
|
97
|
+
def from_json(cls, data: dict[str, Any]) -> Schema:
|
|
98
|
+
hints: dict[int, tuple[str, str]] = {}
|
|
99
|
+
for h in data.get("display_hints") or []:
|
|
100
|
+
for s in h.get("settings") or []:
|
|
101
|
+
hints.setdefault(int(s["setting_id"]), (h.get("key", ""), s.get("widget_type", "")))
|
|
102
|
+
settings = {}
|
|
103
|
+
for s in data.get("settings") or []:
|
|
104
|
+
sid = int(s["id"])
|
|
105
|
+
group, widget = hints.get(sid, (None, None))
|
|
106
|
+
settings[sid] = Setting(
|
|
107
|
+
id=sid,
|
|
108
|
+
name=str(s.get("display_name", sid)),
|
|
109
|
+
options=tuple(SettingOption(int(o["id"]), str(o.get("display_name", o["id"]))) for o in s.get("options") or []),
|
|
110
|
+
group=group,
|
|
111
|
+
widget=widget,
|
|
112
|
+
)
|
|
113
|
+
status_fields: dict[int, StatusField] = {}
|
|
114
|
+
for g in (data.get("status") or {}).get("groups") or []:
|
|
115
|
+
for f in g.get("fields") or []:
|
|
116
|
+
status_fields[int(f["id"])] = StatusField(int(f["id"]), str(f.get("name", "")), str(g.get("group", "")))
|
|
117
|
+
filters: list[Filter] = []
|
|
118
|
+
for f in data.get("filters") or []:
|
|
119
|
+
conds = []
|
|
120
|
+
for a in f.get("activated_by") or []:
|
|
121
|
+
if "setting_id" in a:
|
|
122
|
+
conds.append(Condition(int(a["setting_id"]), None, frozenset(int(x) for x in a.get("ids") or [])))
|
|
123
|
+
elif "status_id" in a:
|
|
124
|
+
conds.append(Condition(None, int(a["status_id"]), frozenset(int(x) for x in a.get("values") or [])))
|
|
125
|
+
bl = {int(b["setting_id"]): frozenset(int(x) for x in b.get("opt_ids") or []) for b in f.get("blacklist") or []}
|
|
126
|
+
filters.append(Filter(tuple(conds), bl))
|
|
127
|
+
return cls(
|
|
128
|
+
version=int(data.get("version") or 0),
|
|
129
|
+
schema_version=int(data.get("schema_version") or 0),
|
|
130
|
+
settings=settings,
|
|
131
|
+
status_fields=status_fields,
|
|
132
|
+
modes={int(m["id"]): str(m.get("display_name", m["id"])) for m in data.get("modes") or []},
|
|
133
|
+
mode_groups={
|
|
134
|
+
int(g["id"]): (str(g.get("display_name", "")), tuple(int(x) for x in g.get("modes") or []))
|
|
135
|
+
for g in data.get("ui_mode_groups") or []
|
|
136
|
+
},
|
|
137
|
+
commands={str(c["key"]): tuple(c.get("network_types") or []) for c in data.get("commands") or []},
|
|
138
|
+
filters=filters,
|
|
139
|
+
info=dict(data.get("info") or {}),
|
|
140
|
+
raw=data,
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
def blocked_options(self, settings: dict[int, int], status: dict[int, Any]) -> dict[int, set[int]]:
|
|
144
|
+
"""Option ids that the camera would currently refuse, per setting.
|
|
145
|
+
|
|
146
|
+
A filter applies when *all* its ``activated_by`` conditions match (same semantics as the
|
|
147
|
+
on-camera menu).
|
|
148
|
+
"""
|
|
149
|
+
out: dict[int, set[int]] = {}
|
|
150
|
+
for f in self.filters:
|
|
151
|
+
if f.activated_by and all(c.matches(settings, status) for c in f.activated_by):
|
|
152
|
+
for sid, opts in f.blacklist.items():
|
|
153
|
+
out.setdefault(sid, set()).update(opts)
|
|
154
|
+
return out
|
|
155
|
+
|
|
156
|
+
def available_options(self, setting_id: int, settings: dict[int, int], status: dict[int, Any]) -> list[int]:
|
|
157
|
+
blocked = self.blocked_options(settings, status).get(setting_id, set())
|
|
158
|
+
setting = self.settings[setting_id]
|
|
159
|
+
current = settings.get(setting_id)
|
|
160
|
+
return [o.id for o in setting.options if o.id not in blocked or o.id == current]
|
|
161
|
+
|
|
162
|
+
def supports(self, command_key: str, network: str = "wifi") -> bool:
|
|
163
|
+
return network in self.commands.get(command_key, ())
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: python-gopro
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Async local client for GoPro cameras (HTTPS over Camera-on-Home-Network + BLE), built from reverse engineering the MAX2 firmware
|
|
5
|
+
Project-URL: Homepage, https://github.com/hudsonbrendon/python-gopro
|
|
6
|
+
Project-URL: Repository, https://github.com/hudsonbrendon/python-gopro
|
|
7
|
+
Project-URL: Issues, https://github.com/hudsonbrendon/python-gopro/issues
|
|
8
|
+
Author-email: Hudson Brendon <contato.hudsonbrendon@gmail.com>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: ble,cohn,gopro,hero13,home-assistant,max2,open-gopro,reverse-engineering
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Framework :: AsyncIO
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Topic :: Home Automation
|
|
20
|
+
Classifier: Topic :: Multimedia :: Video :: Capture
|
|
21
|
+
Requires-Python: >=3.12
|
|
22
|
+
Requires-Dist: aiohttp>=3.9
|
|
23
|
+
Provides-Extra: ble
|
|
24
|
+
Requires-Dist: bleak>=0.22; extra == 'ble'
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
# python-gopro
|
|
28
|
+
|
|
29
|
+
[](https://pypi.org/project/python-gopro/)
|
|
30
|
+
[](https://github.com/hudsonbrendon/python-gopro/actions/workflows/tests.yml)
|
|
31
|
+
[](LICENSE)
|
|
32
|
+
|
|
33
|
+
Async, local client for GoPro cameras: HTTPS over **Camera on the Home Network (COHN)** and **BLE**.
|
|
34
|
+
It was built by reverse engineering a **GoPro MAX2** (firmware H24.02.01.34.00) and its Linux userland,
|
|
35
|
+
and it is the communication layer of the [GoPro Home Assistant integration](https://github.com/hudsonbrendon/ha-gopro).
|
|
36
|
+
|
|
37
|
+
* No cloud, no USB cable: the camera joins your Wi-Fi once (provisioned over BLE) and is reachable at
|
|
38
|
+
`https://<ip>` with basic auth and its own root CA.
|
|
39
|
+
* **Self-describing**: settings, options, statuses, modes, commands and option filters are read from the
|
|
40
|
+
camera itself (`GET /gp/gpControl`), so HERO12/HERO13/MAX2 and future firmwares work without code changes.
|
|
41
|
+
* Legacy `/gp/gpControl/command/*` routes recovered from the firmware (locate, sleep, tag moment...).
|
|
42
|
+
* BLE: pairing, hardware info, statuses, settings, shutter, presets, date/time, Wi-Fi scan + provisioning,
|
|
43
|
+
COHN certificate/status, keep-alive and wake.
|
|
44
|
+
|
|
45
|
+
## Install
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install python-gopro # HTTP only
|
|
49
|
+
pip install "python-gopro[ble]" # + BLE (bleak)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Quick start
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
import asyncio
|
|
56
|
+
from pygopro import GoProBle, GoProHttp
|
|
57
|
+
|
|
58
|
+
async def main():
|
|
59
|
+
# 1) one-time: put the camera in pairing mode (Preferences > Connections > Connect Device)
|
|
60
|
+
async with GoProBle("GoPro 8832") as ble:
|
|
61
|
+
creds = await ble.provision_cohn("MyWiFi", "wifi-password")
|
|
62
|
+
|
|
63
|
+
# 2) from now on, plain HTTPS on the home network
|
|
64
|
+
async with GoProHttp(creds.host, username=creds.username, password=creds.password,
|
|
65
|
+
certificate=creds.certificate) as cam:
|
|
66
|
+
print(await cam.get_info())
|
|
67
|
+
state = await cam.get_state()
|
|
68
|
+
schema = await cam.get_schema() # every setting/status with names and options
|
|
69
|
+
for sid, value in state.settings.items():
|
|
70
|
+
s = schema.settings.get(sid)
|
|
71
|
+
if s:
|
|
72
|
+
print(s.name, s.option_names.get(value))
|
|
73
|
+
await cam.shutter(True) # start recording
|
|
74
|
+
await cam.shutter(False)
|
|
75
|
+
print(await cam.get_media_list())
|
|
76
|
+
|
|
77
|
+
asyncio.run(main())
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
CLI:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
pygopro ble-scan
|
|
84
|
+
pygopro provision --ssid MyWiFi --wifi-password secret --out gopro.json
|
|
85
|
+
pygopro --creds gopro.json state
|
|
86
|
+
pygopro --creds gopro.json locate on
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Things learned the hard way
|
|
90
|
+
|
|
91
|
+
* **Never call `/gopro/camera/control/wired_usb`.** On the MAX2 it hung and left every `/gopro/*` route
|
|
92
|
+
answering `503 "Unable to establish comminucation with settings controller"`. The power button only
|
|
93
|
+
suspends the camera, so the state survives until the **battery is removed**. The client refuses that
|
|
94
|
+
path and raises `GoProControllerUnavailableError` for the 503.
|
|
95
|
+
* Over BLE, messages must fit in one write; continuation packets written with response are rejected
|
|
96
|
+
(GATT 0xD1). Protobuf queries (`0xF5`) go to the query characteristic.
|
|
97
|
+
* Without valid basic auth the COHN server closes the socket without an answer.
|
|
98
|
+
|
|
99
|
+
See [docs/PROTOCOL.md](docs/PROTOCOL.md) for the full write-up.
|
|
100
|
+
|
|
101
|
+
## License
|
|
102
|
+
|
|
103
|
+
MIT. Not affiliated with GoPro, Inc. "GoPro" is a trademark of GoPro, Inc.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
pygopro/__init__.py,sha256=lHwGsEmXZ33GJkVjQHFrgKSe_qAi8bE6TY9wGPsOXLE,1479
|
|
2
|
+
pygopro/__main__.py,sha256=bYt9eEaoRQWdejEHFD8REx9jxVEdZptECFsV7F49Ink,30
|
|
3
|
+
pygopro/ble.py,sha256=ilTzLxy1YN47vYwQ3izJRGfkMC1_5FZ0rpHt-FoI2Zo,19341
|
|
4
|
+
pygopro/cli.py,sha256=xZVN7_EqM8C91L0sq94wRQZUQXSPsK2Lb-rVFWprbTw,5355
|
|
5
|
+
pygopro/const.py,sha256=lbH7uxDSUHntK8_2orLqkWoxtM-y6te7U3KRkrlmOY0,6469
|
|
6
|
+
pygopro/exceptions.py,sha256=4yTwdQudZVlyvwTUKfwfLwAtRDooBehur11Q3UlXmmE,1153
|
|
7
|
+
pygopro/firmware.py,sha256=gxf_DOXDbo_fM-qbhf7cpiiT6dgu6lvB4ZoXPSWMon4,2092
|
|
8
|
+
pygopro/http.py,sha256=BGGrPRGTCwhVOn0n9hO8KxAsCPgmLwc6YlnyhWf_I0g,15517
|
|
9
|
+
pygopro/models.py,sha256=qNyFdT6PJpMCG4uNcNJWRMg1MiEi56Ri2ntwu9AFpJU,6484
|
|
10
|
+
pygopro/protocol.py,sha256=kuoQc0I9V4z-AW9KC4ra09P95Jv56mhODty5mN7aRm8,6110
|
|
11
|
+
pygopro/schema.py,sha256=9lFnNiJXh7BcjOAFfYvOc8gtM-pBv8yJNAc-4J6kgl8,6611
|
|
12
|
+
python_gopro-0.1.0.dist-info/METADATA,sha256=aJy_KaMfcgtdMxpcoTsWLtp1eiNdV4dIPc8J1hXFHf0,4615
|
|
13
|
+
python_gopro-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
14
|
+
python_gopro-0.1.0.dist-info/entry_points.txt,sha256=IqEfrCpVSXCHZGT9gruPTyVoT4yaN7KkmpMg0F5r-9k,45
|
|
15
|
+
python_gopro-0.1.0.dist-info/licenses/LICENSE,sha256=4Zgd3fbLJqWSkwKA-hh1rNN6DC9tNQ3rWLX93fingOw,1071
|
|
16
|
+
python_gopro-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Hudson Brendon
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|