From 807f2f4039cca50a02efba6fe66c6a7bec5d85d2 Mon Sep 17 00:00:00 2001 From: "Michael K. Avanessian" Date: Sun, 28 Jan 2024 20:32:02 -0800 Subject: [PATCH 1/3] Added deep_link support. Changed behavior to also include digital releases. --- .vscode/settings.json | 5 ++ .../radarr_upcoming_media/sensor.py | 68 +++++++++---------- 2 files changed, 39 insertions(+), 34 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..a04b218 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "*.yaml": "home-assistant" + } +} \ No newline at end of file diff --git a/custom_components/radarr_upcoming_media/sensor.py b/custom_components/radarr_upcoming_media/sensor.py index c262f6b..c0a4a92 100644 --- a/custom_components/radarr_upcoming_media/sensor.py +++ b/custom_components/radarr_upcoming_media/sensor.py @@ -88,44 +88,43 @@ def extra_state_attributes(self): self.card_json.append(default) for movie in sorted(self.data, key=lambda i: i['path']): card_item = {} - if ('inCinemas' in movie and - days_until(movie['inCinemas'], self._tz) > -1): - if not self.theaters: - continue - card_item['airdate'] = movie['inCinemas'] - if days_until(movie['inCinemas'], self._tz) <= 7: - card_item['release'] = 'In Theaters $day' - else: - card_item['release'] = 'In Theaters $day, $date' - elif 'physicalRelease' in movie: - card_item['airdate'] = movie['physicalRelease'] - if days_until(movie['physicalRelease'], self._tz) <= 7: + in_cinemas_date = movie.get('inCinemas') + physical_release_date = movie.get('physicalRelease') + digital_release_date = movie.get('digitalRelease') + + should_include = False + if in_cinemas_date and days_until(in_cinemas_date, self._tz) > -1: + should_include = self.theaters + if not should_include and (physical_release_date and days_until(physical_release_date, self._tz) > -1 or + digital_release_date and days_until(digital_release_date, self._tz) > -1): + should_include = True + + if should_include: + card_item['airdate'] = movie.get('inCinemas', movie.get('physicalRelease', movie.get('digitalRelease'))) + if days_until(card_item['airdate'], self._tz) <= 7: card_item['release'] = 'Available $day' else: card_item['release'] = 'Available $day, $date' - else: - continue - card_item['flag'] = movie.get('hasFile', '') - card_item['title'] = movie.get('title', '') - card_item['runtime'] = movie.get('runtime', '') - card_item['studio'] = movie.get('studio', '') - card_item['genres'] = movie.get('genres', '') - if 'ratings' in movie and movie['ratings']['value'] > 0: - card_item['rating'] = ('\N{BLACK STAR} ' + - str(movie['ratings']['value'])) - else: - card_item['rating'] = '' - if 'images' in movie: - if len(movie['images']): - card_item['poster'] = movie['images'][0] - if len(movie['images']) > 1 and '.jpg' in movie['images'][1]: - card_item['fanart'] = movie['images'][1] + card_item['flag'] = movie.get('hasFile', '') + card_item['title'] = movie.get('title', '') + card_item['runtime'] = movie.get('runtime', '') + card_item['studio'] = movie.get('studio', '') + card_item['genres'] = movie.get('genres', '') + if 'ratings' in movie and movie['ratings'].get('value', 0) > 0: + card_item['rating'] = ('\N{BLACK STAR} ' + + str(movie['ratings']['value'])) else: - card_item['fanart'] = '' - else: - continue - self.card_json.append(card_item) - self.change_detected = False + card_item['rating'] = '' + if 'images' in movie: + if len(movie['images']): + card_item['poster'] = movie['images'][0] + if len(movie['images']) > 1 and '.jpg' in movie['images'][1]: + card_item['fanart'] = movie['images'][1] + else: + card_item['fanart'] = '' + card_item['deep_link'] = f'http://{self.host}:{self.port}/movie/{movie.get("tmdbId")}' + self.card_json.append(card_item) + self.change_detected = False attributes['data'] = self.card_json return attributes @@ -196,6 +195,7 @@ def update(self): ]][:3]) except: movie['genres'] = '' + movie['deep_link'] = f'http://{self.host}:{self.port}/movie/{movie.get("id", "unknown")}' else: self._state = '%s cannot be reached' % self.host From c6a7e2626334804cfbcd6a73c08422f3bf6c07b4 Mon Sep 17 00:00:00 2001 From: "Michael K. Avanessian" Date: Sun, 28 Jan 2024 21:18:52 -0800 Subject: [PATCH 2/3] Reverted code back to original behavior when filtering movies out. --- .../radarr_upcoming_media/sensor.py | 68 ++++++++++--------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/custom_components/radarr_upcoming_media/sensor.py b/custom_components/radarr_upcoming_media/sensor.py index c0a4a92..788d26f 100644 --- a/custom_components/radarr_upcoming_media/sensor.py +++ b/custom_components/radarr_upcoming_media/sensor.py @@ -88,43 +88,45 @@ def extra_state_attributes(self): self.card_json.append(default) for movie in sorted(self.data, key=lambda i: i['path']): card_item = {} - in_cinemas_date = movie.get('inCinemas') - physical_release_date = movie.get('physicalRelease') - digital_release_date = movie.get('digitalRelease') - - should_include = False - if in_cinemas_date and days_until(in_cinemas_date, self._tz) > -1: - should_include = self.theaters - if not should_include and (physical_release_date and days_until(physical_release_date, self._tz) > -1 or - digital_release_date and days_until(digital_release_date, self._tz) > -1): - should_include = True - - if should_include: - card_item['airdate'] = movie.get('inCinemas', movie.get('physicalRelease', movie.get('digitalRelease'))) - if days_until(card_item['airdate'], self._tz) <= 7: + if ('inCinemas' in movie and + days_until(movie['inCinemas'], self._tz) > -1): + if not self.theaters: + continue + card_item['airdate'] = movie['inCinemas'] + if days_until(movie['inCinemas'], self._tz) <= 7: + card_item['release'] = 'In Theaters $day' + else: + card_item['release'] = 'In Theaters $day, $date' + elif 'physicalRelease' in movie: + card_item['airdate'] = movie['physicalRelease'] + if days_until(movie['physicalRelease'], self._tz) <= 7: card_item['release'] = 'Available $day' else: card_item['release'] = 'Available $day, $date' - card_item['flag'] = movie.get('hasFile', '') - card_item['title'] = movie.get('title', '') - card_item['runtime'] = movie.get('runtime', '') - card_item['studio'] = movie.get('studio', '') - card_item['genres'] = movie.get('genres', '') - if 'ratings' in movie and movie['ratings'].get('value', 0) > 0: - card_item['rating'] = ('\N{BLACK STAR} ' + - str(movie['ratings']['value'])) + else: + continue + card_item['flag'] = movie.get('hasFile', '') + card_item['title'] = movie.get('title', '') + card_item['runtime'] = movie.get('runtime', '') + card_item['studio'] = movie.get('studio', '') + card_item['genres'] = movie.get('genres', '') + if 'ratings' in movie and movie['ratings'].get('value', 0) > 0: + card_item['rating'] = ('\N{BLACK STAR} ' + + str(movie['ratings']['value'])) + else: + card_item['rating'] = '' + if 'images' in movie: + if len(movie['images']): + card_item['poster'] = movie['images'][0] + if len(movie['images']) > 1 and '.jpg' in movie['images'][1]: + card_item['fanart'] = movie['images'][1] else: - card_item['rating'] = '' - if 'images' in movie: - if len(movie['images']): - card_item['poster'] = movie['images'][0] - if len(movie['images']) > 1 and '.jpg' in movie['images'][1]: - card_item['fanart'] = movie['images'][1] - else: - card_item['fanart'] = '' - card_item['deep_link'] = f'http://{self.host}:{self.port}/movie/{movie.get("tmdbId")}' - self.card_json.append(card_item) - self.change_detected = False + card_item['fanart'] = '' + else: + continue + card_item['deep_link'] = f'http://{self.host}:{self.port}/movie/{movie.get("tmdbId")}' + self.card_json.append(card_item) + self.change_detected = False attributes['data'] = self.card_json return attributes From a987a6dd08e93218c3a12b8703e728ecef33d34b Mon Sep 17 00:00:00 2001 From: "Michael K. Avanessian" Date: Thu, 1 Feb 2024 13:11:28 -0800 Subject: [PATCH 3/3] Updated manifest.json file with new version --- custom_components/radarr_upcoming_media/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/radarr_upcoming_media/manifest.json b/custom_components/radarr_upcoming_media/manifest.json index c0675c3..7c104d5 100644 --- a/custom_components/radarr_upcoming_media/manifest.json +++ b/custom_components/radarr_upcoming_media/manifest.json @@ -1,7 +1,7 @@ { "domain": "radarr_upcoming_media", "name": "Radarr Upcoming Media", - "version": "0.3.6", + "version": "0.3.7", "documentation": "https://github.com/custom-components/sensor.radarr_upcoming_media", "dependencies": [], "codeowners": ["@maykar"],