Removed culled_at flag if a media item gets redownloaded

This commit is contained in:
Kieran Eglin 2024-07-19 16:24:43 -07:00
parent ea0763b27d
commit 5727a83287
No known key found for this signature in database
GPG key ID: 193984967FCF432D
3 changed files with 9 additions and 3 deletions

View file

@ -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

View file

@ -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

View file

@ -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"