mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-02-12 17:14:22 +01:00
31 lines
719 B
Elixir
31 lines
719 B
Elixir
defmodule Philomena.Channels.PicartoChannel do
|
|
@api_online "https://api.picarto.tv/api/v1/online?adult=true&gaming=true"
|
|
|
|
@spec live_channels(DateTime.t()) :: map()
|
|
def live_channels(now) do
|
|
@api_online
|
|
|> Philomena.Http.get()
|
|
|> case do
|
|
{:ok, %Tesla.Env{body: body, status: 200}} ->
|
|
body
|
|
|> Jason.decode!()
|
|
|> Map.new(&{&1["name"], fetch(&1, now)})
|
|
|
|
_error ->
|
|
%{}
|
|
end
|
|
end
|
|
|
|
defp fetch(api, now) do
|
|
%{
|
|
title: api["title"],
|
|
is_live: true,
|
|
nsfw: api["adult"],
|
|
viewers: api["viewers"],
|
|
thumbnail_url: api["thumbnails"]["web"],
|
|
last_fetched_at: now,
|
|
last_live_at: now,
|
|
description: nil
|
|
}
|
|
end
|
|
end
|