dc0313d875
* Made method to getting singular media details; Renamed other related method * Takes a fun and flirty digression to remove abstractions around yt-dlp since I'm 100% committed to using it exclusively * Removed commented test code * Lays the groundwork for fast indexing * Added module for working with youtube RSS feed * Added methods to kick off indexing workers from RSS response * Improve short detection (#59) * Made media attribute-related yt-dlp calls return a struct * Added shorts attribute to media items * Added ability to discern a short from yt-dlp response * Updated search to use new shorts attribute * Fast index UI (#63) * Added fast_index field and adds it to source form * Added fast indexing to source changeset operations * Added fast indexing worker and updated other modules to start using it * Handled fast index worker on source update * Add support modals (#65) * Added fast indexing upgrade modal * Improved modal on smaller screens * Updated links to work again * Added donation modal * Reverted source fast index to 15 minutes * Removed unneeded HTML attributes from old alpine approach
112 lines
3.8 KiB
Elixir
112 lines
3.8 KiB
Elixir
defmodule Pinchflat.YtDlp.Backend.MediaCollectionTest do
|
|
use Pinchflat.DataCase
|
|
import Mox
|
|
import Pinchflat.SourcesFixtures
|
|
|
|
alias Pinchflat.YtDlp.Backend.Media
|
|
alias Pinchflat.YtDlp.Backend.MediaCollection
|
|
|
|
@channel_url "https://www.youtube.com/c/TheUselessTrials"
|
|
|
|
setup :verify_on_exit!
|
|
|
|
describe "get_media_attributes_for_collection/2" do
|
|
test "returns a list of video attributes with no blank elements" do
|
|
expect(YtDlpRunnerMock, :run, fn _url, _opts, _ot, _addl_opts ->
|
|
{:ok, source_attributes_return_fixture() <> "\n\n"}
|
|
end)
|
|
|
|
assert {:ok, [%Media{media_id: "video1"}, %Media{media_id: "video2"}, %Media{media_id: "video3"}]} =
|
|
MediaCollection.get_media_attributes_for_collection(@channel_url)
|
|
end
|
|
|
|
test "it passes the expected default args" do
|
|
expect(YtDlpRunnerMock, :run, fn _url, opts, ot, _addl_opts ->
|
|
assert opts == [:simulate, :skip_download]
|
|
assert ot == Media.indexing_output_template()
|
|
|
|
{:ok, ""}
|
|
end)
|
|
|
|
assert {:ok, _} = MediaCollection.get_media_attributes_for_collection(@channel_url)
|
|
end
|
|
|
|
test "returns the error straight through when the command fails" do
|
|
expect(YtDlpRunnerMock, :run, fn _url, _opts, _ot, _addl_opts -> {:error, "Big issue", 1} end)
|
|
|
|
assert {:error, "Big issue", 1} = MediaCollection.get_media_attributes_for_collection(@channel_url)
|
|
end
|
|
|
|
test "passes the explict tmpfile path to runner" do
|
|
expect(YtDlpRunnerMock, :run, fn _url, _opts, _ot, addl_opts ->
|
|
assert [{:output_filepath, filepath}] = addl_opts
|
|
assert String.ends_with?(filepath, ".json")
|
|
|
|
{:ok, ""}
|
|
end)
|
|
|
|
assert {:ok, _} = MediaCollection.get_media_attributes_for_collection(@channel_url)
|
|
end
|
|
|
|
test "supports an optional file_listener_handler that gets passed a filename" do
|
|
expect(YtDlpRunnerMock, :run, fn _url, _opts, _ot, _addl_opts -> {:ok, ""} end)
|
|
current_self = self()
|
|
|
|
handler = fn filename ->
|
|
send(current_self, {:handler, filename})
|
|
end
|
|
|
|
assert {:ok, _} =
|
|
MediaCollection.get_media_attributes_for_collection(@channel_url, file_listener_handler: handler)
|
|
|
|
assert_receive {:handler, filename}
|
|
assert String.ends_with?(filename, ".json")
|
|
end
|
|
end
|
|
|
|
describe "get_source_details/1" do
|
|
test "it returns a map with data on success" do
|
|
expect(YtDlpRunnerMock, :run, fn _url, _opts, _ot ->
|
|
Phoenix.json_library().encode(%{
|
|
channel: "TheUselessTrials",
|
|
channel_id: "UCQH2",
|
|
playlist_id: "PLQH2",
|
|
playlist_title: "TheUselessTrials - Videos"
|
|
})
|
|
end)
|
|
|
|
assert {:ok, res} = MediaCollection.get_source_details(@channel_url)
|
|
|
|
assert %{
|
|
channel_id: "UCQH2",
|
|
channel_name: "TheUselessTrials",
|
|
playlist_id: "PLQH2",
|
|
playlist_name: "TheUselessTrials - Videos"
|
|
} = res
|
|
end
|
|
|
|
test "it passes the expected args to the backend runner" do
|
|
expect(YtDlpRunnerMock, :run, fn @channel_url, opts, ot ->
|
|
assert opts == [:simulate, :skip_download, playlist_end: 1]
|
|
assert ot == "%(.{channel,channel_id,playlist_id,playlist_title})j"
|
|
|
|
{:ok, "{}"}
|
|
end)
|
|
|
|
assert {:ok, _} = MediaCollection.get_source_details(@channel_url)
|
|
end
|
|
|
|
test "it returns an error if the runner returns an error" do
|
|
expect(YtDlpRunnerMock, :run, fn _url, _opts, _ot -> {:error, "Big issue", 1} end)
|
|
|
|
assert {:error, "Big issue", 1} = MediaCollection.get_source_details(@channel_url)
|
|
end
|
|
|
|
test "it returns an error if the output is not JSON" do
|
|
expect(YtDlpRunnerMock, :run, fn _url, _opts, _ot -> {:ok, "Not JSON"} end)
|
|
|
|
assert {:error, %Jason.DecodeError{}} = MediaCollection.get_source_details(@channel_url)
|
|
end
|
|
end
|
|
end
|