about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2022-06-14 17:04:15 -0700
committerFranck Cuny <franck@fcuny.net>2022-06-14 17:19:36 -0700
commit1aff3aabc25fad85e9a91cc0182b508c51fd0ebc (patch)
treec99dd067200b26c88b2a344cf6d1d0c2fe9b28a6
parentdelete reference to namespaces (diff)
downloadworld-1aff3aabc25fad85e9a91cc0182b508c51fd0ebc.tar.gz
feat(home/beet): import albums on the NAS
Two new scripts are created. The first one is to copy an album (usually
in zip format) from my desktop to the NAS. Once the file is copied, the
script calls the second script, which extract the album and call beet to
get it imported in my music collection.

Change-Id: I93509e0cc213ba884a9282e1f474a0f9298a1fb7
Reviewed-on: https://cl.fcuny.net/c/world/+/417
Tested-by: CI
Reviewed-by: Franck Cuny <franck@fcuny.net>
Diffstat (limited to '')
-rw-r--r--home/beets/default.nix74
-rw-r--r--home/scripts/bc-to-nas.nix14
-rw-r--r--home/scripts/default.nix2
3 files changed, 60 insertions, 30 deletions
diff --git a/home/beets/default.nix b/home/beets/default.nix
index c88fd85..0d7a3b9 100644
--- a/home/beets/default.nix
+++ b/home/beets/default.nix
@@ -1,5 +1,17 @@
 { config, lib, pkgs, ... }:
-let cfg = config.my.home.beets;
+let
+  cfg = config.my.home.beets;
+  bc-to-beet = pkgs.writeShellScriptBin "bc-to-beet" ''
+    ALBUM_PATH="''${1}"
+    ALBUM_NAME=$(basename "''${ALBUM_PATH}")
+
+    mkdir -p ~/import
+    rm -rf ~/import/tmp-bc
+    unzip -d ~/import/tmp-bc ~/import/album.zip
+    beet import ~/import/tmp-bc
+    rm -rf ~/import/tmp-bc
+    rm -rf ~/import/album.zip
+  '';
 in
 {
   options.my.home.beets = with lib; {
@@ -11,36 +23,40 @@ in
     };
   };
 
-  config.programs.beets = lib.mkIf cfg.enable {
-    enable = true;
-    settings = {
-      directory = cfg.musicDirectory;
-      plugins =
-        "fromfilename discogs duplicates fetchart embedart badfiles lastgenre scrub";
-      paths = {
-        default = "$albumartist/$album%aunique{}/$track $title";
-        singleton = "Singles/$artist/$title";
-        comp = "Compilations/$album%aunique{}/$track - $title";
-        "albumtype:soundtrack" = "Soundtracks/$album ($year)/$track $title";
-      };
-      import = {
-        copy = true;
-        move = true;
-      };
-      va_name = "Various Artists";
-      embedart = { ifempty = true; };
+  config = lib.mkIf cfg.enable {
+    home.packages = with pkgs; [ bc-to-beet ];
 
-      lastgenre = {
-        auto = false;
-        canonical = true;
-        fallback = "unknown";
-        force = true;
-        prefer_specific = true;
-      };
+    programs.beets = {
+      enable = true;
+      settings = {
+        directory = cfg.musicDirectory;
+        plugins =
+          "fromfilename discogs duplicates fetchart embedart badfiles lastgenre scrub";
+        paths = {
+          default = "$albumartist/$album%aunique{}/$track $title";
+          singleton = "Singles/$artist/$title";
+          comp = "Compilations/$album%aunique{}/$track - $title";
+          "albumtype:soundtrack" = "Soundtracks/$album ($year)/$track $title";
+        };
+        import = {
+          copy = true;
+          move = true;
+        };
+        va_name = "Various Artists";
+        embedart = { ifempty = true; };
+
+        lastgenre = {
+          auto = false;
+          canonical = true;
+          fallback = "unknown";
+          force = true;
+          prefer_specific = true;
+        };
 
-      fetchart = {
-        cautious = true;
-        sources = "filesystem coverart itunes amazon lastfm wikipedia";
+        fetchart = {
+          cautious = true;
+          sources = "filesystem coverart itunes amazon lastfm wikipedia";
+        };
       };
     };
   };
diff --git a/home/scripts/bc-to-nas.nix b/home/scripts/bc-to-nas.nix
new file mode 100644
index 0000000..efa95d2
--- /dev/null
+++ b/home/scripts/bc-to-nas.nix
@@ -0,0 +1,14 @@
+{ lib, pkgs, ... }:
+let
+  bc-to-nas = pkgs.writeShellScriptBin "bc-to-nas" ''
+    set -euo pipefail
+
+    ALBUM_PATH="''${1}"
+    ALBUM_NAME=$(basename "''${ALBUM_PATH}")
+    NAS=$(${pkgs.tailscale}/bin/tailscale status --json | ${pkgs.jq}/bin/jq -r '.Peer | map(select(.HostName == "tahoe"))[0].TailscaleIPs[0]')
+
+    scp "''${ALBUM_PATH}" "''${NAS}:~/import/album.zip"
+    ssh "''${NAS}" bc-to-beet ~/import/album.zip
+  '';
+in
+{ config = { home.packages = with pkgs; [ bc-to-nas ]; }; }
diff --git a/home/scripts/default.nix b/home/scripts/default.nix
index bc19e44..741bade 100644
--- a/home/scripts/default.nix
+++ b/home/scripts/default.nix
@@ -1,5 +1,5 @@
 { ... }:
 
 {
-  imports = [ ./perf-flamegraph.nix ];
+  imports = [ ./perf-flamegraph.nix ./bc-to-nas.nix ];
 }