about summary refs log tree commit diff stats
path: root/modules/home/conf/beets
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--modules/home/conf/beets/default.nix205
-rw-r--r--modules/home/conf/beets/plugins.nix64
-rw-r--r--modules/home/conf/beets/plugins/badfiles/default.nix13
-rw-r--r--modules/home/conf/beets/plugins/default.nix15
-rw-r--r--modules/home/conf/beets/plugins/duplicates/default.nix5
-rw-r--r--modules/home/conf/beets/plugins/fuzzy/default.nix6
-rw-r--r--modules/home/conf/beets/plugins/ihate/default.nix8
-rw-r--r--modules/home/conf/beets/plugins/inline/default.nix42
-rw-r--r--modules/home/conf/beets/plugins/lastgenre/default.nix7
-rw-r--r--modules/home/conf/beets/plugins/lyrics/default.nix6
-rw-r--r--modules/home/conf/beets/plugins/mbsubmit/default.nix9
-rw-r--r--modules/home/conf/beets/plugins/play/default.nix14
-rw-r--r--modules/home/conf/beets/plugins/replaygain/default.nix24
-rw-r--r--modules/home/conf/beets/plugins/smartplaylist/default.nix33
14 files changed, 256 insertions, 195 deletions
diff --git a/modules/home/conf/beets/default.nix b/modules/home/conf/beets/default.nix
index aa5cc671..58008bd6 100644
--- a/modules/home/conf/beets/default.nix
+++ b/modules/home/conf/beets/default.nix
@@ -3,13 +3,17 @@
   lib,
   config,
   ...
-}: {
+}: let
+  plugins = import ./plugins.nix;
+in {
+  imports = [
+    ./plugins
+  ];
+
   programs.beets = {
     enable = true;
     package = pkgs.beets.override {
-      pluginOverrides = {
-        beatport.enable = true;
-      };
+      pluginOverrides = {};
     };
 
     settings = {
@@ -52,202 +56,13 @@
         "albumtype:soundtrack" = j ["Soundtracks" "$genre" "$first_artist" "$album" "$track $title"];
       };
 
-      # Plugin config
-      lastgenre = {
-        prefer_specific = false;
-        # Lookup the track, not the album
-        source = "track";
-      };
-      fetchart = {};
-      lyrics = {
-        # Always fetch lyrics (and update them, if some were found)
-        force = true;
-      };
-      hook = {
-        hooks = [
-          {
-            # Also generate the replaygain for the album variant (so selecting between
-            # track and album becomes possible)
-            event = "import";
-            command = "echo Remember to run 'beet replaygain --album' to generate the album replaygain values for the imported songs!";
-          }
-        ];
-      };
-      replaygain = {
-        auto = true;
-        backend = "ffmpeg";
+      inherit plugins;
 
-        r128_targetlevel = 89;
-
-        # Re-calculate the replay gain value even for files, that already have one set.
-        overwrite = true;
-      };
-      duplicates = {
-        keys = ["acoustid_fingerprint"];
-      };
-      fuzzy = {
-        # The prefix denoting that a search should be run in fuzzy mode
-        prefix = ".";
-      };
-      ihate = {
-        warn = [
-          "title:commentary"
-          "albumtype:live"
-        ];
-      };
-      play = {
-        command = "${lib.getExe pkgs.mpc-cli} $args add";
-        relative_to = config.services.mpd.musicDirectory;
-
-        # Run the command with the returned paths as arguments
-        raw = true;
-      };
-      smartplaylist = {
-        relative_to = config.services.mpd.musicDirectory;
-        playlist_dir = config.services.mpd.playlistDirectory;
-        forward_slash = false;
-
-        # Show the real m3u file paths, when running `--pretend`
-        pretend_paths = true;
-
-        playlists = [
-          {
-            name = "artists-$first_artist.m3u";
-            query = "";
-          }
-          {
-            name = "ratings-good.m3u";
-            query = "rating:0.7..1.0";
-          }
-          {
-            name = "ratings-mediocre.m3u";
-            query = "rating:0.4..0.7";
-          }
-          {
-            name = "ratings-bad.m3u";
-            query = "rating:0.0..0.4";
-          }
-          {
-            name = "not_played.m3u";
-            query = "-play_count: artist:";
-          }
-        ];
-      };
-      item_fields = {
-        # Taken from https://github.com/trapd00r/configs/blob/4f3dada5700846cca6c2869e6fa6b3c795b87b67/beets/config.yaml
-        first_artist =
-          /*
-          python
-          */
-          ''
-            # import an album to another artists directory, like:
-            # Tom Jones │1999│ Burning Down the House [Single, CD, FLAC]
-            # to The Cardigans/+singles/Tom Jones & the Cardigans │1999│ Burning Down the House [Single, CD, FLAC]
-            # https://github.com/beetbox/beets/discussions/4012#discussioncomment-1021414
-            # beet import --set myartist='The Cardigans'
-            # we must first check to see if myartist is defined, that is, given on
-            # import time, or we raise an NameError exception.
-            try:
-              myartist
-            except NameError:
-              import re
-              return re.split(',|\\s+(feat(.?|uring)|&|(Vs|Ft).)', albumartist, 1, flags=re.IGNORECASE)[0]
-            else:
-              return myartist
-          '';
-
-        first_artist_singleton =
-          /*
-          python
-          */
-          ''
-            try:
-              myartist
-            except NameError:
-              import re
-              return re.split(',|\\s+(feat(.?|uring)|&|(Vs|Ft).)', artist, 1, flags=re.IGNORECASE)[0]
-            else:
-              return myartist
-          '';
-      };
+      # Plugin config
       # scrub = {
       #   auto = true;
       # };
 
-      mbsubmit = {
-        picard_path = lib.getExe pkgs.picard;
-      };
-
-      badfiles = {
-        check_on_import = true;
-        commands = {
-          flac = "${lib.getExe pkgs.flac} --test --warnings-as-errors --silent";
-          mp3 = "${lib.getExe pkgs.mp3val}";
-        };
-      };
-
-      plugins = [
-        # Remove all previous tags before import (this is useful to ensure, that
-        # the metadata in the libary.db is synced with the tags on disk)
-        # # FIXME: I think, that this also removes the deezer id, which is not ideal
-        # <2024-08-07>
-        # "scrub"
-
-        # Help submitting stuff to music brainz
-        "mbsubmit"
-
-        # Calculate replay gain
-        "replaygain"
-
-        # Check for bad files
-        "badfiles"
-
-        # Alows to use inline python for parsing tags
-        "inline"
-
-        # Support player integration
-        "play"
-
-        # Show tags on files/queries
-        "info"
-
-        # Create playlist from `play_count`/`skip_count` (gathered by the `mpdstats`
-        # plugin)
-        # Note that this should come _before_ the `mpdupdate` plugin, to ensure that
-        # `mpdupgate` can propagate changed playlist to `mpd`.
-        "smartplaylist"
-
-        # Warn, when importing a matching item
-        "ihate"
-
-        # Allow fuzzy searching
-        "fuzzy"
-
-        # Filter out duplicates
-        "duplicates"
-
-        # Generate fingerprints
-        "chroma"
-
-        # Download album art
-        "fetchart"
-
-        # Fetches tags from `last.fm` and adds them as genres to imported music
-        "lastgenre"
-
-        # Run commands on events
-        "hook"
-
-        # Fetch lyrics
-        "lyrics"
-
-        # Allow beets to understand deezer id's
-        # "deezer"
-
-        "mpdstats" # Transfer MPD stats to beets
-        "mpdupdate" # Update MPD database on import
-      ];
-
       musicbrainz = {
         # Search for deezer id's and use them in the autotagger
         # external_ids = {
diff --git a/modules/home/conf/beets/plugins.nix b/modules/home/conf/beets/plugins.nix
new file mode 100644
index 00000000..7ab6819a
--- /dev/null
+++ b/modules/home/conf/beets/plugins.nix
@@ -0,0 +1,64 @@
+{...}:
+# NOTE: This list is here and not split over the various plugin dirs, as we need a way to
+# specify the order plugins are loaded in. <2024-08-11>
+[
+  # Remove all previous tags before import (this is useful to ensure, that
+  # the metadata in the libary.db is synced with the tags on disk)
+  # # FIXME: I think, that this also removes the deezer id, which is not ideal
+  # <2024-08-07>
+  # "scrub"
+
+  # Help submitting stuff to music brainz
+  "mbsubmit"
+
+  # Calculate replay gain
+  "replaygain"
+
+  # Check for bad files
+  "badfiles"
+
+  # Alows to use inline python for parsing tags
+  "inline"
+
+  # Support player integration
+  "play"
+
+  # Show tags on files/queries
+  "info"
+
+  # Create playlist from `play_count`/`skip_count` (gathered by the `mpdstats`
+  # plugin)
+  # Note that this should come _before_ the `mpdupdate` plugin, to ensure that
+  # `mpdupgate` can propagate changed playlist to `mpd`.
+  "smartplaylist"
+
+  # Warn, when importing a matching item
+  "ihate"
+
+  # Allow fuzzy searching
+  "fuzzy"
+
+  # Filter out duplicates
+  "duplicates"
+
+  # Generate fingerprints
+  "chroma"
+
+  # Download album art
+  "fetchart"
+
+  # Fetches tags from `last.fm` and adds them as genres to imported music
+  "lastgenre"
+
+  # Run commands on events
+  "hook"
+
+  # Fetch lyrics
+  "lyrics"
+
+  # Allow beets to understand deezer id's
+  # "deezer"
+
+  "mpdstats" # Transfer MPD stats to beets
+  "mpdupdate" # Update MPD database on import
+]
diff --git a/modules/home/conf/beets/plugins/badfiles/default.nix b/modules/home/conf/beets/plugins/badfiles/default.nix
new file mode 100644
index 00000000..bc61097b
--- /dev/null
+++ b/modules/home/conf/beets/plugins/badfiles/default.nix
@@ -0,0 +1,13 @@
+{
+  lib,
+  pkgs,
+  ...
+}: {
+  programs.beets.settings.badfiles = {
+    check_on_import = true;
+    commands = {
+      flac = "${lib.getExe pkgs.flac} --test --warnings-as-errors --silent";
+      mp3 = "${lib.getExe pkgs.mp3val}";
+    };
+  };
+}
diff --git a/modules/home/conf/beets/plugins/default.nix b/modules/home/conf/beets/plugins/default.nix
new file mode 100644
index 00000000..9fc04a8d
--- /dev/null
+++ b/modules/home/conf/beets/plugins/default.nix
@@ -0,0 +1,15 @@
+{...}: {
+  imports = [
+    ./badfiles
+    ./duplicates
+    ./fuzzy
+    ./ihate
+    ./inline
+    ./lastgenre
+    ./lyrics
+    ./mbsubmit
+    ./play
+    ./replaygain
+    ./smartplaylist
+  ];
+}
diff --git a/modules/home/conf/beets/plugins/duplicates/default.nix b/modules/home/conf/beets/plugins/duplicates/default.nix
new file mode 100644
index 00000000..c8a6c108
--- /dev/null
+++ b/modules/home/conf/beets/plugins/duplicates/default.nix
@@ -0,0 +1,5 @@
+{...}: {
+  programs.beets.settings.duplicates = {
+    keys = ["acoustid_fingerprint"];
+  };
+}
diff --git a/modules/home/conf/beets/plugins/fuzzy/default.nix b/modules/home/conf/beets/plugins/fuzzy/default.nix
new file mode 100644
index 00000000..b86b3a20
--- /dev/null
+++ b/modules/home/conf/beets/plugins/fuzzy/default.nix
@@ -0,0 +1,6 @@
+{...}: {
+  programs.beets.settings.fuzzy = {
+    # The prefix denoting that a search should be run in fuzzy mode
+    prefix = ".";
+  };
+}
diff --git a/modules/home/conf/beets/plugins/ihate/default.nix b/modules/home/conf/beets/plugins/ihate/default.nix
new file mode 100644
index 00000000..145f5f8b
--- /dev/null
+++ b/modules/home/conf/beets/plugins/ihate/default.nix
@@ -0,0 +1,8 @@
+{...}: {
+  programs.beets.settings.ihate = {
+    warn = [
+      "title:commentary"
+      "albumtype:live"
+    ];
+  };
+}
diff --git a/modules/home/conf/beets/plugins/inline/default.nix b/modules/home/conf/beets/plugins/inline/default.nix
new file mode 100644
index 00000000..0dda8cfc
--- /dev/null
+++ b/modules/home/conf/beets/plugins/inline/default.nix
@@ -0,0 +1,42 @@
+{...}: {
+  programs.beets.settings = {
+    item_fields = {
+      # Taken from https://github.com/trapd00r/configs/blob/4f3dada5700846cca6c2869e6fa6b3c795b87b67/beets/config.yaml
+      first_artist =
+        /*
+        python
+        */
+        ''
+          # import an album to another artists directory, like:
+          # Tom Jones │1999│ Burning Down the House [Single, CD, FLAC]
+          # to The Cardigans/+singles/Tom Jones & the Cardigans │1999│ Burning Down the House [Single, CD, FLAC]
+          # https://github.com/beetbox/beets/discussions/4012#discussioncomment-1021414
+          # beet import --set myartist='The Cardigans'
+          # we must first check to see if myartist is defined, that is, given on
+          # import time, or we raise an NameError exception.
+          try:
+            myartist
+          except NameError:
+            import re
+            return re.split(',|\\s+(feat(.?|uring)|&|(Vs|Ft).)', albumartist, 1, flags=re.IGNORECASE)[0]
+          else:
+            return myartist
+        '';
+
+      first_artist_singleton =
+        /*
+        python
+        */
+        ''
+          try:
+            myartist
+          except NameError:
+            import re
+            return re.split(',|\\s+(feat(.?|uring)|&|(Vs|Ft).)', artist, 1, flags=re.IGNORECASE)[0]
+          else:
+            return myartist
+        '';
+    };
+    album_fields = {};
+  };
+}
diff --git a/modules/home/conf/beets/plugins/lastgenre/default.nix b/modules/home/conf/beets/plugins/lastgenre/default.nix
new file mode 100644
index 00000000..d10ca49f
--- /dev/null
+++ b/modules/home/conf/beets/plugins/lastgenre/default.nix
@@ -0,0 +1,7 @@
+{...}: {
+  programs.beets.settings.lastgenre = {
+    prefer_specific = false;
+    # Lookup the track, not the album
+    source = "track";
+  };
+}
diff --git a/modules/home/conf/beets/plugins/lyrics/default.nix b/modules/home/conf/beets/plugins/lyrics/default.nix
new file mode 100644
index 00000000..80544aea
--- /dev/null
+++ b/modules/home/conf/beets/plugins/lyrics/default.nix
@@ -0,0 +1,6 @@
+{...}: {
+  programs.beets.settings.lyrics = {
+    # Always fetch lyrics (and update them, if some were found)
+    force = true;
+  };
+}
diff --git a/modules/home/conf/beets/plugins/mbsubmit/default.nix b/modules/home/conf/beets/plugins/mbsubmit/default.nix
new file mode 100644
index 00000000..b70f1c63
--- /dev/null
+++ b/modules/home/conf/beets/plugins/mbsubmit/default.nix
@@ -0,0 +1,9 @@
+{
+  lib,
+  pkgs,
+  ...
+}: {
+  programs.beets.settings.mbsubmit = {
+    picard_path = lib.getExe pkgs.picard;
+  };
+}
diff --git a/modules/home/conf/beets/plugins/play/default.nix b/modules/home/conf/beets/plugins/play/default.nix
new file mode 100644
index 00000000..f5bc3c9b
--- /dev/null
+++ b/modules/home/conf/beets/plugins/play/default.nix
@@ -0,0 +1,14 @@
+{
+  lib,
+  pkgs,
+  config,
+  ...
+}: {
+  programs.beets.settings.play = {
+    command = "${lib.getExe pkgs.mpc-cli} $args add";
+    relative_to = config.services.mpd.musicDirectory;
+
+    # Run the command with the returned paths as arguments
+    raw = true;
+  };
+}
diff --git a/modules/home/conf/beets/plugins/replaygain/default.nix b/modules/home/conf/beets/plugins/replaygain/default.nix
new file mode 100644
index 00000000..611f3799
--- /dev/null
+++ b/modules/home/conf/beets/plugins/replaygain/default.nix
@@ -0,0 +1,24 @@
+{...}: {
+  programs.beets.settings = {
+    replaygain = {
+      auto = true;
+      backend = "ffmpeg";
+
+      r128_targetlevel = 89;
+
+      # Re-calculate the replay gain value even for files, that already have one set.
+      overwrite = true;
+    };
+
+    hook = {
+      hooks = [
+        {
+          # Also generate the replaygain for the album variant (so selecting between
+          # track and album becomes possible)
+          event = "import";
+          command = "echo Remember to run 'beet replaygain --album' to generate the album replaygain values for the imported songs!";
+        }
+      ];
+    };
+  };
+}
diff --git a/modules/home/conf/beets/plugins/smartplaylist/default.nix b/modules/home/conf/beets/plugins/smartplaylist/default.nix
new file mode 100644
index 00000000..b55c487c
--- /dev/null
+++ b/modules/home/conf/beets/plugins/smartplaylist/default.nix
@@ -0,0 +1,33 @@
+{config, ...}: {
+  programs.beets.settings.smartplaylist = {
+    relative_to = config.services.mpd.musicDirectory;
+    playlist_dir = config.services.mpd.playlistDirectory;
+    forward_slash = false;
+
+    # Show the real m3u file paths, when running `--pretend`
+    pretend_paths = true;
+
+    playlists = [
+      {
+        name = "artists-$first_artist.m3u";
+        query = "";
+      }
+      {
+        name = "ratings-good.m3u";
+        query = "rating:0.7..1.0";
+      }
+      {
+        name = "ratings-mediocre.m3u";
+        query = "rating:0.4..0.7";
+      }
+      {
+        name = "ratings-bad.m3u";
+        query = "rating:0.0..0.4";
+      }
+      {
+        name = "not_played.m3u";
+        query = "-play_count: artist:";
+      }
+    ];
+  };
+}