Haptic-Apps / Slide

Slide is an open-source, ad-free Reddit browser for Android.
https://reddit.com/r/slideforreddit
GNU General Public License v3.0
1.78k stars 344 forks source link

Pixelate NSFW/Spoiler posts and support new spoiler tags #2357

Open Nxt3 opened 7 years ago

Nxt3 commented 7 years ago

Thought it would be cool since that's what Reddit does on the desktop.

Here is a library for it. https://github.com/DanielMartinus/Pixelate

Let me know if this sounds like something you'd want and I could see about implementing it.

Also, support the new Reddit spoiler system

ccrama commented 7 years ago

That would be awesome! FWIW, Reddit actually already pixellates in their backend and the pixellated version is returned in the JSON as a "variation" of the preview image (same with NSFW content). Might be worth adding it to both? The reason I didn't before is the image is tied to the thumbnail display settings, and would only show if users set it to always show thumbnails but that may have changed

Nxt3 commented 7 years ago

Does JRAW support that? I figured this would look nicer than the red thumbnails we have currently.

ccrama commented 7 years ago

I actually think it does, but if it doesn't, it's something that would be relatively easy to add into either JRAW or parsing the json directly ourselves. I'll see if I can find an example of the json

Nxt3 commented 7 years ago

Could you give me some pointers on where to start? It's been a while since I've done anything in Slide :P

ccrama commented 7 years ago

Oh sorry, did not see your last reply! The relevant code in JRAW is here, and the relevant place in Slide is here. The check for NSFW is close to the top of the logic tree, and adding in spoiler support around there is probably the best place for it. Also, instead of showing a NSFW thumbnail image, we can show the big image with the pixelation. Let me know if you want me to look into anything/help out with this!

Thanks :)

Nxt3 commented 7 years ago

So where are you actually setting the thumbnail? There is a lot of code here relating to quality and it's throwing me off. For the sake of this, assume I have Thumbnails enabled (meaning, no large images, everything is thumbnails).

ccrama commented 7 years ago

The NSFW check is before the quality check, so if we implement it before quality, it will work as intended. Wherever we set the image to be the R.drawable.nsfw, that will override showing the actual image preview (regardless of quality). Adding a spoiler statement below the NSFW one and implementing the pixelation there is how we should do it. For the sake of implementation, we can ignore the quality settings for the NSFW and spoiler previews (if they exist). If the spoiler/nsfw image does not exist, we can just show the NSFW or spoiler placeholder image

Nxt3 commented 7 years ago

I'm not sure if JRAW supports the pixelation then. Let alone how to get it.

ccrama commented 7 years ago

It supports it because Reddit returns this with the standard JSON for submissions. The "variations" for the thumbnail modes are these pixellated images. Reddit is not pixellating in-app or in-browser, it does this in the background and returns it with the submission JSON

ccrama commented 7 years ago

The Thumbnails object does this (code here and here) in JRAW. It appears this just takes from "resolutions" instead of "variants", but we could change this pretty easily. This is what the JSON looks like

image

"Obfuscated" is for spoilers, while "NSFW" is for NSFW images, and we could make a "Thumbnail" object reading from the "images>variants>obfuscated>resolutions" JSON tree instead of "images>resolutions"

Nxt3 commented 7 years ago

I see now. How do we know which variation is the blurred one? I'm not having much luck changing that.

ccrama commented 7 years ago

See my edit @Nxt3 , JRAW names each object in "resolutions" as a "variation", but is still reading from "images>resolutions". That is a bit confusing but is not the same as the "variant" in the JSON tree image I pasted.

Instead, we should see if "images>variants>obfusicated" or "images>variants>nsfw" exists, and create a Thumbnail object from that JSON array

Nxt3 commented 7 years ago

Could you post the url you used for getting that JSON back?

ccrama commented 7 years ago

Sure, here you go

https://www.reddit.com/r/StarWars/comments/5pv2sj/rogue_one_weekly_spoiler_megathread_final_edition/.json

Nxt3 commented 7 years ago

Maybe I'm not getting it, but none of those urls lead to a blurred image. Try this one: https://www.reddit.com/r/dataisbeautiful/comments/5qakm4/reddits_favorite_swear_word_is_shit_the_subreddit/.json Same problem. None of the variations are blurred thumbnails.

ccrama commented 7 years ago

Hmm it is for me, "images>variants>obfuscated>source" returns this image

image

and your other link returns

image

in "images>variant>nsfw". The second link also contains an "obfuscated" tree which returns the image without the red tint. I think the json only works if thumbnails are enabled for that subreddit, though, which may lead to other results for you (if you have them disabled)

sersorrel commented 6 years ago

Is there any news on the >!spoilers!< support? The official reddit apps are about to start supporting them, and several other apps apparently already support them, so I think several mods are planning to introduce them in their subreddits pretty soon.