From 37d6890f9c74cf97f7dc4614f280b733d4c60e35 Mon Sep 17 00:00:00 2001 From: Chaska <166928710+chaskayote@users.noreply.github.com> Date: Sun, 12 May 2024 13:32:05 -0500 Subject: [PATCH] Fixing InkBunny to pull tags --- lib/philomena/scrapers/inkbunny.ex | 57 +++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/lib/philomena/scrapers/inkbunny.ex b/lib/philomena/scrapers/inkbunny.ex index 6ca89508..275723b9 100644 --- a/lib/philomena/scrapers/inkbunny.ex +++ b/lib/philomena/scrapers/inkbunny.ex @@ -17,22 +17,53 @@ defmodule Philomena.Scrapers.Inkbunny do json = Jason.decode!(body) [submission] = json["submissions"] - description = "##\s#{submission["title"]}\n#{submission["description"]}" + rating = if submission["rating_name"] == "General", do: "safe" + r = submission["ratings"] - images = - for x <- submission["files"] do - %{ - url: "#{x["file_url_full"]}", - camo_url: Camo.Image.image_url(x["file_url_screen"]) - } + rating = + cond do + [] = r -> + rating + + Enum.find(r, fn x -> x["name"] == "Strong Violence" end) -> + false + + Enum.find(r, fn x -> x["name"] == "Sexual Themes" end) -> + "explicit" + + Enum.find(r, fn x -> x["name"] == "Violence" end) -> + "grimdark" + + Enum.find(r, fn x -> x["name"] == "Nudity" end) -> + "nude only" end - %{ - source_url: url, - author_name: submission["username"], - description: description, - images: images - } + if rating do + description = "##\s#{submission["title"]}\n#{submission["description"]}" + + tags = + for x <- submission["keywords"], x["contributed"] == "f" do + x["keyword_name"] + end + + images = + for x <- submission["files"] do + %{ + url: "#{x["file_url_full"]}", + camo_url: Camo.Image.image_url(x["file_url_screen"]) + } + end + + %{ + source_url: url, + author_name: submission["username"], + description: description, + tags: [rating | tags], + images: images + } + else + %{errors: ["Requested image does not have an acceptable rating for submission."]} + end end defp inkbunny_sid do