* Updated package.json (and made an excuse to make a branch) * Video filepath parser (#6) * Restructured files; Added parser placeholder * More restructuring * Added basic parser for hydrating template strings * Improved docs * More docs * Initial implementation of media profiles (#7) * [WIP] Added basic video download method * [WIP] Very-WIP first steps at parsing options and downloading * Made my options safe by default and removed special safe versions * Ran html generator for mediaprofile model - leaving as-is for now * Addressed a bunch of TODO comments * Add "channel" type Media Source (#8) * [WIP] Working on fetching channel metadata in yt-dlp backend * Finished first draft of methods to do with querying channels * Renamed CommandRunnerMock to have a more descriptive name * Ran the phx generator for the channel model * Renamed Downloader namespace to MediaClient * [WIP] saving before attempting LiveView * LiveView did not work out but here's a working controller how about * Index a channel (#9) * Ran a MediaItem generator; Reformatted to my liking * [WIP] added basic index function * setup oban * Added basic Oban job for indexing * Added in workers for indexing; hooked them into record creation flow * Added a task model with a phx generator * Tied together tasks with jobs and channels * Download indexed videos (#10) * Clarified documentation * more comments * [WIP] hooked up basic video downloading; starting work on metadata * Added metadata model and parsing Adding the metadata model made me realize that, in many cases, yt-dlp returns undesired input in stdout, breaking parsing. In order to get the metadata model working, I had to change the way in which the app interacts with yt-dlp. Now, output is written as a file to disk which is immediately re-read and returned. * Added tests for video download worker * Hooked up video downloading to the channel indexing pipeline * Adds tasks for media items * Updated video metadata parser to extract the title * Ran linting
119 lines
3.5 KiB
Elixir
119 lines
3.5 KiB
Elixir
defmodule PinchflatWeb.ChannelControllerTest do
|
|
use PinchflatWeb.ConnCase
|
|
import Mox
|
|
|
|
import Pinchflat.ProfilesFixtures
|
|
import Pinchflat.MediaSourceFixtures
|
|
|
|
setup do
|
|
media_profile = media_profile_fixture()
|
|
|
|
{
|
|
:ok,
|
|
%{
|
|
create_attrs: %{
|
|
media_profile_id: media_profile.id,
|
|
original_url: "https://www.youtube.com/channel/abc123"
|
|
},
|
|
update_attrs: %{
|
|
original_url: "https://www.youtube.com/channel/321xyz"
|
|
},
|
|
invalid_attrs: %{original_url: nil, media_profile_id: nil}
|
|
}
|
|
}
|
|
end
|
|
|
|
setup :verify_on_exit!
|
|
|
|
describe "index" do
|
|
test "lists all channels", %{conn: conn} do
|
|
conn = get(conn, ~p"/media_sources/channels")
|
|
assert html_response(conn, 200) =~ "Listing Channels"
|
|
end
|
|
end
|
|
|
|
describe "new channel" do
|
|
test "renders form", %{conn: conn} do
|
|
conn = get(conn, ~p"/media_sources/channels/new")
|
|
assert html_response(conn, 200) =~ "New Channel"
|
|
end
|
|
end
|
|
|
|
describe "create channel" do
|
|
test "redirects to show when data is valid", %{conn: conn, create_attrs: create_attrs} do
|
|
expect(YtDlpRunnerMock, :run, 1, &runner_function_mock/3)
|
|
conn = post(conn, ~p"/media_sources/channels", channel: create_attrs)
|
|
|
|
assert %{id: id} = redirected_params(conn)
|
|
assert redirected_to(conn) == ~p"/media_sources/channels/#{id}"
|
|
|
|
conn = get(conn, ~p"/media_sources/channels/#{id}")
|
|
assert html_response(conn, 200) =~ "Channel #{id}"
|
|
end
|
|
|
|
test "renders errors when data is invalid", %{conn: conn, invalid_attrs: invalid_attrs} do
|
|
conn = post(conn, ~p"/media_sources/channels", channel: invalid_attrs)
|
|
assert html_response(conn, 200) =~ "New Channel"
|
|
end
|
|
end
|
|
|
|
describe "edit channel" do
|
|
setup [:create_channel]
|
|
|
|
test "renders form for editing chosen channel", %{conn: conn, channel: channel} do
|
|
conn = get(conn, ~p"/media_sources/channels/#{channel}/edit")
|
|
assert html_response(conn, 200) =~ "Edit Channel"
|
|
end
|
|
end
|
|
|
|
describe "update channel" do
|
|
setup [:create_channel]
|
|
|
|
test "redirects when data is valid", %{conn: conn, channel: channel, update_attrs: update_attrs} do
|
|
expect(YtDlpRunnerMock, :run, 1, &runner_function_mock/3)
|
|
|
|
conn = put(conn, ~p"/media_sources/channels/#{channel}", channel: update_attrs)
|
|
assert redirected_to(conn) == ~p"/media_sources/channels/#{channel}"
|
|
|
|
conn = get(conn, ~p"/media_sources/channels/#{channel}")
|
|
assert html_response(conn, 200) =~ "https://www.youtube.com/channel/321xyz"
|
|
end
|
|
|
|
test "renders errors when data is invalid", %{
|
|
conn: conn,
|
|
channel: channel,
|
|
invalid_attrs: invalid_attrs
|
|
} do
|
|
conn = put(conn, ~p"/media_sources/channels/#{channel}", channel: invalid_attrs)
|
|
assert html_response(conn, 200) =~ "Edit Channel"
|
|
end
|
|
end
|
|
|
|
describe "delete channel" do
|
|
setup [:create_channel]
|
|
|
|
test "deletes chosen channel", %{conn: conn, channel: channel} do
|
|
conn = delete(conn, ~p"/media_sources/channels/#{channel}")
|
|
assert redirected_to(conn) == ~p"/media_sources/channels"
|
|
|
|
assert_error_sent 404, fn ->
|
|
get(conn, ~p"/media_sources/channels/#{channel}")
|
|
end
|
|
end
|
|
end
|
|
|
|
defp create_channel(_) do
|
|
channel = channel_fixture()
|
|
%{channel: channel}
|
|
end
|
|
|
|
defp runner_function_mock(_url, _opts, _ot) do
|
|
{
|
|
:ok,
|
|
Phoenix.json_library().encode!(%{
|
|
channel: "some name",
|
|
channel_id: "some_channel_id_#{:rand.uniform(1_000_000)}"
|
|
})
|
|
}
|
|
end
|
|
end
|