99import okhttp3 .Response ;
1010import okhttp3 .ResponseBody ;
1111import org .apache .log4j .Logger ;
12+ import org .jetbrains .annotations .Contract ;
1213import org .jetbrains .annotations .NotNull ;
1314import org .jetbrains .annotations .Nullable ;
1415import org .jetbrains .annotations .Range ;
@@ -789,21 +790,37 @@ private class EventsDispatcher {
789790 }
790791 }
791792
792- private void sendImage () {
793- PlayableId id = state .getCurrentPlayable ();
794- if (id == null ) return ;
793+ @ Contract ("null, null -> fail" )
794+ private void sendImage (@ Nullable Metadata .Track track , @ Nullable Metadata .Episode episode ) {
795+ Metadata .ImageGroup group = null ;
796+ if (track != null ) {
797+ if (track .hasAlbum () && track .getAlbum ().hasCoverGroup ())
798+ group = track .getAlbum ().getCoverGroup ();
799+ } else if (episode != null ) {
800+ if (episode .hasCoverImage ())
801+ group = episode .getCoverImage ();
802+ } else {
803+ throw new IllegalStateException ();
804+ }
795805
796- Map <String , String > metadata = state .metadataFor (id );
797806 ImageId image = null ;
798- for (String key : ImageId .IMAGE_SIZES_URLS ) {
799- if (metadata .containsKey (key )) {
800- image = ImageId .fromUri (metadata .get (key ));
801- break ;
807+ if (group == null ) {
808+ PlayableId id = state .getCurrentPlayable ();
809+ if (id == null ) return ;
810+
811+ Map <String , String > metadata = state .metadataFor (id );
812+ for (String key : ImageId .IMAGE_SIZES_URLS ) {
813+ if (metadata .containsKey (key )) {
814+ image = ImageId .fromUri (metadata .get (key ));
815+ break ;
816+ }
802817 }
818+ } else {
819+ image = ImageId .biggestImage (group );
803820 }
804821
805822 if (image == null ) {
806- LOGGER .warn ("No image found in metadata: " + id );
823+ LOGGER .warn ("No image found in metadata." );
807824 return ;
808825 }
809826
@@ -814,9 +831,9 @@ private void sendImage() {
814831 if (resp .code () == 200 && (body = resp .body ()) != null )
815832 metadataPipe .safeSend (MetadataPipe .TYPE_SSNC , MetadataPipe .CODE_PICT , body .bytes ());
816833 else
817- LOGGER .warn (String .format ("Failed download image. {id: %s, code: %d}" , image .hexId (), resp .code ()));
834+ LOGGER .warn (String .format ("Failed downloading image. {id: %s, code: %d}" , image .hexId (), resp .code ()));
818835 } catch (IOException ex ) {
819- LOGGER .warn ("Failed download image." , ex );
836+ LOGGER .warn ("Failed downloading image." , ex );
820837 }
821838 }
822839
@@ -922,7 +939,7 @@ void metadataAvailable() {
922939 metadataPipe .safeSend (MetadataPipe .TYPE_CORE , MetadataPipe .CODE_ASAR , artist );
923940
924941 sendProgress ();
925- sendImage ();
942+ sendImage (track , episode );
926943 }
927944 }
928945
0 commit comments