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
62 lines
1.8 KiB
Elixir
62 lines
1.8 KiB
Elixir
defmodule Pinchflat.Tasks.MediaItemTasks do
|
|
@moduledoc """
|
|
Contains methods used by OR used to create/manage tasks for media items.
|
|
|
|
Tasks/workers are meant to be thin wrappers so most of the actual work they
|
|
do is also defined here. Essentially, a one-stop-shop for media-related tasks/workers.
|
|
"""
|
|
alias Pinchflat.Media
|
|
alias Pinchflat.Tasks
|
|
alias Pinchflat.Sources.Source
|
|
alias Pinchflat.Workers.MediaDownloadWorker
|
|
|
|
alias Pinchflat.YtDlp.Backend.Media, as: YtDlpMedia
|
|
|
|
@doc """
|
|
Fetches the file size of a media item and saves it to the database.
|
|
|
|
Returns {:ok, media_item} | {:error, any()}
|
|
"""
|
|
def compute_and_save_media_filesize(media_item) do
|
|
case File.stat(media_item.media_filepath) do
|
|
{:ok, %{size: size}} ->
|
|
Media.update_media_item(media_item, %{media_size_bytes: size})
|
|
|
|
err ->
|
|
err
|
|
end
|
|
end
|
|
|
|
@doc """
|
|
Indexes a single media item for a source and enqueues a download job if the
|
|
media should be downloaded. This method creates the media item record so it's
|
|
the one-stop-shop for adding a media item (and possibly downloading it) just
|
|
by a URL and source.
|
|
|
|
Returns {:ok, media_item} | {:error, any()}
|
|
"""
|
|
def index_and_enqueue_download_for_media_item(%Source{} = source, url) do
|
|
maybe_media_item = create_media_item_from_url(source, url)
|
|
|
|
case maybe_media_item do
|
|
{:ok, media_item} ->
|
|
if source.download_media && Media.pending_download?(media_item) do
|
|
%{id: media_item.id}
|
|
|> MediaDownloadWorker.new()
|
|
|> Tasks.create_job_with_task(media_item)
|
|
end
|
|
|
|
{:ok, media_item}
|
|
|
|
err ->
|
|
err
|
|
end
|
|
end
|
|
|
|
defp create_media_item_from_url(source, url) do
|
|
{:ok, media_attrs} = YtDlpMedia.get_media_attributes(url)
|
|
|
|
Media.create_media_item_from_backend_attrs(source, media_attrs)
|
|
end
|
|
end
|