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

[FR] Add media browser #23

Closed
chemelli74 opened this issue May 9, 2022 · 67 comments · Fixed by #60
Closed

[FR] Add media browser #23

chemelli74 opened this issue May 9, 2022 · 67 comments · Fixed by #60

Comments

@chemelli74
Copy link
Contributor

Would be nice to have media browsing in HA.

Thx for considering,

Simone

@arag00rn
Copy link

I agree, would be great!

@elad-bar
Copy link
Owner

Added the support, thanks for the FR

@chemelli74
Copy link
Contributor Author

Hi @elad-bar,

thx for the quick addition!
I get the following error while browsing:

image

Anything already known ?
Simone

@elad-bar
Copy link
Owner

Will fix it in few minutes, thanks

@elad-bar elad-bar reopened this May 20, 2022
@elad-bar
Copy link
Owner

@chemelli74 please check with latest version (v1.1.29), if it's working please close the issue.

thanks

@arag00rn
Copy link

Hi,
I'm using latest version (v1.1.29). I do see videos but I cannot open them.
I tried to debug and seems that it's trying to make a GET on https even if I configured the plugin for standard http.

Thanks,
Andrea

@chemelli74
Copy link
Contributor Author

Hi,

now the list is correctly retrieved, but playback is not proxied.
This means that you need direct access to the shinobi server to stream.
And that you need to configure both Shinobi and HA on the same protocol (http or https).

Not sure if this is the correct info, but hopefully it sheds some light: https://developers.home-assistant.io/docs/core/entity/media-player/?_highlight=proxy#proxy-album-art-for-media-browser

Simone

@elad-bar
Copy link
Owner

That is the media player documentation, not sure it is correct for media source, will check it tomorrow

@elad-bar
Copy link
Owner

Checked it and for Media Browser there is no need for proxy, for media player there is indeed as you have mentioned.

As for http vs https, most casting devices requires transportation to be secured, I have SSL set up for the Shinobi Video as well to allow the streaming of it to any of my TVs and devices

@chemelli74
Copy link
Contributor Author

Checked it and for Media Browser there is no need for proxy, for media player there is indeed as you have mentioned.

Investigating a bit further, to make it work will all setup ( so make the streaming via HA ), there is need to work with API views.
One example:

Simone

@elad-bar
Copy link
Owner

It will take time for me to learn and implement the proxy, hope that next week I'll have some good news...

@elad-bar
Copy link
Owner

checked it furter, according to the following thread, media browser handles the proxy by itself:
home-assistant thread

will keep checking it, just to understand better the flow I need to check -
HA is configured with SSL, Shinobi without, right?

@arag00rn
Copy link

Hi,

In my case yes.
HA with SSL, Shinobi without SSL.

Andrea

@elad-bar
Copy link
Owner

What is the error you are getting if you are trying to play with it?

@arag00rn
Copy link

arag00rn commented May 23, 2022

From Chrome Dev console I see: ERR_SSL_PROTOCOL_ERROR

I guess it's because it's trying to open a http connection using https

@elad-bar
Copy link
Owner

ok, will set it up locally and try to reproduce it
thanks

@chemelli74
Copy link
Contributor Author

HI @elad-bar, any progress ? ;-)

Thx,

Simone

@chemelli74
Copy link
Contributor Author

@elad-bar did you got the time to check this by any chance ?

Thank you in advance,

Simone

@elad-bar
Copy link
Owner

hi @chemelli74,
I didn't manage to reproduce the issue so couldn't solve it,
My HA has 2 addresses for accessing it - http out of the box from HA, https from reverse proxy,
same goes for the Shinobi video.

integration between HA to Shinobi is using the https address of shinobi (to allow streaming / casting for other devices),
to access the HA i'm using https address as well.

Media Browsing is working smoothly from within the house or external network.

if your setup is different, please share so I'll be able to understand how to reproduce that issue.

thanks

@arag00rn
Copy link

@chemelli74 I solved the issue using a reverse proxy with SSL.

(https) -> HA -> (https) proxy (http) -> Shinobi

@elad-bar
Copy link
Owner

@chemelli74 can you please share the status at your system?

thanks

@elad-bar
Copy link
Owner

@chemelli74 is that issue still relevant?

thanks

@chemelli74
Copy link
Contributor Author

I think so.
My system is:

https(browser) -> reverse(https->http) -> http(HA)

So browser access HA via https but HA access Shinobi via http (and it's not internet exposed).

Simone

@elad-bar
Copy link
Owner

mine is also working the same, https is available only in the reverse proxy, meaning communication between:

  • browser to service - will be https -> https
  • service to service - can be one of - http -> http / https -> http / https -> https

not sure i understand what is the issue if that's the case,
if you would like to have proxy because the Shinobi is not exposed to the world that's another motivation (not related to http / https).

thanks

@chemelli74
Copy link
Contributor Author

if you would like to have proxy because the Shinobi is not exposed to the world that's another motivation (not related to http / https).

If you "proxy" internally in HA the request you get the solution of all scenario:

shinobi -> http -> HA, use proxy view -> https -> browser

And Shinobi is not reachable from internet ;-)

Simone

@chemelli74
Copy link
Contributor Author

@elad-bar
Copy link
Owner

I know how to implement it thanks for the link you have posted above, but i'm not sure about its ROI.

Shinobi Video has several implementations of auth (much stronger than HA), meaning, no real reason that if HA is exposed to the world, Shinobi Video will not.

Will get to it someday but not sure it will be in the upcoming month.

@elad-bar
Copy link
Owner

@chemelli74, just to understand your use case once again, when you are not at home, meaning using the HA externally, do you watch the live stream and the videos from HA?

thanks

@elad-bar
Copy link
Owner

For me the sensors are working, pls open another issue (as it's not related to the current feature request) for it with more detail including what version of Shinobi are you using (if docker, which image), you have mentioned plugin, which plugin, logs in debug log at the time of the event

Thanks

@elad-bar
Copy link
Owner

elad-bar commented Aug 4, 2023

@chemelli74 any updates?

Thanks

@chemelli74
Copy link
Contributor Author

@chemelli74 any updates?

Thanks

Sorry, I need first to figure out why the new version on shinobi server (just installed) and the latest version of the integration don't generate the camera entity

@elad-bar
Copy link
Owner

elad-bar commented Aug 5, 2023

Do you have logs in debug level to share?

Thanks

@chemelli74
Copy link
Contributor Author

Do you have logs in debug level to share?

Thanks

Sorry was very busy for a house moving.
Here what I see:

2023-08-12 19:07:49.378 INFO (MainThread) [custom_components.shinobi.managers.rest_api] Initializing Shinobi Server API
2023-08-12 19:07:49.378 INFO (MainThread) [custom_components.shinobi.managers.rest_api] Status changed from 'Connected to the API' to 'Establishing connection to API'
2023-08-12 19:07:49.449 INFO (MainThread) [custom_components.shinobi.managers.rest_api] Status changed from 'Establishing connection to API' to 'Connected with temporary API key'
2023-08-12 19:07:49.478 INFO (MainThread) [custom_components.shinobi.managers.rest_api] Status changed from 'Connected with temporary API key' to 'Connected to the API'
2023-08-12 19:07:49.517 INFO (MainThread) [custom_components.shinobi.managers.websockets] Status changed from 'Disconnected by the system' to 'Connected to the API'
2023-08-12 19:07:49.517 INFO (MainThread) [custom_components.shinobi.managers.websockets] Starting to listen connected
2023-08-12 19:08:41.375 WARNING (MainThread) [custom_components.shinobi.managers.websockets] Status changed from 'Connected to the API' to 'Not connected'
2023-08-12 19:08:46.378 INFO (MainThread) [custom_components.shinobi.managers.websockets] Status changed from 'Not connected' to 'Disconnected by the system'

@elad-bar
Copy link
Owner

Good luck, logs are in info level, when you have time, please share debug log level

Thanks

@chemelli74
Copy link
Contributor Author

Good luck, logs are in info level, when you have time, please share debug log level

:-(
Too tired probably, sorry.

Enabled now I see the same single line repeated every second:

2023-08-12 19:34:21.427 DEBUG (MainThread) [custom_components.shinobi.managers.coordinator] Finished fetching Shinobi Video data in 0.000 seconds (success: True)
2023-08-12 19:34:22.426 DEBUG (MainThread) [custom_components.shinobi.managers.coordinator] Finished fetching Shinobi Video data in 0.000 seconds (success: True)
2023-08-12 19:34:23.425 DEBUG (MainThread) [custom_components.shinobi.managers.coordinator] Finished fetching Shinobi Video data in 0.000 seconds (success: True)
2023-08-12 19:34:24.426 DEBUG (MainThread) [custom_components.shinobi.managers.coordinator] Finished fetching Shinobi Video data in 0.000 seconds (success: True)
2023-08-12 19:34:25.425 DEBUG (MainThread) [custom_components.shinobi.managers.coordinator] Finished fetching Shinobi Video data in 0.000 seconds (success: True)
2023-08-12 19:34:26.426 DEBUG (MainThread) [custom_components.shinobi.managers.coordinator] Finished fetching Shinobi Video data in 0.000 seconds (success: True)
2023-08-12 19:34:27.427 DEBUG (MainThread) [custom_components.shinobi.managers.coordinator] Finished fetching Shinobi Video data in 0.000 seconds (success: True)
2023-08-12 19:34:28.427 DEBUG (MainThread) [custom_components.shinobi.managers.coordinator] Finished fetching Shinobi Video data in 0.000 seconds (success: True)
2023-08-12 19:34:29.425 DEBUG (MainThread) [custom_components.shinobi.managers.coordinator] Finished fetching Shinobi Video data in 0.000 seconds (success: True)
2023-08-12 19:34:30.426 DEBUG (MainThread) [custom_components.shinobi.managers.coordinator] Finished fetching Shinobi Video data in 0.000 seconds (success: True)
2023-08-12 19:34:31.426 DEBUG (MainThread) [custom_components.shinobi.managers.coordinator] Finished fetching Shinobi Video data in 0.000 seconds (success: True)
2023-08-12 19:34:32.425 DEBUG (MainThread) [custom_components.shinobi.managers.coordinator] Finished fetching Shinobi Video data in 0.000 seconds (success: True)

Simone

@elad-bar
Copy link
Owner

@chemelli74 I will need the log for the entire loading until you are facing the issue in debug level to understand the issue, for now, in the logs you have shared, I don't see any issue.

thanks

@chemelli74
Copy link
Contributor Author

@elad-bar thx for the patience!

I'm now back home so I could play a bit more. Here the debug full log with a "reload" of the integration to get the full info:
home-assistant_shinobi_2023-08-25T17-43-14.686Z.log

Let me know if I can do something more.
If you prefer you can join HomeAssistant on Discord and then contact me: chemelli74#2180

Simone

@chemelli74
Copy link
Contributor Author

BTW, I redacted the username and password in 2 different places:

2023-08-25 19:39:26.658 INFO (MainThread) [custom_components.shinobi.managers.flow_manager] Config flow started, Step: user, Input: {'title': 'Shinobi Video', 'host': '192.168.1.15', 'path': '/', 'port': 8080, 'ssl': False, 'username': '**redacted**', 'password': '**redacted**plain**'}

2023-08-25 19:41:47.697 INFO (MainThread) [custom_components.shinobi.managers.flow_manager] {'host': '192.168.1.15', 'path': '/', 'port': 8080, 'ssl': False, 'username': '**redacted**', 'password': '**redacted**encrypted**', 'title': 'Shinobi Video'}

I think you should not log them so it's easier for everyone to share without security concerns.
If you want there is a helper for that in core: https://github.com/home-assistant/core/blob/dev/homeassistant/components/diagnostics/util.py#L25

Simone

@elad-bar
Copy link
Owner

elad-bar commented Aug 31, 2023

BTW, I redacted the username and password in 2 different places:

2023-08-25 19:39:26.658 INFO (MainThread) [custom_components.shinobi.managers.flow_manager] Config flow started, Step: user, Input: {'title': 'Shinobi Video', 'host': '192.168.1.15', 'path': '/', 'port': 8080, 'ssl': False, 'username': '**redacted**', 'password': '**redacted**plain**'}

2023-08-25 19:41:47.697 INFO (MainThread) [custom_components.shinobi.managers.flow_manager] {'host': '192.168.1.15', 'path': '/', 'port': 8080, 'ssl': False, 'username': '**redacted**', 'password': '**redacted**encrypted**', 'title': 'Shinobi Video'}

I think you should not log them so it's easier for everyone to share without security concerns. If you want there is a helper for that in core: https://github.com/home-assistant/core/blob/dev/homeassistant/components/diagnostics/util.py#L25

Simone

thanks for the feedback and suggestion, applying it to all my component, already available in v3.0.4 (for diagnostic only)

@chemelli74
Copy link
Contributor Author

Any idea why the CAM entity is not created in my setup ?

Simone

@chemelli74
Copy link
Contributor Author

Any idea for investigating?

Simone

@chemelli74
Copy link
Contributor Author

After applying #56 and #57, I have the camera working but not the media browsing:

2023-10-25 10:33:59.697 ERROR (stream_worker) [homeassistant.components.stream.stream.camera.shinobi_video_terrazzo] Error from stream worker: Stream ended; no additional packets

image

@elad-bar
Copy link
Owner

elad-bar commented Nov 5, 2023

merging your code and testing it before releasing new version, it doesn't look like related but will check it anyway, thanks for the contribution!

@chemelli74
Copy link
Contributor Author

This is my current status:

2023-11-13 18:47:54.670 DEBUG (MainThread) [custom_components.shinobi.media_source] Browse media, Identifier: camera/e3536f7b75cb09effb99bca15d1198e8, Title: Shinobi Video / Shinobi Video
2023-11-13 18:47:54.670 INFO (MainThread) [custom_components.shinobi.media_source] {'e3536f7b75cb09effb99bca15d1198e8': <custom_components.shinobi.managers.coordinator.Coordinator object at 0x7f1d66c52cd0>}
2023-11-13 18:47:54.670 INFO (MainThread) [custom_components.shinobi.media_source] e3536f7b75cb09effb99bca15d1198e8
2023-11-13 18:47:54.670 INFO (MainThread) [custom_components.shinobi.media_source] {'e3536f7b75cb09effb99bca15d1198e8': <custom_components.shinobi.managers.coordinator.Coordinator object at 0x7f1d66c52cd0>}
2023-11-13 18:47:54.670 INFO (MainThread) [custom_components.shinobi.media_source] e3536f7b75cb09effb99bca15d1198e8
2023-11-13 18:47:54.670 DEBUG (MainThread) [custom_components.shinobi.media_source] Building monitors list
2023-11-13 18:47:54.670 DEBUG (MainThread) [custom_components.shinobi.managers.rest_api] GET http://192.168.1.15:8080/KGpA1PAHwOtz1uYAxzKZxK9fNUddA1/videoBrowser/4KKLbBiHNU
2023-11-13 18:47:54.678 DEBUG (MainThread) [custom_components.shinobi.managers.rest_api] Status of http://192.168.1.15:8080/KGpA1PAHwOtz1uYAxzKZxK9fNUddA1/videoBrowser/4KKLbBiHNU: 200
2023-11-13 18:47:54.680 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [139763627365952] Error handling message: Unknown error (unknown_error) admin from <**REDACTED**> (Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 26, in _handle_async_response
    await func(hass, connection, msg)
  File "/usr/src/homeassistant/homeassistant/components/media_source/__init__.py", line 174, in websocket_browse_media
    media = await async_browse_media(hass, msg.get("media_content_id", ""))
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/media_source/__init__.py", line 125, in async_browse_media
    item = await _get_media_item(hass, media_content_id, None).async_browse()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/media_source/models.py", line 79, in async_browse
    return await self.async_media_source().async_browse_media(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/shinobi/media_source.py", line 118, in async_browse_media
    *await action(identifier),
     ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/shinobi/media_source.py", line 221, in _async_build_monitors
    if snapshot.startswith("/"):
       ^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'startswith'
2023-11-13 18:47:56.035 DEBUG (MainThread) [custom_components.shinobi.managers.coordinator] Finished fetching Shinobi Video data in 0.000 seconds (s                                                                                                                                                   success: True)
2023-11-13 18:47:56.036 DEBUG (MainThread) [custom_components.shinobi.managers.websockets] Checking event's triggers, Identified: 0
2023-11-13 18:47:57.019 DEBUG (MainThread) [custom_components.shinobi.managers.websockets] Checking event's triggers, Identified: 0
2023-11-13 18:47:57.218 DEBUG (MainThread) [custom_components.shinobi.managers.coordinator] Finished fetching Shinobi Video data in 0.000 seconds (success: True)

@elad-bar
Copy link
Owner

I need to apply the same fix you have added in camera to media source component

@chemelli74
Copy link
Contributor Author

I need to apply the same fix you have added in camera to media source component

Didn't investigate yet, was just to report before loosing the log again ;-)

@chemelli74
Copy link
Contributor Author

Applied the change blindly and we did some progress: I can see the folders and the list of the videos 🥳
But still not able to play them:

image

@elad-bar
Copy link
Owner

Pls open developer tools in browser and look for error in console

@chemelli74
Copy link
Contributor Author

Mixed Content: The page at 'https://xxxxxx:8123/media-browser/browser/app%2Cmedia-source%3A%2F%2Fshinobi/app%2Cmedia-source%3A%2F%2Fshinobi%2Fcamera%2Fe3536f7b75cb09effb99bca15d1198e8/album%2Cmedia-source%3A%2F%2Fshinobi%2Fcamera%2Fe3536f7b75cb09effb99bca15d1198e8%2FOTbmfgEU4G10080/album%2Cmedia-source%3A%2F%2Fshinobi%2Fcamera%2Fe3536f7b75cb09effb99bca15d1198e8%2FOTbmfgEU4G10080%2F2023-11-13' was loaded over HTTPS, but requested an insecure video 'http://192.168.1.15:8080/KGpA1PAHwOtz1uYAxzKZxK9fNUddA1/videos/4KKLbBiHNU/OTbmfgEU4G10080/2023-11-13T17-15-01.mp4'. This request has been blocked; the content must be served over HTTPS.

@elad-bar
Copy link
Owner

As described in the error, you are trying to access unsecured url while the hosting site is secured,
To make it work you need to have shinobi configured as https

@chemelli74
Copy link
Contributor Author

As described in the error, you are trying to access unsecured url while the hosting site is secured, To make it work you need to have shinobi configured as https

Actually if it's proxied it should not be needed. It was one of the point for asking this implementation ;-)

@elad-bar
Copy link
Owner

Is it configured working with proxy?

@chemelli74
Copy link
Contributor Author

Is it configured working with proxy?

What you mean exactly ?

@elad-bar
Copy link
Owner

You asked foe the feature and it was released in v3.0.1 as mentioned above

Added Use original Stream switch component under device of server

@elad-bar
Copy link
Owner

Sorry, in v3.0.0 - Add proxy view for recordings

@chemelli74
Copy link
Contributor Author

You asked foe the feature and it was released in v3.0.1 as mentioned above

Added Use original Stream switch component under device of server

Sorry my fault, I though it was autodetected as for other components.
I just enabled "Shinobi Video Server Use Proxy for Recording" switch and now it works fine.

Would you evaluate taking a PR that create the URL from the calling path so it will be always correct ?

Otherwise a user have to change the switch based on the fact that he is or out the home.

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 a pull request may close this issue.

4 participants