Added logic to ignore downloads that aren't in the right live state
This commit is contained in:
parent
d9c48370df
commit
6b7ab73f68
3 changed files with 40 additions and 3 deletions
|
|
@ -94,6 +94,10 @@ defmodule Pinchflat.Downloading.MediaDownloadWorker do
|
||||||
{:recovered, _} ->
|
{:recovered, _} ->
|
||||||
{:error, :retry}
|
{:error, :retry}
|
||||||
|
|
||||||
|
# TODO: test
|
||||||
|
{:error, :unsuitable_for_download} ->
|
||||||
|
{:ok, :non_retry}
|
||||||
|
|
||||||
{:error, message} ->
|
{:error, message} ->
|
||||||
action_on_error(message)
|
action_on_error(message)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,14 @@ defmodule Pinchflat.Downloading.MediaDownloader do
|
||||||
{:ok, parsed_json} ->
|
{:ok, parsed_json} ->
|
||||||
update_media_item_from_parsed_json(media_with_preloads, parsed_json)
|
update_media_item_from_parsed_json(media_with_preloads, parsed_json)
|
||||||
|
|
||||||
|
# TODO: test
|
||||||
|
{:error, :unsuitable_for_download} ->
|
||||||
|
Logger.warning(
|
||||||
|
"Media item ##{media_with_preloads.id} isn't suitable for download yet. May be an active or processing live stream"
|
||||||
|
)
|
||||||
|
|
||||||
|
{:error, :unsuitable_for_download}
|
||||||
|
|
||||||
{:error, message, _exit_code} ->
|
{:error, message, _exit_code} ->
|
||||||
Logger.error("yt-dlp download error for media item ##{media_with_preloads.id}: #{inspect(message)}")
|
Logger.error("yt-dlp download error for media item ##{media_with_preloads.id}: #{inspect(message)}")
|
||||||
|
|
||||||
|
|
@ -108,7 +116,12 @@ defmodule Pinchflat.Downloading.MediaDownloader do
|
||||||
{:ok, options} = DownloadOptionBuilder.build(item_with_preloads, override_opts)
|
{:ok, options} = DownloadOptionBuilder.build(item_with_preloads, override_opts)
|
||||||
runner_opts = [output_filepath: output_filepath, use_cookies: item_with_preloads.source.use_cookies]
|
runner_opts = [output_filepath: output_filepath, use_cookies: item_with_preloads.source.use_cookies]
|
||||||
|
|
||||||
YtDlpMedia.download(url, options, runner_opts)
|
# TODO: test
|
||||||
|
case YtDlpMedia.get_downloadable_status(url) do
|
||||||
|
{:ok, :downloadable} -> YtDlpMedia.download(url, options, runner_opts)
|
||||||
|
{:ok, :ignorable} -> {:error, :unsuitable_for_download}
|
||||||
|
err -> err
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp recoverable_errors do
|
defp recoverable_errors do
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,19 @@ defmodule Pinchflat.YtDlp.Media do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# TODO: test
|
||||||
|
def get_downloadable_status(url) do
|
||||||
|
case backend_runner().run(url, [:simulate, :skip_download], "%(.{live_status})j") do
|
||||||
|
{:ok, output} ->
|
||||||
|
output
|
||||||
|
|> Phoenix.json_library().decode!()
|
||||||
|
|> parse_downloadable_status()
|
||||||
|
|
||||||
|
err ->
|
||||||
|
err
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Downloads a thumbnail for a single piece of media. Usually used for
|
Downloads a thumbnail for a single piece of media. Usually used for
|
||||||
downloading thumbnails for internal use
|
downloading thumbnails for internal use
|
||||||
|
|
@ -71,11 +84,10 @@ defmodule Pinchflat.YtDlp.Media do
|
||||||
Returns {:ok, %Media{}} | {:error, any, ...}.
|
Returns {:ok, %Media{}} | {:error, any, ...}.
|
||||||
"""
|
"""
|
||||||
def get_media_attributes(url, command_opts \\ [], addl_opts \\ []) do
|
def get_media_attributes(url, command_opts \\ [], addl_opts \\ []) do
|
||||||
runner = Application.get_env(:pinchflat, :yt_dlp_runner)
|
|
||||||
all_command_opts = [:simulate, :skip_download] ++ command_opts
|
all_command_opts = [:simulate, :skip_download] ++ command_opts
|
||||||
output_template = indexing_output_template()
|
output_template = indexing_output_template()
|
||||||
|
|
||||||
case runner.run(url, all_command_opts, output_template, addl_opts) do
|
case backend_runner().run(url, all_command_opts, output_template, addl_opts) do
|
||||||
{:ok, output} ->
|
{:ok, output} ->
|
||||||
output
|
output
|
||||||
|> Phoenix.json_library().decode!()
|
|> Phoenix.json_library().decode!()
|
||||||
|
|
@ -147,6 +159,14 @@ defmodule Pinchflat.YtDlp.Media do
|
||||||
defp parse_uploaded_at(%{"upload_date" => nil}), do: nil
|
defp parse_uploaded_at(%{"upload_date" => nil}), do: nil
|
||||||
defp parse_uploaded_at(response), do: MetadataFileHelpers.parse_upload_date(response["upload_date"])
|
defp parse_uploaded_at(response), do: MetadataFileHelpers.parse_upload_date(response["upload_date"])
|
||||||
|
|
||||||
|
defp parse_downloadable_status(response) do
|
||||||
|
case response["live_status"] do
|
||||||
|
status when status in ["is_live", "is_upcoming", "post_live"] -> {:ok, :ignorable}
|
||||||
|
status when status in ["was_live", "not_live"] -> {:ok, :downloadable}
|
||||||
|
_ -> {:error, "Unknown live status: #{response["live_status"]}"}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
defp backend_runner do
|
defp backend_runner do
|
||||||
# This approach lets us mock the command for testing
|
# This approach lets us mock the command for testing
|
||||||
Application.get_env(:pinchflat, :yt_dlp_runner)
|
Application.get_env(:pinchflat, :yt_dlp_runner)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue