|
41 | 41 | import us.shandian.giga.util.Utility; |
42 | 42 |
|
43 | 43 | import static org.schabi.newpipe.BuildConfig.DEBUG; |
| 44 | +import static org.schabi.newpipe.extractor.ServiceList.YouTube; |
44 | 45 |
|
45 | 46 | public class DownloadMission extends Mission { |
46 | 47 | private static final long serialVersionUID = 6L;// last bump: 07 october 2019 |
@@ -866,12 +867,25 @@ public void fetchThumbnail(@NonNull final List<Image> images) { |
866 | 867 | final String thumbnailUrl = ImageStrategy.choosePreferredImage( |
867 | 868 | images, PreferredImageQuality.HIGH); |
868 | 869 | // TODO: get context from somewhere else |
869 | | - thumbnail = CoilHelper.INSTANCE.loadBitmapBlocking(App.getInstance(), thumbnailUrl); |
| 870 | + Bitmap originalThumbnail = CoilHelper.INSTANCE.loadBitmapBlocking( |
| 871 | + App.getInstance(), thumbnailUrl); |
| 872 | + |
| 873 | + // YouTube Music streams have non square thumbnails to fit the player aspect ratio |
| 874 | + // of 16:9. We can safely crop the thumbnail to a square because the squared thumbnail |
| 875 | + // is padded with bars on the sides. |
| 876 | + if (originalThumbnail != null && streamInfo.getService().equals(YouTube) |
| 877 | + && streamInfo.getSongMetadata() != null // i.e. YT Music stream |
| 878 | + && originalThumbnail.getWidth() > originalThumbnail.getHeight()) { |
| 879 | + int cropSize = Math.min(originalThumbnail.getWidth(), originalThumbnail.getHeight()); |
| 880 | + int xOffset = (originalThumbnail.getWidth() - cropSize) / 2; |
| 881 | + originalThumbnail = Bitmap.createBitmap(originalThumbnail, xOffset, 0, |
| 882 | + cropSize, cropSize); |
| 883 | + } |
| 884 | + this.thumbnail = originalThumbnail; |
870 | 885 | thumbnailFetched = true; |
871 | 886 | } catch (final Exception e) { |
872 | 887 | Log.w(TAG, "fetchThumbnail: failed to load thumbnail", e); |
873 | 888 | thumbnailFetched = true; |
874 | | - return; |
875 | 889 | } |
876 | 890 | } |
877 | 891 |
|
|
0 commit comments