From 9a3b9115ffd8492c7a64c285ae90df067ac764e7 Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Sun, 27 Nov 2022 15:17:39 +0300 Subject: Fix Imgur bug for insecure mp4 links (#1240) --- .../activities/LinkResolverActivity.java | 6 +++-- .../infinityforreddit/post/ParsePost.java | 30 +++++++++++++--------- 2 files changed, 22 insertions(+), 14 deletions(-) (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit') 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 748d7b53..5bba98bc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java @@ -299,11 +299,13 @@ public class LinkResolverActivity extends AppCompatActivity { intent.putExtra(ViewImgurMediaActivity.EXTRA_IMGUR_TYPE, ViewImgurMediaActivity.IMGUR_TYPE_IMAGE); intent.putExtra(ViewImgurMediaActivity.EXTRA_IMGUR_ID, path.substring(1)); startActivity(intent); - } else if (path.endsWith("gifv")) { + } else if (path.endsWith("gifv") || path.endsWith("mp4")) { String url = uri.toString(); // Insecure imgur links won't load url = url.replaceFirst("http://" , "https://"); - url = url.substring(0, url.length() - 5) + ".mp4"; + if (path.endsWith("gifv")) { + url = url.substring(0, url.length() - 5) + ".mp4"; + } Intent intent = new Intent(this, ViewVideoActivity.class); intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_IMGUR); intent.putExtra(ViewVideoActivity.EXTRA_IS_NSFW, getIntent().getBooleanExtra(EXTRA_IS_NSFW, false)); 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 dddb4d69..d1bdd74c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java @@ -378,9 +378,13 @@ public class ParsePost { 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"; + if (authority.contains("imgur.com") && (url.endsWith(".gifv") || url.endsWith(".mp4"))) { + // Insecure imgur links won't load + url = url.replaceFirst("http://" , "https://"); + + if (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, @@ -430,10 +434,16 @@ public class ParsePost { post.setPreviews(previews); post.setVideoUrl(url); - } else if (url.endsWith("mp4")) { - //Video post + } else if (Uri.parse(url).getAuthority().contains("imgur.com") && (url.endsWith("gifv") || url.endsWith("mp4"))) { + // Imgur gifv/mp4 int postType = Post.VIDEO_TYPE; + // Insecure imgur links won't load + url = url.replaceFirst("http://" , "https://"); + if (url.endsWith("gifv")) { + 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, @@ -441,14 +451,11 @@ 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 + post.setIsImgur(true); + } else if (url.endsWith("mp4")) { + //Video post 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, @@ -456,7 +463,6 @@ public class ParsePost { post.setPreviews(previews); post.setVideoUrl(url); post.setVideoDownloadUrl(url); - post.setIsImgur(true); } else { if (url.contains(permalink)) { //Text post but with a preview -- cgit v1.2.3