diff --git a/README.md b/README.md index 2f573f96..d81c458c 100644 --- a/README.md +++ b/README.md @@ -552,11 +552,16 @@ echo -n "cloud password" | shasum -a 256 | awk '{print toupper($0)}' [TP-Link Kasa](https://www.kasasmart.com/) non-standard protocol [more info](https://medium.com/@hu3vjeen/reverse-engineering-tp-link-kc100-bac4641bf1cd). +- `username` - urlsafe email, `alex@gmail.com` -> `alex%40gmail.com` +- `password` - base64password, `secret1` -> `c2VjcmV0MQ==` + ```yaml streams: - kasa: kasa://user:pass@192.168.1.123:19443/https/stream/mixed + kc401: kasa://username:password@192.168.1.123:19443/https/stream/mixed ``` +Tested: KD110, KC200, KC401, KC420WS, EC71. + #### Source: GoPro *[New in v1.8.3](https://github.com/AlexxIT/go2rtc/releases/tag/v1.8.3)* diff --git a/pkg/kasa/producer.go b/pkg/kasa/producer.go index bcca1678..d138cb68 100644 --- a/pkg/kasa/producer.go +++ b/pkg/kasa/producer.go @@ -37,14 +37,34 @@ func Dial(url string) (*Producer, error) { return nil, err } + // KC200 + // HTTP/1.0 200 OK + // Content-Type: multipart/x-mixed-replace;boundary=data-boundary-- + // KD110, KC401, KC420WS: + // HTTP/1.0 200 OK + // Content-Type: multipart/x-mixed-replace;boundary=data-boundary-- + // Transfer-Encoding: chunked + // HTTP/1.0 + chunked = out of standard, so golang remove this header + // and we need to check first two bytes + buf := bufio.NewReader(res.Body) + + b, err := buf.Peek(2) + if err != nil { + return nil, err + } + rd := struct { io.Reader io.Closer }{ - httputil.NewChunkedReader(res.Body), + buf, res.Body, } + if string(b) != "--" { + rd.Reader = httputil.NewChunkedReader(buf) + } + prod := &Producer{rd: core.NewReadBuffer(rd)} if err = prod.probe(); err != nil { return nil, err