fp/services/bright/lib/bright_web/controllers/rss_controller.ex

63 lines
1.6 KiB
Elixir

# defmodule BrightWeb.RssController do
# use BrightWeb, :controller
# plug :put_layout, false
# alias BrightWeb.Streams.Vod
# def index(conn, _params) do
# vods = Vod.list_vods()
# updated_at = Vod.most_recently_updated_vod.updated_at
# conn
# |> put_resp_content_type("text/xml")
# |> render("index.xml", vods: vods, updated_at: updated_at)
# end
# end
defmodule BrightWeb.RssController do
use BrightWeb, :controller
alias Bright.Streams
alias Bright.Streams.Vod
alias Atomex.{Feed, Entry}
@author "CJ_Clippy"
@email "cj@futureporn.net"
def vods(conn, _params) do
vods = Streams.list_vods()
feed = build_feed(vods, conn)
conn
|> put_resp_content_type("text/xml")
|> send_resp(200, feed)
end
def build_feed(vods, conn) do
Feed.new(~p"/", DateTime.utc_now(), "Futureporn VOD RSS")
|> Feed.author(@author, email: @email)
|> Feed.link(~p"/feeds/vods.xml", rel: "self")
|> Feed.entries(Enum.map(vods, &get_entry(conn, &1)))
|> Feed.build()
|> Atomex.generate_document()
end
defp get_entry(
conn,
%Vod{id: id, torrent: torrent, origin_temp_input_url: origin_temp_input_url, updated_at: updated_at, playlist_url: playlist_url}
) do
Entry.new(
# Routes.post_url(conn, :show, kind, slug),
id,
DateTime.from_naive!(updated_at, "Etc/UTC"),
"vod #{id}"
)
# |> Entry.link(Routes.post_url(conn, :show, kind, slug))
|> Entry.link("https://futureporn.net/vods/#{id}")
|> Entry.content(playlist_url, type: "text")
|> Feed.add_field(:guid, %{isPermalink: false}, torrent)
|> Entry.build()
end
end