1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
defmodule Nola.Plugins.Link.ImgDebridLink do
@behaviour Nola.Plugins.Link
@impl true
def match(uri = %URI{host: host, path: path}, _opts)
when host in ["img.debrid-link.fr", "img.debrid-link.com"] 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.com/api/#{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 ->
Logger.info("error: #{inspect(error)}")
:error
end
end
end
|