Refactored parse_upload_date
This commit is contained in:
parent
3b89a346ef
commit
e8c8613074
4 changed files with 8 additions and 8 deletions
|
|
@ -26,7 +26,7 @@ defmodule Pinchflat.Media.MediaItem do
|
|||
:livestream,
|
||||
:source_id,
|
||||
:short_form_content,
|
||||
:upload_date,
|
||||
:uploaded_at,
|
||||
:upload_date_index,
|
||||
:duration_seconds,
|
||||
# these fields are captured only on download
|
||||
|
|
|
|||
|
|
@ -88,14 +88,13 @@ defmodule Pinchflat.Metadata.MetadataFileHelpers do
|
|||
|
||||
@doc """
|
||||
Parses an upload date from the YYYYMMDD string returned in yt-dlp metadata
|
||||
and returns a Date struct.
|
||||
and returns a DateTime struct, appending a time of 00:00:00Z.
|
||||
|
||||
Returns Date.t()
|
||||
Returns DateTime.t()
|
||||
"""
|
||||
def parse_upload_date(upload_date) do
|
||||
<<year::binary-size(4)>> <> <<month::binary-size(2)>> <> <<day::binary-size(2)>> = upload_date
|
||||
|
||||
# TODO: test new
|
||||
case DateTime.from_iso8601("#{year}-#{month}-#{day}T00:00:00Z") do
|
||||
{:ok, datetime, _} -> datetime
|
||||
_ -> raise "Invalid upload date: #{upload_date}"
|
||||
|
|
|
|||
|
|
@ -132,10 +132,10 @@ defmodule Pinchflat.Metadata.MetadataFileHelpersTest do
|
|||
end
|
||||
|
||||
describe "parse_upload_date/1" do
|
||||
test "returns a date from the given metadata upload date" do
|
||||
test "returns a datetime from the given metadata upload date" do
|
||||
upload_date = "20210101"
|
||||
|
||||
assert Helpers.parse_upload_date(upload_date) == ~D[2021-01-01]
|
||||
assert Helpers.parse_upload_date(upload_date) == ~U[2021-01-01 00:00:00Z]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ defmodule Pinchflat.MediaFixtures do
|
|||
short_form_content: false,
|
||||
media_filepath: "/video/#{Faker.File.file_name(:video)}",
|
||||
source_id: SourcesFixtures.source_fixture().id,
|
||||
upload_date: DateTime.utc_now()
|
||||
uploaded_at: DateTime.utc_now()
|
||||
})
|
||||
|> Pinchflat.Media.create_media_item()
|
||||
|
||||
|
|
@ -97,7 +97,8 @@ defmodule Pinchflat.MediaFixtures do
|
|||
description: "desc1",
|
||||
aspect_ratio: 1.67,
|
||||
duration: 123.45,
|
||||
upload_date: "20210101"
|
||||
upload_date: "20210101",
|
||||
timestamp: 1_600_000_000
|
||||
}
|
||||
|
||||
Phoenix.json_library().encode!(media_attributes)
|
||||
|
|
|
|||
Loading…
Reference in a new issue