aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2021-12-12 14:32:58 +0000
committerAlex Ning <chineseperson5@gmail.com>2021-12-12 14:32:58 +0000
commit228cc4bb7544af67336c912d00428b5e3beb4d01 (patch)
tree3ba344bcc2d6de89ac0cd94575b2592d763bd0e2 /app/src/main
parentf97e01ed668948a6dcc86ada3a1f8bb6a41fc6fa (diff)
downloadinfinity-for-reddit-228cc4bb7544af67336c912d00428b5e3beb4d01.tar
infinity-for-reddit-228cc4bb7544af67336c912d00428b5e3beb4d01.tar.gz
infinity-for-reddit-228cc4bb7544af67336c912d00428b5e3beb4d01.tar.bz2
infinity-for-reddit-228cc4bb7544af67336c912d00428b5e3beb4d01.tar.lz
infinity-for-reddit-228cc4bb7544af67336c912d00428b5e3beb4d01.tar.xz
infinity-for-reddit-228cc4bb7544af67336c912d00428b5e3beb4d01.tar.zst
infinity-for-reddit-228cc4bb7544af67336c912d00428b5e3beb4d01.zip
Fix post parsing logic for Gfycat, Redgifs and Streamable videos.
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java118
1 files changed, 103 insertions, 15 deletions
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 5e51d9c7..c0fbbe3d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java
@@ -332,6 +332,31 @@ public class ParsePost {
} else {
post.setSelfText(Utils.modifyMarkdown(data.getString(JSONUtils.SELFTEXT_KEY).trim()));
}
+
+ Uri uri = Uri.parse(url);
+ String authority = uri.getAuthority();
+
+ if (authority != null) {
+ if (authority.contains("gfycat.com")) {
+ String gfycatId = url.substring(url.lastIndexOf("/") + 1).toLowerCase();
+ post.setPostType(Post.VIDEO_TYPE);
+ post.setIsGfycat(true);
+ post.setVideoUrl(url);
+ post.setGfycatId(gfycatId);
+ } else if (authority.contains("redgifs.com")) {
+ String gfycatId = url.substring(url.lastIndexOf("/") + 1).toLowerCase();
+ post.setPostType(Post.VIDEO_TYPE);
+ post.setIsRedgifs(true);
+ post.setVideoUrl(url);
+ post.setGfycatId(gfycatId);
+ } else if (authority.equals("streamable.com")) {
+ String shortCode = url.substring(url.lastIndexOf("/") + 1);
+ post.setPostType(Post.VIDEO_TYPE);
+ post.setIsStreamable(true);
+ post.setVideoUrl(url);
+ post.setStreamableShortCode(shortCode);
+ }
+ }
}
}
}
@@ -477,6 +502,31 @@ public class ParsePost {
}
post.setPreviews(previews);
+
+ Uri uri = Uri.parse(url);
+ String authority = uri.getAuthority();
+
+ if (authority != null) {
+ if (authority.contains("gfycat.com")) {
+ String gfycatId = url.substring(url.lastIndexOf("/") + 1).toLowerCase();
+ post.setPostType(Post.VIDEO_TYPE);
+ post.setIsGfycat(true);
+ post.setVideoUrl(url);
+ post.setGfycatId(gfycatId);
+ } else if (authority.contains("redgifs.com")) {
+ String gfycatId = url.substring(url.lastIndexOf("/") + 1).toLowerCase();
+ post.setPostType(Post.VIDEO_TYPE);
+ post.setIsRedgifs(true);
+ post.setVideoUrl(url);
+ post.setGfycatId(gfycatId);
+ } else if (authority.equals("streamable.com")) {
+ String shortCode = url.substring(url.lastIndexOf("/") + 1);
+ post.setPostType(Post.VIDEO_TYPE);
+ post.setIsStreamable(true);
+ post.setVideoUrl(url);
+ post.setStreamableShortCode(shortCode);
+ }
+ }
}
}
}
@@ -514,6 +564,36 @@ public class ParsePost {
postType, voteType, nComments, upvoteRatio, flair, awards, nAwards, hidden,
spoiler, nsfw, stickied, archived, locked, saved, isCrosspost);
//Need attention
+ if (data.isNull(JSONUtils.SELFTEXT_KEY)) {
+ post.setSelfText("");
+ } else {
+ post.setSelfText(Utils.modifyMarkdown(data.getString(JSONUtils.SELFTEXT_KEY).trim()));
+ }
+
+ Uri uri = Uri.parse(url);
+ String authority = uri.getAuthority();
+
+ if (authority != null) {
+ if (authority.contains("gfycat.com")) {
+ String gfycatId = url.substring(url.lastIndexOf("/") + 1).toLowerCase();
+ post.setPostType(Post.VIDEO_TYPE);
+ post.setIsGfycat(true);
+ post.setVideoUrl(url);
+ post.setGfycatId(gfycatId);
+ } else if (authority.contains("redgifs.com")) {
+ String gfycatId = url.substring(url.lastIndexOf("/") + 1).toLowerCase();
+ post.setPostType(Post.VIDEO_TYPE);
+ post.setIsRedgifs(true);
+ post.setVideoUrl(url);
+ post.setGfycatId(gfycatId);
+ } else if (authority.equals("streamable.com")) {
+ String shortCode = url.substring(url.lastIndexOf("/") + 1);
+ post.setPostType(Post.VIDEO_TYPE);
+ post.setIsStreamable(true);
+ post.setVideoUrl(url);
+ post.setStreamableShortCode(shortCode);
+ }
+ }
}
}
}
@@ -522,22 +602,30 @@ public class ParsePost {
try {
Uri uri = Uri.parse(url);
String authority = uri.getAuthority();
- if (authority != null && (authority.contains("gfycat.com"))) {
- post.setIsGfycat(true);
- post.setVideoUrl(url);
- String gfycatId = url.substring(url.lastIndexOf("/") + 1);
- if (gfycatId.contains("-")) {
- gfycatId = gfycatId.substring(0, gfycatId.indexOf('-'));
- }
- post.setGfycatId(gfycatId.toLowerCase());
- } else if (authority != null && authority.contains("redgifs.com")) {
- String gfycatId = url.substring(url.lastIndexOf("/") + 1);
- if (gfycatId.contains("-")) {
- gfycatId = gfycatId.substring(0, gfycatId.indexOf('-'));
+ if (authority != null) {
+ if (authority.contains("gfycat.com")) {
+ post.setIsGfycat(true);
+ post.setVideoUrl(url);
+ String gfycatId = url.substring(url.lastIndexOf("/") + 1);
+ if (gfycatId.contains("-")) {
+ gfycatId = gfycatId.substring(0, gfycatId.indexOf('-'));
+ }
+ post.setGfycatId(gfycatId.toLowerCase());
+ } else if (authority.contains("redgifs.com")) {
+ String gfycatId = url.substring(url.lastIndexOf("/") + 1);
+ if (gfycatId.contains("-")) {
+ gfycatId = gfycatId.substring(0, gfycatId.indexOf('-'));
+ }
+ post.setIsRedgifs(true);
+ post.setVideoUrl(url);
+ post.setGfycatId(gfycatId.toLowerCase());
+ } else if (authority.equals("streamable.com")) {
+ String shortCode = url.substring(url.lastIndexOf("/") + 1);
+ post.setPostType(Post.VIDEO_TYPE);
+ post.setIsStreamable(true);
+ post.setVideoUrl(url);
+ post.setStreamableShortCode(shortCode);
}
- post.setIsRedgifs(true);
- post.setVideoUrl(url);
- post.setGfycatId(gfycatId.toLowerCase());
}
} catch (IllegalArgumentException ignore) { }
} else if (post.getPostType() == Post.LINK_TYPE || post.getPostType() == Post.NO_PREVIEW_LINK_TYPE) {