diff options
author | Jordan Bracco <href@random.sh> | 2024-09-28 16:27:40 +0200 |
---|---|---|
committer | Jordan Bracco <href@random.sh> | 2024-09-28 16:27:40 +0200 |
commit | c62bb105703d3ee9cf034ecb8397b5d54844ed1e (patch) | |
tree | 2ab41e7b0813483d12966e4b79bb8d2f3d385988 /lib/plugins | |
parent | kick roulette: ignore args (diff) |
link: img.debrid-link
Diffstat (limited to 'lib/plugins')
-rw-r--r-- | lib/plugins/link/img_debrid_link.ex | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/plugins/link/img_debrid_link.ex b/lib/plugins/link/img_debrid_link.ex new file mode 100644 index 0000000..a2972eb --- /dev/null +++ b/lib/plugins/link/img_debrid_link.ex @@ -0,0 +1,32 @@ +defmodule Nola.Plugins.Link.ImgDebridLink do + @behaviour Nola.Plugins.Link + + @impl true + def match(uri = %URI{host: "img.debrid-link.fr", path: path}, _opts) do + case String.split(path, "/") do + ["", ids] -> {true, %{id: ids}} + _ -> false + end + end + + def match(_, _), do: false + + @impl true + def post_match(_, _, _, _), do: false + + @impl true + def expand(_uri, %{id: ids}, _opts) do + with \ + {:ok, %HTTPoison.Response{status_code: 200, body: body}} <- HTTPoison.get("https://img.debrid-link.fr/api/v1/images/#{ids}/infos", [], []), + {:ok, %{"success" => true, "value" => values}} <- Jason.decode(body) + do + items = for %{"name" => name, "url" => %{"direct" => direct_url}} <- values do + "#{name}: #{direct_url}" + end + {:ok, items} + else + _ -> :error + end + end + +end |