PlexDevices - Custom Media Player Component

Update posted (Nvidia shield fix)

Testing now.

OK, I cleared my cache, deleted the pycache and installed the new code. I’m not running the Shield at the moment and this is what I see.

I’m going to go and run Plex on the Shield and then capture the screen when it’s running…

Same as before…

Error log:

17-02-16 22:08:24 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/requests/packages/urllib3/connection.py", line 141, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/requests/packages/urllib3/util/connection.py", line 83, in create_connection
    raise err
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/requests/packages/urllib3/util/connection.py", line 73, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 356, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/lib/python3.4/http/client.py", line 1090, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python3.4/http/client.py", line 1128, in _send_request
    self.endheaders(body)
  File "/usr/lib/python3.4/http/client.py", line 1086, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python3.4/http/client.py", line 924, in _send_output
    self.send(msg)
  File "/usr/lib/python3.4/http/client.py", line 859, in send
    self.connect()
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/requests/packages/urllib3/connection.py", line 166, in connect
    conn = self._new_conn()
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/requests/packages/urllib3/connection.py", line 150, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
requests.packages.urllib3.exceptions.NewConnectionError: <requests.packages.urllib3.connection.HTTPConnection object at 0x6476e810>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/requests/adapters.py", line 423, in send
    timeout=timeout
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 649, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/requests/packages/urllib3/util/retry.py", line 376, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
requests.packages.urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=32500): Max retries exceeded with url: /player/playback/pause?commandID=1&type=video (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x6476e810>: Failed to establish a new connection: [Errno 111] Connection refused',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/tasks.py", line 233, in _step
    result = coro.throw(exc)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/core.py", line 1018, in _event_to_service_call
    yield from service_handler.func(service_call)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/media_player/__init__.py", line 364, in async_service_handler
    yield from getattr(player, method['method'])(**params)
  File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.4/asyncio/tasks.py", line 286, in _wakeup
    value = future.result()
  File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
    raise self._exception
  File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/hass/custom_components/media_player/plexdevices.py", line 623, in media_pause
    self.device.pause(self._active_media_plexapi_type)
  File "/home/hass/deps/plexapi/client.py", line 126, in pause
    def pause(self, mtype): self.sendCommand('playback/pause', type=mtype)
  File "/home/hass/deps/plexapi/client.py", line 85, in sendCommand
    return self.query(path, headers=headers)
  File "/home/hass/deps/plexapi/client.py", line 66, in query
    response = method(url, headers=headers, timeout=TIMEOUT, **kwargs)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/requests/sessions.py", line 501, in get
    return self.request('GET', url, **kwargs)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/requests/sessions.py", line 488, in request
    resp = self.send(prep, **send_kwargs)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/requests/sessions.py", line 609, in send
    r = adapter.send(request, **kwargs)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/requests/adapters.py", line 487, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=32500): Max retries exceeded with url: /player/playback/pause?commandID=1&type=video (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x6476e810>: Failed to establish a new connection: [Errno 111] Connection refused',))

Hey @JesseWebDotCom - not running a shield (client or server) but receiving this still:

Traceback (most recent call last):
  File "uvloop/future.pyx", line 372, in uvloop.loop.BaseTask._fast_step (uvloop/loop.c:112669)
  File "/usr/src/app/homeassistant/helpers/entity_component.py", line 336, in _async_process_entity
    new_entity, self, update_before_add=update_before_add
  File "/usr/src/app/homeassistant/helpers/entity_component.py", line 205, in async_add_entity
    yield from entity.async_update_ha_state()
  File "/usr/src/app/homeassistant/helpers/entity.py", line 240, in async_update_ha_state
    attr)
  File "/usr/src/app/homeassistant/helpers/entity.py", line 306, in _attr_setter
    value = getattr(self, name)
  File "/config/custom_components/media_player/plexdevices.py", line 573, in supported_features
    if "127.0.0.1" in self._convert_na_to_none(self.device.baseurl):
AttributeError: 'NoneType' object has no attribute 'baseurl'

I have started a thread in the Plex forum:

Maybe Plex team could help us out.

So I just tried it out with 38.3 and plexdevices using Plex on an AppleTV. It works and seems to give all information. Though volume control does not work with this client it seems and Im not surprised at that.

What I would have hoped would start working with your improvements was channels and playing movies from there, but they don’t seem to be represented anywhere in Plex context.

Also noticed that media_season: is still shown even when no media is playing. Small bug perhaps?

I would still like you to reconsider also using the web hooks, since the same issue with slow updates as with the original plugin still exists. Even though I increase polling frequency it is still annoying that it is not instant now that Plex enables the possibility of getting notifications.

But don’t take too much on my grind with web hooks, still an awesome job you’ve done! :smiley:

/R

1 Like

May be a bit OT but important to anyone considering the ShieldTV as a Plex Media Server:

Well, the Shield PMS issues may not even be worth sorting out at the moment. I thought I did proper research before buying my Shield 16GB, but as it turns out, I didn’t do enough.

Plex Media Server will only store it’s metadata on the internal storage, even if you have added adoptable storage. With a large collection, you can quickly eat up all your internal storage leaving you with performance issues (which fortunately I am not experiencing yet).

Plex blames nVidia, but this is BS because Kodi is able to store its data anywhere. Plex decided to use a secure location and changing this is totally on them. As a lifetime PlexPass member, I feel cheated and lied to. They’ve known about this for months now and have released new PMS versions but no fix.

I may end up moving to kodi if I can’t find a way around this or it is fixed. In the meantime, I’ll probably be moving my music libraries off the Shield in order to conserve space.

Here’s a post explaining this in the nVidia forums:
https://forums.geforce.com/default/topic/976481/shield-tv/when-will-we-be-able-to-save-plex-data-and-settings-/1/

Wouldn’t it be possible to redirect the folder on a system level to point to an external or event remote drive?

Are you using the latest version as I believe I fixed that issue? You should see the following code:

    @property
    def supported_features(self):
        """Flag media player features that are supported."""

        # Disable controls if player is local (127.0.0.1)
        # Like when running client and server on a single Nvidia shield
        # or when casting to an Nvidia shield running a plex server
        if self.local:
            return None
        # No mute since Shield only supports volume 2-100
        elif self.make == "SHIELD Android TV":
            return SUPPORT_PLEX
        elif self.device:
            return SUPPORT_PLEX | SUPPORT_VOLUME_MUTE
        else:
            return None

No, unfortunately Plex decided to put their metadata library in a secure location instead the standard data location off of root, so there’s no way to redirect this with a symlink or anything.

They pushed this through advertisements constantly but never let on about this limitation. I just sent them a nice tweet about it.

As a lifetime PlexPass subscriber, I’d want to take advantage of Webhooks as well. Does anyone with a PlexPass subscriber know how to take advantage of that?

Fix posted to address the season issue

1 Like

@rpitera, have you tried using Plex DVR to record TV shows to a writable Samba share? Have a look at Storage Limitation section in Plex’s website:

Plex relies in the list of storage devices directly from NVIDIA Shield. Kodi does not. I’m not sure if there’s a file manager for Kodi, but in NVIDIA Shield, Android TV does not allow write access to Samba shares unless it’s classified as an “internal volume” similar to USB hard drives connected to the Shield. If you connect your external USB hard drive to Shield as a Media Storage, Android TV won’t allow write access to it unless you classify it as internal volume.

This is even with a Media Optimizer feature. Plex can’t write transcoded movie to a Samba share.

Honestly, I don’t think you’ve been cheated by Plex. I’m not sure if it’s a limitation only in NVIDIA Shield or if it’s a limitation for Android TV as a whole, which includes Nexus Player and other Android TV devices.

Again, sorry for going OT and will gladly move this to a PM if anyone objects.

@GraysonPeddie I think your missing the point here; it’s not about storing media and I don’t use DVR. This is about the metadata for your collections; all the movie/tv posters, ratings info, banners, thumbnails etc. All the stuff that makes Plex really useful in cataloging your collection. For PlexPass members this also includes all the information in the enhanced music libraries as well. None of this can be stored anywhere on the Shield except for the Shield devices internal memory, even if you increase that space by using adoptable storage as Plex decided to use a secure location.

This isn’t an OS issue or even a Shield issue, this is solely due to Plex programming. Kodi uses the standard data location in Android, so when you adopt a USB drive as internal storage, your metadata is stored there.

It’s not about the collections or DVR or samba shares. It’s all about where your metadata is stored. Even with a moderately large collection, you can quickly eat up your internal storage space and some have even reported their Shield’s crashing as a result. Plex advertised the Shield as the “ultimate media server” and pushed it hard, but never let on about these limitations until months later. The article you referenced - which I already saw - was only added when users started complaining about the multiple issues. Things like the inability to use PlexMix on the Shield wasn’t even added to that page until a couple of weeks ago.

So yeah, I feel cheated. And the limitation is not for Android TV as a whole, only Plex Media Server on the Shield, since that’s the only Android TV device currently supported to run PMS.

Okay. My apologies for going off-topic.

I don’t know if it’s possible to store metadata in another storage device, such as a Samba share, though, but I get your point.

1 Like

When browsing your server in the web client go in to your account and you should find web hooks.

Plex has posted a node.js example on how to do home automation with web hooks

/R

I got that, but what URL do I put in it for Webhooks? Do I put in something like http:\\localhost:1250 (I used “\” instead of “//” so Discourse does not convert the localhost address into links; otherwise, I’ll get a “Popular Link” badge…)?

Can you guys create a new discussion topic on web hooks? Its better for this thread and for people who want to know about web hooks

I continued discussion in my new thread.

Please pardon me for going off-topic.

FIX DEPLOYED

When using both entity_namespace and use_custom_entity_ids:
BEFORE FIX: media_player.xyz
AFTER FIX: media_player.plex_xyz