Skip to content

External app name + icon metadata#60

Merged
zehnm merged 53 commits into
unfoldedcircle:mainfrom
thomasm789:external-metadata
Apr 24, 2025
Merged

External app name + icon metadata#60
zehnm merged 53 commits into
unfoldedcircle:mainfrom
thomasm789:external-metadata

Conversation

@thomasm789
Copy link
Copy Markdown
Contributor

@thomasm789 thomasm789 commented Apr 12, 2025

@zehnm first draft, I need support in understanding how to setup the use_external_metadata flag. I have setup_flow working and "use_external_metadata" is being stored correctly. But I don't know how to consume the values from config yet in tv.py. Challenge for another time.

@thomasm789 thomasm789 marked this pull request as ready for review April 12, 2025 16:12
@thomasm789
Copy link
Copy Markdown
Contributor Author

thomasm789 commented Apr 13, 2025

@zehnm Finished the feature off (updating title metadata). All working as expected. Can you take a look? Maybe we can push this to prod first before the app icons?

@thomasm789 thomasm789 changed the title External metadata External app name metadata Apr 13, 2025
@zehnm zehnm self-requested a review April 13, 2025 18:22
@thomasm789 thomasm789 changed the title External app name metadata External app name + icon metadata Apr 13, 2025
Copy link
Copy Markdown
Contributor

@zehnm zehnm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image fetching doesn't work, likely because the PIL package is missing.

Comment thread intg-androidtv/setup_flow.py Outdated
Comment thread intg-androidtv/apps.py
Comment thread intg-androidtv/external_metadata.py
@albaintor
Copy link
Copy Markdown
Contributor

albaintor commented Apr 15, 2025

The icon image should act as a fallback, if there's no media artwork. AFAIK there's no supported app yet, that returns artwork with Google Cast.

That's interesting... I'm currently seeing this in the logs.

DEBUG:driver:[SHIELD] device update: {<Attributes.STATE: 'state'>: <States.BUFFERING: 'BUFFERING'>, <Attributes.MEDIA_ALBUM: 'media_album'>: '', <Attributes.MEDIA_ARTIST: 'media_artist'>: '', <Attributes.MEDIA_IMAGE_URL: 'media_image_url'>: MediaImage(url='https://images.metahub.space/poster/small/tt3581920/img', height=None, width=None)}

Interesting indeed, which app were you using ?

The media artwork is a new feature from the last PR.
The app icon should be stored in a separate property in order to get the following algorithm :

  1. When a media artwork is received (which occurs when chromecast is enabled and media event holds a non empty artwork) -> store it and send it to the remote
  2. When no media artwork is defined (chromecast disabled or new media event with no artwork) -> use the app icon instead

So basically you should make a dynamic media_artwork property and do like media_title algorithm : send the new value only when it is different from the old value.

@zehnm
Copy link
Copy Markdown
Contributor

zehnm commented Apr 16, 2025

This simple logic might work, but I couldn't find an app yet that provides Cast media images. Diff against 61d412a

  • Cast images have priority
  • App images are stored in _use_app_url
  • If cast is disabled, or no image available from cast: use app image
diff --git a/intg-androidtv/tv.py b/intg-androidtv/tv.py
index a55315a..af818ac 100644
--- a/intg-androidtv/tv.py
+++ b/intg-androidtv/tv.py
@@ -237,6 +237,8 @@ class AndroidTv(CastStatusListener, MediaStatusListener, ConnectionStatusListene
         self._last_update_position_time: float = 0
         self._media_type = METADATA_TYPE_MOVIE
         self._media_image_url: str | None = None
+        self._app_image_url: str = ""
+        self._use_app_url = not device_config.use_chromecast
         self._player_state = media_player.States.ON
         self._muted = False
 
@@ -651,7 +653,9 @@ class AndroidTv(CastStatusListener, MediaStatusListener, ConnectionStatusListene
                         update[MediaAttr.SOURCE] = metadata.get("name")
 
                     if metadata.get("icon"):
-                        update["media_image_url"] = metadata.get("icon")
+                        self._app_image_url = metadata.get("icon")
+                        if self._use_app_url:
+                            update[MediaAttr.MEDIA_IMAGE_URL] = self._app_image_url
 
             except Exception as e:
                 _LOG.warning("[%s] Failed to get external metadata: %s", self.log_id, e)
@@ -887,11 +891,17 @@ class AndroidTv(CastStatusListener, MediaStatusListener, ConnectionStatusListene
             and len(status.images) > 0
             and status.images[0] != self._media_image_url
         ):
-            self._media_image_url = status.images[0]
+            self._media_image_url = status.images[0].url
             update[MediaAttr.MEDIA_IMAGE_URL] = self._media_image_url
+            # prevent media image being overwritten with app icon
+            self._use_app_url = False
         elif self._media_image_url:
             self._media_image_url = None
-            update[MediaAttr.MEDIA_IMAGE_URL] = ""
+
+        if not self._media_image_url:
+            # safe to use media image for app icon
+            self._use_app_url = True
+            update[MediaAttr.MEDIA_IMAGE_URL] = self._app_image_url
 
         if update:
             _LOG.debug(

@zehnm
Copy link
Copy Markdown
Contributor

zehnm commented Apr 16, 2025

One more fix required in the Cast implementation: self._media_image_url = status.images[0].url. Not sure if url is always available, needs to be checked. I'll update the previous diff.
Using Stremio I got media artwork once for a single movie, but then never again, not even the same one 🤷‍♂️

zehnm added a commit that referenced this pull request Apr 17, 2025
Correctly set the media_image_url from Cast.
Needs to be reverted for PR #60
zehnm added a commit that referenced this pull request Apr 18, 2025
Correctly set the media_image_url from Cast.
Needs to be reverted for PR #60
@thomasm789 thomasm789 requested a review from zehnm April 22, 2025 21:26
Copy link
Copy Markdown
Contributor

@zehnm zehnm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍
Thanks again for your contribution, this is a really nice enhancement!
We'll fine-tune the metadata handling with Chromecast after the next release. There are also a few UI related improvements planned.

@zehnm zehnm merged commit 351f15a into unfoldedcircle:main Apr 24, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants