Skip to content

Library rewrite - #3

Open
devmlb wants to merge 14 commits into
indykoning:masterfrom
devmlb:master
Open

Library rewrite#3
devmlb wants to merge 14 commits into
indykoning:masterfrom
devmlb:master

Conversation

@devmlb

@devmlb devmlb commented Jul 22, 2026

Copy link
Copy Markdown

After spending a few days digging around the web, decompiling APKs, DLLs, and SO libraries, and sniffing and analyzing packets with Wireshark, I finally managed to rewrite the p2pcam library to make it more reliable and robust.

Here are the new features:

  • LanScanner class for automatic camera discovery on the LAN
  • LanVideoClient class which is based on my own observations and reverse engineering of the network protocol, as well as on part of @jheyman's video surveillance script.
  • MJPEGServer class for serving an MJPEG HTTP stream with thread-safe frame updates, supporting multiple clients.
  • CLI (old example.py script replacement) that allows users to easily discover cameras, stream video, save frames, serve MJPEG streams over HTTP, and apply image transformations (flip, timestamp)

With these changes, I was able to get a video stream without interruptions and as smooth as the one from the original app!

Note: I bumped the package version to 0.0.4 in setup.py to reflect these significant improvements, but you can set it as you want.

@indykoning indykoning left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to first rewrite the p2pcam library to make it more reliable and robust. Although I’m not a big fan of AI, I have to admit that it really helped me, especially when analyzing packets with Wireshark.

Honestly this is quite impressive either way, i don't mind AI usage personally so long as you understand the code that has been written.

I'm seeing some imports which may not be installed by default, could you create a requirements.txt with those dependencies?

And a nice future stability improvement, could you add the ruff formatting tool?
It'll do quite some quality improvements, but could also do some code changes which i cannot test myself anymore so i cannot add it myself.

Comment thread p2pcam/lan_video.py
Comment on lines +248 to +249
# Continue-packet state machine (ported faithfully from the original
# reverse-engineered client.py, lines 490-641).

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Continue-packet state machine (ported faithfully from the original
# reverse-engineered client.py, lines 490-641).
# Continue-packet state machine.

Comment thread setup.py
setuptools.setup(
name="p2pcam",
version="0.0.3",
version="0.0.4",

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
version="0.0.4",
version="1.0.0",

@indykoning

Copy link
Copy Markdown
Owner

This is some ruff configuration i have for another project

The github action

name: Ruff
on: 
  - push
  - pull_request

jobs:
  ruff:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: astral-sh/ruff-action@v3
        with:
          src: "./p2pcam"
          version: "0.15.16"

.ruff.toml

# The contents of this file is based on https://github.com/home-assistant/core/blob/dev/pyproject.toml

target-version = "py313"

[lint]
select = [
    "ALL",
]

ignore = [
    "ANN401", # Dynamically typed expressions (typing.Any) are disallowed
    "ANN001",
    "ANN201",
    "ANN202",
    "D203", # no-blank-line-before-class (incompatible with formatter)
    "D212", # multi-line-summary-first-line (incompatible with formatter)
    "COM812", # incompatible with formatter
    "ISC001", # incompatible with formatter
    "E501", # Line length is not important
    "EM101",  
    "TRY003", # Allow exception messages to be used directly
    "ERA001", # Commented out code is allowed for examples
    "T201", # Prints are allowed in examples
    "PLR0913",
    "FBT001", # Boolean positional args are part of the existing public API
    "FBT002",
    "N999",
]

[lint.flake8-pytest-style]
fixture-parentheses = false

[lint.pyupgrade]
keep-runtime-typing = true

[lint.mccabe]
max-complexity = 25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants