From bec10f4008d65fbba3d4daeaccf60156af429630 Mon Sep 17 00:00:00 2001 From: "Michael K. Avanessian" Date: Sun, 28 Jan 2024 16:30:29 -0800 Subject: [PATCH 1/3] Added Sonarr V4 support. Added deep_link support. --- .../sonarr_upcoming_media/sensor.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/custom_components/sonarr_upcoming_media/sensor.py b/custom_components/sonarr_upcoming_media/sensor.py index 5626b2d..b2e8e76 100644 --- a/custom_components/sonarr_upcoming_media/sensor.py +++ b/custom_components/sonarr_upcoming_media/sensor.py @@ -109,9 +109,9 @@ def extra_state_attributes(self): else: card_item['studio'] = '' if ('ratings' in show['series'] and - show['series']['ratings']['value'] > 0): + show['series']['ratings']['value'] > 0): card_item['rating'] = ('\N{BLACK STAR} ' + - str(show['series']['ratings']['value'])) + str(show['series']['ratings']['value'])) else: card_item['rating'] = '' if 'genres' in show['series']: @@ -121,16 +121,19 @@ def extra_state_attributes(self): try: for img in show['series']['images']: if img['coverType'] == 'poster': - card_item['poster'] = re.sub('.jpg', '_t.jpg', img['url']) + card_item['poster'] = re.sub('.jpg', '_t.jpg', img['remoteUrl']) except: continue try: card_item['fanart'] = '' for img in show['series']['images']: if img['coverType'] == 'fanart': - card_item['fanart'] = re.sub('.jpg', '_t.jpg', img['url']) + card_item['fanart'] = re.sub('.jpg', '_t.jpg', img['remoteUrl']) except: pass + series_title = show['series']['title'] + series_slug = series_title.lower().replace(' ', '-') # Slugify the series title + card_item['deep_link'] = f'http://{self.host}:{self.port}/series/{series_slug}?apikey={self.apikey}' card_json.append(card_item) attributes['data'] = card_json return attributes @@ -139,8 +142,8 @@ def update(self): start = get_date(self._tz) end = get_date(self._tz, self.days) try: - api = requests.get('http{0}://{1}:{2}/{3}api/calendar?start={4}' - '&end={5}'.format(self.ssl, self.host, + api = requests.get('http{0}://{1}:{2}/{3}api/v3/calendar?start={4}' + '&end={5}&includeEpisodeImages=true&includeSeries=true'.format(self.ssl, self.host, self.port, self.urlbase, start, end), headers={'X-Api-Key': self.apikey}, timeout=10) @@ -175,4 +178,4 @@ def days_until(date, tz): now = datetime.now().strftime('%Y-%m-%d') now = time.strptime(now, '%Y-%m-%d') now = time.mktime(now) - return int((date - now) / 86400) + return int((date - now) / 86400) \ No newline at end of file From fdb1080bd31b60abbfb8a527e4c1c64fce95d81b Mon Sep 17 00:00:00 2001 From: "Michael K. Avanessian" Date: Sun, 28 Jan 2024 20:47:29 -0800 Subject: [PATCH 2/3] Fixed indentation for a couple of lines --- custom_components/sonarr_upcoming_media/sensor.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/custom_components/sonarr_upcoming_media/sensor.py b/custom_components/sonarr_upcoming_media/sensor.py index b2e8e76..063e026 100644 --- a/custom_components/sonarr_upcoming_media/sensor.py +++ b/custom_components/sonarr_upcoming_media/sensor.py @@ -109,9 +109,9 @@ def extra_state_attributes(self): else: card_item['studio'] = '' if ('ratings' in show['series'] and - show['series']['ratings']['value'] > 0): + show['series']['ratings']['value'] > 0): card_item['rating'] = ('\N{BLACK STAR} ' + - str(show['series']['ratings']['value'])) + str(show['series']['ratings']['value'])) else: card_item['rating'] = '' if 'genres' in show['series']: @@ -132,8 +132,8 @@ def extra_state_attributes(self): except: pass series_title = show['series']['title'] - series_slug = series_title.lower().replace(' ', '-') # Slugify the series title - card_item['deep_link'] = f'http://{self.host}:{self.port}/series/{series_slug}?apikey={self.apikey}' + series_slug = series_title.lower().replace(' ', '-') + card_item['deep_link'] = f'http://{self.host}:{self.port}/series/{series_slug}' card_json.append(card_item) attributes['data'] = card_json return attributes @@ -178,4 +178,4 @@ def days_until(date, tz): now = datetime.now().strftime('%Y-%m-%d') now = time.strptime(now, '%Y-%m-%d') now = time.mktime(now) - return int((date - now) / 86400) \ No newline at end of file + return int((date - now) / 86400) From d2c93a45ab908f7c8712a324564cb4255b9d6ef3 Mon Sep 17 00:00:00 2001 From: "Michael K. Avanessian" Date: Thu, 1 Feb 2024 12:55:53 -0800 Subject: [PATCH 3/3] Modified manifest.json with new version number --- custom_components/sonarr_upcoming_media/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/sonarr_upcoming_media/manifest.json b/custom_components/sonarr_upcoming_media/manifest.json index 37aa0f7..8850085 100644 --- a/custom_components/sonarr_upcoming_media/manifest.json +++ b/custom_components/sonarr_upcoming_media/manifest.json @@ -1,7 +1,7 @@ { "domain": "sonarr_upcoming_media", "name": "Sonarr Upcoming Media", - "version": "0.2.7", + "version": "0.2.8", "documentation": "https://github.com/custom-components/sensor.sonarr_upcoming_media", "dependencies": [], "codeowners": ["@maykar"],