pinchflat/test/support/fixtures/sources_fixtures.ex
Kieran 05f3deebfa Source NFO downloads (#95)
* Hooked up series directory finding to source metadata runner

* Fixed aired NFO tag for episodes

* Updated MI NFO builder to take in a filepath

* Hooked up NFO generation to the source worker

* Added NFO controls to form

* Improved the way the source metadata worker updates the source

* Consolidated NFO selection options in media profile instead of source
2024-03-18 17:27:28 -07:00

102 lines
2.6 KiB
Elixir

defmodule Pinchflat.SourcesFixtures do
@moduledoc """
This module defines test helpers for creating
entities via the `Pinchflat.Sources` context.
"""
alias Pinchflat.Repo
alias Pinchflat.ProfilesFixtures
alias Pinchflat.Sources.Source
@doc """
Generate a source.
"""
def source_fixture(attrs \\ %{}) do
{:ok, source} =
%Source{}
|> Source.changeset(
Enum.into(
attrs,
%{
collection_name: "Source ##{:rand.uniform(1_000_000)}",
collection_id: Base.encode16(:crypto.hash(:md5, "#{:rand.uniform(1_000_000)}")),
collection_type: "channel",
custom_name: "Cool and good internal name!",
original_url: "https://www.youtube.com/channel/#{Faker.String.base64(12)}",
media_profile_id: ProfilesFixtures.media_profile_fixture().id,
index_frequency_minutes: 60
}
),
:pre_insert
)
|> Repo.insert()
source
end
@doc """
Generate a source with metadata.
"""
def source_with_metadata(attrs \\ %{}) do
merged_attrs =
Map.merge(attrs, %{
metadata: %{
metadata_filepath: Application.get_env(:pinchflat, :metadata_directory) <> "/metadata.json.gz"
}
})
source_fixture(merged_attrs)
end
def source_attributes_return_fixture do
source_attributes = [
%{
id: "video1",
title: "Video 1",
webpage_url: "https://example.com/video1",
was_live: false,
description: "desc1",
aspect_ratio: 1.67,
duration: 12.34,
upload_date: "20210101"
},
%{
id: "video2",
title: "Video 2",
webpage_url: "https://example.com/video2",
was_live: true,
description: "desc2",
aspect_ratio: 1.67,
duration: 345.67,
upload_date: "20220202"
},
%{
id: "video3",
title: "Video 3",
webpage_url: "https://example.com/video3",
was_live: false,
description: "desc3",
aspect_ratio: 1.0,
duration: 678.90,
upload_date: "20230303"
}
]
source_attributes
|> Enum.map_join("\n", &Phoenix.json_library().encode!(&1))
end
def source_details_return_fixture(attrs \\ %{}) do
channel_id = Faker.String.base64(12)
%{
channel_id: channel_id,
channel: "Channel Name",
playlist_id: channel_id,
playlist_title: "Channel Name",
filename: Path.join([Application.get_env(:pinchflat, :media_directory), "foo", "bar.mp4"])
}
|> Map.merge(attrs)
|> Phoenix.json_library().encode!()
end
end