diff --git a/lib/pinchflat/metadata/metadata_parser.ex b/lib/pinchflat/metadata/metadata_parser.ex index ef048b8..60456d8 100644 --- a/lib/pinchflat/metadata/metadata_parser.ex +++ b/lib/pinchflat/metadata/metadata_parser.ex @@ -8,6 +8,8 @@ defmodule Pinchflat.Metadata.MetadataParser do and not have it, ya know? """ + alias Pinchflat.YtDlp.Media, as: YtDlpMedia + @doc """ Parses the given JSON response from yt-dlp and returns a map of the needful media_item attributes, along with anything needed for @@ -24,15 +26,12 @@ defmodule Pinchflat.Metadata.MetadataParser do end defp parse_media_metadata(metadata) do - %{ - media_id: metadata["id"], - title: metadata["title"], - original_url: metadata["original_url"], - description: metadata["description"], - media_filepath: metadata["filepath"], - livestream: !!metadata["was_live"], - duration_seconds: metadata["duration"] && round(metadata["duration"]) - } + Map.merge( + Map.from_struct(YtDlpMedia.response_to_struct(metadata)), + %{ + media_filepath: metadata["filepath"] + } + ) end defp parse_subtitle_metadata(metadata) do diff --git a/test/support/files/media_metadata.json b/test/support/files/media_metadata.json index fff1620..dc57e72 100644 --- a/test/support/files/media_metadata.json +++ b/test/support/files/media_metadata.json @@ -9637,7 +9637,7 @@ "uploader_url": "https://www.youtube.com/@PinchflatTestChannel", "upload_date": "20210720", "availability": "public", - "original_url": "ABC123", + "original_url": "https://www.youtube.com/watch?v=ABC123", "webpage_url_basename": "watch", "webpage_url_domain": "youtube.com", "extractor": "youtube", diff --git a/test/support/fixtures/media_fixtures.ex b/test/support/fixtures/media_fixtures.ex index c9766ee..c78a09a 100644 --- a/test/support/fixtures/media_fixtures.ex +++ b/test/support/fixtures/media_fixtures.ex @@ -13,13 +13,6 @@ defmodule Pinchflat.MediaFixtures do def media_item_fixture(attrs \\ %{}) do media_id = Faker.String.base64(12) - # TODO: remove - attrs2 = Enum.into(attrs, %{}) - - if attrs2[:upload_date] || attrs2["upload_date"] do - raise "upload_date is not allowed in media_item_fixture. Use uploaded_at instead." - end - {:ok, media_item} = attrs |> Enum.into(%{