Remove obsolete Obsidian import logic

This commit is contained in:
Claudio Ortolina
2026-02-18 22:07:57 +00:00
parent aa21f66255
commit 3079ebdd02
7 changed files with 1 additions and 162 deletions
-64
View File
@@ -1,64 +0,0 @@
defmodule Mix.Tasks.Obsidian.Import do
@shortdoc "Import records from an Obsidian Vault containing Media entries "
@moduledoc """
Import records from an Obsidian Vault containing Media entries.
Requires the path of the vault as argument to the task:
`mix obsidian.import path/to/vault`
"""
use Mix.Task
@impl Mix.Task
def run(args) do
case args do
[] ->
Mix.Shell.IO.error("Error: requires the path to the obsidian vault record folder")
System.halt(1)
[path] ->
Mix.Shell.IO.info("Seeding the database from #{path}")
%{valid: valid, errors: errors} =
Path.wildcard("#{path}/*.md")
|> Enum.reduce(%{valid: [], errors: []}, fn entry, acc ->
file_stat = File.stat!(entry)
case entry
|> File.read!()
|> Obsidian.Parser.from_file_contents() do
{:ok, parsed_entry} ->
inserted_at =
file_stat.ctime
|> NaiveDateTime.from_erl!()
|> DateTime.from_naive!("Etc/UTC")
updated_at =
file_stat.mtime
|> NaiveDateTime.from_erl!()
|> DateTime.from_naive!("Etc/UTC")
data =
parsed_entry
|> Map.put(:inserted_at, inserted_at)
|> Map.put(:updated_at, updated_at)
%{acc | valid: [data | acc.valid]}
{:error, error} ->
%{acc | errors: [{entry, error} | acc.errors]}
end
end)
Mix.Shell.IO.info("Parsed #{length(valid)} entries")
Mix.Shell.IO.error("Failed to parse #{length(errors)} entries")
MusicLibrary.Repo.insert_all(MusicLibrary.Records.Record, valid)
_other ->
Mix.Shell.IO.error("Error: too many arguments")
System.halt(1)
end
end
end
+1 -1
View File
@@ -1,6 +1,6 @@
defmodule MusicBrainz.API do defmodule MusicBrainz.API do
@moduledoc """ @moduledoc """
The original data from Obsidian maps records to MusicBrainz release groups, so we can leverage the MusicBrainz API to: We can leverage the MusicBrainz API to:
- Import new records - Import new records
- Extend the metadata associated with existing records - Extend the metadata associated with existing records
-4
View File
@@ -1,4 +0,0 @@
defmodule Obsidian.Entry do
@enforce_keys [:type, :musicbrainz_id, :title, :release, :cover_url, :genres]
defstruct [:type, :musicbrainz_id, :title, :release, :cover_url, :genres]
end
-42
View File
@@ -1,42 +0,0 @@
defmodule Obsidian.Parser do
alias Obsidian.Entry
def from_file_contents(file_contents) do
with {:ok, meta} <- parse_frontmatter(file_contents) do
{:ok,
%Entry{
type: parse_subtype(meta["subType"]),
musicbrainz_id: meta["id"],
title: meta["title"],
release: meta["year"] |> parse_release(),
cover_url: meta["image"],
genres: meta["genres"]
}}
end
end
defp parse_frontmatter("---\n" <> rest) do
with [frontmatter, _] <- String.split(rest, "\n---\n"),
{:ok, [meta]} <- YamlElixir.read_all_from_string(frontmatter) do
{:ok, meta}
else
_ ->
{:error, "Invalid frontmatter"}
end
end
defp parse_frontmatter(_file_contents) do
{:error, "Invalid frontmatter"}
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
defp parse_release(nil), do: nil
defp parse_release(year) when is_integer(year), do: Integer.to_string(year)
defp parse_release(year) when is_binary(year), do: year
end
-1
View File
@@ -92,7 +92,6 @@ defmodule MusicLibrary.MixProject do
{:req, "~> 0.5.8"}, {:req, "~> 0.5.8"},
# Parsing # Parsing
{:yaml_elixir, "~> 2.11"},
{:nimble_parsec, "~> 1.4"}, {:nimble_parsec, "~> 1.4"},
# Image manipulation # Image manipulation
-2
View File
@@ -76,6 +76,4 @@
"vix": {:hex, :vix, "0.38.0", "77529ee4f6ced339c3d5f90a9eacf306f5b7109d3d1b5e3ef391a984ad404f75", [:make, :mix], [{:cc_precompiler, "~> 0.1.4 or ~> 0.2", [hex: :cc_precompiler, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.7.3 or ~> 0.8", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:kino, "~> 0.7", [hex: :kino, repo: "hexpm", optional: true]}], "hexpm", "dca58f654922fa678d5df8e028317483d9c0f8acb2e2714076a8468695687aa7"}, "vix": {:hex, :vix, "0.38.0", "77529ee4f6ced339c3d5f90a9eacf306f5b7109d3d1b5e3ef391a984ad404f75", [:make, :mix], [{:cc_precompiler, "~> 0.1.4 or ~> 0.2", [hex: :cc_precompiler, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.7.3 or ~> 0.8", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:kino, "~> 0.7", [hex: :kino, repo: "hexpm", optional: true]}], "hexpm", "dca58f654922fa678d5df8e028317483d9c0f8acb2e2714076a8468695687aa7"},
"websock": {:hex, :websock, "0.5.3", "2f69a6ebe810328555b6fe5c831a851f485e303a7c8ce6c5f675abeb20ebdadc", [:mix], [], "hexpm", "6105453d7fac22c712ad66fab1d45abdf049868f253cf719b625151460b8b453"}, "websock": {:hex, :websock, "0.5.3", "2f69a6ebe810328555b6fe5c831a851f485e303a7c8ce6c5f675abeb20ebdadc", [:mix], [], "hexpm", "6105453d7fac22c712ad66fab1d45abdf049868f253cf719b625151460b8b453"},
"websock_adapter": {:hex, :websock_adapter, "0.5.9", "43dc3ba6d89ef5dec5b1d0a39698436a1e856d000d84bf31a3149862b01a287f", [:mix], [{:bandit, ">= 0.6.0", [hex: :bandit, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.6", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "5534d5c9adad3c18a0f58a9371220d75a803bf0b9a3d87e6fe072faaeed76a08"}, "websock_adapter": {:hex, :websock_adapter, "0.5.9", "43dc3ba6d89ef5dec5b1d0a39698436a1e856d000d84bf31a3149862b01a287f", [:mix], [{:bandit, ">= 0.6.0", [hex: :bandit, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.6", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "5534d5c9adad3c18a0f58a9371220d75a803bf0b9a3d87e6fe072faaeed76a08"},
"yamerl": {:hex, :yamerl, "0.10.0", "4ff81fee2f1f6a46f1700c0d880b24d193ddb74bd14ef42cb0bcf46e81ef2f8e", [:rebar3], [], "hexpm", "346adb2963f1051dc837a2364e4acf6eb7d80097c0f53cbdc3046ec8ec4b4e6e"},
"yaml_elixir": {:hex, :yaml_elixir, "2.12.1", "d74f2d82294651b58dac849c45a82aaea639766797359baff834b64439f6b3f4", [:mix], [{:yamerl, "~> 0.10", [hex: :yamerl, repo: "hexpm", optional: false]}], "hexpm", "d9ac16563c737d55f9bfeed7627489156b91268a3a21cd55c54eb2e335207fed"},
} }
-48
View File
@@ -1,48 +0,0 @@
defmodule Obsidian.ParserTest do
use ExUnit.Case, async: true
alias Obsidian.{Entry, Parser}
@marbles_entry_path Path.expand("../support/fixtures/obsidian/marillion-marbles.md", __DIR__)
@guardians_entry_path Path.expand("../support/fixtures/obsidian/guardians.md", __DIR__)
test "parses the content of the Obsidian album entry" do
entry_contents = File.read!(@marbles_entry_path)
assert Parser.from_file_contents(entry_contents) ==
{:ok,
%Entry{
type: :album,
musicbrainz_id: "20790e26-98e4-3ad3-a67f-b674758b942d",
title: "Marbles",
release: "2004",
cover_url:
"https://coverartarchive.org/release-group/20790e26-98e4-3ad3-a67f-b674758b942d/front",
genres: [
"alternative rock",
"art rock",
"baroque pop",
"pop rock",
"progressive rock",
"psychedelic pop",
"rock"
]
}}
end
test "handles special characters in titles" do
entry_contents = File.read!(@guardians_entry_path)
assert Parser.from_file_contents(entry_contents) ==
{:ok,
%Entry{
genres: ["classic rock", "pop", "pop rock", "rock"],
cover_url:
"https://coverartarchive.org/release-group/950092d6-45f6-4269-87da-99a9ff2fcc52/front",
musicbrainz_id: "950092d6-45f6-4269-87da-99a9ff2fcc52",
title: "Guardians of the Galaxy: Awesome Mix, Vol. 1",
type: :album,
release: "2014"
}}
end
end