From 7d60a635a9109036219db72beb3792d22a5f4e7f Mon Sep 17 00:00:00 2001 From: Kolja Windeler Date: Tue, 27 Jul 2021 20:19:24 +0200 Subject: [PATCH] search for thumbnails with highest resolution --- .../ytube_music_player/manifest.json | 2 +- .../ytube_music_player/media_player.py | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/custom_components/ytube_music_player/manifest.json b/custom_components/ytube_music_player/manifest.json index 871c476..3a7ca37 100644 --- a/custom_components/ytube_music_player/manifest.json +++ b/custom_components/ytube_music_player/manifest.json @@ -16,5 +16,5 @@ "@KoljaWindeler" ], "iot_class": "cloud_polling", - "version": "20210727.01" + "version": "20210727.02" } diff --git a/custom_components/ytube_music_player/media_player.py b/custom_components/ytube_music_player/media_player.py index de8feb9..fe26532 100644 --- a/custom_components/ytube_music_player/media_player.py +++ b/custom_components/ytube_music_player/media_player.py @@ -762,17 +762,21 @@ def extract_info(self, _track): pass try: + _album_art_ref = None if 'thumbnail' in _track: _album_art_ref = _track['thumbnail'] ## returns a list, if 'thumbnails' in _album_art_ref: _album_art_ref = _album_art_ref['thumbnails'] - # thumbnail [0] is super tiny 32x32? / thumbnail [1] is ok-ish / thumbnail [2] is quite nice quality - if isinstance(_album_art_ref,list): - info['track_album_cover'] = _album_art_ref[len(_album_art_ref)-1]['url'] elif 'thumbnails' in _track: _album_art_ref = _track['thumbnails'] ## returns a list - if isinstance(_album_art_ref,list): - info['track_album_cover'] = _album_art_ref[len(_album_art_ref)-1]['url'] + + if isinstance(_album_art_ref,list): + th_width = 0 + for th in _album_art_ref: + if('width' in th and 'url' in th): + if(th['width']>th_width): + th_width = th['width'] + info['track_album_cover'] = th['url'] except: pass @@ -1240,7 +1244,7 @@ async def async_get_url(self, videoId=None, retry=True): #self.log_me('debug','found stream') #self.log_me('debug',streamingData[i]) if('audioQuality' in streamingData[i]): - self.log_me('debug','- found stream with audioQuality '+streamingData[i]['audioQuality']+' ('+str(i)+')') + # self.log_me('debug','- found stream with audioQuality '+streamingData[i]['audioQuality']+' ('+str(i)+')') # store only stream with better quality, accept 0 once if(quality_mapper.get(streamingData[i]['audioQuality'],0) > found_quality): found_quality = quality_mapper.get(streamingData[i]['audioQuality'],0)