Skip to content

Commit 3b5795a

Browse files
committed
Fix
- fixing hardcoded url error to dynamic
1 parent 68f25cf commit 3b5795a

File tree

5 files changed

+11
-5
lines changed

5 files changed

+11
-5
lines changed

custom_components/plex_recently_added/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from homeassistant.core import HomeAssistant
44
from homeassistant.exceptions import ConfigEntryNotReady
55
from homeassistant.const import (
6+
CONF_NAME,
67
CONF_API_KEY,
78
CONF_HOST,
89
CONF_PORT,
@@ -37,6 +38,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
3738
try:
3839
client = await setup_client(
3940
hass,
41+
config_entry.data[CONF_NAME],
4042
config_entry.data[CONF_SSL],
4143
config_entry.data[CONF_API_KEY],
4244
config_entry.data[CONF_MAX],

custom_components/plex_recently_added/config_flow.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ async def async_step_user(
6969
try:
7070
await setup_client(
7171
self.hass,
72+
user_input[CONF_NAME],
7273
user_input[CONF_SSL],
7374
user_input[CONF_API_KEY],
7475
user_input[CONF_MAX],

custom_components/plex_recently_added/helpers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
async def setup_client(
55
hass: HomeAssistant,
6+
name: str,
67
ssl: bool,
78
token: str,
89
max: int,
@@ -14,7 +15,7 @@ async def setup_client(
1415
exclude_keywords: list,
1516
verify_ssl: bool,
1617
):
17-
client = PlexApi(hass, ssl, token, max, on_deck, host, port, section_types, section_libraries, exclude_keywords, verify_ssl)
18+
client = PlexApi(hass, name, ssl, token, max, on_deck, host, port, section_types, section_libraries, exclude_keywords, verify_ssl)
1819

1920
await client.update()
2021
return client

custom_components/plex_recently_added/parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def parse_library(root):
1919

2020
return output
2121

22-
def parse_data(data, max, base_url, token, identifier, section_key):
22+
def parse_data(data, max, base_url, token, identifier, section_key, images_base_url):
2323
data = sorted(data, key=lambda i: i['addedAt'], reverse=True)[:max]
2424

2525
output = []
@@ -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": (f'/pms_plex_recently_added?path={thumb}') if thumb else "",
51-
"fanart": (f'/pms_plex_recently_added?path={art}') if art else "",
50+
"poster": (f'{images_base_url}?path={thumb}') if thumb else "",
51+
"fanart": (f'{images_base_url}?path={art}') if art else "",
5252
"flag": "viewCount" not in item,
5353
"deep_link": deep_link if identifier else None
5454
}

custom_components/plex_recently_added/plex_api.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class PlexApi():
1616
def __init__(
1717
self,
1818
hass: HomeAssistant,
19+
name: str,
1920
ssl: bool,
2021
token: str,
2122
max: int,
@@ -38,6 +39,7 @@ def __init__(
3839
self._section_libraries = section_libraries
3940
self._exclude_keywords = exclude_keywords
4041
self._verify_ssl = verify_ssl
42+
self._images_base_url = f'/{name.lower() + "_" if len(name) > 0 else ""}plex_recently_added'
4143

4244
async def update(self):
4345
info_url = 'http{0}://{1}:{2}'.format(
@@ -127,7 +129,7 @@ async def update(self):
127129

128130
data_out = {}
129131
for k in data.keys():
130-
data_out[k] = {'data': [DEFAULT_PARSE_DICT] + parse_data(data[k], self._max, info_url, self._token, identifier, k)}
132+
data_out[k] = {'data': [DEFAULT_PARSE_DICT] + parse_data(data[k], self._max, info_url, self._token, identifier, k, self._images_base_url)}
131133

132134
return {
133135
"data": {**data_out},

0 commit comments

Comments
 (0)