From fe5c00dbeff0adcc3f35ec9639c47a8f8b3338c4 Mon Sep 17 00:00:00 2001 From: Kieran Date: Mon, 10 Feb 2025 12:13:37 -0800 Subject: [PATCH] [Enhancement] Download failures due to videos being members-only are not immediately retried (#609) --- .../downloading/media_download_worker.ex | 6 +++++- .../downloading/media_download_worker_test.exs | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/pinchflat/downloading/media_download_worker.ex b/lib/pinchflat/downloading/media_download_worker.ex index 7a6f8e8..6ed5787 100644 --- a/lib/pinchflat/downloading/media_download_worker.ex +++ b/lib/pinchflat/downloading/media_download_worker.ex @@ -129,7 +129,11 @@ defmodule Pinchflat.Downloading.MediaDownloadWorker do defp action_on_error(message) do # This will attempt re-download at the next indexing, but it won't be retried # immediately as part of job failure logic - non_retryable_errors = ["Video unavailable", "Sign in to confirm"] + non_retryable_errors = [ + "Video unavailable", + "Sign in to confirm", + "This video is available to this channel's members" + ] if String.contains?(to_string(message), non_retryable_errors) do Logger.error("yt-dlp download will not be retried: #{inspect(message)}") diff --git a/test/pinchflat/downloading/media_download_worker_test.exs b/test/pinchflat/downloading/media_download_worker_test.exs index 812ec95..9b2e0f8 100644 --- a/test/pinchflat/downloading/media_download_worker_test.exs +++ b/test/pinchflat/downloading/media_download_worker_test.exs @@ -147,6 +147,22 @@ defmodule Pinchflat.Downloading.MediaDownloadWorkerTest do end) end + test "does not set the job to retryable you aren't a member", %{media_item: media_item} do + expect(YtDlpRunnerMock, :run, 2, fn + _url, :get_downloadable_status, _opts, _ot, _addl -> + {:ok, "{}"} + + _url, :download, _opts, _ot, _addl -> + {:error, "This video is available to this channel's members on level: foo", 1} + end) + + Oban.Testing.with_testing_mode(:inline, fn -> + {:ok, job} = Oban.insert(MediaDownloadWorker.new(%{id: media_item.id, quality_upgrade?: true})) + + assert job.state == "completed" + end) + end + test "ensures error are returned in a 2-item tuple", %{media_item: media_item} do expect(YtDlpRunnerMock, :run, 2, fn _url, :get_downloadable_status, _opts, _ot, _addl -> {:ok, "{}"}