Skip to content

Commit 68f25cf

Browse files
committed
Update
- custom url for plex poster/art so the token is protected - added (check README) to error when the app is configured
1 parent 05d6ec2 commit 68f25cf

File tree

5 files changed

+36
-4
lines changed

5 files changed

+36
-4
lines changed

custom_components/plex_recently_added/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from .plex_api import (
2727
FailedToLogin,
2828
)
29+
from .redirect import ImagesRedirect
2930

3031

3132
PLATFORMS = [
@@ -51,6 +52,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
5152
raise ConfigEntryNotReady("Failed to Log-in") from err
5253
coordinator = PlexDataCoordinator(hass, client)
5354

55+
hass.http.register_view(ImagesRedirect(config_entry))
5456
await coordinator.async_config_entry_first_refresh()
5557
hass.data.setdefault(DOMAIN, {})[config_entry.entry_id] = coordinator
5658

custom_components/plex_recently_added/parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ def parse_data(data, max, base_url, token, identifier, section_key):
4747
"studio": item.get("grandparentTitle", ""),
4848
"aired": date,
4949
"runtime": math.floor(int(item.get("duration", 0)) / 60000),
50-
"poster": (base_url + thumb + f'?X-Plex-Token={token}') if thumb else "",
51-
"fanart": (base_url + art + f'?X-Plex-Token={token}') if art else "",
50+
"poster": (f'/pms_plex_recently_added?path={thumb}') if thumb else "",
51+
"fanart": (f'/pms_plex_recently_added?path={art}') if art else "",
5252
"flag": "viewCount" not in item,
5353
"deep_link": deep_link if identifier else None
5454
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from homeassistant.components.http import HomeAssistantView
2+
from homeassistant.config_entries import ConfigEntry
3+
from aiohttp import web
4+
import requests
5+
6+
from homeassistant.const import (
7+
CONF_API_KEY,
8+
CONF_NAME,
9+
CONF_HOST,
10+
CONF_PORT,
11+
CONF_SSL
12+
)
13+
14+
from .const import DOMAIN
15+
16+
class ImagesRedirect(HomeAssistantView):
17+
requires_auth = False
18+
19+
def __init__(self, config_entry: ConfigEntry):
20+
super().__init__()
21+
self._token = config_entry.data[CONF_API_KEY]
22+
self._base_url = f'http{'s' if config_entry.data[CONF_SSL] else ''}://{config_entry.data[CONF_HOST]}:{config_entry.data[CONF_PORT]}'
23+
self.name = f'{self._token}_Plex_Recently_Added'
24+
self.url = f'/{config_entry.data[CONF_NAME].lower() + "_" if len(config_entry.data[CONF_NAME]) > 0 else ""}plex_recently_added'
25+
26+
async def get(self, request):
27+
path = request.query.get("path", "")
28+
url = f'{self._base_url}{path}?X-Plex-Token={self._token}'
29+
return web.HTTPFound(url)
30+

custom_components/plex_recently_added/strings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"cannot_be_reached": "Plex cannot be reached"
2323
},
2424
"abort": {
25-
"already_configured": "User is already configured",
25+
"already_configured": "User is already configured (check README)",
2626
"failed_to_login": "Failed to Log-in",
2727
"cannot_be_reached": "Plex cannot be reached"
2828
}

custom_components/plex_recently_added/translations/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"cannot_be_reached": "Plex cannot be reached"
2323
},
2424
"abort": {
25-
"already_configured": "User is already configured",
25+
"already_configured": "User is already configured (check README)",
2626
"failed_to_login": "Failed to Log-in",
2727
"cannot_be_reached": "Plex cannot be reached"
2828
}

0 commit comments

Comments
 (0)