Can parse an obsidian entry to retrieve correct metadata

This commit is contained in:
Claudio Ortolina
2024-09-13 13:35:39 +01:00
parent e4ae157275
commit 2c42f3ea32
6 changed files with 108 additions and 3 deletions
+24
View File
@@ -0,0 +1,24 @@
defmodule MusicLibrary.Records.Parser do
alias MusicLibrary.Records.Record
def from_entry_contents(entry_contents) do
with {:ok, meta, _body} <- FrontMatter.parse(entry_contents) do
{:ok,
%Record{
type: parse_subtype(meta["subType"]),
musicbrainz_id: meta["id"],
title: meta["title"],
year: meta["year"],
image: meta["image"],
genres: meta["genres"]
}}
end
end
defp parse_subtype("Album"), do: :album
defp parse_subtype("ep"), do: :ep
defp parse_subtype("Live"), do: :live
defp parse_subtype("Compilation"), do: :compilation
defp parse_subtype("Single"), do: :single
defp parse_subtype(_), do: :other
end