54 lines
1.7 KiB
Elixir
54 lines
1.7 KiB
Elixir
defmodule Pinchflat.Downloading.DownloadingHelpers do
|
|
require Logger
|
|
|
|
alias Pinchflat.Media
|
|
alias Pinchflat.Tasks
|
|
alias Pinchflat.Sources
|
|
alias Pinchflat.Sources.Source
|
|
alias Pinchflat.FastIndexing.YoutubeRss
|
|
alias Pinchflat.Media.MediaItem
|
|
alias Pinchflat.FastIndexing.FastIndexingWorker
|
|
alias Pinchflat.Downloading.MediaDownloadWorker
|
|
alias Pinchflat.FastIndexing.MediaIndexingWorker
|
|
alias Pinchflat.YtDlp.Backend.MediaCollection
|
|
alias Pinchflat.SlowIndexing.MediaCollectionIndexingWorker
|
|
alias Pinchflat.Utils.FilesystemUtils.FileFollowerServer
|
|
|
|
alias Pinchflat.YtDlp.Backend.Media, as: YtDlpMedia
|
|
|
|
@doc """
|
|
Starts tasks for downloading media for any of a sources _pending_ media items.
|
|
Jobs are not enqueued if the source is set to not download media. This will return :ok.
|
|
|
|
NOTE: this starts a download for each media item that is pending,
|
|
not just the ones that were indexed in this job run. This should ensure
|
|
that any stragglers are caught if, for some reason, they weren't enqueued
|
|
or somehow got de-queued.
|
|
|
|
Returns :ok
|
|
"""
|
|
def enqueue_pending_download_tasks(%Source{download_media: true} = source) do
|
|
source
|
|
|> Media.list_pending_media_items_for()
|
|
|> Enum.each(fn media_item ->
|
|
%{id: media_item.id}
|
|
|> MediaDownloadWorker.new()
|
|
|> Tasks.create_job_with_task(media_item)
|
|
end)
|
|
end
|
|
|
|
def enqueue_pending_download_tasks(%Source{download_media: false}) do
|
|
:ok
|
|
end
|
|
|
|
@doc """
|
|
Deletes ALL pending tasks for a source's media items.
|
|
|
|
Returns :ok
|
|
"""
|
|
def dequeue_pending_download_tasks(%Source{} = source) do
|
|
source
|
|
|> Media.list_pending_media_items_for()
|
|
|> Enum.each(&Tasks.delete_pending_tasks_for/1)
|
|
end
|
|
end
|