Renamed friendly_name to custom_name

This commit is contained in:
Kieran Eglin 2024-03-02 11:47:17 -08:00
parent 381eaed40a
commit b65a88cc29
No known key found for this signature in database
GPG key ID: 193984967FCF432D
10 changed files with 24 additions and 17 deletions

View file

@ -15,7 +15,7 @@ defmodule Pinchflat.Sources.Source do
collection_name
collection_id
collection_type
friendly_name
custom_name
index_frequency_minutes
download_media
last_indexed_at
@ -27,7 +27,7 @@ defmodule Pinchflat.Sources.Source do
collection_name
collection_id
collection_type
friendly_name
custom_name
index_frequency_minutes
download_media
original_url
@ -35,7 +35,7 @@ defmodule Pinchflat.Sources.Source do
)a
schema "sources" do
field :friendly_name, :string
field :custom_name, :string
field :collection_name, :string
field :collection_id, :string
field :collection_type, Ecto.Enum, values: [:channel, :playlist]
@ -58,7 +58,7 @@ defmodule Pinchflat.Sources.Source do
def changeset(source, attrs) do
source
|> cast(attrs, @allowed_fields)
|> dynamic_default(:friendly_name, fn cs -> get_field(cs, :collection_name) end)
|> dynamic_default(:custom_name, fn cs -> get_field(cs, :collection_name) end)
|> validate_required(@required_fields)
|> unique_constraint([:collection_id, :media_profile_id])
end

View file

@ -110,7 +110,7 @@ defmodule Pinchflat.Profiles.Options.YtDlp.DownloadOptionBuilder do
source = media_item_with_preloads.source
%{
"source_friendly_name" => source.friendly_name,
"source_custom_name" => source.custom_name,
"source_collection_type" => source.collection_type
}
end

View file

@ -17,7 +17,7 @@
<section>
<strong>Source:</strong>
<.inline_link href={~p"/sources/#{@media_item.source_id}"}>
<%= @media_item.source.friendly_name %>
<%= @media_item.source.custom_name %>
</.inline_link>
</section>

View file

@ -50,7 +50,7 @@
<:tab title="Sources">
<.table rows={@media_profile.sources} table_class="text-black dark:text-white">
<:col :let={source} label="Name">
<%= source.friendly_name || source.collection_name %>
<%= source.custom_name || source.collection_name %>
</:col>
<:col :let={source} label="Type"><%= source.collection_type %></:col>
<:col :let={source} label="Should Download?">

View file

@ -14,7 +14,7 @@
<div class="flex flex-col gap-10 min-w-max">
<.table rows={@sources} table_class="text-black dark:text-white">
<:col :let={source} label="Name">
<%= source.friendly_name || source.collection_name %>
<%= source.custom_name || source.collection_name %>
</:col>
<:col :let={source} label="Type"><%= source.collection_type %></:col>
<:col :let={source} label="Should Download?">

View file

@ -4,7 +4,7 @@
</.error>
<.input
field={f[:friendly_name]}
field={f[:custom_name]}
type="text"
label="Custom Name"
help="Something descriptive. Does not impact indexing or downloading"

View file

@ -0,0 +1,7 @@
defmodule Pinchflat.Repo.Migrations.RenameFriendlyNameToCustomName do
use Ecto.Migration
def change do
rename table(:sources), :friendly_name, to: :custom_name
end
end

View file

@ -9,7 +9,7 @@ defmodule Pinchflat.Profiles.Options.YtDlp.DownloadOptionBuilderTest do
setup do
media_profile = media_profile_fixture(%{output_path_template: "{{ title }}.%(ext)s"})
source = source_fixture(%{media_profile_id: media_profile.id, friendly_name: "my source"})
source = source_fixture(%{media_profile_id: media_profile.id, custom_name: "my source"})
media_item = Repo.preload(media_item_fixture(source_id: source.id), source: :media_profile)
{:ok, media_item: media_item}
@ -24,11 +24,11 @@ defmodule Pinchflat.Profiles.Options.YtDlp.DownloadOptionBuilderTest do
test "it respects custom output path options", %{media_item: media_item} do
media_item =
update_media_profile_attribute(media_item, %{output_path_template: "{{ source_friendly_name }}.%(ext)s"})
update_media_profile_attribute(media_item, %{output_path_template: "{{ source_custom_name }}.%(ext)s"})
assert {:ok, res} = DownloadOptionBuilder.build(media_item)
assert {:output, "/tmp/test/videos/#{media_item.source.friendly_name}.%(ext)s"} in res
assert {:output, "/tmp/test/videos/#{media_item.source.custom_name}.%(ext)s"} in res
end
end

View file

@ -66,18 +66,18 @@ defmodule Pinchflat.SourcesTest do
assert String.starts_with?(source.collection_id, "some_playlist_id_")
end
test "you can specify a custom friendly_name" do
test "you can specify a custom custom_name" do
expect(YtDlpRunnerMock, :run, &channel_mock/3)
valid_attrs = %{
media_profile_id: media_profile_fixture().id,
original_url: "https://www.youtube.com/channel/abc123",
friendly_name: "some custom name"
custom_name: "some custom name"
}
assert {:ok, %Source{} = source} = Sources.create_source(valid_attrs)
assert source.friendly_name == "some custom name"
assert source.custom_name == "some custom name"
end
test "friendly name is pulled from collection_name if not specified" do
@ -90,7 +90,7 @@ defmodule Pinchflat.SourcesTest do
assert {:ok, %Source{} = source} = Sources.create_source(valid_attrs)
assert source.friendly_name == "some channel name"
assert source.custom_name == "some channel name"
end
test "collection_type is inferred from source details" do

View file

@ -19,7 +19,7 @@ defmodule Pinchflat.SourcesFixtures do
collection_name: "Source ##{:rand.uniform(1_000_000)}",
collection_id: Base.encode16(:crypto.hash(:md5, "#{:rand.uniform(1_000_000)}")),
collection_type: "channel",
friendly_name: "Cool and good internal name!",
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