From 67bc84689f307e7da377c08125c54a3cce30cb92 Mon Sep 17 00:00:00 2001 From: Yuriy Liskov Date: Sat, 17 Oct 2020 20:38:29 +0300 Subject: [PATCH] amplify resolution info --- MediaServiceCore | 2 +- README.md | 7 ++++- .../common/app/models/data/Video.java | 4 +-- .../exoplayer/selector/TrackSelectorUtil.java | 31 +++++++++++++++++-- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/MediaServiceCore b/MediaServiceCore index de2ef53c2..483a7e110 160000 --- a/MediaServiceCore +++ b/MediaServiceCore @@ -1 +1 @@ -Subproject commit de2ef53c26b6b0e63868233c453b819d4fddf984 +Subproject commit 483a7e1105f2fc8f3ba155da74704553e991292d diff --git a/README.md b/README.md index 72bdfca59..c6abf5133 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,12 @@ of the following components: To build, install and run a debug version, run this from the root of the project: -```./gradlew assembleDebug``` +``` +git clone https://github.com/yuliskov/SmartTubeNext.git +cd SmartTubeNext +git submodule update --init +./gradlew buildStbetaDebug +``` # Unit Tests diff --git a/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/models/data/Video.java b/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/models/data/Video.java index 498587c4e..d4aa59a2f 100644 --- a/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/models/data/Video.java +++ b/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/models/data/Video.java @@ -70,9 +70,9 @@ public final class Video implements Parcelable { video.title = item.getTitle(); video.category = item.getContentType(); video.description = item.getDescription(); - video.videoId = item.getMediaId(); + video.videoId = item.getVideoId(); video.channelId = item.getChannelId(); - video.videoUrl = item.getMediaUrl(); + video.videoUrl = item.getVideoUrl(); video.bgImageUrl = item.getBackgroundImageUrl(); video.cardImageUrl = item.getCardImageUrl(); video.studio = item.getAuthor(); diff --git a/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/exoplayer/selector/TrackSelectorUtil.java b/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/exoplayer/selector/TrackSelectorUtil.java index 7b0754269..4373274c8 100644 --- a/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/exoplayer/selector/TrackSelectorUtil.java +++ b/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/exoplayer/selector/TrackSelectorUtil.java @@ -6,6 +6,8 @@ import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.util.MimeTypes; import com.liskovsoft.sharedutils.helpers.Helpers; +import java.util.HashMap; + public class TrackSelectorUtil { public static final String CODEC_SHORT_AVC = "avc"; public static final String CODEC_SHORT_VP9 = "vp9"; @@ -13,6 +15,19 @@ public class TrackSelectorUtil { public static final String CODEC_SHORT_MP4A = "mp4a"; public static final String CODEC_SHORT_VORBIS = "vorbis"; private static final String SEPARATOR = ", "; + private static final HashMap mResolutionMap = new HashMap<>(); + + static { + mResolutionMap.put(256, 144); + mResolutionMap.put(426, 240); + mResolutionMap.put(640, 360); + mResolutionMap.put(854, 480); + mResolutionMap.put(1280, 720); + mResolutionMap.put(1920, 1080); + mResolutionMap.put(2560, 1440); + mResolutionMap.put(3840, 2160); + mResolutionMap.put(7680, 4320); + } /** * Builds a track name for display. @@ -23,7 +38,7 @@ public class TrackSelectorUtil { public static CharSequence buildTrackNameShort(Format format) { String trackName; if (MimeTypes.isVideo(format.sampleMimeType)) { - trackName = joinWithSeparator(joinWithSeparator(joinWithSeparator(joinWithSeparator(buildResolutionString(format), + trackName = joinWithSeparator(joinWithSeparator(joinWithSeparator(joinWithSeparator(buildResolutionShortString(format), buildFPSString(format)), buildBitrateString(format)), extractCodec(format)), buildHDRString(format)); } else if (MimeTypes.isAudio(format.sampleMimeType)) { trackName = joinWithSeparator(joinWithSeparator(joinWithSeparator(joinWithSeparator(buildLanguageString(format), @@ -46,8 +61,18 @@ public class TrackSelectorUtil { return format.frameRate == Format.NO_VALUE ? "" : Helpers.formatFloat(format.frameRate) + "fps"; } - private static String buildResolutionString(Format format) { - return format.width == Format.NO_VALUE || format.height == Format.NO_VALUE ? "" : format.height + "p"; + /** + * Build short resolution: e.g. 720p, 1080p etc + */ + private static String buildResolutionShortString(Format format) { + if (format.width == Format.NO_VALUE || format.height == Format.NO_VALUE) { + return ""; + } + + // Try to amplify resolution of aspect ratios that differ from 16:9 + Integer height = mResolutionMap.get(format.width); + + return height != null ? height + "p" : format.height + "p"; } private static String buildAudioPropertyString(Format format) {