diff options
author | scria1000 <91804886+scria1000@users.noreply.github.com> | 2021-12-20 13:18:40 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-20 13:18:40 +0000 |
commit | a7b58cf0a410a1670aa9230cab4d05938caf6648 (patch) | |
tree | 9b72e4b935b681b62108e364647819f991016085 /app | |
parent | 34127032de45b6f860d998daf3adfebcb029e0fc (diff) | |
download | infinity-for-reddit-a7b58cf0a410a1670aa9230cab4d05938caf6648.tar infinity-for-reddit-a7b58cf0a410a1670aa9230cab4d05938caf6648.tar.gz infinity-for-reddit-a7b58cf0a410a1670aa9230cab4d05938caf6648.tar.bz2 infinity-for-reddit-a7b58cf0a410a1670aa9230cab4d05938caf6648.tar.lz infinity-for-reddit-a7b58cf0a410a1670aa9230cab4d05938caf6648.tar.xz infinity-for-reddit-a7b58cf0a410a1670aa9230cab4d05938caf6648.tar.zst infinity-for-reddit-a7b58cf0a410a1670aa9230cab4d05938caf6648.zip |
Support imgur gifv with audio (#602)
Support imgur gifv videos with audio.
Diffstat (limited to '')
6 files changed, 88 insertions, 20 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java index fe7c89c3..a8c609f2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java @@ -261,6 +261,8 @@ public class LinkResolverActivity extends AppCompatActivity { startActivity(intent); } else if (path.endsWith("gifv")) { String url = uri.toString(); + // Insecure imgur links won't load + url = url.replaceFirst("http://" , "https://"); url = url.substring(0, url.length() - 5) + ".mp4"; Intent intent = new Intent(this, ViewVideoActivity.class); intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_DIRECT); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java index 2727e40a..b53ddf7e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java @@ -126,6 +126,7 @@ public class ViewVideoActivity extends AppCompatActivity { public static final String EXTRA_V_REDD_IT_URL = "EVRIU"; public static final String EXTRA_STREAMABLE_SHORT_CODE = "ESSC"; public static final String EXTRA_IS_NSFW = "EIN"; + public static final int VIDEO_TYPE_IMGUR = 7; public static final int VIDEO_TYPE_STREAMABLE = 5; public static final int VIDEO_TYPE_V_REDD_IT = 4; public static final int VIDEO_TYPE_DIRECT = 3; @@ -523,9 +524,13 @@ public class ViewVideoActivity extends AppCompatActivity { player.prepare(new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(mVideoUri)); preparePlayer(savedInstanceState); } - } else if (videoType == VIDEO_TYPE_DIRECT) { + } else if (videoType == VIDEO_TYPE_DIRECT || videoType == VIDEO_TYPE_IMGUR) { videoDownloadUrl = mVideoUri.toString(); - videoFileName = FilenameUtils.getName(videoDownloadUrl); + if (videoType == VIDEO_TYPE_DIRECT) { + videoFileName = FilenameUtils.getName(videoDownloadUrl); + } else { + videoFileName = "imgur-" + FilenameUtils.getName(videoDownloadUrl); + } // Produces DataSource instances through which media data is loaded. dataSourceFactory = new CacheDataSourceFactory(mSimpleCache, new DefaultHttpDataSourceFactory(Util.getUserAgent(this, "Infinity"))); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java index 0f268f08..6b63a0c0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java @@ -1657,7 +1657,10 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler if (canStartActivity) { canStartActivity = false; Intent intent = new Intent(mActivity, ViewVideoActivity.class); - if (mPost.isGfycat()) { + if (mPost.isImgur()) { + intent.setData(Uri.parse(mPost.getVideoUrl())); + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_IMGUR); + } else if (mPost.isGfycat()) { intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT); intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, mPost.getGfycatId()); if (mPost.isLoadGfycatOrStreamableVideoSuccess()) { @@ -1882,7 +1885,10 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler canStartActivity = false; if (mPost.getPostType() == Post.VIDEO_TYPE) { Intent intent = new Intent(mActivity, ViewVideoActivity.class); - if (mPost.isGfycat()) { + if (mPost.isImgur()) { + intent.setData(Uri.parse(mPost.getVideoUrl())); + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_IMGUR); + } else if (mPost.isGfycat()) { intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT); intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, mPost.getGfycatId()); } else if (mPost.isRedgifs()) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java index eb2dd24e..f69b8378 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -1943,7 +1943,10 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie canStartActivity = false; if (post.getPostType() == Post.VIDEO_TYPE) { Intent intent = new Intent(mActivity, ViewVideoActivity.class); - if (post.isGfycat()) { + if (post.isImgur()) { + intent.setData(Uri.parse(post.getVideoUrl())); + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_IMGUR); + } else if (post.isGfycat()) { intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT); intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId()); } else if (post.isRedgifs()) { @@ -2683,7 +2686,10 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie if (post != null) { markPostRead(post, true); Intent intent = new Intent(mActivity, ViewVideoActivity.class); - if (post.isGfycat()) { + if (post.isImgur()) { + intent.setData(Uri.parse(post.getVideoUrl())); + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_IMGUR); + } else if (post.isGfycat()) { intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT); intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId()); if (post.isLoadGfycatOrStreamableVideoSuccess()) { @@ -3968,7 +3974,10 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie if (post != null) { markPostRead(post, true); Intent intent = new Intent(mActivity, ViewVideoActivity.class); - if (post.isGfycat()) { + if (post.isImgur()) { + intent.setData(Uri.parse(post.getVideoUrl())); + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_IMGUR); + } else if (post.isGfycat()) { intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT); intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId()); if (post.isLoadGfycatOrStreamableVideoSuccess()) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java index c7c7c997..b3260973 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java @@ -13,6 +13,7 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; +import java.util.Objects; import java.util.concurrent.Executor; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -400,20 +401,38 @@ public class ParsePost { post.setVideoDownloadUrl(videoDownloadUrl); } else if (data.has(JSONUtils.PREVIEW_KEY)) { if (data.getJSONObject(JSONUtils.PREVIEW_KEY).has(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY)) { - //Gif video post (HLS) int postType = Post.VIDEO_TYPE; - String videoUrl = Html.fromHtml(data.getJSONObject(JSONUtils.PREVIEW_KEY) - .getJSONObject(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY).getString(JSONUtils.HLS_URL_KEY)).toString(); - String videoDownloadUrl = data.getJSONObject(JSONUtils.PREVIEW_KEY) - .getJSONObject(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY).getString(JSONUtils.FALLBACK_URL_KEY); - - post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, authorFlair, - authorFlairHTML, postTimeMillis, title, permalink, score, postType, voteType, - nComments, upvoteRatio, flair, awards, nAwards, hidden, spoiler, nsfw, stickied, - archived, locked, saved, isCrosspost); - post.setPreviews(previews); - post.setVideoUrl(videoUrl); - post.setVideoDownloadUrl(videoDownloadUrl); + Uri uri = Uri.parse(url); + String authority = uri.getAuthority(); + // The hls stream inside REDDIT_VIDEO_PREVIEW_KEY can sometimes lack an audio track + // This happens with imgur gifv that are actually mp4, even the official Reddit app has this bug + if (authority.contains("imgur.com") && url.endsWith(".gifv")) { + url = url.substring(0, url.length() - 5) + ".mp4"; + + post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, authorFlair, + authorFlairHTML, postTimeMillis, title, permalink, score, postType, voteType, + nComments, upvoteRatio, flair, awards, nAwards, hidden, spoiler, nsfw, stickied, + archived, locked, saved, isCrosspost); + post.setPreviews(previews); + post.setVideoUrl(url); + post.setVideoDownloadUrl(url); + post.setIsImgur(true); + } else { + //Gif video post (HLS) + + String videoUrl = Html.fromHtml(data.getJSONObject(JSONUtils.PREVIEW_KEY) + .getJSONObject(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY).getString(JSONUtils.HLS_URL_KEY)).toString(); + String videoDownloadUrl = data.getJSONObject(JSONUtils.PREVIEW_KEY) + .getJSONObject(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY).getString(JSONUtils.FALLBACK_URL_KEY); + + post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, authorFlair, + authorFlairHTML, postTimeMillis, title, permalink, score, postType, voteType, + nComments, upvoteRatio, flair, awards, nAwards, hidden, spoiler, nsfw, stickied, + archived, locked, saved, isCrosspost); + post.setPreviews(previews); + post.setVideoUrl(videoUrl); + post.setVideoDownloadUrl(videoDownloadUrl); + } } else { if (url.endsWith("jpg") || url.endsWith("png")) { //Image post @@ -449,6 +468,22 @@ public class ParsePost { post.setPreviews(previews); post.setVideoUrl(url); post.setVideoDownloadUrl(url); + } else if (url.endsWith("gifv") && Objects.equals(Uri.parse(url).getAuthority(), "i.imgur.com")) { + // Imgur gifv/mp4 + int postType = Post.VIDEO_TYPE; + + // Insecure imgur links won't load + url = url.replaceFirst("http://" , "https://"); + url = url.substring(0, url.length() - 5) + ".mp4"; + + post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, + authorFlair, authorFlairHTML, postTimeMillis, title, url, permalink, score, + postType, voteType, nComments, upvoteRatio, flair, awards, nAwards, + hidden, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost); + post.setPreviews(previews); + post.setVideoUrl(url); + post.setVideoDownloadUrl(url); + post.setIsImgur(true); } else { if (url.contains(permalink)) { //Text post but with a preview diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java index c20df496..82060f0e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java @@ -52,6 +52,7 @@ public class Post implements Parcelable { private String videoDownloadUrl; private String gfycatId; private String streamableShortCode; + private boolean isImgur; private boolean isGfycat; private boolean isRedgifs; private boolean isStreamable; @@ -175,6 +176,7 @@ public class Post implements Parcelable { videoDownloadUrl = in.readString(); gfycatId = in.readString(); streamableShortCode = in.readString(); + isImgur = in.readByte() != 0; isGfycat = in.readByte() != 0; isRedgifs = in.readByte() != 0; isStreamable = in.readByte() != 0; @@ -333,6 +335,14 @@ public class Post implements Parcelable { this.streamableShortCode = shortCode; } + public void setIsImgur(boolean isImgur) { + this.isImgur = isImgur; + } + + public boolean isImgur() { + return isImgur; + } + public boolean isGfycat() { return isGfycat; } @@ -553,6 +563,7 @@ public class Post implements Parcelable { parcel.writeString(videoDownloadUrl); parcel.writeString(gfycatId); parcel.writeString(streamableShortCode); + parcel.writeByte((byte) (isImgur ? 1 : 0)); parcel.writeByte((byte) (isGfycat ? 1 : 0)); parcel.writeByte((byte) (isRedgifs ? 1 : 0)); parcel.writeByte((byte) (isStreamable ? 1 : 0)); |