Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow empty password on camera #834

Open
drewp opened this issue Nov 16, 2024 · 4 comments
Open

allow empty password on camera #834

drewp opened this issue Nov 16, 2024 · 4 comments

Comments

@drewp
Copy link

drewp commented Nov 16, 2024

This works:
ffprobe rtsp://admin:@cam-li:554/

But this config fails:
camera_li: { name: li, host: cam-li, port: 554, path: /, username: admin, password: "", width: 2048, height: 1536, fps: 10, codec: h264, audio_codec: aac }

I wish https://github.com/roflcoopter/viseron/blob/dev/viseron/components/ffmpeg/stream.py#L210 only checked username, and perhaps that 214 defaulted to empty string.

@drewp
Copy link
Author

drewp commented Nov 16, 2024

A workaround is to abuse this code...

            f"{protocol}://"
            f"{auth}"
            f"{self._config[CONFIG_HOST]}:{stream_config[CONFIG_PORT]}"
            f"{stream_config[CONFIG_PATH]}"

and jam the auth into the hostname :)

host: "admin:@cam-li"

@roflcoopter
Copy link
Owner

Smart workaround!

Changing the code to this:

    def get_stream_url(self, stream_config: dict[str, Any]) -> str:
        """Return stream url."""
        auth = ""
        if (
            self._config[CONFIG_USERNAME] is not None
            and self._config[CONFIG_PASSWORD] is not None
        ):
            auth = (
                f"{self._config[CONFIG_USERNAME]}"
                ":"
                f"{escape_string(self._config[CONFIG_PASSWORD])}"
                "@"
            )

        protocol = (
            stream_config[CONFIG_PROTOCOL]
            if stream_config[CONFIG_PROTOCOL]
            else STREAM_FORMAT_MAP[stream_config[CONFIG_STREAM_FORMAT]]["protocol"]
        )

        return (
            f"{protocol}://"
            f"{auth}"
            f"{self._config[CONFIG_HOST]}:{stream_config[CONFIG_PORT]}"
            f"{stream_config[CONFIG_PATH]}"
        )

WIth this config:

ffmpeg:
  camera:
    camera1:
      name: Camera 1
      host: ipcamera.iot
      port: 554
      path: /onvif/profile.0
      username: admin
      password: ""

Produces this result: rtsp://admin:@ipcamera.iot:554/onvif/profile.0

Is that the correct format for your use case?

@drewp
Copy link
Author

drewp commented Nov 17, 2024

Behavior LGTM.

I have no idea if escape_string is right for password (nor if 'no-op' is the right thing for username), but that hasn't changed.

As a code clarity note, consider making local username and password vars, which would save many linebreaks below:

    def get_stream_url(self, stream_config: dict[str, Any]) -> str:
        username = self._config[CONFIG_USERNAME]
        password = self._config[CONFIG_PASSWORD]
        auth = ""
        if username is not None and password is not None:
            auth = f"{username}:{escape_string(password)}@" 

@roflcoopter
Copy link
Owner

Looks good, thanks for the suggestion!

Will be in dev soon and the next release

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

No branches or pull requests

2 participants