From 5727a83287d607c12070a7507be2c4161024b140 Mon Sep 17 00:00:00 2001 From: Kieran Eglin Date: Fri, 19 Jul 2024 16:24:43 -0700 Subject: [PATCH] Removed culled_at flag if a media item gets redownloaded --- lib/pinchflat/downloading/media_downloader.ex | 1 + lib/pinchflat/downloading/media_retention_worker.ex | 4 +--- test/pinchflat/downloading/media_downloader_test.exs | 7 +++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/pinchflat/downloading/media_downloader.ex b/lib/pinchflat/downloading/media_downloader.ex index eb7a09f..a10e6b9 100644 --- a/lib/pinchflat/downloading/media_downloader.ex +++ b/lib/pinchflat/downloading/media_downloader.ex @@ -79,6 +79,7 @@ defmodule Pinchflat.Downloading.MediaDownloader do |> MetadataParser.parse_for_media_item() |> Map.merge(%{ media_downloaded_at: DateTime.utc_now(), + culled_at: nil, nfo_filepath: determine_nfo_filepath(media_with_preloads, parsed_json), metadata: %{ # IDEA: might be worth kicking off a job for this since thumbnail fetching diff --git a/lib/pinchflat/downloading/media_retention_worker.ex b/lib/pinchflat/downloading/media_retention_worker.ex index 65752b4..6f97cbd 100644 --- a/lib/pinchflat/downloading/media_retention_worker.ex +++ b/lib/pinchflat/downloading/media_retention_worker.ex @@ -58,9 +58,7 @@ defmodule Pinchflat.Downloading.MediaRetentionWorker do |> Repo.all() Logger.info("Deleting #{length(deletable_media)} media items that are from before the source cutoff") - # TODO: I should ensure that `culled_at` is set to nil if the media item - # gets re-downloaded. Because in this case the user could just change the cutoff date and re-download - # and I don't think it makes sense to still indicate that the media item was culled. + Enum.each(deletable_media, fn media_item -> # Note that I'm not setting `prevent_download` on the media_item here. # That's because cutoff_date can easily change and it's a valid behavior to re-download older diff --git a/test/pinchflat/downloading/media_downloader_test.exs b/test/pinchflat/downloading/media_downloader_test.exs index 0aa5a8b..be5f10e 100644 --- a/test/pinchflat/downloading/media_downloader_test.exs +++ b/test/pinchflat/downloading/media_downloader_test.exs @@ -5,6 +5,7 @@ defmodule Pinchflat.Downloading.MediaDownloaderTest do import Pinchflat.SourcesFixtures import Pinchflat.ProfilesFixtures + alias Pinchflat.Media alias Pinchflat.Downloading.MediaDownloader setup do @@ -123,6 +124,12 @@ defmodule Pinchflat.Downloading.MediaDownloaderTest do assert DateTime.diff(DateTime.utc_now(), updated_media_item.media_downloaded_at) < 2 end + test "it sets the culled_at to nil", %{media_item: media_item} do + Media.update_media_item(media_item, %{culled_at: DateTime.utc_now()}) + assert {:ok, updated_media_item} = MediaDownloader.download_for_media_item(media_item) + assert updated_media_item.culled_at == nil + end + test "it extracts the title", %{media_item: media_item} do assert {:ok, updated_media_item} = MediaDownloader.download_for_media_item(media_item) assert updated_media_item.title == "Pinchflat Example Video"