Cleaned up the stragglers

This commit is contained in:
Kieran Eglin 2024-05-28 12:36:51 -07:00
parent 814f94675f
commit 3fc83735c1
No known key found for this signature in database
GPG key ID: 193984967FCF432D
13 changed files with 18 additions and 57 deletions

View file

@ -41,9 +41,10 @@ defmodule Pinchflat.Media do
Returns a list of media_items that are redownloadable based on the redownload delay Returns a list of media_items that are redownloadable based on the redownload delay
of the media_profile their source belongs to. of the media_profile their source belongs to.
The logic is that a media_item is past_redownload_delay if the media_item's The logic is that a media_item is past_redownload_delay if the media_item's uploaded_at is
upload_date is at least redownload_delay_days ago AND at least redownload_delay_days ago AND `media_downloaded_at` - `redownload_delay_days`
`media_downloaded_at` - `redownload_delay_days` is before the media_item's `upload_date`. is before the media_item's `uploaded_at`.
This logic grabs media that we've recently downloaded AND is recently uploaded, but This logic grabs media that we've recently downloaded AND is recently uploaded, but
doesn't grab media that we've recently downloaded and was uploaded a long time ago. doesn't grab media that we've recently downloaded and was uploaded a long time ago.
This also makes things work as expected when downloading media from a source for the This also makes things work as expected when downloading media from a source for the
@ -135,7 +136,7 @@ defmodule Pinchflat.Media do
Unlike `create_media_item`, this will attempt an update if the media_item Unlike `create_media_item`, this will attempt an update if the media_item
already exists. This is so that future indexing can pick up attributes that already exists. This is so that future indexing can pick up attributes that
we may not have asked for in the past (eg: upload_date) we may not have asked for in the past (eg: uploaded_at)
Returns {:ok, %MediaItem{}} | {:error, %Ecto.Changeset{}} Returns {:ok, %MediaItem{}} | {:error, %Ecto.Changeset{}}
""" """

View file

@ -38,7 +38,6 @@ defmodule Pinchflat.Metadata.NfoBuilder do
end end
defp build_for_media_item(metadata) do defp build_for_media_item(metadata) do
# TODO: see how this works post-change
upload_date = MetadataFileHelpers.parse_upload_date(metadata["upload_date"]) upload_date = MetadataFileHelpers.parse_upload_date(metadata["upload_date"])
# Cribbed from a combination of the Kodi wiki, ytdl-nfo, and ytdl-sub. # Cribbed from a combination of the Kodi wiki, ytdl-nfo, and ytdl-sub.
# WHO NEEDS A FANCY XML PARSER ANYWAY?! # WHO NEEDS A FANCY XML PARSER ANYWAY?!

View file

@ -28,7 +28,7 @@ defmodule Pinchflat.Podcasts.PodcastHelpers do
MediaQuery.new() MediaQuery.new()
|> where(^dynamic(^MediaQuery.for_source(source) and ^MediaQuery.downloaded())) |> where(^dynamic(^MediaQuery.for_source(source) and ^MediaQuery.downloaded()))
|> order_by(desc: :upload_date) |> order_by(desc: :uploaded_at)
|> Repo.maybe_limit(limit) |> Repo.maybe_limit(limit)
|> Repo.all() |> Repo.all()
|> Enum.filter(fn media_item -> File.exists?(media_item.media_filepath) end) |> Enum.filter(fn media_item -> File.exists?(media_item.media_filepath) end)

View file

@ -7,7 +7,6 @@ defmodule Pinchflat.Podcasts.RssFeedBuilder do
import Pinchflat.Utils.XmlUtils, only: [safe: 1] import Pinchflat.Utils.XmlUtils, only: [safe: 1]
alias Pinchflat.Utils.DatetimeUtils
alias Pinchflat.Podcasts.PodcastHelpers alias Pinchflat.Podcasts.PodcastHelpers
alias PinchflatWeb.Router.Helpers, as: Routes alias PinchflatWeb.Router.Helpers, as: Routes
@ -83,7 +82,7 @@ defmodule Pinchflat.Podcasts.RssFeedBuilder do
<title>#{safe(media_item.title)}</title> <title>#{safe(media_item.title)}</title>
<link>#{safe(media_item.original_url)}</link> <link>#{safe(media_item.original_url)}</link>
<description>#{safe(media_item.description)}</description> <description>#{safe(media_item.description)}</description>
<pubDate>#{generate_upload_date(media_item)}</pubDate> <pubDate>#{Calendar.strftime(media_item.uploaded_at, @datetime_format)}</pubDate>
<itunes:duration>#{media_item.duration_seconds}</itunes:duration> <itunes:duration>#{media_item.duration_seconds}</itunes:duration>
<enclosure <enclosure
url="#{media_stream_path(url_base, media_item)}" url="#{media_stream_path(url_base, media_item)}"
@ -133,12 +132,6 @@ defmodule Pinchflat.Podcasts.RssFeedBuilder do
end end
end end
defp generate_upload_date(media_item) do
media_item.upload_date
|> DatetimeUtils.date_to_datetime()
|> Calendar.strftime(@datetime_format)
end
defp podcast_route(action, params) do defp podcast_route(action, params) do
Routes.podcast_path(PinchflatWeb.Endpoint, action, params) Routes.podcast_path(PinchflatWeb.Endpoint, action, params)
end end

View file

@ -1,17 +0,0 @@
defmodule Pinchflat.Utils.DatetimeUtils do
@moduledoc """
Utility methods for working with dates and datetimes
"""
@doc """
Converts a Date to a DateTime
Returns %DateTime{}
"""
def date_to_datetime(date) do
date
|> Date.to_gregorian_days()
|> Kernel.*(86_400)
|> DateTime.from_gregorian_seconds()
end
end

View file

@ -90,7 +90,7 @@ defmodule Pinchflat.YtDlp.Media do
livestream: !!response["was_live"], livestream: !!response["was_live"],
duration_seconds: response["duration"] && round(response["duration"]), duration_seconds: response["duration"] && round(response["duration"]),
short_form_content: response["webpage_url"] && short_form_content?(response), short_form_content: response["webpage_url"] && short_form_content?(response),
uploaded_at: parse_uploaded_at(response) uploaded_at: response["upload_date"] && parse_uploaded_at(response)
} }
end end

View file

@ -31,7 +31,7 @@
<.media_preview media_item={@media_item} /> <.media_preview media_item={@media_item} />
</div> </div>
<aside class="mt-4 xl:mt-0"> <aside class="mt-4 xl:mt-0">
<div>Uploaded: <%= @media_item.upload_date %></div> <div>Uploaded: <%= DateTime.to_date(@media_item.uploaded_at) %></div>
<div> <div>
<span :if={URI.parse(@media_item.original_url).scheme =~ "http"}> <span :if={URI.parse(@media_item.original_url).scheme =~ "http"}>
<.subtle_link href={@media_item.original_url} target="_blank">Open Original</.subtle_link> <.subtle_link href={@media_item.original_url} target="_blank">Open Original</.subtle_link>

View file

@ -32,7 +32,7 @@ defmodule Pinchflat.Pages.HistoryTableLive do
</.subtle_link> </.subtle_link>
</:col> </:col>
<:col :let={media_item} label="Upload Date"> <:col :let={media_item} label="Upload Date">
<%= media_item.upload_date %> <%= DateTime.to_date(media_item.uploaded_at) %>
</:col> </:col>
<:col :let={media_item} label="Indexed At"> <:col :let={media_item} label="Indexed At">
<%= format_datetime(media_item.inserted_at) %> <%= format_datetime(media_item.inserted_at) %>

View file

@ -50,7 +50,7 @@ defmodule Pinchflat.Sources.MediaItemTableLive do
</.subtle_link> </.subtle_link>
</:col> </:col>
<:col :let={media_item} label="Upload Date"> <:col :let={media_item} label="Upload Date">
<%= media_item.uploaded_at %> <%= DateTime.to_date(media_item.uploaded_at) %>
</:col> </:col>
<:col :let={media_item} :if={@media_state == "other"} label="Manually Ignored?"> <:col :let={media_item} :if={@media_state == "other"} label="Manually Ignored?">
<.icon name={if media_item.prevent_download, do: "hero-check", else: "hero-x-mark"} /> <.icon name={if media_item.prevent_download, do: "hero-check", else: "hero-x-mark"} />
@ -66,7 +66,6 @@ defmodule Pinchflat.Sources.MediaItemTableLive do
""" """
end end
# TODO: see how uploaded_at looks in the UI (above)
def mount(_params, session, socket) do def mount(_params, session, socket) do
PinchflatWeb.Endpoint.subscribe("media_table") PinchflatWeb.Endpoint.subscribe("media_table")

View file

@ -16,7 +16,7 @@ defmodule Pinchflat.Downloading.MediaQualityUpgradeWorkerTest do
media_item = media_item =
media_item_fixture(%{ media_item_fixture(%{
source_id: source.id, source_id: source.id,
upload_date: now_minus(6, :days), uploaded_at: now_minus(6, :days),
media_downloaded_at: now_minus(5, :days) media_downloaded_at: now_minus(5, :days)
}) })
@ -32,7 +32,7 @@ defmodule Pinchflat.Downloading.MediaQualityUpgradeWorkerTest do
_media_item = _media_item =
media_item_fixture(%{ media_item_fixture(%{
source_id: source.id, source_id: source.id,
upload_date: now_minus(6, :days), uploaded_at: now_minus(6, :days),
media_downloaded_at: now_minus(1, :day) media_downloaded_at: now_minus(1, :day)
}) })

View file

@ -26,9 +26,9 @@ defmodule Pinchflat.Podcasts.PodcastHelpersTest do
test "orders by upload date where newest is first" do test "orders by upload date where newest is first" do
source = source_fixture() source = source_fixture()
oldest = media_item_with_attachments(%{source_id: source.id, upload_date: now_minus(2, :day)}) oldest = media_item_with_attachments(%{source_id: source.id, uploaded_at: now_minus(2, :day)})
current = media_item_with_attachments(%{source_id: source.id, upload_date: now()}) current = media_item_with_attachments(%{source_id: source.id, uploaded_at: now()})
older = media_item_with_attachments(%{source_id: source.id, upload_date: now_minus(1, :days)}) older = media_item_with_attachments(%{source_id: source.id, uploaded_at: now_minus(1, :days)})
assert [^current, ^older, ^oldest] = PodcastHelpers.persisted_media_items_for(source) assert [^current, ^older, ^oldest] = PodcastHelpers.persisted_media_items_for(source)
end end

View file

@ -117,8 +117,8 @@ defmodule Pinchflat.Podcasts.RssFeedBuilderTest do
assert String.contains?(item_xml, ~s(<itunes:summary><![CDATA[#{media_item.description}]]></itunes:summary>)) assert String.contains?(item_xml, ~s(<itunes:summary><![CDATA[#{media_item.description}]]></itunes:summary>))
end end
test "returns pubDate based off the media's upload_date", %{source: source} do test "returns pubDate based off the media's uploaded_at", %{source: source} do
media_item_with_attachments(%{source_id: source.id, upload_date: ~D[2020-01-01]}) media_item_with_attachments(%{source_id: source.id, uploaded_at: ~U[2020-01-01 00:00:00Z]})
res = RssFeedBuilder.build(source) res = RssFeedBuilder.build(source)
[_before, item_xml, _after] = String.split(res, ~r(</?item>)) [_before, item_xml, _after] = String.split(res, ~r(</?item>))

View file

@ -1,14 +0,0 @@
defmodule Pinchflat.Utils.DatetimeUtilsTest do
use Pinchflat.DataCase
alias Pinchflat.Utils.DatetimeUtils
describe "date_to_datetime/1" do
test "converts a Date to a DateTime" do
date = ~D[2022-01-01]
datetime = DatetimeUtils.date_to_datetime(date)
assert datetime == ~U[2022-01-01 00:00:00Z]
end
end
end