Cleaned up the stragglers
This commit is contained in:
parent
814f94675f
commit
3fc83735c1
13 changed files with 18 additions and 57 deletions
|
|
@ -41,9 +41,10 @@ defmodule Pinchflat.Media do
|
|||
Returns a list of media_items that are redownloadable based on the redownload delay
|
||||
of the media_profile their source belongs to.
|
||||
|
||||
The logic is that a media_item is past_redownload_delay if the media_item's
|
||||
upload_date is at least redownload_delay_days ago AND
|
||||
`media_downloaded_at` - `redownload_delay_days` is before the media_item's `upload_date`.
|
||||
The logic is that a media_item is past_redownload_delay if the media_item's uploaded_at is
|
||||
at least redownload_delay_days ago AND `media_downloaded_at` - `redownload_delay_days`
|
||||
is before the media_item's `uploaded_at`.
|
||||
|
||||
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.
|
||||
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
|
||||
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{}}
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@ defmodule Pinchflat.Metadata.NfoBuilder do
|
|||
end
|
||||
|
||||
defp build_for_media_item(metadata) do
|
||||
# TODO: see how this works post-change
|
||||
upload_date = MetadataFileHelpers.parse_upload_date(metadata["upload_date"])
|
||||
# Cribbed from a combination of the Kodi wiki, ytdl-nfo, and ytdl-sub.
|
||||
# WHO NEEDS A FANCY XML PARSER ANYWAY?!
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ defmodule Pinchflat.Podcasts.PodcastHelpers do
|
|||
|
||||
MediaQuery.new()
|
||||
|> where(^dynamic(^MediaQuery.for_source(source) and ^MediaQuery.downloaded()))
|
||||
|> order_by(desc: :upload_date)
|
||||
|> order_by(desc: :uploaded_at)
|
||||
|> Repo.maybe_limit(limit)
|
||||
|> Repo.all()
|
||||
|> Enum.filter(fn media_item -> File.exists?(media_item.media_filepath) end)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ defmodule Pinchflat.Podcasts.RssFeedBuilder do
|
|||
|
||||
import Pinchflat.Utils.XmlUtils, only: [safe: 1]
|
||||
|
||||
alias Pinchflat.Utils.DatetimeUtils
|
||||
alias Pinchflat.Podcasts.PodcastHelpers
|
||||
alias PinchflatWeb.Router.Helpers, as: Routes
|
||||
|
||||
|
|
@ -83,7 +82,7 @@ defmodule Pinchflat.Podcasts.RssFeedBuilder do
|
|||
<title>#{safe(media_item.title)}</title>
|
||||
<link>#{safe(media_item.original_url)}</link>
|
||||
<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>
|
||||
<enclosure
|
||||
url="#{media_stream_path(url_base, media_item)}"
|
||||
|
|
@ -133,12 +132,6 @@ defmodule Pinchflat.Podcasts.RssFeedBuilder do
|
|||
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
|
||||
Routes.podcast_path(PinchflatWeb.Endpoint, action, params)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -90,7 +90,7 @@ defmodule Pinchflat.YtDlp.Media do
|
|||
livestream: !!response["was_live"],
|
||||
duration_seconds: response["duration"] && round(response["duration"]),
|
||||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
<.media_preview media_item={@media_item} />
|
||||
</div>
|
||||
<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>
|
||||
<span :if={URI.parse(@media_item.original_url).scheme =~ "http"}>
|
||||
<.subtle_link href={@media_item.original_url} target="_blank">Open Original</.subtle_link>
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ defmodule Pinchflat.Pages.HistoryTableLive do
|
|||
</.subtle_link>
|
||||
</:col>
|
||||
<:col :let={media_item} label="Upload Date">
|
||||
<%= media_item.upload_date %>
|
||||
<%= DateTime.to_date(media_item.uploaded_at) %>
|
||||
</:col>
|
||||
<:col :let={media_item} label="Indexed At">
|
||||
<%= format_datetime(media_item.inserted_at) %>
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ defmodule Pinchflat.Sources.MediaItemTableLive do
|
|||
</.subtle_link>
|
||||
</:col>
|
||||
<:col :let={media_item} label="Upload Date">
|
||||
<%= media_item.uploaded_at %>
|
||||
<%= DateTime.to_date(media_item.uploaded_at) %>
|
||||
</:col>
|
||||
<: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"} />
|
||||
|
|
@ -66,7 +66,6 @@ defmodule Pinchflat.Sources.MediaItemTableLive do
|
|||
"""
|
||||
end
|
||||
|
||||
# TODO: see how uploaded_at looks in the UI (above)
|
||||
def mount(_params, session, socket) do
|
||||
PinchflatWeb.Endpoint.subscribe("media_table")
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ defmodule Pinchflat.Downloading.MediaQualityUpgradeWorkerTest do
|
|||
media_item =
|
||||
media_item_fixture(%{
|
||||
source_id: source.id,
|
||||
upload_date: now_minus(6, :days),
|
||||
uploaded_at: now_minus(6, :days),
|
||||
media_downloaded_at: now_minus(5, :days)
|
||||
})
|
||||
|
||||
|
|
@ -32,7 +32,7 @@ defmodule Pinchflat.Downloading.MediaQualityUpgradeWorkerTest do
|
|||
_media_item =
|
||||
media_item_fixture(%{
|
||||
source_id: source.id,
|
||||
upload_date: now_minus(6, :days),
|
||||
uploaded_at: now_minus(6, :days),
|
||||
media_downloaded_at: now_minus(1, :day)
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -26,9 +26,9 @@ defmodule Pinchflat.Podcasts.PodcastHelpersTest do
|
|||
test "orders by upload date where newest is first" do
|
||||
source = source_fixture()
|
||||
|
||||
oldest = media_item_with_attachments(%{source_id: source.id, upload_date: now_minus(2, :day)})
|
||||
current = media_item_with_attachments(%{source_id: source.id, upload_date: now()})
|
||||
older = media_item_with_attachments(%{source_id: source.id, upload_date: now_minus(1, :days)})
|
||||
oldest = media_item_with_attachments(%{source_id: source.id, uploaded_at: now_minus(2, :day)})
|
||||
current = media_item_with_attachments(%{source_id: source.id, uploaded_at: now()})
|
||||
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)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -117,8 +117,8 @@ defmodule Pinchflat.Podcasts.RssFeedBuilderTest do
|
|||
assert String.contains?(item_xml, ~s(<itunes:summary><![CDATA[#{media_item.description}]]></itunes:summary>))
|
||||
end
|
||||
|
||||
test "returns pubDate based off the media's upload_date", %{source: source} do
|
||||
media_item_with_attachments(%{source_id: source.id, upload_date: ~D[2020-01-01]})
|
||||
test "returns pubDate based off the media's uploaded_at", %{source: source} do
|
||||
media_item_with_attachments(%{source_id: source.id, uploaded_at: ~U[2020-01-01 00:00:00Z]})
|
||||
|
||||
res = RssFeedBuilder.build(source)
|
||||
[_before, item_xml, _after] = String.split(res, ~r(</?item>))
|
||||
|
|
|
|||
|
|
@ -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
|
||||
Loading…
Reference in a new issue