Fix Redgifs sound.

This commit is contained in:
Docile-Alligator 2025-08-30 11:45:14 -04:00
parent 98a06cc165
commit 51ec964568
5 changed files with 105 additions and 34 deletions

View File

@ -312,7 +312,7 @@ public class LinkResolverActivity extends AppCompatActivity {
if (path.startsWith("/CL0/")) {
handleUri(Uri.parse(path.substring("/CL0/".length())));
}
}/* else if (authority.contains("redgifs.com")) {
} else if (authority.contains("redgifs.com")) {
if (path.matches(REDGIFS_PATTERN)) {
Intent intent = new Intent(this, ViewVideoActivity.class);
intent.putExtra(ViewVideoActivity.EXTRA_REDGIFS_ID, path.substring(path.lastIndexOf("/") + 1));
@ -322,7 +322,7 @@ public class LinkResolverActivity extends AppCompatActivity {
} else {
deepLinkError(uri);
}
}*/ else if (authority.contains("imgur.com")) {
} else if (authority.contains("imgur.com")) {
if (path.matches(IMGUR_GALLERY_PATTERN)) {
Intent intent = new Intent(this, ViewImgurMediaActivity.class);
intent.putExtra(ViewImgurMediaActivity.EXTRA_IMGUR_TYPE, ViewImgurMediaActivity.IMGUR_TYPE_GALLERY);

View File

@ -1063,10 +1063,12 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
} else if (post.isRedgifs()) {
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS);
intent.putExtra(ViewVideoActivity.EXTRA_REDGIFS_ID, post.getRedgifsId());
if (post.isLoadRedgifsOrStreamableVideoSuccess()) {
intent.setData(Uri.parse(post.getVideoUrl()));
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl());
/*if (post.isLoadRedgifsOrStreamableVideoSuccess()) {
intent.setData(Uri.parse(post.getVideoUrl()));
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl());
}
}*/
} else if (post.isStreamable()) {
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_STREAMABLE);
intent.putExtra(ViewVideoActivity.EXTRA_STREAMABLE_SHORT_CODE, post.getStreamableShortCode());

View File

@ -1826,10 +1826,12 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
} else if (post.isRedgifs()) {
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS);
intent.putExtra(ViewVideoActivity.EXTRA_REDGIFS_ID, post.getRedgifsId());
if (post.isLoadRedgifsOrStreamableVideoSuccess()) {
intent.setData(Uri.parse(post.getVideoUrl()));
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl());
/*if (post.isLoadRedgifsOrStreamableVideoSuccess()) {
intent.setData(Uri.parse(post.getVideoUrl()));
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl());
}
}*/
} else if (post.isStreamable()) {
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_STREAMABLE);
intent.putExtra(ViewVideoActivity.EXTRA_STREAMABLE_SHORT_CODE, post.getStreamableShortCode());

View File

@ -347,14 +347,30 @@ public class ParsePost {
String authority = uri.getAuthority();
if (authority != null) {
/*if (authority.contains("redgifs.com")) {
String redgifsId = url.substring(url.lastIndexOf("/") + 1).toLowerCase();
post.setPostType(Post.VIDEO_TYPE);
post.setIsRedgifs(true);
post.setVideoUrl(url);
post.setRedgifsId(redgifsId);
} else */
if (authority.equals("streamable.com")) {
if (authority.contains("redgifs.com")) {
String redgifsId = getRedgifsId(data);
if (redgifsId != null) {
post.setPostType(Post.VIDEO_TYPE);
post.setIsRedgifs(true);
post.setVideoUrl(getRedgifsVideoUrl(redgifsId));
post.setVideoDownloadUrl(post.getVideoUrl());
post.setRedgifsId(redgifsId);
}
/*try {
String redgifsId = data.getJSONObject(JSONUtils.MEDIA_KEY).getJSONObject(JSONUtils.O_EMBED_KEY).getString(JSONUtils.THUMBNAIL_URL_KEY);
redgifsId = redgifsId.substring(redgifsId.lastIndexOf("/") + 1);
int dashIndex = redgifsId.lastIndexOf("-");
if (dashIndex >= 0) {
redgifsId = redgifsId.substring(0, dashIndex);
post.setPostType(Post.VIDEO_TYPE);
post.setIsRedgifs(true);
post.setVideoUrl(url);
post.setRedgifsId(redgifsId);
}
} catch (JSONException e) {
}*/
} else if (authority.equals("streamable.com")) {
String shortCode = url.substring(url.lastIndexOf("/") + 1);
post.setPostType(Post.VIDEO_TYPE);
post.setIsStreamable(true);
@ -551,14 +567,22 @@ public class ParsePost {
String authority = uri.getAuthority();
if (authority != null) {
/*if (authority.contains("redgifs.com")) {
String redgifsId = url.substring(url.lastIndexOf("/") + 1).toLowerCase();
if (authority.contains("redgifs.com")) {
String redgifsId = getRedgifsId(data);
if (redgifsId != null) {
post.setPostType(Post.VIDEO_TYPE);
post.setIsRedgifs(true);
post.setVideoUrl(getRedgifsVideoUrl(redgifsId));
post.setVideoDownloadUrl(post.getVideoUrl());
post.setRedgifsId(redgifsId);
}
/*String redgifsId = url.substring(url.lastIndexOf("/") + 1).toLowerCase();
post.setPostType(Post.VIDEO_TYPE);
post.setIsRedgifs(true);
post.setVideoUrl(url);
post.setRedgifsId(redgifsId);
} else*/
if (authority.equals("streamable.com")) {
post.setRedgifsId(redgifsId);*/
} else if (authority.equals("streamable.com")) {
String shortCode = url.substring(url.lastIndexOf("/") + 1);
post.setPostType(Post.VIDEO_TYPE);
post.setIsStreamable(true);
@ -623,14 +647,21 @@ public class ParsePost {
String authority = uri.getAuthority();
if (authority != null) {
/*if (authority.contains("redgifs.com")) {
String redgifsId = url.substring(url.lastIndexOf("/") + 1).toLowerCase();
if (authority.contains("redgifs.com")) {
String redgifsId = getRedgifsId(data);
if (redgifsId != null) {
post.setPostType(Post.VIDEO_TYPE);
post.setIsRedgifs(true);
post.setVideoUrl(getRedgifsVideoUrl(redgifsId));
post.setVideoDownloadUrl(post.getVideoUrl());
post.setRedgifsId(redgifsId);
}
/*String redgifsId = url.substring(url.lastIndexOf("/") + 1).toLowerCase();
post.setPostType(Post.VIDEO_TYPE);
post.setIsRedgifs(true);
post.setVideoUrl(url);
post.setRedgifsId(redgifsId);
} else*/
if (authority.equals("streamable.com")) {
post.setRedgifsId(redgifsId);*/
} else if (authority.equals("streamable.com")) {
String shortCode = url.substring(url.lastIndexOf("/") + 1);
post.setPostType(Post.VIDEO_TYPE);
post.setIsStreamable(true);
@ -646,16 +677,22 @@ public class ParsePost {
try {
String authority = uri.getAuthority();
if (authority != null) {
/*if (authority.contains("redgifs.com")) {
String redgifsId = url.substring(url.lastIndexOf("/") + 1);
if (authority.contains("redgifs.com")) {
String redgifsId = getRedgifsId(data);
if (redgifsId != null) {
post.setIsRedgifs(true);
post.setVideoUrl(getRedgifsVideoUrl(redgifsId));
post.setVideoDownloadUrl(post.getVideoUrl());
post.setRedgifsId(redgifsId);
}
/*String redgifsId = url.substring(url.lastIndexOf("/") + 1);
if (redgifsId.contains("-")) {
redgifsId = redgifsId.substring(0, redgifsId.indexOf('-'));
}
post.setIsRedgifs(true);
post.setVideoUrl(url);
post.setRedgifsId(redgifsId.toLowerCase());
} else*/
if (authority.equals("streamable.com")) {
post.setRedgifsId(redgifsId.toLowerCase());*/
} else if (authority.equals("streamable.com")) {
String shortCode = url.substring(url.lastIndexOf("/") + 1);
post.setPostType(Post.VIDEO_TYPE);
post.setIsStreamable(true);
@ -722,14 +759,21 @@ public class ParsePost {
String authority = uri.getAuthority();
if (authority != null) {
/*if (authority.contains("redgifs.com")) {
String redgifsId = url.substring(url.lastIndexOf("/") + 1).toLowerCase();
if (authority.contains("redgifs.com")) {
String redgifsId = getRedgifsId(data);
if (redgifsId != null) {
post.setPostType(Post.VIDEO_TYPE);
post.setIsRedgifs(true);
post.setVideoUrl(getRedgifsVideoUrl(redgifsId));
post.setVideoDownloadUrl(post.getVideoUrl());
post.setRedgifsId(redgifsId);
}
/*String redgifsId = url.substring(url.lastIndexOf("/") + 1).toLowerCase();
post.setPostType(Post.VIDEO_TYPE);
post.setIsRedgifs(true);
post.setVideoUrl(url);
post.setRedgifsId(redgifsId);
} else*/
if (authority.equals("streamable.com")) {
post.setRedgifsId(redgifsId);*/
} else if (authority.equals("streamable.com")) {
String shortCode = url.substring(url.lastIndexOf("/") + 1);
post.setPostType(Post.VIDEO_TYPE);
post.setIsStreamable(true);
@ -774,6 +818,27 @@ public class ParsePost {
return post;
}
@Nullable
private static String getRedgifsId(JSONObject data) {
try {
String redgifsId = data.getJSONObject(JSONUtils.MEDIA_KEY).getJSONObject(JSONUtils.O_EMBED_KEY).getString(JSONUtils.THUMBNAIL_URL_KEY);
redgifsId = redgifsId.substring(redgifsId.lastIndexOf("/") + 1);
int dashIndex = redgifsId.lastIndexOf("-");
if (dashIndex >= 0) {
return redgifsId.substring(0, dashIndex);
}
return null;
} catch (JSONException e) {
e.printStackTrace();
return null;
}
}
private static String getRedgifsVideoUrl(String redgifsId) {
return "https://media.redgifs.com/" + redgifsId + ".mp4";
}
public interface ParsePostsListingListener {
void onParsePostsListingSuccess(LinkedHashSet<Post> newPostData, String lastItem);
void onParsePostsListingFail();

View File

@ -205,6 +205,8 @@ public class JSONUtils {
public static final String APPROVED_AT_UTC_KEY = "approved_at_utc";
public static final String APPROVED_BY_KEY = "approved_by";
public static final String SPAM_KEY = "spam";
public static final String O_EMBED_KEY = "oembed";
public static final String THUMBNAIL_URL_KEY = "thumbnail_url";
@Nullable
public static Map<String, MediaMetadata> parseMediaMetadata(JSONObject data) {