pinchflat/lib/pinchflat/media_source/source.ex
Kieran bdef6c75bb
Change Channel to Source (#12)
* Ensure channel detail lookup doesn't download the video - oops

* Ran the needful migrations for replacing channels with sources

* got media source test back working

* channel tasks test

* Media indexing worker test

* media tests

* Got all tests working except controller tests

* got all tests working

* Renamed Channel struct to Source

* renamed ChannelTasks

* More renaming; renamed channel details module

* Removed Channel yt-dlp module, instead throwing things in the VideoCollection module

* Renamed what looks like the last of the outstanding data
2024-02-02 10:45:21 -08:00

38 lines
1.1 KiB
Elixir

defmodule Pinchflat.MediaSource.Source do
@moduledoc """
The Source schema.
"""
use Ecto.Schema
import Ecto.Changeset
alias Pinchflat.Media.MediaItem
alias Pinchflat.Profiles.MediaProfile
@allowed_fields ~w(name collection_id collection_type index_frequency_minutes original_url media_profile_id)a
@required_fields @allowed_fields -- ~w(index_frequency_minutes)a
schema "sources" do
field :name, :string
field :collection_id, :string
field :collection_type, Ecto.Enum, values: [:channel, :playlist]
field :index_frequency_minutes, :integer
# This should only be used for user reference going forward
# as the collection_id should be used for all API calls
field :original_url, :string
belongs_to :media_profile, MediaProfile
has_many :media_items, MediaItem, foreign_key: :source_id
timestamps(type: :utc_datetime)
end
@doc false
def changeset(source, attrs) do
source
|> cast(attrs, @allowed_fields)
|> validate_required(@required_fields)
|> unique_constraint([:collection_id, :media_profile_id])
end
end